incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r454630 - in /incubator/xap/trunk/src/xap/data: bridge/FormatterChainBridge.js formatter/FormatterChain.js
Date Tue, 10 Oct 2006 05:52:17 GMT
Author: mturyn
Date: Mon Oct  9 22:52:16 2006
New Revision: 454630

URL: http://svn.apache.org/viewvc?view=rev&rev=454630
Log:
Formatting chaining enabled.

Modified:
    incubator/xap/trunk/src/xap/data/bridge/FormatterChainBridge.js
    incubator/xap/trunk/src/xap/data/formatter/FormatterChain.js

Modified: incubator/xap/trunk/src/xap/data/bridge/FormatterChainBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/bridge/FormatterChainBridge.js?view=diff&rev=454630&r1=454629&r2=454630
==============================================================================
--- incubator/xap/trunk/src/xap/data/bridge/FormatterChainBridge.js (original)
+++ incubator/xap/trunk/src/xap/data/bridge/FormatterChainBridge.js Mon Oct  9 22:52:16 2006
@@ -15,13 +15,15 @@
  *
  */
 Xap.provide("xap.data.bridge.FormatterChainBridge");
-Xap.require("xap.taghandling.AttributeConversionException");
-Xap.require("xap.data.InitializationException");
-Xap.require("xap.data.formatter.JsFormatterImpl");
+
 Xap.require("xap.data.formatter.FormatterChain");
+
+Xap.require("xap.taghandling.AttributeConversionException");
+//Xap.require("xap.data.InitializationException");
+
+
 //Xap.require("xap.data.formatter.FormatterInitializationException") ;
 Xap.require("xap.xml.dom.XapElement");
-Xap.require("xap.util.Vector");
 /**
  * FormatterChainBridge is the bridge class for the formatterChain tag used
  * by the data framework to declare a chain of formatters.
@@ -29,12 +31,13 @@
  * @author ikaplansky
  */
 xap.data.bridge.FormatterChainBridge = function () {
+	xap.data.bridge.FormatterBridge.call(this);
 };
 Xap.setupClassAsSubclassOf("xap.data.bridge.FormatterChainBridge", "xap.data.bridge.FormatterBridge");
 	
-	//-----------------------------------------------------------------------
-	// Constants.
-	//-----------------------------------------------------------------------
+//-----------------------------------------------------------------------
+// Constants.
+//-----------------------------------------------------------------------
 /*private static final String*/
 xap.data.bridge.FormatterChainBridge.FORMATTER_REFERENCE_ELEMENT_NAME = "formatterReference";
 /*private static final String*/
@@ -51,7 +54,7 @@
 **/
 xap.data.bridge.FormatterChainBridge.prototype.createFormatter = function () {
 	/*String*/
-	var className = getElement().getAttribute(XmlDataTokens.CLASS);
+	var className = this.getElement().getAttribute(xap.data.bridge.XmlDataTokens.CLASS);
 	/*FormatterChain*/
 	var formatter = null;
 	try {
@@ -64,7 +67,7 @@
 //			}
 	}
 	catch (e) { // AttributeConversionException
-		this.reportInvalidXmlException(XmlDataTokens.CLASS, className, this.getElement(), e);
+		this.reportInvalidXmlException(xap.data.XmlDataTokens.CLASS, className, this.getElement(),
e);
 	}
 	return formatter;
 };
@@ -76,19 +79,18 @@
  * @throws InitializationException 
 **/
 xap.data.bridge.FormatterChainBridge.prototype.initializeFormatter = function () {
-	superclass.initializeFormatter.call(this);
+	this.superclass.initializeFormatter.call(this);
 	/*FormatterChain*/
-	var chain = /*((FormatterChain))*/
-	this.getFormatter();
+	var chain = this.getFormatter();
 	/*Vector*/
-	var children = this.getElement().getChildren();
-	for (var i = 0; i < children.size(); i++) {
+	var children = this.getElement().childNodes;
+	for (var i = 0; i < children.length; i++) {
 		/*Object*/
-		var child = children.elementAt(i);
+		var child = children[i];
 		if (child instanceof xap.xml.dom.XapElement) {
 			/*Element*/
 			var formatterRef = /*((Element))*/
-			child;
+								child;
 			this.appendFormatter(chain, formatterRef);
 		} else {
 //			   throw new FormatterInitializationException(
@@ -103,9 +105,9 @@
 	}
 };
 	
-	//-----------------------------------------------------------------------
-	// Private Methods.
-	//-----------------------------------------------------------------------
+//-----------------------------------------------------------------------
+// Private Methods.
+//-----------------------------------------------------------------------
 /**
  * @private
  * @return {void}
@@ -115,12 +117,14 @@
  * @throws InitializationException  
 **/
 xap.data.bridge.FormatterChainBridge.prototype.appendFormatter = function (chain, formatterRef)
{
-	if (formatterRef.getLocalName().equals(xap.data.bridge.FormatterChainBridge.FORMATTER_REFERENCE_ELEMENT_NAME))
{
+	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 = getFormatterContainer().getFormatter(formatterId);
+			var f = this.getFormatterContainer().getFormatter(formatterId);
 			if (f != null) {
 				chain.appendFormatter(f);
 			} else {

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=454630&r1=454629&r2=454630
==============================================================================
--- incubator/xap/trunk/src/xap/data/formatter/FormatterChain.js (original)
+++ incubator/xap/trunk/src/xap/data/formatter/FormatterChain.js Mon Oct  9 22:52:16 2006
@@ -1,11 +1,33 @@
-
-Xap.require("xap.session.ClientSession") ;
-Xap.require("xap.data.InitializationException") ;
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *	  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.
+ *
+**/
+Xap.require("xap.session.ClientSession");
+//Xap.require("xap.data.InitializationException");
 //Xap.require("xap.util.Log") ;
-Xap.require("xap.util.LogFactory") ;
-Xap.require("xap.util.ResourceDictionary") ;
-Xap.require("xap.xml.dom.XapElement") ;
+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.
+//-----------------------------------------------------------------------
 /**
  * FormatterChain is a chain of formatters that are executed in order.
  * 
@@ -29,21 +51,21 @@
  * previously declared formatters. The formatterChain's id can be used in any 
  * place a formatter id is expected.
  * 
- * @version $Revision: 1.4 $
  * @author ikaplansky
  */
-Xap.provide("xap.data.formatter.FormatterChain") ; 
-Xap.setupClassAsSubclassOf("xap.data.formatter.FormatterChain","Formatter") ;
+xap.data.formatter.FormatterChain = function () {
+	xap.data.formatter.JsFormatterImpl.call(this) ;
+};
+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";
+/*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";
 	
 
 	//-----------------------------------------------------------------------
@@ -52,164 +74,148 @@
 	// contains the chain of formatters that will be applied in order to the
 	// argument of the format(Object) method.
 /**
- * @private Vector
+ * @private Array
 **/
-xap.data.formatter.FormatterChain.prototype._formatters =  null;
-	
-	//-----------------------------------------------------------------------
-	// Constructors.
-	//-----------------------------------------------------------------------
+xap.data.formatter.FormatterChain.prototype._formatters = null;
 	
-	public FormatterChain() {
-		// for use by reflection
-	}
-	
-	//-----------------------------------------------------------------------
-	// Formatter Interface.
-	//-----------------------------------------------------------------------
+
 	
-	/**
-	 * @see Formatter#initialize(String, ClientSession, Element)
-	  *
+//-----------------------------------------------------------------------
+// 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( String id, ClientSession
session,
-							 Element formatterElement ) {
- * @throws InitializationException 
-		this._formatters = new Array(0) ;
-	}
-
-	/**
-	 * @see Formatter#format(Object)
-	  *
+xap.data.formatter.FormatterChain.prototype.initialize = function (id, session, formatterElement)
{
+	this._formatters = new Array(0);
+};
+/**
+ * @see Formatter#format(Object)
+ *
  * @public
  * @return {Object}
+ * @throws FormatException 
 **/
-xap.data.formatter.FormatterChain.prototype.format  = function( Object object ) throws FormatException
{
-		/*Object*/
-var formattedObject =  object;
-		for( int i=0; i < this._formatters.size(); i++ ) {
-			/*Formatter*/
-var f =  (Formatter) this._formatters.elementAt( i ); 
-			formattedObject = f.format( formattedObject );
-		}
-		return formattedObject;
+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);
 	}
+	return formattedObject;
+};
 	
 	
-	//-----------------------------------------------------------------------
-	// Public Methods.
-	//-----------------------------------------------------------------------
-	
-	/**
-	 * Appends the specified formatter at the end of the chain
-	 * @param formatter
-	  *
+//-----------------------------------------------------------------------
+// Public Methods.
+//-----------------------------------------------------------------------
+/**
+ * Appends the specified formatter at the end of the chain
+ * @param formatter
+ *
  * @public
  * @return {void}
 **/
-xap.data.formatter.FormatterChain.prototype.appendFormatter = function( Formatter formatter
) {
-		/*if(*/
-var formatter = = null ) {
-			throw new IllegalArgumentException( ResourceDictionary.getMessage(
-					NULL_FORMATTER_MSGID, FormatterChain.class ));
+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);
 		}
-		if( this._formatters.contains( formatter )) {
-			if( getLog().isDebug() ) {
-				this.getLog().debug( ResourceDictionary.getMessage( 
-						FORMATTER_INSTANCE_ALREADY_IN_CHAIN_MSGID,
-						FormatterChain.class,
-						formatter.toString()));
-			}
-		}
-		this._formatters.addElement( formatter );
 	}
-
-	/**
-	 * Inserts the specified formatter at the specified index.
-	 * 
-	 * @param formatter
-	 * @param index
-	  *
+	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 formatter,
int index ) {
-		/*if(*/
-var formatter = = null ) {
-			throw new IllegalArgumentException( ResourceDictionary.getMessage(
-					NULL_FORMATTER_MSGID, FormatterChain.class ));
-		}
-		if( this._formatters.contains( formatter )) {
-			if( getLog().isDebug() ) {
-				this.getLog().debug( ResourceDictionary.getMessage( 
-						FORMATTER_INSTANCE_ALREADY_IN_CHAIN_MSGID,
-						FormatterChain.class,
-						formatter.toString()));
-			}
+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);
 		}
-		this._formatters.insertElementAt( formatter, index );
 	}
-	
-	/**
-	 * Removes the first occurence of the formatter from this formatter chain.
-	 * 
-	 * @param formatter
-	 * @return the removed Formatter instance
-	  *
+	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 formatter
) {
-		/*if(*/
-var formatter = = null ) {
-			throw new IllegalArgumentException( ResourceDictionary.getMessage(
-					NULL_FORMATTER_MSGID, FormatterChain.class ));
-		}
-		/*int*/
-var i =  this._formatters.indexOf( formatter );
-		/*if(*/
-var i = = -1 ) {
-			return null;
-		}
-		/*Formatter*/
-var f =  (Formatter) this._formatters.elementAt( i );
-		this._formatters.removeElementAt( i );
-		return f;
-	}
-
-	/**
-	 * Removes the formatter at the specified index in the chain.
-	 * 
-	 * @param index
-	 * @return the removed Formatter instance.
-	  *
+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( int index ) {
-		/*Formatter*/
-var f =  (Formatter) this._formatters.elementAt( index );
-		this._formatters.removeElementAt( index );
-		return f;
-	}
-	
-	/**
-	 * Removes all Formatter instances from this chain.
-	  *
+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.removeAllElements();
-	}
-	
+xap.data.formatter.FormatterChain.prototype.removeAll = function () {
+	this._formatters = new Array(0);
+};
 /**
  * @private
  * @return {Log}
 **/
-xap.data.formatter.FormatterChain.prototype.getLog = function(){
-		return LogFactory.getLog( "FormatterChain" );
-	}
-}
+xap.data.formatter.FormatterChain.prototype.getLog = function () {
+	return xap.util.LogFactory.getLog("xap.data.formatter.FormatterChain");
+};
+



Mime
View raw message