incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmarga...@apache.org
Subject svn commit: r483005 - in /incubator/xap/trunk: WebContent/examples/dataBinding/ src/xap/data/ src/xap/data/bridge/ src/xap/data/controller/ src/xap/data/datasource/ src/xap/data/events/ src/xap/data/formatter/ src/xap/util/
Date Wed, 06 Dec 2006 09:58:45 GMT
Author: jmargaris
Date: Wed Dec  6 01:58:43 2006
New Revision: 483005

URL: http://svn.apache.org/viewvc?view=rev&rev=483005
Log:
cleaned up some unused methods/classes
got formatters working properly
updated simpleEmployees example to use escape syntax,
formatters, formatter chains

Added:
    incubator/xap/trunk/WebContent/examples/dataBinding/titles.xml   (with props)
Removed:
    incubator/xap/trunk/src/xap/data/DataServiceFactory.js
    incubator/xap/trunk/src/xap/data/DataServiceImpl.js
    incubator/xap/trunk/src/xap/data/events/
Modified:
    incubator/xap/trunk/WebContent/examples/dataBinding/simpleEmployees.xal
    incubator/xap/trunk/src/xap/data/bridge/DataAttributeConverter.js
    incubator/xap/trunk/src/xap/data/bridge/DataFrameworkBridge.js
    incubator/xap/trunk/src/xap/data/bridge/FormatterBridge.js
    incubator/xap/trunk/src/xap/data/controller/Binding.js
    incubator/xap/trunk/src/xap/data/controller/BindingResolver.js
    incubator/xap/trunk/src/xap/data/controller/Iterator.js
    incubator/xap/trunk/src/xap/data/datasource/ObjectDataSource.js
    incubator/xap/trunk/src/xap/data/formatter/DecimalFormatter.js
    incubator/xap/trunk/src/xap/data/formatter/FormatterChain.js
    incubator/xap/trunk/src/xap/data/formatter/JsFormatterImpl.js
    incubator/xap/trunk/src/xap/data/formatter/MessageFormatter.js
    incubator/xap/trunk/src/xap/util/TypeUtils.js

Modified: incubator/xap/trunk/WebContent/examples/dataBinding/simpleEmployees.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dataBinding/simpleEmployees.xal?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dataBinding/simpleEmployees.xal (original)
+++ incubator/xap/trunk/WebContent/examples/dataBinding/simpleEmployees.xal Wed Dec  6 01:58:43
2006
@@ -6,6 +6,25 @@
 		source="employees.xml"
 	/>
 	
+	<messageFormatter 
+		xmlns="http://openxal.org/core/data" 
+		id="firstNameList" 
+		format="The first 3 names are {0}, {1} and {2}"
+	/>
+	
+	<messageFormatter 
+		xmlns="http://openxal.org/core/data" 
+		id="middleNameCount" 
+		format="The number of middle names is {0} (to 2 decimal places)"
+	/>
+	
+	
+	<decimalFormatter 
+		xmlns="http://openxal.org/core/data"
+		id="decimalFormat" 
+		format="0.00"
+	/>
+	
 	<binding 	
 		xmlns="http://openxal.org/core/data" 
 		dataSource="myDataSource" 
@@ -13,6 +32,14 @@
 		id="employeeCount"
 	/>
 	
+	
+	<formatterChain id="middleNameFormatter" xmlns="http://openxal.org/core/data">
+		<formatterReference formatter="decimalFormat"/>
+		<formatterReference formatter="middleNameCount"/>	
+	</data:formatterChain>
+	
+	
+	
 
 	<xm:modifications xmlns:xm="http://openxal.org/core/xmodify">
 		<xm:append select="/ui">
@@ -38,8 +65,7 @@
 				<iterator xmlns="http://openxal.org/core/data" name="anIterator" dataSource="myDataSource"
select="//employee" type="ONE_TIME">
 
 					<xal:row>
-						<xal:cell text="{*('@id')}" fontFamily="Garamond" fontSize="11pt"/>
-											
+						<xal:cell text="{*('@id')}" fontFamily="Garamond" fontSize="11pt"/>								
 						<xal:cell text="{*('@lname')}" fontFamily="Garamond" fontSize="11pt"/>
 						<xal:cell text="{*('@fname')}" fontFamily="Garamond" fontSize="11pt"/>
 						<xal:cell text="{*('@mname')}" fontFamily="Garamond" fontSize="11pt"/>						
@@ -47,7 +73,8 @@
 				</iterator>
 			</xal:table>
 			
-			<label 
+			
+			<label fontSize="11pt"
 				text="{ bind(binding:employeeCount) }" 
 			/>
 			
@@ -55,7 +82,23 @@
 			<label 
 				text="\{ bind(binding:employeeCount) } is the binding string above" 
 			/>
-
+			
+			<label height="10px"/>
+			
+			<label text="{ bind('dataSource=myDataSource;select=/employees/employee/@fname;formatter=firstNameList')}"/>
+			<label text="\{bind('dataSource=myDataSource;select=/employees/employee/@fname;formatter=firstNameList')}
is the binding above"/>
+		
+			<label height="10px"/>
+			
+			<label text="{ bind('dataSource=myDataSource;select=count(/employees/employee);formatter=decimalFormat')}"/>
+			<label text="\{ bind('dataSource=myDataSource;select=count(/employees/employee);formatter=decimalFormat')}
is above(forces 2 digits post decimal)"/>
+	
+			<label height="10px"/>
+			
+			<label text="{ bind('dataSource=myDataSource;select=count(/employees/employee/@mname);formatter=middleNameFormatter')}"/>
+			<label text="\{ bind('dataSource=myDataSource;select=count(/employees/employee/@mname);formatter=middleNameFormatter')}
is above(a formatter chain)"/>
+			
+			
 		</xm:append>
 	</xm:modifications>
 </xal>

Added: incubator/xap/trunk/WebContent/examples/dataBinding/titles.xml
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dataBinding/titles.xml?view=auto&rev=483005
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dataBinding/titles.xml (added)
+++ incubator/xap/trunk/WebContent/examples/dataBinding/titles.xml Wed Dec  6 01:58:43 2006
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<titles>
+    <title>King</title>
+    <title>Monkey</title>
+    <title>Madame</title>
+</titles>
\ No newline at end of file

Propchange: incubator/xap/trunk/WebContent/examples/dataBinding/titles.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/xap/trunk/src/xap/data/bridge/DataAttributeConverter.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/bridge/DataAttributeConverter.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/bridge/DataAttributeConverter.js (original)
+++ incubator/xap/trunk/src/xap/data/bridge/DataAttributeConverter.js Wed Dec  6 01:58:43
2006
@@ -18,7 +18,6 @@
 Xap.provide("xap.data.bridge.DataAttributeConverter");
 Xap.require("xap.taghandling.AttributeConversionException");
 Xap.require("xap.taghandling.AttributeConverter");
-Xap.require("xap.data.DataServiceImpl");
 Xap.require("xap.data.controller.BindingType");
 Xap.require("xap.data.bridge.XmlDataTokens");
 Xap.require("xap.data.formatter.JsFormatterImpl") 

Modified: incubator/xap/trunk/src/xap/data/bridge/DataFrameworkBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/bridge/DataFrameworkBridge.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/bridge/DataFrameworkBridge.js (original)
+++ incubator/xap/trunk/src/xap/data/bridge/DataFrameworkBridge.js Wed Dec  6 01:58:43 2006
@@ -16,8 +16,7 @@
  */
 Xap.provide("xap.data.bridge.DataFrameworkBridge");
 Xap.require("xap.taghandling.AbstractTagImpl");
-Xap.require("xap.data.DataServiceImpl");
-Xap.require("xap.data.DataServiceFactory");
+Xap.require("xap.data.DataFramework");
 Xap.require("xap.data.datasource.DataSourceContainerImpl") ;
 Xap.require("xap.data.formatter.FormatterContainerImpl") ; 
 Xap.require("xap.util.LogFactory");
@@ -38,7 +37,7 @@
 //-----------------------------------------------------------------------
 /*public DataServiceImpl*/
 xap.data.bridge.DataFrameworkBridge.prototype.getDataService = function () {
-	return xap.data.DataServiceFactory.getDataService(this.getSession());
+	return xap.data.DataFramework.getDataService(this.getSession());
 };
 /*Public DataSourceContainer*/
 xap.data.bridge.DataFrameworkBridge.prototype.getDataSourceContainer = function () {

Modified: incubator/xap/trunk/src/xap/data/bridge/FormatterBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/bridge/FormatterBridge.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/bridge/FormatterBridge.js (original)
+++ incubator/xap/trunk/src/xap/data/bridge/FormatterBridge.js Wed Dec  6 01:58:43 2006
@@ -20,7 +20,6 @@
 Xap.require("xap.util.Exception");
 Xap.require("xap.taghandling.AttributeConversionException");
 Xap.require("xap.xml.InvalidXmlException");
-Xap.require("xap.data.DataServiceImpl");
 Xap.require("xap.data.formatter.JsFormatterImpl");
 Xap.require("xap.data.bridge.XmlDataTokens");
 

Modified: incubator/xap/trunk/src/xap/data/controller/Binding.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/controller/Binding.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/controller/Binding.js (original)
+++ incubator/xap/trunk/src/xap/data/controller/Binding.js Wed Dec  6 01:58:43 2006
@@ -18,8 +18,7 @@
 Xap.provide("xap.data.controller.Binding");
 
 Xap.require("xap.util.TypeUtils");
-Xap.require("xap.data.DataServiceImpl");
-Xap.require("xap.data.DataServiceFactory");
+Xap.require("xap.data.DataFramework");
 Xap.require("xap.data.controller.BindingType");
 Xap.require("xap.util.Vector");
 Xap.require("xap.data.controller.AttributeValueLocation");
@@ -60,7 +59,7 @@
 	binding._session = session;
 	binding._bindingType = bindingType;
 	if (name && name.length > 0) {
-		binding._source = xap.data.DataServiceFactory.getDataService(session).getDataSourceContainer().getDataSource(name);
+		binding._source = xap.data.DataFramework.getDataService(session).getDataSourceContainer().getDataSource(name);
 		if (!binding._source) {
 			// Find the ancestor iterator context with the
 			// specified name, since there was not data source with
@@ -300,7 +299,7 @@
 			}
 		}
 		catch (dataException) { //DataException
-			this._session.handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE +
": no data retrieved: "+dataException, dataException);
+			this._session.handleException(dataException);
 		}
 	}
 	

Modified: incubator/xap/trunk/src/xap/data/controller/BindingResolver.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/controller/BindingResolver.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/controller/BindingResolver.js (original)
+++ incubator/xap/trunk/src/xap/data/controller/BindingResolver.js Wed Dec  6 01:58:43 2006
@@ -18,10 +18,7 @@
 Xap.provide("xap.data.controller.BindingResolver");
 Xap.require("xap.session.ClientSession");
 Xap.require("xap.data.DataFramework");
-Xap.require("xap.data.DataServiceImpl");
 Xap.require("xap.data.bridge.XmlDataTokens");
-//Xap.require("xap.data.formatter.JsFormatterImpl") ;
-//Xap.require("xap.util.EscapeSyntaxException") ;
 Xap.require("xap.util.EscapeSyntaxParser") ;
 Xap.require("xap.data.controller.ContextStack") ;
 /**

Modified: incubator/xap/trunk/src/xap/data/controller/Iterator.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/controller/Iterator.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/controller/Iterator.js (original)
+++ incubator/xap/trunk/src/xap/data/controller/Iterator.js Wed Dec  6 01:58:43 2006
@@ -19,14 +19,8 @@
 Xap.require("xap.data.controller.IteratorContainerImpl");
 Xap.require("xap.data.controller.ElementLocation");
 Xap.require("xap.session.ClientSession"); 
-//Xap.require("xap.UiUpdateQueue") 
 Xap.require("xap.util.Exception"); 
-//Xap.require("xap.data.DataException") 
 Xap.require("xap.data.DataFramework");
-Xap.require("xap.data.DataServiceImpl");
-Xap.require("xap.data.DataServiceFactory");
-
-//Xap.require("xap.data.datasource.DataSetRetrievalListener") 
 Xap.require("xap.xml.dom.XapElement");
 Xap.require("xap.data.controller.BindingResolver");
 Xap.require("xap.data.controller.ContextFrame");
@@ -73,7 +67,7 @@
     this._iteratedLocations = new xap.util.Vector();
     this._iteratedLocations.addElement(iteratorLocation);
     /*DataFramework*/
-    var svc = xap.data.DataServiceFactory.getDataService(this._session);
+    var svc = xap.data.DataFramework.getDataService(this._session);
 
 	//get the context stack from the resolver
     /*BindingResolver*/
@@ -102,13 +96,8 @@
         /*ContextFrame*/
         var context = this._contextStack.getContext(ancestorIteratorName);
         if (context == null) {
-//	this._session.handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE
-//            +"::Iterator(): can't get context corresponding to ancestor named '" + ancestorIteratorName
+ "'.",
-//					  new DataControllerException(DataControllerException.RELATIVE_ITERATOR_INVALID_PARENT_REFERENCE,
-//								  new String [] { ancestorIteratorName, this._iteratorElement.toString() }));
-// TODO:  Proper exception handling---bring
-// back DataControllerException:
-            this._session.handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE
+ ": no ancestor iterator.", "DataControllerException.RELATIVE_ITERATOR_INVALID_PARENT_REFERENCE",
[ancestorIteratorName, "" + this._iteratorElement]);
+        	//TODO handle better
+            this._session.handleException(new xap.util.Exception("No ancestor iterator"));
             this.invalidate();
             return;
         }
@@ -117,7 +106,7 @@
             context.getDataSource().getDataSet(this._select, this, context);
         }
         catch (e) { //DataException
-            this._session.handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE
+ ": can't get data set from context.", e);
+            this._session.handleException(e);
         }
     }
 };
@@ -306,10 +295,9 @@
         /*ContextFrame*/
         var context = this._contextStack.getCurrentContext();
         if (context == null) {
-            this._session.handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE
+ "::Iterator.iterate():  relative iterator without a parent context.", new xap.util.Exception("DataControllerException.RELATIVE_ITERATOR_WITHOUT_PARENT"
+ this._iteratorElement));
-			//						new DataControllerException(DataControllerException.RELATIVE_ITERATOR_WITHOUT_PARENT,
-			//								this._iteratorElement.toString() )
-			// Use a better exception, like this ne, in the above?			
+        	
+        	//TODO handle better
+            this._session.handleException( new xap.util.Exception("Relative iterator without
parent:" + this._iteratorElement));	
             this.invalidate();
             return;
         }
@@ -317,7 +305,7 @@
         context.getDataSource().getDataSet(this._select, this, context);
     }
     catch (e) { //DataException
-        this._session.handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE
+ "::Iterator.iterate(): can't get data set from context.", e);
+        this._session.handleException(e);
     }
 };
 /**
@@ -380,7 +368,7 @@
 	//unfreeze is scheduled at the very end of this method.
    // this._session.getDisplayService().freezeUiUpdates(true);
     /*BindingResolver*/
-    var resolver = (xap.data.DataServiceFactory.getDataService(this._session)).getBindingResolver();
+    var resolver = xap.data.DataFramework.getDataService(this._session).getBindingResolver();
     /*ContextStack*/
     var oldContextStack = resolver.getContextStack();
     this._iterating = true;
@@ -453,7 +441,7 @@
     }
     catch (e) { //Exception
         this.invalidate();
-        this._session.handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE
+ "::Iterator.iterateOverDataSet()", new DataControllerException(DataControllerException.ITERATOR_LOOP_EXCEPTION,
e));
+        this._session.handleException(e);
     }
     finally {
         this._iterating = false;
@@ -541,7 +529,7 @@
 //		}
 
 	// Remove this iterator from the iterator container
-    (xap.data.DataServiceFactory.getDataService(this._session)).getIteratorContainer().removeIterator(this);
+    xap.data.DataFramework.getDataService(this._session).getIteratorContainer().removeIterator(this);
 };
 /**
  * @private
@@ -566,7 +554,7 @@
 			// Stop listening to the parent location and invalidate it.
     this._parentLocation.setLocationListener(null);
     this._parentLocation.invalidate();
-    (xap.data.DataServiceFactory.getDataService(this._session)).getIteratorContainer().removeIterator(this);
+	xap.data.DataFramework.getDataService(this._session).getIteratorContainer().removeIterator(this);
 //		}
 };
 /*

Modified: incubator/xap/trunk/src/xap/data/datasource/ObjectDataSource.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/datasource/ObjectDataSource.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/datasource/ObjectDataSource.js (original)
+++ incubator/xap/trunk/src/xap/data/datasource/ObjectDataSource.js Wed Dec  6 01:58:43 2006
@@ -24,13 +24,7 @@
 import java.lang.reflect.Method;
 */
 
-Xap.require("xap.session.ClientSession"); 
-//Xap.require("xap.netservice.HttpResponse") ;
-//Xap.require("xap.netservice.NetServiceException") ;
-//Xap.require("xap.netservice.NetServiceListener") ; 
-Xap.require("xap.data.DataServiceImpl"); 
-//Xap.require("xap.data.InitializationException") ;
-//Xap.require("xap.data.controller.Context") ; 
+Xap.require("xap.session.ClientSession"); 
 Xap.require("xap.util.LogFactory");
 Xap.require("xap.util.ResourceDictionary");
 Xap.require("xap.xml.dom.XapElement");
@@ -333,7 +327,7 @@
 		if (this.getLog().isDebug()) {
 			this.getLog().exception(e);
 		}
-		this.getClientSession().handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE+e,
e);
+		this.getClientSession().handleException( e);
 	}
 };
 /**
@@ -366,7 +360,7 @@
 		if (this.getLog().isDebug()) {
 			this.getLog().exception(e);
 		}
-		this.getClientSession().handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE,
e);
+		this.getClientSession().handleException(e);
 	}
 };
 

Modified: incubator/xap/trunk/src/xap/data/formatter/DecimalFormatter.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/formatter/DecimalFormatter.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/formatter/DecimalFormatter.js (original)
+++ incubator/xap/trunk/src/xap/data/formatter/DecimalFormatter.js Wed Dec  6 01:58:43 2006
@@ -16,9 +16,9 @@
 **/
 Xap.provide("xap.data.formatter.DecimalFormatter"); 
 
-//Xap.require("xap.util.TypeConversionException");
 Xap.require("xap.util.Exception");
 Xap.require("xap.data.formatter.JsFormatterImpl");
+Xap.require("xap.util.TypeUtils");
 
 
 
@@ -41,18 +41,7 @@
 };
 Xap.setupClassAsSubclassOf("xap.data.formatter.DecimalFormatter", "xap.data.formatter.JsFormatterImpl");
 
-//-----------------------------------------------------------------------
-// Public Methods.
-//-----------------------------------------------------------------------
-/**
- * @return the underlying text object used by this formatter.
- *
- * @public
- * @return {DecimalFormat}
-**/
-xap.data.formatter.DecimalFormatter.prototype.getDecimalFormat = function () {
-	return this.getFormat();
-};
+
 //-----------------------------------------------------------------------
 // Protected Methods.
 //-----------------------------------------------------------------------
@@ -62,23 +51,9 @@
  * @protected
  * @return {Object}
 **/
-xap.data.formatter.DecimalFormatter.prototype.formatObject = function (object) {
-	/*Object*/
-	var fObject = object;
-	var sObject = "" + object;
-	if (typeof nObject != "number") {
-		try {
-	//			toFormat
-	//			= this.getSession().getTypeConversionService().convert(object, Number.class );
-			fObject = parseFloat(sObject);
-		}
-		catch (e) { // TypeConversionException
-			if (this.getLog().isDebug()) {
-				this.getLog().exception(e);
-			}
-		}
-	}
-	return xap.data.formatter.DecimalFormatter.format(fObject, this.getDecimalFormat());
+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
@@ -92,31 +67,7 @@
  *
 **/
 xap.data.formatter.DecimalFormatter.format = function (pfNumber, psFormatString) {
-//	var formArr = psFormatString.split("0") ;
-//	var sNumber = "" + pfNumber ;
-//
-//	// Sorry, half the world---we're making
-//	// "." the decimal separator; locales will come later
-//	var sepString = "." ;
-//
-//	var formWhole = "" ;
-//	var sepIndex = -1 ;
-//	while( ++sepIndex < sNumber.length){
-//		if( formArr[sepIndex].indexOf(sepString) != -1 ){
-//			break ;
-//		}
-//	}
-// Never throw away leading integer digits:
-//	var leadingDigits
-
-	// testing:
 	var nDecis = psFormatString.length - psFormatString.indexOf(".") - 1;
-	var nAcc = nDecis ;
-	var acc = 0.05 ;
-	while( --nAcc > 0 ){
-		acc = acc /10 ;
-	}
-	var sNumber = ""+pfNumber ;
-	return (pfNumber-acc).toFixed(nDecis);
+	return (pfNumber).toFixed(nDecis);
 };
 

Modified: incubator/xap/trunk/src/xap/data/formatter/FormatterChain.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/formatter/FormatterChain.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/formatter/FormatterChain.js (original)
+++ incubator/xap/trunk/src/xap/data/formatter/FormatterChain.js Wed Dec  6 01:58:43 2006
@@ -14,17 +14,15 @@
  *  limitations under the License.
  *
 **/
+
+Xap.provide("xap.data.formatter.FormatterChain"); 
+
 Xap.require("xap.session.ClientSession");
-//Xap.require("xap.data.InitializationException");
-//Xap.require("xap.util.Log") ;
 Xap.require("xap.data.formatter.JsFormatterImpl") ;
-
 Xap.require("xap.util.LogFactory");
-//Xap.require("xap.util.ResourceDictionary") ;
 Xap.require("xap.xml.dom.XapElement");
-// Used here a lot to avoid needing vectors:
 Xap.require("xap.util.ArrayHelper");
-Xap.provide("xap.data.formatter.FormatterChain"); 
+
 //-----------------------------------------------------------------------
 // Constructors.
 //-----------------------------------------------------------------------
@@ -58,27 +56,6 @@
 };
 Xap.setupClassAsSubclassOf("xap.data.formatter.FormatterChain", "xap.data.formatter.JsFormatterImpl");
 
-	//-----------------------------------------------------------------------
-	// Constants.
-	//-----------------------------------------------------------------------
-	// {0} formatter.toString()
-/*private static final String*/
-xap.data.formatter.FormatterChain.FORMATTER_INSTANCE_ALREADY_IN_CHAIN_MSGID = "formatterAlreadyInChain";
-/*private static final String*/
-xap.data.formatter.FormatterChain.NULL_FORMATTER_MSGID = "nullFormatter";
-	
-
-	//-----------------------------------------------------------------------
-	// Instance Variables.
-	//-----------------------------------------------------------------------
-	// contains the chain of formatters that will be applied in order to the
-	// argument of the format(Object) method.
-/**
- * @private Array
-**/
-xap.data.formatter.FormatterChain.prototype._formatters = null;
-	
-
 	
 //-----------------------------------------------------------------------
 // Formatter Interface.
@@ -142,75 +119,8 @@
 	}
 	this._formatters.push(formatter);
 };
-/**
- * Inserts the specified formatter at the specified index.
- * 
- * @param formatter
- * @param index
- *
- * @public
- * @return {void}
-**/
-xap.data.formatter.FormatterChain.prototype.insertFormatterAt = function (formatter, index)
{
-	if (formatter == null) {
-//			throw new IllegalArgumentException( ResourceDictionary.getMessage(
-//					NULL_FORMATTER_MSGID, FormatterChain.class ));
-		throw new xap.util.Exception("Attempted to insert a null in the 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);
-		}
-	}
-	xap.util.ArrayHelper.insertElementAt(this._formatters, formatter, index);
-};
-/**
- * Removes the first occurence of the formatter from this formatter chain.
- * 
- * @param formatter
- * @return the removed Formatter instance
- *
- * @public
- * @return {Formatter}
-**/
-xap.data.formatter.FormatterChain.prototype.removeFormatter = function (formatter) {
-	if (formatter == null) {
-//			throw new IllegalArgumentException( ResourceDictionary.getMessage(
-//					NULL_FORMATTER_MSGID, FormatterChain.class ));
-// TODO:  Improve exceptions
-		throw new xap.util.Exception("Requested null to be removed from chain.");
-	}
-	xap.util.ArrayHelper.removeElement(this._formatters, formatter);
-	return formatter;
-};
-/**
- * Removes the formatter at the specified index in the chain.
- * 
- * @param index
- * @return the removed Formatter instance.
- *
- * @public
- * @return {Formatter}
-**/
-xap.data.formatter.FormatterChain.prototype.removeFormatterAt = function (index) {
-	/*Formatter*/
-	var f = this._formatters[index];
-	this._formatters.splice(index, 1);
-	return f;
-};
-/**
- * Removes all Formatter instances from this chain.
- *
- * @public
- * @return {void}
-**/
-xap.data.formatter.FormatterChain.prototype.removeAll = function () {
-	this._formatters = new Array(0);
-};
+
+
 /**
  * @private
  * @return {Log}

Modified: incubator/xap/trunk/src/xap/data/formatter/JsFormatterImpl.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/formatter/JsFormatterImpl.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/formatter/JsFormatterImpl.js (original)
+++ incubator/xap/trunk/src/xap/data/formatter/JsFormatterImpl.js Wed Dec  6 01:58:43 2006
@@ -14,35 +14,17 @@
  *  limitations under the License.
  *
  **/
+ 
 /**
- * Ease-of-use base class for Formatter implementations that use
- * instances of the java.text.Format.
- *
- * @author ikaplansky
- */
+ * 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.data.formatter.JsFormatterImpl = function () {
-};
-Xap.setupClassAsSubclassOf("xap.data.formatter.JsFormatterImpl", "Object");
-//-----------------------------------------------------------------------
-// Instance Variables.
-//-----------------------------------------------------------------------
-/**
- * @private Format
-**/
-xap.data.formatter.JsFormatterImpl.prototype._format = null;
-/**
- * private ClientSession
- **/
-xap.data.formatter.JsFormatterImpl.prototype._session = null;
-/**
- * @private Element
-**/
-xap.data.formatter.JsFormatterImpl.prototype._formatterElement = null;
-//-----------------------------------------------------------------------
-// Formatter Interface.
-//-----------------------------------------------------------------------
+
+xap.data.formatter.JsFormatterImpl = function () {};
+
 /**
  * @see Formatter#initialize(String, ClientSession, Element)
  *
@@ -58,25 +40,9 @@
 	this._session = session;
 	this._formatterElement = formatterElement;
 };
-/**
- * @see Formatter#format(Object)
- *
- * @public
- * @param object{Object}
- * @return {Object}
- * @throws FormatException
-**/
-xap.data.formatter.JsFormatterImpl.prototype.format = function (object) {
-	try {
-		if (object != null) {
-			return this.formatObject(object);
-		}
-		throw new FormatException(FormatException.NULL_FORMAT_ARGUMENT_MSGID);
-	}
-	catch (e) { // IllegalArgumentException
-		throw new FormatException(FormatException.ILLEGAL_FORMAT_ARG_MSGID, object.toString(),
e);
-	}
-};
+
+
+
 //-----------------------------------------------------------------------
 // Public Methods.
 //-----------------------------------------------------------------------
@@ -110,6 +76,8 @@
 xap.data.formatter.JsFormatterImpl.prototype.getLog = function () {
 	return LogFactory.getLog("Formatter");
 };
+
+
 /**
  * @protected
  * @return {ClientSession}
@@ -117,13 +85,9 @@
 xap.data.formatter.JsFormatterImpl.prototype.getSession = function () {
 	return this._session;
 };
-/**
- * @protected
- * @return {Element}
-**/
-xap.data.formatter.JsFormatterImpl.prototype.getFormatterElement = function () {
-	return this._formatterElement;
-};
+
+
+
 /**
  * @protected
  * @param session{ClientSession}
@@ -132,21 +96,3 @@
 xap.data.formatter.JsFormatterImpl.prototype.setSession = function (session) {
 	this._session = session;
 };
-//-----------------------------------------------------------------------
-// Protected Abstract Methods.
-//-----------------------------------------------------------------------
-/**
- * Format the specified object according to this Formatter's configuration
- *
- * @param object to format
- * @return formatted object
- * @throws FormatException
- *
- * @protected
- * @param object{Object}
- * @return {Object}
- * @throws FormatException;
-**/
-xap.data.formatter.JsFormatterImpl.prototype.formatObject = function (object) {
-};
-

Modified: incubator/xap/trunk/src/xap/data/formatter/MessageFormatter.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/formatter/MessageFormatter.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/data/formatter/MessageFormatter.js (original)
+++ incubator/xap/trunk/src/xap/data/formatter/MessageFormatter.js Wed Dec  6 01:58:43 2006
@@ -32,6 +32,7 @@
 Xap.require("xap.data.formatter.JsFormatterImpl");
 // Peer
 Xap.require("xap.util.MessageFormat");
+Xap.require("xap.util.TypeUtils");
 
 //-----------------------------------------------------------------------
 // Constructors.
@@ -41,64 +42,17 @@
 };
 Xap.setupClassAsSubclassOf("xap.data.formatter.MessageFormatter", "xap.data.formatter.JsFormatterImpl");
 
-	//-----------------------------------------------------------------------
-	// Constants.
-	//-----------------------------------------------------------------------
-/*private static final String*/
-xap.data.formatter.MessageFormatter.ATTEMPT_AGRESSIVE_CONVERSION_MSGID = "attemptAggressiveConversion";
 
-
-	
-	//-----------------------------------------------------------------------
-	// Public Methods.
-	//-----------------------------------------------------------------------
 /**
- * @return the underlying java.text.MessageFormat object used by 
- * this formatter.
- *
- * @public
- * @return {MessageFormat}
-**/
-xap.data.formatter.MessageFormatter.prototype.getMessageFormat = function () {
-	return /*(MessageFormat)*/
-	this.getFormat();
+ * Formats based on the existing format string that was hopefully set already.
+ */
+xap.data.formatter.MessageFormatter.prototype.format = function (object) {
+	return xap.data.formatter.MessageFormatter.format(object, this.getFormat());
 };
-	
-	//-----------------------------------------------------------------------
-	// Protected Methods.
-	//-----------------------------------------------------------------------
-/**
- * @see AbstractJavaFormatter#formatObject 
- *
- * @protected
- * @return {Object}
- *
- * @param object{Object}
- * @throws FormatException  
-**/
-xap.data.formatter.MessageFormatter.prototype.formatObject = function (object) {
-	var result = null ;
-	try {
-		var formatStr = this.getFormat();
-		result = xap.data.formatter.MessageFormatter.format(object, formatStr);
-	}
-	catch (e) { // IllegalArgumentException
-		this.constructor.s_log.error("MessageFormatter.formatObject: \n" + e);
-		throw e;
-	}
-	return result ;
-};
-xap.data.formatter.MessageFormatter.format = function (obj, fmtStr) {
-	var arrObj = null;
-	if (typeof obj == "object" && typeof obj.length != "undefined") {
-		arrObj = new Array(obj.length);
-		for (var j = 0; j < obj.length; ++j) {
-			arrObj[j] = obj[j];
-		}
-	} else {
-		arrObj = [("" + obj)];
-	}
-	var result = xap.util.MessageFormat.format(fmtStr, arrObj);
-	return result;
+
+
+xap.data.formatter.MessageFormatter.format = function (obj, fmtStr) {
+	obj = xap.util.TypeUtils.convertToArray(obj); 
+	return xap.util.MessageFormat.format(fmtStr, obj);
 };
 

Modified: incubator/xap/trunk/src/xap/util/TypeUtils.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/TypeUtils.js?view=diff&rev=483005&r1=483004&r2=483005
==============================================================================
--- incubator/xap/trunk/src/xap/util/TypeUtils.js (original)
+++ incubator/xap/trunk/src/xap/util/TypeUtils.js Wed Dec  6 01:58:43 2006
@@ -28,6 +28,38 @@
 	return "" + obj;
 }
 
+
+xap.util.TypeUtils.convertToNumber = function( obj ) {
+	
+	//if not a number convert it to string then parse it
+	if (typeof obj != "number"){
+		obj = xap.util.TypeUtils.convertToString(obj);
+		return parseFloat(obj);
+	}
+	return obj;
+}
+
+
+/**
+ * Convert the passed in thing to an array.
+ * If it is an already an array we unwrap the dom types
+ * into a new one, otherwise we unwrap the singleton
+ * object into an array
+ */
+xap.util.TypeUtils.convertToArray  = function( obj ) {
+	
+	var returnArray = new Array();
+	if (obj instanceof Array){
+		for (var i =0; i<obj.length;i++){
+			returnArray.push(xap.util.TypeUtils._unwrapDomType(obj[i]));
+		}
+	}
+	else{
+		returnArray.push(xap.util.TypeUtils._unwrapDomType(obj));
+	}
+	return returnArray;
+}
+
 xap.util.TypeUtils._unwrapDomType = function(obj){
 	if (obj instanceof google.XNode){
 		if (obj.nodeType==google.DOM_TEXT_NODE){



Mime
View raw message