You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by jm...@apache.org on 2007/02/21 08:28:59 UTC

svn commit: r509935 - in /incubator/xap/trunk/codebase/src/xap/data: ./ bridge/ controller/ datasource/ formatter/

Author: jmargaris
Date: Wed Feb 21 00:28:58 2007
New Revision: 509935

URL: http://svn.apache.org/viewvc?view=rev&rev=509935
Log:
better documentation and some simplification,
renamed JSFormatterImpl to something better

Added:
    incubator/xap/trunk/codebase/src/xap/data/formatter/AbstractFormatter.js
      - copied, changed from r506849, incubator/xap/trunk/codebase/src/xap/data/formatter/JsFormatterImpl.js
Removed:
    incubator/xap/trunk/codebase/src/xap/data/datasource/DataSetFactory.js
    incubator/xap/trunk/codebase/src/xap/data/formatter/JsFormatterImpl.js
Modified:
    incubator/xap/trunk/codebase/src/xap/data/DataFramework.js
    incubator/xap/trunk/codebase/src/xap/data/DataNamespaceHandler.js
    incubator/xap/trunk/codebase/src/xap/data/bridge/BindingBridge.js
    incubator/xap/trunk/codebase/src/xap/data/bridge/DataAttributeConverter.js
    incubator/xap/trunk/codebase/src/xap/data/bridge/DecimalFormatterBridge.js
    incubator/xap/trunk/codebase/src/xap/data/bridge/FormatterBridge.js
    incubator/xap/trunk/codebase/src/xap/data/bridge/FormatterChainBridge.js
    incubator/xap/trunk/codebase/src/xap/data/bridge/MessageFormatterBridge.js
    incubator/xap/trunk/codebase/src/xap/data/controller/Iterator.js
    incubator/xap/trunk/codebase/src/xap/data/datasource/AbstractDataSet.js
    incubator/xap/trunk/codebase/src/xap/data/datasource/AbstractDataSource.js
    incubator/xap/trunk/codebase/src/xap/data/datasource/ArrayDataSet.js
    incubator/xap/trunk/codebase/src/xap/data/datasource/QueryRecord.js
    incubator/xap/trunk/codebase/src/xap/data/formatter/DecimalFormatter.js
    incubator/xap/trunk/codebase/src/xap/data/formatter/FormatterChain.js
    incubator/xap/trunk/codebase/src/xap/data/formatter/MessageFormatter.js

Modified: incubator/xap/trunk/codebase/src/xap/data/DataFramework.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/DataFramework.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/DataFramework.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/DataFramework.js Wed Feb 21 00:28:58 2007
@@ -41,11 +41,15 @@
  *
 **/
 xap.data.DataFramework = function(sess) {
+	/** @private */
 	this._session = sess;
+	/** @private */
 	this._dataSourceContainer =  new xap.session.Container(sess);
+	/** @private */
 	this._bindingContainer = new xap.session.Container(sess);
-								
+	/** @private */							
 	this._formatterContainer = new xap.session.Container(sess);
+	/** @private */
 	this._iteratorContainer = new xap.data.controller.IteratorContainerImpl(sess);
 		
 	//add the dataSourceContainer to the container of containers

Modified: incubator/xap/trunk/codebase/src/xap/data/DataNamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/DataNamespaceHandler.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/DataNamespaceHandler.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/DataNamespaceHandler.js Wed Feb 21 00:28:58 2007
@@ -11,7 +11,6 @@
  *	  http://www.apache.org/licenses/LICENSE-2.0
  *
  *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
@@ -23,26 +22,35 @@
 Xap.require("xap.taghandling.PluginDocumentHandler");
 Xap.require("xap.data.controller.BindingResolver") ;	
 
-/**
- * @class
- * The namespace handler for the http://openxal.apache.org/data namespace. This handler
- * will look at a tag in the namespace and determing which document it belongs in (if any),
- * then add that tag to the document root. It also creates the requisite 
- * documents and makes them plug-in aware.
+/** 
+ * Creates a new DataNamespaceHandler. DataNamespaceHandler is typically created
+ * automatically during the app initialization process.
  * 
- * @author JMargaris
- *
+ * @class DataNamespaceHandler handles all tags in the
+ * <code>http://openxal.org/core/data</code> namespace. This is the root plugin
+ * class for all data binding functionality and must be included in an application
+ * to make use of data binding.
+ * 
+ * @constructor
  */
+xap.data.DataNamespaceHandler = function() {};
+
+
+/** @private */
+xap.data.DataNamespaceHandler.DOCUMENT_NAMES = [
+							"bindings", 
+							"dataSources",
+							"formatters" ];
+
+
+
 /**
- * Creates the handler which in turn sets up the documents
- * @constructor
- * @public
- * @param sess{ClientSession}
- * @return {DataNamespaceHandler}
- **/
-xap.data.DataNamespaceHandler = function (sess) {
-	this._session = sess;
+ * Called when the namespace handler is loaded by the application.
+ */
+xap.data.DataNamespaceHandler.prototype.pluginLoaded = function(session) {
+	this._session = session;
 	
+	//STEP 1: Register all the documents with plugin handlers
 	var parser = xap.xml.ParserFactory.getParser();
 	for (var i = 0; i < xap.data.DataNamespaceHandler.DOCUMENT_NAMES.length; i++) {
 		var currentDocumentName = xap.data.DataNamespaceHandler.DOCUMENT_NAMES[i];
@@ -55,11 +63,11 @@
 				
 			//IMPORTANT DOC what if the doc is already there? that would be bad
 			//we need to document that they not use these names
-			this._session.getDocumentContainer().put(currentDocumentName, dataDocument);
+			session.getDocumentContainer().put(currentDocumentName, dataDocument);
 	
 			//for each document, create  namespace
 			//handler for that document
-			var p = new xap.taghandling.PluginDocumentHandler(sess, dataDocument, xap.data.DataNamespaceHandler.DOCUMENT_NAMES[i]);
+			var p = new xap.taghandling.PluginDocumentHandler(session, dataDocument, xap.data.DataNamespaceHandler.DOCUMENT_NAMES[i]);
 
 		}
 		catch (ex) {
@@ -67,48 +75,28 @@
 			//if we did this right this should never ever happen
 			//it can only happen if DOCUMENTS[i] was screwed up somehow
 			//ex.printStackTrace();
-			sess.handleException(ex);
+			session.handleException(ex);
 		}
 	}
-};
-
-
 	
-//the names of the documents to create and make plug-in aware
-/*private static final String[]*/
-xap.data.DataNamespaceHandler.DOCUMENT_NAMES = [
-							"bindings", 
-							"dataSources",
-							"formatters" ];
-
-
-
-xap.data.DataNamespaceHandler.prototype.pluginLoaded = function (session) {
+	//STEP 2: add ourselves as a handler
 	session.getNamespaceHandlerManager().addHandler("http://openxal.org/core/data", this);
-	this._session = session;
 	
-	// Originally in DataPlugin
-	//set the attribute resolver on uiContentHandler() to
-	//out resolver that can recognize bindings
-	/*BindingResolver*/
-	var resolver = new xap.data.controller.BindingResolver(this._session);
-		
-		//also set it on the framework service
-	var frameworkService = xap.data.DataFramework.getDataService(this._session) ;
+	
+	//STEP 3: Create the resolver
+	var resolver = new xap.data.controller.BindingResolver(session);
+	var frameworkService = xap.data.DataFramework.getDataService(session) ;
 	frameworkService.setBindingResolver( resolver ) ;
 	
 };
+
+
 /**
- * @public
- * @return {void}
- * @param element{xap.xml.dom.XapElement}
- * @param provider{DocumentRegistry}
- **/
+ * Called when a tag in our namespace is encountered at the first level
+ * of an XML document.
+ */
 xap.data.DataNamespaceHandler.prototype.receiveDispatch = function (element) {
-	/*DocumentHandler*/
-//	var d = provider; //[Was the second argument.]
-	/*ClientSession*/
-	var clientSession = this._session; //d.getClientSession();
+	var clientSession = this._session; 
 		
 	//when we get a tag like "sqlDataSource" figure out which document
 	//it belonged to it needs to end up in. Technically you could have
@@ -116,8 +104,6 @@
 	//and then we would be out of luck
 	// TODO:  care about that later; for now
 	for (var i = 0; i < xap.data.DataNamespaceHandler.DOCUMENT_NAMES.length; i++) {
-		// "bindings", "formatters", "dataSources"
-		/*String*/
 		var currentDocumentName = xap.data.DataNamespaceHandler.DOCUMENT_NAMES[i];
 		/*Element*/
 		var definition = clientSession.getPluginRegistry().getPluginDefinition(element.getLocalName(), element.getNamespaceUri(), currentDocumentName);
@@ -138,13 +124,13 @@
 			}
 			return;
 		}
-	} // end iteration over document names (["dataSources", "bindings", "formatters"] to date)
+	} // end iteration over document names
 	
 
 	//if we got here it means we didn't find any proper definition which is
 	//an error
 	//TODO:  fix exception handling
-	var ex =  new xap.util.Exception("UNHANDLED_TAG_IN_NAMESPACE" + ":  " + element.getNamespaceUri() + ", " + element.getLocalName()) ;	
+	var ex =  new xap.util.Exception("Undhandled data tag in namespace:  " + element.getNamespaceUri() + ", " + element.getLocalName()) ;	
 	clientSession.handleException(ex);
 };
 

Modified: incubator/xap/trunk/codebase/src/xap/data/bridge/BindingBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/bridge/BindingBridge.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/bridge/BindingBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/bridge/BindingBridge.js Wed Feb 21 00:28:58 2007
@@ -22,7 +22,7 @@
 Xap.require("xap.data.DataFramework");
 Xap.require("xap.data.controller.Binding");
 Xap.require("xap.data.controller.BindingType");
-Xap.require("xap.data.formatter.JsFormatterImpl");
+Xap.require("xap.data.formatter.AbstractFormatter");
 Xap.require("xap.xml.dom.XapElement");
 Xap.require("xap.data.bridge.XmlDataTokens") ;
 Xap.require("xap.data.bridge.DataAttributeConverter") ;

Modified: incubator/xap/trunk/codebase/src/xap/data/bridge/DataAttributeConverter.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/bridge/DataAttributeConverter.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/bridge/DataAttributeConverter.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/bridge/DataAttributeConverter.js Wed Feb 21 00:28:58 2007
@@ -22,7 +22,7 @@
 Xap.require("xap.taghandling.AttributeConverter");
 Xap.require("xap.data.controller.BindingType");
 Xap.require("xap.data.bridge.XmlDataTokens");
-Xap.require("xap.data.formatter.JsFormatterImpl") 
+Xap.require("xap.data.formatter.AbstractFormatter") 
 
 
 xap.data.bridge.DataAttributeConverter = function(){

Modified: incubator/xap/trunk/codebase/src/xap/data/bridge/DecimalFormatterBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/bridge/DecimalFormatterBridge.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/bridge/DecimalFormatterBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/bridge/DecimalFormatterBridge.js Wed Feb 21 00:28:58 2007
@@ -17,71 +17,56 @@
  *
  */
 Xap.provide("xap.data.bridge.DecimalFormatterBridge");
+
 Xap.require("xap.data.bridge.FormatterBridge");
-Xap.require("xap.xml.InvalidXmlException"); 
+Xap.require('xap.util.Exception');
 Xap.require("xap.data.formatter.DecimalFormatter");
-Xap.require("xap.data.formatter.JsFormatterImpl");
 
 
 
-/**
- * DecimalFormatterBridge class handles the configuration element for a
- * DecimalFormatter instance.
- *
- * @author ikaplansky
+/** 
+ * Creates a new DecimalFormatterBridge.
+ * 
+ * @class DecimalFormatterBridge is the bridge class to a 
+ * <code>xap.data.formatter.DecimalFormatter</code>
+ * 
+ * @see xap.data.formatter.DecimalFormatter
+ * 
+ * @constructor
+ * 
  */
 xap.data.bridge.DecimalFormatterBridge = function () {
 	xap.data.bridge.FormatterBridge.call(this);
 };
+
+//for doc
+xap.data.bridge.DecimalFormatterBridge.prototype = new xap.data.bridge.FormatterBridge();
+
 Xap.setupClassAsSubclassOf("xap.data.bridge.DecimalFormatterBridge", "xap.data.bridge.FormatterBridge");
-	
-	//-----------------------------------------------------------------------
-	// Protected Methods.
-	//-----------------------------------------------------------------------
+
+
 /**
- * @see FormatterBridge#createFormatter()
- *
- * @protected
- * @return {Formatter}
-**/
+ * Overridden to create a DecimalFormatter rather than a generic formatter.
+ * 
+ * @return {xap.data.formatter.DecimalFormatter} The new DecimalFormatter.
+ */
 xap.data.bridge.DecimalFormatterBridge.prototype.createFormatter = function () {
-	/*String*/
-	var className = this.getElement().getAttribute(xap.data.bridge.XmlDataTokens.CLASS);
-
-	/*DecimalFormatter*/
-	var formatter = null;
-	try {
-		formatter = new xap.data.formatter.DecimalFormatter();
-	}
-	catch (e) { 
-		this.reportInvalidXmlException(xap.data.bridge.XmlDataTokens.CLASS, "decimal formatter", this.getElement(), e);
-	}
-	return formatter;
+	//TODO try to read class/src here?
+	return new xap.data.formatter.DecimalFormatter();
 };
+
 /**
- * @see FormatterBridge#initializeFormatter()
- *
- * @protected
- * @return {void}
- * @throws InitializationException
-**/
+ * Overridden to do more parsing of the initial XML element
+ * to set up the DecimalFormatter.
+ */
 xap.data.bridge.DecimalFormatterBridge.prototype.initializeFormatter = function () {
 	xap.data.bridge.FormatterBridge.prototype.initializeFormatter.call(this);
-	try {
-		/*Locale*/
-		var locale = this.getLocale();
-		/*String*/
-		var format = this.getFormatPattern();
-		// TODO: Implement using the actual formatting object
-		// in the bridge class, not here---but implement it:
-		/*DecimalFormat*/
-		//var theDecimalFormat = new xap.data.formatter.DecimalFormatter(format);
-		this.getFormatter().setFormat(format);
-	}
-	catch (e) { // InvalidXmlException
-//			throw new InitializationException(
-//					InitializationException.INVALID_XML_MSGID,
-//					DecimalFormatterBridge.class.getName(), e );
+	
+	var formatPattern = this.getFormatPattern();
+	if (!formatPattern){
+		throw new xap.util.Exception("Error creating  decimal formatter, expected 'format' attribute: " +
+			this.getElement().toXml());
 	}
+	this.getFormatter().setFormat(formatPattern);
 };
 

Modified: incubator/xap/trunk/codebase/src/xap/data/bridge/FormatterBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/bridge/FormatterBridge.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/bridge/FormatterBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/bridge/FormatterBridge.js Wed Feb 21 00:28:58 2007
@@ -21,56 +21,53 @@
 Xap.require("xap.data.bridge.DataFrameworkBridge");
 Xap.require("xap.util.Exception");
 Xap.require("xap.xml.InvalidXmlException");
-Xap.require("xap.data.formatter.JsFormatterImpl");
+Xap.require("xap.data.formatter.AbstractFormatter");
 Xap.require("xap.data.bridge.XmlDataTokens");
 
-
-/**
+
+/** 
+ * Creates a new FormatterBridge. FormatterBridge classes are typically instantiated
+ * during the XML parsing process.
+ * 
+ * @class FormatterBridge is the base class for all formatter bridges. 
  * FormatterBridge is a generic formatter bridge which uses
  * the <code>class</code> attribute to look up an implementation of 
- * a formatter, creates
- * and initializes and registers an instance of it in the formatter 
- * container with the specified <code>id</code> attribute.
- *
- * @author jmargaris
+ * a formatter, instantiates it and puts it into the formatter container.
+ * The formatter implementation is typically a 
+ * <code>xap.data.formatter.AbstractFormatter</code> although it does
+ * not have to be. The formatter implementation must at least
+ * implement the <code>format</code> method.
+ * 
+ * @constructor
+ * 
  */
 xap.data.bridge.FormatterBridge = function () {
-	xap.data.bridge.DataFrameworkBridge.call(this) ;
-};
+	xap.data.bridge.DataFrameworkBridge.call(this) ;
+	/** @private */
+	this._formatter = null;
+};
+
+//for doc
+xap.data.bridge.FormatterBridge.prototype = new xap.data.bridge.DataFrameworkBridge();
+
 Xap.setupClassAsSubclassOf("xap.data.bridge.FormatterBridge", "xap.data.bridge.DataFrameworkBridge");
+
 	
-//-----------------------------------------------------------------------
-// Constants.
-//-----------------------------------------------------------------------
-/*protected static final String*/
-xap.data.bridge.FormatterBridge.FORMAT_PATTERN_ATTRIBUTE = "format";
-/*protected static final String*/
-xap.data.bridge.FormatterBridge.LOCALE_ATTRIBUTE = "locale";
 	
-//-----------------------------------------------------------------------
-// Instance Variables.
-//-----------------------------------------------------------------------
 /**
- * @private Formatter
- **/
-xap.data.bridge.FormatterBridge.prototype._formatter = null;
-	
-//-----------------------------------------------------------------------
-// Public Methods.
-//-----------------------------------------------------------------------
-/**
- * @public
- * @return {Formatter}
- **/
+ * Returns the formatter associated with this bridge. This is typically
+ * a <code>xap.data.formatter.AbstractFormatter</code> although it does not have
+ * to be.
+ */
 xap.data.bridge.FormatterBridge.prototype.getFormatter = function () {
 	return this._formatter;
-};
+};
+
 /**
  * Creates and initializes a formatter based on the configuration
- * specified in the formatter element tag.
+ * specified in the formatter element tag, called during
+ * XML processing.
  *
- * @public
- * @return {void}
  **/
 xap.data.bridge.FormatterBridge.prototype.init = function () {
 	xap.data.bridge.DataFrameworkBridge.prototype.init.call(this);
@@ -81,100 +78,51 @@
 	catch (e) { // InitializationException e
 		this.getSession().handleException(e);
 	}
-	/*catch () { // InvalidXmlException e
-	this.getSession().handleException( ExceptionContext.INVALID_XML_EXCEPTION, e );
-	} */
 };
 	
-//-----------------------------------------------------------------------
-// Protected Methods.
-//-----------------------------------------------------------------------
 /**
- * Calls initialize() on the formatter and adds it to the formatterContainer
- * if the initialize call was successfull.
- * @throws InitializationException
- *
- * @protected
- * @return {void}
- * @throws InitializationException 
- **/
+ * Adds the formatter to the formatter container with the ID
+ * specified in the XML element.
+ */
 xap.data.bridge.FormatterBridge.prototype.initializeFormatter = function () {
-	/*String*/
+	//TODO check to see if ID is auto-generated?
 	var id = this.getElement().getAttribute(xap.data.bridge.XmlDataTokens.ID);
-	
-	//TODO do we even need this at all? addedToContainer can
-	//track the session instead
-	if (this._formatter.initialize){
-		this._formatter.initialize(id, this.getSession(), this.getElement());
-	}
 	this.getFormatterContainer().put(id, this._formatter);
-};
+};
+
 /**
  * Creates the formatter. The default implementation looks at the 
  * "class" attribute of the element and returns an instance of
  * that class. Subclasses should override this method
- * to return their own formatter implementations.
- * @return Formatter instance
+ * to return their own formatter implementations. That implementation
+ * must at least support the <code>format</code> method and are typically
+ * subclasses of <code>xap.data.formatter.AbstractFormatter</code>.
+ * 
+ * @return A newly constructed formatter.
  * @throws InvalidXmlException
- *
- * @protected
- * @return {Formatter}
- * @throws InvalidXmlException 
  **/
 xap.data.bridge.FormatterBridge.prototype.createFormatter = function () {
-	/*String*/
-	var className = this.getElement().getAttribute(xap.data.bridge.XmlDataTokens.CLASS);
-	/*Formatter*/
-	var formatter = null;
-	try {	
-		
+	var className = this.getElement().getAttribute(xap.data.bridge.XmlDataTokens.CLASS);
+	try {		
 		//IMPORTANT read the src / class attribute, both?
-		formatter = eval( "new "+className + "()" ) ;
-		return formatter;
+		//should do the same thing here as we do for other MCOs, we really
+		//need a single generic method that handles all src/class user
+		//defined items
+		return eval( "new "+className + "()" ) ;
 	}
 	catch (e) { 
 		throw this.constructInvalidXmlException(xap.data.bridge.XmlDataTokens.CLASS, className, this.getElement(), e);
 	}
 };
-/**
- * Constructs a Locale object from the value of the LOCAL_ATTRIBUTE attribute.
- * Since most formatters will support specifying locales in one form or 
- * another it's useful to have this on the base bridge.  An example locale
- * attribute is specified as follows: locale="en_US"
- * 
- * @return Locale instance
- * @throws InvalidXmlException
- *
- * @protected
- * @return {Locale}
- * @throws InvalidXmlException
- **/
-xap.data.bridge.FormatterBridge.prototype.getLocale = function () {
-// TODO: Get real.
-	return {s:"en_us", country:"us"} ;
-
 
-	/*Locale*/
-	var locale = Locale.getDefault();
-	/*String*/
-	var localeAttr = this.getElement().getAttribute(LOCALE_ATTRIBUTE);
-	if (localeAttr != null) {
-		try {
-			locale = xap.data.bridge.DataAttributeConverter.toLocale(localeAttr);
-		}
-		catch (e) { 
-			throw this.constructInvalidXmlException(LOCALE_ATTRIBUTE, localeAttr, this.getElement(), e);
-		}
-	}
-	return locale;
-};
 /**
- * @return The value of the FORMAT_PATTERN_ATTRIBUTE
- *
- * @protected
- * @return {String}
+ * Returns the value of the 'format' attribute of the XML element representing
+ * the formatter. Formatters should store primary formatting information
+ * in the 'format' attribute.
+ * 
+ * @return {String} The value of the 'format' attribute.
  **/
 xap.data.bridge.FormatterBridge.prototype.getFormatPattern = function () {
-	return this.getElement().getAttribute(xap.data.bridge.FormatterBridge.FORMAT_PATTERN_ATTRIBUTE);
+	return this.getElement().getAttribute('format');
 };
 

Modified: incubator/xap/trunk/codebase/src/xap/data/bridge/FormatterChainBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/bridge/FormatterChainBridge.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/bridge/FormatterChainBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/bridge/FormatterChainBridge.js Wed Feb 21 00:28:58 2007
@@ -18,125 +18,92 @@
  */
 Xap.provide("xap.data.bridge.FormatterChainBridge");
 
+Xap.require("xap.data.bridge.FormatterBridge");
+Xap.require('xap.util.Exception');
 Xap.require("xap.data.formatter.FormatterChain");
 Xap.require("xap.xml.dom.XapElement");
-/**
- * FormatterChainBridge is the bridge class for the formatterChain tag used
- * by the data framework to declare a chain of formatters.
+
+
+/** 
+ * Creates a new FormatterChainBridge.
+ * 
+ * @class FormatterChainBridge is the bridge class to a 
+ * <code>xap.data.formatter.FormatterChain</code>
+ * 
+ * @see xap.data.formatter.FormatterChain
+ * 
+ * @constructor
  * 
- * @author ikaplansky
  */
 xap.data.bridge.FormatterChainBridge = function () {
 	xap.data.bridge.FormatterBridge.call(this);
 };
+
+//for doc
+xap.data.bridge.FormatterChainBridge.prototype = new xap.data.bridge.FormatterBridge();
+
 Xap.setupClassAsSubclassOf("xap.data.bridge.FormatterChainBridge", "xap.data.bridge.FormatterBridge");
 	
-//-----------------------------------------------------------------------
-// Constants.
-//-----------------------------------------------------------------------
-/*private static final String*/
-xap.data.bridge.FormatterChainBridge.FORMATTER_REFERENCE_ELEMENT_NAME = "formatterReference";
-/*private static final String*/
-xap.data.bridge.FormatterChainBridge.FORMATTER_ID_ATTRIBUTE = "formatter";
-	
-	//-----------------------------------------------------------------------
-	// Protected Methods.
-	//-----------------------------------------------------------------------
+
 /**
- * @see FormatterBridge#createFormatter()
- *
- * @protected
- * @return {Formatter}
-**/
+ * Overridden to create a FormatterChain rather than a generic formatter.
+ * 
+ * @return {xap.data.formatter.FormatterChain} The new FormatterChain.
+ */
 xap.data.bridge.FormatterChainBridge.prototype.createFormatter = function () {
-	/*String*/
-	var className = this.getElement().getAttribute(xap.data.bridge.XmlDataTokens.CLASS);
-	/*FormatterChain*/
-	var formatter = null;
-	try {
-		formatter = new xap.data.formatter.FormatterChain();
-	}
-	catch (e) { 
-		this.reportInvalidXmlException(xap.data.bridge.XmlDataTokens.CLASS, className, this.getElement(), e);
-	}
-	return formatter;
+	return new xap.data.formatter.FormatterChain();
 };
+
+
 /**
- * @see FormatterBridge#initializeFormatter()
- *
- * @protected
- * @return {void}
- * @throws InitializationException 
-**/
+ * Overridden to do more parsing of the initial XML element
+ * to set up the formatter chain.
+ */
 xap.data.bridge.FormatterChainBridge.prototype.initializeFormatter = function () {
 	this.superclass.initializeFormatter.call(this);
-	/*FormatterChain*/
+	
+	//FormatterChain
 	var chain = this.getFormatter();
-	/*Vector*/
+
 	var children = this.getElement().childNodes;
 	for (var i = 0; i < children.length; i++) {
-		/*Object*/
 		var child = children[i];
 		if (child instanceof xap.xml.dom.XapElement) {
-			/*Element*/
-			var formatterRef = /*((Element))*/
-								child;
-			this.appendFormatter(chain, formatterRef);
+			//TODO is checking nodeType better here than instanceof?
+			this._appendFormatter(chain, child);
 		} else {
-//			   throw new FormatterInitializationException(
-//					   FormatterInitializationException.
-//						   ILLEGAL_FORMATTER_CHAIN_CHILD_TYPE_MSGID,
-//						   new String[]{
-//							   child.toString(),
-//							   FORMATTER_REFERENCE_ELEMENT_NAME + " element"
-//					   }); 
-			throw new xap.util.Exception(child.toString());
+			//TODO better error reporting
+			throw new xap.util.Exception("Error creating formatter chain from :" + this.getElement().toXml());
 		}
 	}
 };
 	
-//-----------------------------------------------------------------------
-// Private Methods.
-//-----------------------------------------------------------------------
+
 /**
  * @private
- * @return {void}
- *
- * @param chain{FormatterChain}
- * @param formatterRef{Element}
- * @throws InitializationException  
-**/
-xap.data.bridge.FormatterChainBridge.prototype.appendFormatter = function (chain, formatterRef) {
-	if (formatterRef.getLocalName()
-				== xap.data.bridge.FormatterChainBridge.FORMATTER_REFERENCE_ELEMENT_NAME
-		) {
-		/*String*/
-		var formatterId = formatterRef.getAttribute(xap.data.bridge.FormatterChainBridge.FORMATTER_ID_ATTRIBUTE);
-		if (formatterId != null) {
-			/*Formatter*/
-			var f = this.getFormatterContainer().get(formatterId);
-			if (f != null) {
-				chain.appendFormatter(f);
-			} else {
-//					throw new FormatterInitializationException(
-//							FormatterInitializationException.
-//												xap.data.bridge.FormatterChainBridge.FORMATTER_IS_NOT_DEFINED_MSGID,
-//												formatterId );
-				throw new xap.util.Exception("appendFormatter:" + formatterId);
-			}
-		} else {
-//				throw new FormatterInitializationException(
-//						FormatterInitializationException.NULL_FORMATTER_ID_MSGID,
-//						formatterRef.toXml( true ));
-			throw new xap.util.Exception("nullFormatter: " + formatterRef.toXml(true));
-		}
-	} else {
-//			throw new FormatterInitializationException(
-//						FormatterInitializationException.
-//								xap.data.bridge.FormatterChainBridge.ILLEGAL_FORMATTER_CHAIN_CHILD_TAG_MSGID,
-//						new String[]{
-//							formatterRef.getLocalName(), xap.data.bridge.FormatterChainBridge.FORMATTER_REFERENCE_ELEMENT_NAME });
-		throw new xap.util.Exception("illegal format");
+ * Appends a formatter to the given chain based
+ * on the reference element passed in.
+ */
+xap.data.bridge.FormatterChainBridge.prototype._appendFormatter = function (chain, formatterRef) {
+	if (formatterRef.nodeName != 'formatterReference'){
+		//TODO make better
+		throw new xap.util.Exception("Error creating formatter chain, "+
+			"expected child node named 'formatterReference': " + this.getElement().toXml());
+	}
+	
+	var formatterId = formatterRef.getAttribute('formatter');
+	if (!formatterId){
+		//TODO make better
+		throw new xap.util.Exception("Error creating formatter chain, "+
+			"expected attribute named 'formatter': " + this.getElement().toXml());
 	}
+	
+	var f = this.getFormatterContainer().get(formatterId);
+	if (!f){
+		//TODO make better
+		throw new xap.util.Exception("Error creating formatter chain, "+
+			"bad reference to formatter with id '" + formatterId +"': " + this.getElement().toXml());
+	}	
+	chain.appendFormatter(f);
 };
 

Modified: incubator/xap/trunk/codebase/src/xap/data/bridge/MessageFormatterBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/bridge/MessageFormatterBridge.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/bridge/MessageFormatterBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/bridge/MessageFormatterBridge.js Wed Feb 21 00:28:58 2007
@@ -18,70 +18,54 @@
  */
 Xap.provide("xap.data.bridge.MessageFormatterBridge");
 Xap.require("xap.data.bridge.FormatterBridge");
-Xap.require("xap.xml.InvalidXmlException"); 
+Xap.require("xap.util.Exception"); 
 Xap.require("xap.data.formatter.MessageFormatter");
-Xap.require("xap.data.formatter.JsFormatterImpl");
 
 
 
-/**
- * MessageFormatterBridge class handles the configuration element for a
- * MessageFormatter instance.
- *
- * @author ikaplansky
+/** 
+ * Creates a new MessageFormatterBridge.
+ * 
+ * @class MessageFormatterBridge is the bridge class to a 
+ * <code>xap.data.formatter.MessageFormatter</code>
+ * 
+ * @see xap.data.formatter.MessageFormatter
+ * 
+ * @constructor
+ * 
  */
 xap.data.bridge.MessageFormatterBridge = function () {
 	xap.data.bridge.FormatterBridge.call(this);
 };
+
+//for doc
+xap.data.bridge.MessageFormatterBridge.prototype = new xap.data.bridge.FormatterBridge();
+
 Xap.setupClassAsSubclassOf("xap.data.bridge.MessageFormatterBridge", "xap.data.bridge.FormatterBridge");
 	
-	//-----------------------------------------------------------------------
-	// Protected Methods.
-	//-----------------------------------------------------------------------
+
+
 /**
- * @see FormatterBridge#createFormatter()
- *
- * @protected
- * @return {Formatter}
-**/
+ * Overridden to create a MessageFormatter rather than a generic formatter.
+ * 
+ * @return {xap.data.formatter.MessageFormatter} The new MessageFormatter.
+ */
 xap.data.bridge.MessageFormatterBridge.prototype.createFormatter = function () {
-	/*String*/
-	var className = this.getElement().getAttribute(xap.data.bridge.XmlDataTokens.CLASS);
-
-	/*MessageFormatter*/
-	var formatter = null;
-	try {
-		formatter = new xap.data.formatter.MessageFormatter();
-	}
-	catch (e) { 
-		this.reportInvalidXmlException(xap.data.bridge.XmlDataTokens.CLASS, "decimal formatter", this.getElement(), e);
-	}
-	return formatter;
+	//TODO try to read class/src here?
+	return new xap.data.formatter.MessageFormatter();
 };
+
 /**
- * @see FormatterBridge#initializeFormatter()
- *
- * @protected
- * @return {void}
- * @throws InitializationException
-**/
+ * Overridden to do more parsing of the initial XML element
+ * to set up the MessageFormatter.
+ */
 xap.data.bridge.MessageFormatterBridge.prototype.initializeFormatter = function () {
 	xap.data.bridge.FormatterBridge.prototype.initializeFormatter.call(this);
-	try {
-		/*Locale*/
-		var locale = this.getLocale();
-		/*String*/
-		var format = this.getFormatPattern();
-		// TODO: Implement using the actual formatting object
-		// in the bridge class, not here---but implement it:
-		/*MessageFormat*/
-		//var theMessageFormat = new xap.data.formatter.MessageFormatter(format);
-		this.getFormatter().setFormat(format);
-	}
-	catch (e) { // InvalidXmlException
-//			throw new InitializationException(
-//					InitializationException.INVALID_XML_MSGID,
-//					MessageFormatterBridge.class.getName(), e );
+	
+	var formatPattern = this.getFormatPattern();
+	if (!formatPattern){
+		throw new xap.util.Exception("Error creating  message formatter, expected 'format' attribute: " +
+			this.getElement().toXml());
 	}
+	this.getFormatter().setFormat(formatPattern);
 };
-

Modified: incubator/xap/trunk/codebase/src/xap/data/controller/Iterator.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/controller/Iterator.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/controller/Iterator.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/controller/Iterator.js Wed Feb 21 00:28:58 2007
@@ -280,8 +280,7 @@
  *
  * @param dataSet{DataSet}
 **/
-xap.data.controller.Iterator.prototype.iterateOverDataSet = function (dataSet) {
-//		synchronized (this._session.getDocumentRegistry().getUiDocument().getDomSynchronizationObject()) {
+xap.data.controller.Iterator.prototype.iterateOverDataSet = function (dataSet) { 
     this._context = dataSet.getDataSource();
     if (this._iteratedLocations.length == 0) {
 		// All contextual information about the iterator has

Modified: incubator/xap/trunk/codebase/src/xap/data/datasource/AbstractDataSet.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/datasource/AbstractDataSet.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/datasource/AbstractDataSet.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/datasource/AbstractDataSet.js Wed Feb 21 00:28:58 2007
@@ -16,160 +16,120 @@
  *  limitations under the License.
  *
  */
-/**
- * An ease-of-use base class for DataSet implementations.
- * 
- * @author jmargaris
- */
+
 Xap.provide("xap.data.datasource.AbstractDataSet"); 
-Xap.require("xap.data.datasource.DataSetFactory") ;
 
 
-//-----------------------------------------------------------------------
-// Constructors.
-//-----------------------------------------------------------------------
-/**
- * @public
- * @return {AbstractDataSet}
- *
- * @param query{String}
- * @param source{DataSource}
- * @param data{Object  }
- **/
+
+/**
+ * @fileoverview 
+ * Implements the data set base class.
+ */
+ 
+
+/** 
+ * Creates a new AbstractDataSet.DataSets should be created by calling the factory method
+ * <code>xap.data.datasource.AbstractDataSet.getDataSet</code> rather than be
+ * constructed directly.
+ * 
+ * @class AbstractDataSet is the base class for all data sets. A DataSet
+ * is an indexed list returned by a query to a DataSource
+ * that remembers the query and data source that produced it.
+ * 
+ * @constructor
+ * @param {String}query The query string that produced this data set.
+ * @param {xap.data.datasource.AbstractDataSource}source The data source this DataSet came from.
+ * @param data The data that came back from the query.
+ * 
+ * @see #getDataSet
+ * 
+ */
 xap.data.datasource.AbstractDataSet = function(query, source, data) {
+	/** @private */
 	this._data = data ;
+	/** @private */
 	this._query = query ;
+	/** @private */
 	this._dataSource = source ;
 };
-Xap.setupClassAsSubclassOf("xap.data.datasource.AbstractDataSet", "Object");
 
-//-----------------------------------------------------------------------
-// Class Methods.
-//-----------------------------------------------------------------------
-/**
- * @public
- * @return {DataSet}
- *
- * @param query{String}
- * @param dataSource{DataSource}
- * @param data{Object  }
- **/
-xap.data.datasource.AbstractDataSet.getDataSet = function (query, dataSource, data) {
-	/*DataSet*/
-	var dataset = xap.data.datasource.DataSetFactory.getInstance().createDataSet(query, dataSource, data);
-	return dataset;
-};
-
-//-----------------------------------------------------------------------
-// Instance Variables.
-//-----------------------------------------------------------------------
-/**
- * @private Object
- **/
-xap.data.datasource.AbstractDataSet.prototype._data = new Array();
-/**
- * @private String
- **/
-xap.data.datasource.AbstractDataSet.prototype._query = null;
-/**
- * @private DataSource
- **/
-xap.data.datasource.AbstractDataSet.prototype._dataSource = null;
 
+/**
+ * A factory method that returns an AbstractDataSet subclasses based on the type
+ * of data passed in. This will currently only handle array-based data
+ * or single instance data. 
+ * 
+ * @param {String}query The query string that produced this data set.
+ * @param {xap.data.datasource.AbstractDataSource} source The data source this DataSet came from.
+ * @param data The data that came back from the query.
+ * 
+ * @return {xap.data.datasource.AbstractDataSet} A subclass of AbstractDataSet
+ * wrapping the data passed in.
+ */
+xap.data.datasource.AbstractDataSet.getDataSet = function (query, source, data) {
+	//if no data, return an empty array
+	if (!data) {
+		return new xap.data.datasource.ArrayDataSet(query, source, []);
+	} 
 	
-
-
+	//if already in array form we are all set
+	else if (data instanceof Array) {
+		return new xap.data.datasource.ArrayDataSet(query, source, data);
+	}
 	
-//-----------------------------------------------------------------------
-// Abstract Methods.
-//-----------------------------------------------------------------------
-/**
- * @see DataSet#size()
- *
- * @public
- * @return {int}
- **/
-xap.data.datasource.AbstractDataSet.prototype.size = function () {
-	return this._data.length;
-};
-/**
- * Returns an Enumeration over the elements in this DataSet in proper 
- * sequence.
- *
- * @return an Enumeration over the elements in this DataSet in proper 
- * sequence.
- *
- * @public
- * @return {abstract}
- **/
-xap.data.datasource.AbstractDataSet.prototype.elements = function () {
-	return this._data.length;
-};
-/**
- * @see DataSet#getData(int)
- * Implemented by subclasses:
- * @public
- * @return {Enumeration}
- **/
-xap.data.datasource.AbstractDataSet.prototype.getData = function (index) {
+	//if not in array form, stick it into a single-element array
+	else {		
+		return new xap.data.datasource.ArrayDataSet(query, source, [data]);
+	}
 };
 
-//-----------------------------------------------------------------------
-// DataSet Implementation.
-//-----------------------------------------------------------------------
-/**
- * @see DataSet#getQuery()
- *
- * @public
- * @return {String}
- **/
+/**
+ * Returns the query string that produced this data set.
+ * @return {String} The query string that produced this data set.
+ * 
+ */
 xap.data.datasource.AbstractDataSet.prototype.getQuery = function () {
 	return this._query;
 };
+
+
 /**
- * @see DataSet#getDataSource()
- *
- * @public
- * @return {DataSource}
- **/
+ * Returns the data source that produced this data set.
+ * @return {xap.data.datasource.AbstractDataSource} The data source that 
+ * produced this data set.
+ * 
+ */
 xap.data.datasource.AbstractDataSet.prototype.getDataSource = function () {
 	return this._dataSource;
 };
+
+
+//METHODS TO IMPLEMENT IN SUBCLASS
+
+
 /**
- * @see DataSet#isEmpty()
- *
- * @public
- * @return {boolean }
- **/
-xap.data.datasource.AbstractDataSet.prototype.isEmpty = function () {
-	return this.size() == 0;
+ * Returns the size of the data set. Subclasses should override this to 
+ * return the correct size.
+ * 
+ * @return {int} Always returns zero.
+ */
+xap.data.datasource.AbstractDataSet.prototype.size = function () {
+	return 0;
 };
 
 
-//-----------------------------------------------------------------------
-// Protected Methods.
-//-----------------------------------------------------------------------
-/**
- * Returns the ACTUAL underlying data object.  Modifying the returned
- * object modifies the dataset.
- *
- * @return The underlying data object.
- *
- * @protected
- * @return {Object}
- **/
-xap.data.datasource.AbstractDataSet.prototype.getData = function () {
-	return this._data;
-};
-/**
- * Sets the underlying data object.
- * 
- * @param o{Object} The underlying data to set.
- *
- * @protected
- * @return {void}
- **/
-xap.data.datasource.AbstractDataSet.prototype.setData = function (o) {
-	this._data = o;
+/**
+ * Returns the data at the specified index. This base class method returns null;
+ * subclasses should override to return the proper value.
+ * 
+ * @param {int} index The index of that data to return.
+ *  @return {int} Always returns null.
+ */
+xap.data.datasource.AbstractDataSet.prototype.getData = function (index) {
+	return null;
 };
+
+//At the bottom to get around some circular reference issues with factory method needing
+//this class
+Xap.require("xap.data.datasource.ArrayDataSet") ;
 

Modified: incubator/xap/trunk/codebase/src/xap/data/datasource/AbstractDataSource.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/datasource/AbstractDataSource.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/datasource/AbstractDataSource.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/datasource/AbstractDataSource.js Wed Feb 21 00:28:58 2007
@@ -315,7 +315,7 @@
  **/
 xap.data.datasource.AbstractDataSource.prototype.handleDataSetQuery = function (query, context, listener) {
 	var theData = this.executeQuery(query, context) ;
-	var dataset = xap.data.datasource.AbstractDataSet.getDataSet(query, this, theData);		
+	var dataset = xap.data.datasource.AbstractDataSet.getDataSet(query, this, theData);	
 	listener.dataSetRetrieved(query, dataset, context);
 };
 

Modified: incubator/xap/trunk/codebase/src/xap/data/datasource/ArrayDataSet.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/datasource/ArrayDataSet.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/datasource/ArrayDataSet.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/datasource/ArrayDataSet.js Wed Feb 21 00:28:58 2007
@@ -17,129 +17,61 @@
  *
  */
 
-/**
- * An implementation of a DataSet which is backed by an array.  
- *
- * @author Igor Kaplansky, mturyn
- */
-Xap.provide("xap.data.datasource.ArrayDataSet");
-
-Xap.require("xap.data.datasource.AbstractDataSet") ;
-
-/**
- * @public
- * @return {ArrayDataSet}
- *
- * @param query{String}
- * @param source{DataSource}
- * @param dataArray{Object  }
-**/
-xap.data.datasource.ArrayDataSet = function (query, source, dataArray) {
-	xap.data.datasource.AbstractDataSet.call(this, query, source, dataArray);
-};
-
-
-Xap.setupClassAsSubclassOf("xap.data.datasource.ArrayDataSet", "xap.data.datasource.AbstractDataSet");
-
-
-	//-----------------------------------------------------------------------
-	// Constructors.
-	//-----------------------------------------------------------------------
-
-/**
- * @see DataSet#size()
- *
- * @public
- * @return {int}
-*/
-xap.data.datasource.ArrayDataSet.prototype.size = function () {
-	return this._data.length;
-};
-/*
- * @see AbstractDataSet#elements()
- *
- * @public
- * @return {Enumeration}
-*/
-//xap.data.datasource.ArrayDataSet.prototype.elements  = function() {
-//		return new ArrayEnumeration( this.getArray() );
-//	}
-/**
- * @see DataSet#getData(int)
- *
- * @public
- * @param index{int} Index into the data set, here held as an array.
- * @return {Object}
-**/
-xap.data.datasource.ArrayDataSet.prototype.getData = function (index) {
-	var result = null ;
-	// Have to be careful here; if you were to use "!index",
-	// that would do damage if the index were 0....
-	if( (typeof index=="undefined") || index==null){
-		result = this._data ;
-	} else {
-		result = this._data[index] ;
-	}
-	return result ;
-};
-
-	//-----------------------------------------------------------------------
-	// Protected Methods.
-	//-----------------------------------------------------------------------
-/**
- * @return The underlying array.
- *
- * @protected
- * @return {Object}
-**/
-xap.data.datasource.ArrayDataSet.prototype.getArray = function () {
-	return _data ;
-};
-	
-//-----------------------------------------------------------------------
-// Private Classes.
-//-----------------------------------------------------------------------
-//
-// Doesn't appear to be necessary, yet....
-//
-//
-//Xap.setupClassAsSubclassOf("xap.data.datasource.ArrayEnumeration","Enumeration") ;
-//
-//		/*private Object*/
-//var this._array =  null;
-//		/*private int*/
-//var this._size =  0;
-//		/*private int*/
-//var this._currentIndex =  0;
-//
-//		ArrayEnumeration( Object array ) {
-//			this._array = array;
-//			this._size = Array.getLength( array );
-//			this._currentIndex = 0;
-//		}
-//
-///**
-// * @public
-// * @return {boolean}
-//**/
-//xap.data.datasource.ArrayDataSet.prototype.hasMoreElements = function() {
-//			return this._currentIndex < this._size;
-//		}
-//
-///**
-// * @public
-// * @return {Object}
-//**/
-//xap.data.datasource.ArrayDataSet.prototype.nextElement = function() {
-//			if( this._currentIndex >= this._size ) {
-//				throw new NoSuchElementException(
-//					"Array does not contain any more elements" );
-//			}
-//			/*Object*/
-//var o =  Array.get( this._array, this._currentIndex );
-//			this._currentIndex++;
-//			return o;
-//		}
-//	}
-//}
-
+Xap.provide("xap.data.datasource.ArrayDataSet");
+Xap.require("xap.data.datasource.AbstractDataSet") ;
+
+/**
+ * @fileoverview 
+ * Implements a data set based on array backing data.
+ */
+ 
+
+/** 
+ * Creates a new ArrayDataSet. DataSets should be created by calling the factory method
+ * <code>xap.data.datasource.AbstractDataSet.getDataSet</code> rather than be
+ * constructed directly.
+ * 
+ * @class AbstractDataSet is a data set based on array backing data.
+ * 
+ * @constructor
+ * @param {String}query The query string that produced this data set.
+ * @param {xap.data.datasource.AbstractDataSource}source The data source this DataSet came from.
+ * @param dataArray An array of backing data for the data set.
+ * 
+ * @see xap.data.datasource.AbstractDataSet#getDataSet
+ * 
+ */
+xap.data.datasource.ArrayDataSet = function (query, source, dataArray) {
+	xap.data.datasource.AbstractDataSet.call(this, query, source, dataArray);
+};
+
+//needed for doc even though the below handles this
+xap.data.datasource.ArrayDataSet.prototype = new xap.data.datasource.AbstractDataSet();
+
+
+/**
+ * Returns the size of the data set.
+ * 
+ * @return {int} The size of the data set.
+ */
+xap.data.datasource.ArrayDataSet.prototype.size = function () {
+	return this._data.length;
+};
+
+
+/**
+ * Returns the data at the specified index.
+ * 
+ * @param {int} index The index of that data to return.
+ * @return The data at the given index.
+ */
+xap.data.datasource.ArrayDataSet.prototype.getData = function (index) {
+	// Have to be careful here; if you were to use "!index",
+	// that would do damage if the index were 0....
+	if( (typeof index=="undefined") || index==null){
+		return null;
+	}
+	else {
+		return this._data[index] ;
+	}
+};
\ No newline at end of file

Modified: incubator/xap/trunk/codebase/src/xap/data/datasource/QueryRecord.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/datasource/QueryRecord.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/datasource/QueryRecord.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/datasource/QueryRecord.js Wed Feb 21 00:28:58 2007
@@ -20,46 +20,57 @@
 
 Xap.provide("xap.data.datasource.QueryRecord") ;
 
-/**
+
+/** 
+ * Creates a new QueryRecord.
+ * 
+ * @class QueryRecord is used to track queries that are attached to a data source,
+ * eitehr because the query in ONE_WAY or becaue the query is ONE_TIME but
+ * has not completed yet.
+ * 
  * @constructor
- * Represents a query and all of its execution contexts. An execution 
- * context consists of a query context (the context for executing the query)
- * and all the listeners that get notified after the execution. Only one
- * QueryRecord is created for a given query.
+ * @param {String}query The query string.
+ * @param {xap.data.controller.ContextFrame} context An optional ContextFrame for nested iteration.
+ * @param listener The listener to call back when the query is complete.
+ * @param {boolean} isDataSetQuery Whether or not the query expects a DataSet or singleton data.
+ * 
  */
- 
-/**
- * @param query{String}
- * @param context{Context}
- * @param listener{RetrievalListener  }
-**/
 xap.data.datasource.QueryRecord = function( query, context, listener, isDataSetQuery ) {
+	/** @private */
 	this._query = query;
+	/** @private */
 	this._context = context;
+	/** @private */
 	this._listener = listener;
+	/** @private */
 	this._isDataSetQuery = isDataSetQuery;
 }
+
 /**
- * @return {String}
-**/
+ * Returns the query.
+ */
 xap.data.datasource.QueryRecord.prototype.getQuery = function(){
 	return this._query;
 }
 
 /**
- * @return {Context}
-**/
+ * Returns the context if any.
+ */
 xap.data.datasource.QueryRecord.prototype.getContext = function() {
 	return this._context;
 }
 
 /**
- * @return {RetrievalListener}
-**/
+ * Returns the listener to call back when the query is completed.
+ */
 xap.data.datasource.QueryRecord.prototype.getListener = function() {
 	return this._listener;
 }
 
+/**
+ * Returns true if the listener is expecting a DataSet rather than
+ * singleton data.
+ */
 xap.data.datasource.QueryRecord.prototype.isDataSetQuery = function() {
 	return this._isDataSetQuery;
 }

Copied: incubator/xap/trunk/codebase/src/xap/data/formatter/AbstractFormatter.js (from r506849, incubator/xap/trunk/codebase/src/xap/data/formatter/JsFormatterImpl.js)
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/formatter/AbstractFormatter.js?view=diff&rev=509935&p1=incubator/xap/trunk/codebase/src/xap/data/formatter/JsFormatterImpl.js&r1=506849&p2=incubator/xap/trunk/codebase/src/xap/data/formatter/AbstractFormatter.js&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/formatter/JsFormatterImpl.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/formatter/AbstractFormatter.js Wed Feb 21 00:28:58 2007
@@ -17,76 +17,56 @@
  *
  **/
  
-/**
- * A base class with a set/get format that assumes there is some sort of
- * format object, like a message format or decimal format notation
- */ 
- 
-Xap.provide("xap.data.formatter.JsFormatterImpl");
-Xap.require("xap.util.Exception");
+Xap.provide("xap.data.formatter.AbstractFormatter");
 
-xap.data.formatter.JsFormatterImpl = function () {};
+/** 
+ * Creates a new AbstractFormatter.
+ * 
+ * @class AbstractFormatter is the base class for all formatters. The <code>getSession</code>
+ * method is automatically injected on all formatters when they are added to the formatter
+ * container. Formatters are typically not interacted with directly in code, instead
+ * they are created via XML declaration and used during the binding resolution process.
+ * 
+ * @constructor
+ * 
+ */
+xap.data.formatter.AbstractFormatter = function() {};
 
-/**
- * @see Formatter#initialize(String, ClientSession, Element)
- *
- * @public
- * @return {void}
- *
- * @param id{String}
- * @param session{ClientSession}
- * @param formatterElement{Element  }
- * @throws InitializationException
-**/
-xap.data.formatter.JsFormatterImpl.prototype.initialize = function (id, session, formatterElement) {
-	this._session = session;
-	this._formatterElement = formatterElement;
-};
 
-
-
-//-----------------------------------------------------------------------
-// Public Methods.
-//-----------------------------------------------------------------------
 /**
- * Sets the Format instance for this Formatter
- * @param format - Format instance
- *
- * @public
- * @param format{Format}
- * @return {void}
+ * Sets the format object on this formatter. The format object is an object
+ * that holds configuration information and will be different for
+ * different subclasses.
+ * 
+ * @param format An object holding format configuration information.
 **/
-xap.data.formatter.JsFormatterImpl.prototype.setFormat = function (format) {
+xap.data.formatter.AbstractFormatter.prototype.setFormat = function (format) {
 	this._format = format;
 };
-/**
- * @return this formatter's Format instance
- *
- * @public
- * @return {Format}
-**/
-xap.data.formatter.JsFormatterImpl.prototype.getFormat = function () {
-	return this._format;
-};
-//-----------------------------------------------------------------------
-// Protected Methods.
-//-----------------------------------------------------------------------
 
 /**
- * @protected
- * @return {ClientSession}
+ * Returns the format object of this formatter. The format object is an object
+ * that holds configuration information and will be different for
+ * different subclasses.
+ * 
+ * @return An object with configuration information.
 **/
-xap.data.formatter.JsFormatterImpl.prototype.getSession = function () {
-	return this._session;
+xap.data.formatter.AbstractFormatter.prototype.getFormat = function () {
+	return this._format;
 };
 
 
-
 /**
- * @protected
- * @param session{ClientSession}
- * @return {void}
-**/
-xap.data.formatter.JsFormatterImpl.prototype.setSession = function (session) {
-	this._session = session;
+ * Formats the object passed in and returns a new object representing
+ * the original object after formatting has been applied. This method should attempt
+ * to do some unwrapping of the object using <code>xap.util.TypeUtils</code>.
+ * The base-class implementation simply returns null, subclasses
+ * should override this to apply formatting.
+ * 
+ * @param object The object to format.
+ * @return A formatted version of the argument passed in.
+ */
+xap.data.formatter.AbstractFormatter.prototype.format = function (object) {
+	return null;	
 };
+

Modified: incubator/xap/trunk/codebase/src/xap/data/formatter/DecimalFormatter.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/formatter/DecimalFormatter.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/formatter/DecimalFormatter.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/formatter/DecimalFormatter.js Wed Feb 21 00:28:58 2007
@@ -16,60 +16,46 @@
  *  limitations under the License.
  *
 **/
-Xap.provide("xap.data.formatter.DecimalFormatter"); 
 
-Xap.require("xap.util.Exception");
-Xap.require("xap.data.formatter.JsFormatterImpl");
+Xap.provide("xap.data.formatter.DecimalFormatter"); 
+Xap.require("xap.data.formatter.AbstractFormatter");
 Xap.require("xap.util.TypeUtils");
 
 
+/** 
+ * Creates a new DecimalFormatter.
+ * 
+ * @class DecimalFormatter formats numbers into a decimal format where the
+ * number of significant digits is determined by the format string.
+ * 
+ * @constructor
+ * 
+ */
+xap.data.formatter.DecimalFormatter = function () {}
+
+//needed to doc correctly
+xap.data.formatter.DecimalFormatter.prototype = new xap.data.formatter.AbstractFormatter();
 
+Xap.setupClassAsSubclassOf("xap.data.formatter.DecimalFormatter", "xap.data.formatter.AbstractFormatter");
 
 
-//-----------------------------------------------------------------------
-// Constructors.
-//-----------------------------------------------------------------------
 /**
- * A DecimalFormatter formats numbers into decimals according to the 
- * specified format. 
+ * Formats the object passed in and returns a new object representing
+ * the original object after formatting has been applied. This method attempts
+ * to convert the argument to a number using
+ * <code>xap.util.TypeUtils.convertToNumber</code>. The format used should
+ * already have been supplied using the <code>setFormat</code> method. 
+ * The format string
+ * should be in the form "xxx.yyy" where "yyy" indicates the number of significant digits.
+ * Information before the decimal point is currently unused.
  * 
- * <p/>
- * For example, given the format "000.0", the number 123.423432322 can be 
- * formatted to display as 123.4
- *
- * @author ikaplansky
+ * @param object The object to format.
+ * @return {String} The string repesentation of the number with significant digits
+ * based on the formatString.
  */
-xap.data.formatter.DecimalFormatter = function () {
-};
-Xap.setupClassAsSubclassOf("xap.data.formatter.DecimalFormatter", "xap.data.formatter.JsFormatterImpl");
-
-
-//-----------------------------------------------------------------------
-// Protected Methods.
-//-----------------------------------------------------------------------
-/**
- * @see AbstractJavaFormatter#formatObject(Object)
- *
- * @protected
- * @return {Object}
-**/
 xap.data.formatter.DecimalFormatter.prototype.format = function (object) {
-	var fObject = obj = xap.util.TypeUtils.convertToNumber(object); 
-	return xap.data.formatter.DecimalFormatter.format(fObject, this.getFormat());
-};
-/**
- * This class method is essentially a
- * replacement for a separate formatter class
- * ---it obviously needs to be broken out into
- * a separate class as soon as possible.
- * @param aNumber{float}
- * @param aFormatString{str}---String in the form a0b0b0c0.00,
- * where a,b,and c can be any character beside 0 and the decimal
- * separator char.
- *
-**/
-xap.data.formatter.DecimalFormatter.format = function (pfNumber, psFormatString) {
-	var nDecis = psFormatString.length - psFormatString.indexOf(".") - 1;
-	return (pfNumber).toFixed(nDecis);
-};
-
+	var number = xap.util.TypeUtils.convertToNumber(object); 
+	var formatString = this.getFormat();
+	var nDecis = formatString.length - formatString.indexOf(".") - 1;
+	return number.toFixed(nDecis);
+};
\ No newline at end of file

Modified: incubator/xap/trunk/codebase/src/xap/data/formatter/FormatterChain.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/formatter/FormatterChain.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/formatter/FormatterChain.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/formatter/FormatterChain.js Wed Feb 21 00:28:58 2007
@@ -18,116 +18,51 @@
 **/
 
 Xap.provide("xap.data.formatter.FormatterChain"); 
+Xap.require("xap.data.formatter.AbstractFormatter");
 
-Xap.require("xap.session.ClientSession");
-Xap.require("xap.data.formatter.JsFormatterImpl") ;
-Xap.require("xap.log.Logger");
-Xap.require("xap.xml.dom.XapElement");
-Xap.require("xap.util.ArrayHelper");
-
-//-----------------------------------------------------------------------
-// Constructors.
-//-----------------------------------------------------------------------
-/**
- * FormatterChain is a chain of formatters that are executed in order.
- * 
- * <p/>
+/** 
+ * Creates a new FormatterChain.
  * 
- * The output of a previous Formatter is used as input to the next one in the
- * chain.  Here is an example of how to declare a formatter chain: <br/><br/>
+ * @class FormatterChain is a formatter that passes values through a chain
+ * of formatters to arrive at a final formatted value.
  * 
- * &lt;data:formatterChain id="formatterChain1" 
- *	xmlns="http://openxal.org/core/data"&gt;<br/>
- * &nbsp;&nbsp;&nbsp;&nbsp;&lt;data:formatterReference formatter="formatter1" 
- *									xmlns="http://openxal.org/core/data"/&gt;<br/>
- * &nbsp;&nbsp;&nbsp;&nbsp;&lt;data:formatterReference formatter="formatter2" 
- *									 xmlns="http://openxal.org/core/data"/&gt;<br/>
- * &nbsp;&nbsp;&nbsp;&nbsp;&lt;data:formatterReference formatter="formatter3" 
- *									 xmlns="http://openxal.org/core/data"/&gt;<br/>
- * &lt;/data:formatterChain&gt; <br><br>
- *	   
- * In the above example a formatterChain is declared that consists of 3 
- * formatters: "formatter1", "formatter2" and "formatter3" which are the ids of
- * previously declared formatters. The formatterChain's id can be used in any 
- * place a formatter id is expected.
+ * @constructor
  * 
- * @author ikaplansky
  */
 xap.data.formatter.FormatterChain = function () {
-	xap.data.formatter.JsFormatterImpl.call(this) ;
+	xap.data.formatter.AbstractFormatter.call(this) ;
+	this.setFormat([]);
 };
-Xap.setupClassAsSubclassOf("xap.data.formatter.FormatterChain", "xap.data.formatter.JsFormatterImpl");
+
+//for doc
+xap.data.formatter.FormatterChain.prototype = new xap.data.formatter.AbstractFormatter();
+
+Xap.setupClassAsSubclassOf("xap.data.formatter.FormatterChain", "xap.data.formatter.AbstractFormatter");
 
 	
-//-----------------------------------------------------------------------
-// Formatter Interface.
-//-----------------------------------------------------------------------
 /**
- * @see Formatter#initialize(String, ClientSession, Element)
- *
- * @public
- * @param id{String} Formatter tag i.d.
- * @param session{ClientSession}
- * @param formatterElement{XapElement} The node in the XAL document corresponding to this chain.
- * @throws InitializationException  
- * @return {void}
-**/
-xap.data.formatter.FormatterChain.prototype.initialize = function (id, session, formatterElement) {
-	this._formatters = new Array(0);
-};
-/**
- * @see Formatter#format(Object)
- *
- * @public
- * @return {Object}
- * @throws FormatException 
-**/
+ * Formats the object passed in and returns a new object representing
+ * the original object after formatting has been applied. This method takes
+ * the result of one formatter in the chain and passes it to the next one.
+ * 
+ * @param object The object to format.
+ * @return The final formatted object.
+ */
 xap.data.formatter.FormatterChain.prototype.format = function (object) {
-	/*Object*/
-	var formattedObject = object;
-	for (var i = 0; i < this._formatters.length; i++) {
-		/*Formatter*/
-		var f = this._formatters[i];
-		formattedObject = f.format(formattedObject);
+	var formatters = this.getFormat(); //getFormat() is an array of formatters
+	for (var i = 0; i < formatters.length; i++) {
+		object = formatters[i].format(object);
 	}
-	return formattedObject;
+	return object;
 };
 	
 	
-//-----------------------------------------------------------------------
-// Public Methods.
-//-----------------------------------------------------------------------
 /**
- * Appends the specified formatter at the end of the chain
- * @param formatter
- *
- * @public
- * @return {void}
-**/
+ * Appends the specified formatter to the end of the formatter chain.
+ * @param {xap.data.formatter.AbstractFormatter} formatter The formatter to append.
+ * 
+ */
 xap.data.formatter.FormatterChain.prototype.appendFormatter = function (formatter) {
-	if (formatter == null) {
-//			throw new IllegalArgumentException( ResourceDictionary.getMessage(
-//					NULL_FORMATTER_MSGID, FormatterChain.class ));
-		throw new xap.util.Exception("FormatterChain.appendFormatter: Attempted to add a null object to a formatter chain.");
-	}
-	if (xap.util.ArrayHelper.indexOf(this._formatters, formatter) != -1) {
-		if (this.getLog().isDebug()) {
-//				this.getLog().debug( ResourceDictionary.getMessage(
-//						FORMATTER_INSTANCE_ALREADY_IN_CHAIN_MSGID,
-//						FormatterChain.class,
-//						formatter.toString()));
-			this.getLog.debug("Formatter already in chain: \n" + formatter);
-		}
-	}
-	this._formatters.push(formatter);
-};
-
-
-/**
- * @private
- * @return {Log}
-**/
-xap.data.formatter.FormatterChain.prototype.getLog = function () {
-	return xap.log.Logger.getLogger("xap.data.formatter.FormatterChain");
+	this.getFormat().push(formatter);
 };
 

Modified: incubator/xap/trunk/codebase/src/xap/data/formatter/MessageFormatter.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/data/formatter/MessageFormatter.js?view=diff&rev=509935&r1=509934&r2=509935
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/data/formatter/MessageFormatter.js (original)
+++ incubator/xap/trunk/codebase/src/xap/data/formatter/MessageFormatter.js Wed Feb 21 00:28:58 2007
@@ -17,57 +17,47 @@
  *
  */
 
-/**
- * MessageFormatter is used to format string messages.
- * 
- * <p/>
- * Here is an example of declaring a MessageFormatter instance: <br/><br/>
- * 
- * &lt;messageFormatter xmlns="http://openxal.org/core/data" id="mf1" 
- *   format="This is a message with a single Date: {0,date}"/&gt; <br/><br/>
- * 
- * The argument to the MessageFormatter is expected to be an Object[] where
- * each Object is of the type expected by the format pattern (specified as the
- * 'format' attribute in the messageFormatter element). If the argument is not
- * an Object[], it will be converted into an Object[].  
- * 
- * <p/>
- * In addition, this formatter will convert each Object in the Object[] into the 
- * type expected by the underlying java's MessageFormat instance.  For example, 
- * the formatter declared above could be called with a single String that 
- * represents a Long and the MessageFormatter will convert it into an Object[] 
- * of size 1 that has a Date object as its only element constructed with the
- * passed in Long (the String will get converted into a Long object first).
- * 
- * @author ikaplansky
- */
+
 Xap.provide("xap.data.formatter.MessageFormatter"); 
-
-// Superclass
-Xap.require("xap.data.formatter.JsFormatterImpl");
-// Peer
+
+Xap.require("xap.data.formatter.AbstractFormatter");
 Xap.require("xap.util.MessageFormat");
 Xap.require("xap.util.TypeUtils");
 
-//-----------------------------------------------------------------------
-// Constructors.
-//-----------------------------------------------------------------------
+
+/** 
+ * Creates a new MessageFormatter.
+ * 
+ * @class MessageFormatter formats based on <code>xap.util.MessageFormat</code>.
+ * 
+ * @constructor
+ * 
+ */
 xap.data.formatter.MessageFormatter = function () {
-	xap.data.formatter.JsFormatterImpl.call(this);
-};
-Xap.setupClassAsSubclassOf("xap.data.formatter.MessageFormatter", "xap.data.formatter.JsFormatterImpl");
+	xap.data.formatter.AbstractFormatter.call(this);
+};
 
+//for doc
+xap.data.formatter.MessageFormatter.prototype = new xap.data.formatter.AbstractFormatter();
+
+Xap.setupClassAsSubclassOf("xap.data.formatter.MessageFormatter", "xap.data.formatter.AbstractFormatter");
 
 /**
- * Formats based on the existing format string that was hopefully set already.
+ * Formats the object passed in and returns a new object representing
+ * the original object after formatting has been applied. This method calls
+ * <code>xap.util.MessageFormat.format</code> to do the formatting after converting
+ * the object to an array using <code>xap.util.TypeUtils.convertToArray</code>.
+ * The format used should
+ * already have been supplied using the <code>setFormat</code> method. 
+ * The format string
+ * should be in a form understandable by <code>xap.util.MessageFormat</code>.
+ * 
+ * @param object The object to format.
+ * @return {String} The argument formatted with the message format.
+ * @see xap.util.MessageFormat
  */
-xap.data.formatter.MessageFormatter.prototype.format = function (object) {
-	return xap.data.formatter.MessageFormatter.format(object, this.getFormat());
-};
-
-
-xap.data.formatter.MessageFormatter.format = function (obj, fmtStr) {
-	obj = xap.util.TypeUtils.convertToArray(obj); 
-	return xap.util.MessageFormat.format(fmtStr, obj);
+xap.data.formatter.MessageFormatter.prototype.format = function (object) {
+	object = xap.util.TypeUtils.convertToArray(object); 
+	return xap.util.MessageFormat.format(this.getFormat(), object);
 };