incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmarga...@apache.org
Subject svn commit: r475630 - in /incubator/xap/trunk/src/xap/data/controller: Binding.js BindingResolver.js
Date Thu, 16 Nov 2006 08:18:43 GMT
Author: jmargaris
Date: Thu Nov 16 00:18:42 2006
New Revision: 475630

URL: http://svn.apache.org/viewvc?view=rev&rev=475630
Log:
Revamp of binding class

Modified:
    incubator/xap/trunk/src/xap/data/controller/Binding.js
    incubator/xap/trunk/src/xap/data/controller/BindingResolver.js

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=475630&r1=475629&r2=475630
==============================================================================
--- incubator/xap/trunk/src/xap/data/controller/Binding.js (original)
+++ incubator/xap/trunk/src/xap/data/controller/Binding.js Thu Nov 16 00:18:42 2006
@@ -16,150 +16,78 @@
  *
  */
 Xap.provide("xap.data.controller.Binding");
-Xap.require("xap.util.Vector");
-Xap.require("xap.session.ClientSession");
-//Xap.require("xap.UiUpdateQueue");
-//Xap.require("xap.data.DataException");
+
+Xap.require("xap.util.TypeUtils");
 Xap.require("xap.data.DataServiceImpl");
-Xap.require("xap.data.DataServiceFactory");
-//Xap.require("xap.data.datasource.DataAccessException") ;
-//Xap.require("xap.data.datasource.DataRetrievalListener") ;
-Xap.require("xap.data.datasource.DataSourceImpl");
-//Xap.require("xap.data.datasource.MalformedQueryException") ;
-//Xap.require("xap.data.datasource.UnsupportedBindingTypeException") ;
-//Xap.require("xap.data.formatter.FormatException") ;
-Xap.require("xap.data.formatter.JsFormatterImpl") ;
-//Xap.require("xap.util.TypeConversionException") ;
-Xap.require("xap.xml.dom.XapElement");
+Xap.require("xap.data.DataServiceFactory");
 Xap.require("xap.data.controller.BindingType");
-/**
- * It's a binding. It must be based on EITHER a DataSource or an iterator.
- * 
- * Maybe two separate subclasses should handle those cases? Depending on how
- * complicated it is I guess.
- * 
- * @author JMargaris
+Xap.require("xap.util.Vector");
+
+
+/*
+ * Binding relative to an iterator or a data source.
  *
  */
+ 
 /**
- * Construct a binding to the given data source with the
- * given select string.
- * <br/>
- * OR
- * <br/>
- * Construct a binding relative to a parent iterator.
- * When we resolve we query the iterator to get the 
- * proper parameters.
- * 
- * @param contextStack{ContextStack}
- * @param select{String}
- * @param name{String}
- * @param session{ClientSession}
- * @param bindingType{BindingType}
- * @param defaultValue{String}
- *
- * @param source{DataSource}
- * @param select{String}
- * @param session{ClientSession}
- * @param bindingType{BindingType}
- * @param defaultValue{String}
- * 
- * @throws DataControllerException
- */
-xap.data.controller.Binding = function () {
-	// Crude way to fold in two Java constructors into one JS one...
-	var theLog = xap.util.LogFactory.getLog("xap.data.controller.Binding");
-	if (arguments.length == 5) {
-		theLog.debug("5-arg Binding()");
-		var source = arguments[0];
-		var select = arguments[1];
-		var session = arguments[2];
-		var bindingType = arguments[3];
-		var defaultValue = arguments[4];
-		this._source = source;
-		this._select = select;
-		this._session = session;
-		this._bindingType = bindingType;
-		if (defaultValue != null) {
-			this._defaultValue = defaultValue;
-		}
-		this._currentValue = this._defaultValue;
-	} else {
-		if (arguments.length == 6) {
-			theLog.debug("6-arg Binding()");
-			var contextStack = arguments[0];
-			var select = arguments[1];
-			var name = arguments[2];
-			var session = arguments[3];
-			var bindingType = arguments[4];
-			var defaultValue = arguments[5];
-			this._select = select;
-			this._session = session;
-			this._bindingType = bindingType;
-			if (name != null && name.length > 0) {
-				this._source = xap.data.DataServiceFactory.getDataService(session).getDataSourceContainer().getDataSource(name);
-				if (this._source == null) {
+ * This should not be used, use on of the create...() methods instead.
+ */ 
+xap.data.controller.Binding = function(){
+	this._defaultValue = "";
+	this._targets = new xap.util.Vector();
+}
+ 
+xap.data.controller.Binding.createDataSourceBinding = 
+		function(source, select, session, bindingType, defaultValue){
+	var binding = new xap.data.controller.Binding();	
+	binding._source = source;
+	binding._select = select;
+	binding._session = session;
+	binding._bindingType = bindingType;
+	if (defaultValue != null) {
+		binding._defaultValue = defaultValue;
+	}
+	binding._currentValue = binding._defaultValue;
+	
+	return binding;	
+}
+
+xap.data.controller.Binding.createIteratorBinding = 
+		function(contextStack, select, name, session, bindingType, defaultValue){
+	var binding = new xap.data.controller.Binding();	
+	binding._select = select;
+	binding._session = session;
+	binding._bindingType = bindingType;
+	if (name && name.length > 0) {
+		binding._source = xap.data.DataServiceFactory.getDataService(session).getDataSourceContainer().getDataSource(name);
+		if (!binding._source) {
 			// Find the ancestor iterator context with the
 			// specified name, since there was not data source with
 			// that name
-					this._context = contextStack.getContext(name);
-					if (this._context == null) {
-				//					throw new DataControllerException(DataControllerException.QUICK_BINDING_NAMED_CONTEXT_NOT_FOUND,
-				//							name);
-						throw new xap.util.Exception("Named context for quick binding not found for '" + name
+ "'.");
-					}
-					this._source = this._context.getDataSource();
-				}
-			} else {
-		// No name specified, use the current context, this is relative to parent
-				this._context = contextStack.getCurrentContext();
-				if (this._context == null) {
-			//			throw new DataControllerException(DataControllerException.RELATIVE_BINDING_WITHOUT_PARENT,
select);
-					throw new xap.util.Exception("Attempted a relative binding without a parent: '" + select
+ "'.");
-				}
-				this._source = this._context.getDataSource();
+			binding._context = contextStack.getContext(name);
+			if (binding._context == null) {
+				throw new xap.util.Exception("Named context for quick binding not found for '" + name
+ "'.");
 			}
-			if (defaultValue != null) {
-				this._defaultValue = defaultValue;
-			}
-			this._currentValue = this._defaultValue;
-		// END: 6-argument (contextStack) version
-		} else {
-			var argString = "[";
-			for (var key in arguments) {
-				if (key == "length") {
-					continue;
-				}
-				if (key != "0") {
-					argString += ", ";
-				}
-				argString += arguments[key];
-			}
-			argString += "]";
-			xap.util.Utils.interrogate(arguments.callee, true);
-			throw new xap.util.Exception("Binding must be created using either" + "five or six parameters,
supplied " + arguments.length + ": " + argString + " .");
+			binding._source = binding._context.getDataSource();
 		}
 	}
-};
-Xap.setupClassAsSubclassOf("xap.data.controller.Binding", "Object");
-/*private*/
-xap.data.controller.Binding.prototype._select = null;
-/*private*/
-xap.data.controller.Binding.prototype._source = null;
-/*private*/
-xap.data.controller.Binding.prototype._context = null;
-/*private*/
-xap.data.controller.Binding.prototype._targets = new xap.util.Vector();
-/*private*/
-xap.data.controller.Binding.prototype._formatter = null;
-/*private*/
-xap.data.controller.Binding.prototype._session;
-/*private*/
-xap.data.controller.Binding.prototype._bindingType = xap.data.controller.BindingType.ONE_TIME;
-/*private*/
-xap.data.controller.Binding.prototype._defaultValue = "";
-/*private*/
-xap.data.controller.Binding.prototype._currentValue = null;
+	else {
+		// No name specified, use the current context, this is relative to parent
+		binding._context = contextStack.getCurrentContext();
+		if (binding._context == null) {
+			throw new xap.util.Exception("Attempted a relative binding without a parent: '" + select
+ "'.");
+		}
+		binding._source = binding._context.getDataSource();
+	}
+	
+	if (defaultValue != null) {
+		binding._defaultValue = defaultValue;
+	}
+	binding._currentValue = binding._defaultValue;
+	return binding;
+}
+ 
+ 
 /**
  * Get the client session for this binding.
  * @public
@@ -168,15 +96,8 @@
 xap.data.controller.Binding.prototype.getSession = function () {
 	return this._session;
 };
-/**
- * Set the binding type for this binding.
- * 
- * @param type{xap.data.controller.BindingType} The binding type.
- */
-/*public*/
-xap.data.controller.Binding.prototype.setBindingType = function (type) {
-	this._bindingType = type;
-};
+
+
 /**
  * Resolve the specified attribute.  This will return the current value associated
  * with this binding and potentially update the value when it becomes available or is
@@ -193,31 +114,33 @@
  * @throws UnsupportedBindingTypeException
  */
 /*public*/
-xap.data.controller.Binding.prototype.resolve = function (e, attributeName) {
-		//if we are based on a data source, just get the data off that source
+xap.data.controller.Binding.prototype.resolveAttribute = function (e, attributeName) {
+
+	//if we are based on a data source, just get the data off that source
 		
-		//if we are based on an iterator, this resolve must be in the context
-		//of a current iteration. So rather than saving it we just look it up
-		//each time. The timing here is important: this must be called
-		//DURING iteration
+	//if we are based on an iterator, this resolve must be in the context
+	//of a current iteration. So rather than saving it we just look it up
+	//each time. The timing here is important: this must be called
+	//DURING iteration
 	if (this._bindingType == xap.data.controller.BindingType.ONE_TIME) {
-			// Reset the current data value to the default value.
-			// Since we are a one time binding, we want the current
-			// data value from the datasource to be retrieved once,
-			// and only the default value should be able to show up
-			// prior to that retrieval.
+		// Reset the current data value to the default value.
+		// Since we are a one time binding, we want the current
+		// data value from the datasource to be retrieved once,
+		// and only the default value should be able to show up
+		// prior to that retrieval.
 		this._currentValue = this._defaultValue;
 	}
 	this.requestData();
 		
-		// If the binding type is not ONE_TIME or
-		// the binding type -is- ONE_TIME and the data was not
-		// returned by the request for data immediately
-		// (indicated by the current value being the default value,
-		// we need to add a bind target so that the data can be set
-		// at a later time 
-	if ((this._bindingType != xap.data.controller.BindingType.ONE_TIME) || ((this._bindingType
== xap.data.controller.BindingType.ONE_TIME) && (this._currentValue == this._defaultValue)))
{
-		this.addBindTarget(new AttributeValueLocation(e, attributeName));
+	// If the binding type is not ONE_TIME or
+	// the binding type -is- ONE_TIME and the data was not
+	// returned by the request for data immediately
+	// (indicated by the current value being the default value,
+	// we need to add a bind target so that the data can be set
+	// at a later time 
+	if ((this._bindingType != xap.data.controller.BindingType.ONE_TIME) || ((this._bindingType
== xap.data.controller.BindingType.ONE_TIME) && (this._currentValue === this._defaultValue)))
{
+		//IMPORTANT this needs to work!
+		//this.addBindTarget(new AttributeValueLocation(e, attributeName));
 	}
 	return this._currentValue;
 };
@@ -239,7 +162,7 @@
  * @throws UnsupportedBindingTypeException
  */
 /*public*/
-xap.data.controller.Binding.prototype.resolve = function (e, value, index) {
+xap.data.controller.Binding.prototype.resolveTextNode = function (e, value, index) {
 	/*boolean*/
 	var calledInParseInitialChildren = false;
 	if (index == -1) {
@@ -262,8 +185,10 @@
 		// (indicated by the current value being the default value,
 		// we need to add a bind target so that the data can be set
 		// at a later time 
-	if ((this._bindingType != xap.data.controller.BindingType.ONE_TIME) || ((this._bindingType
== xap.data.controller.BindingType.ONE_TIME) && (this._currentValue == this._defaultValue)))
{
-		this.addBindTarget(new TextNodeLocation(e, index, calledInParseInitialChildren));
+	if ((this._bindingType != xap.data.controller.BindingType.ONE_TIME) || ((this._bindingType
== xap.data.controller.BindingType.ONE_TIME) && (this._currentValue === this._defaultValue)))
{
+		
+		//IMPORTANT THIS NEEDS TO WORK!
+		//this.addBindTarget(new TextNodeLocation(e, index, calledInParseInitialChildren));
 	}
 	return this._currentValue;
 };
@@ -279,8 +204,8 @@
  * @throws DataAccessException, MalformedQueryException, UnsupportedBindingTypeException

  */
 xap.data.controller.Binding.prototype.resolve = function () {
-		// This non-location based resolution can only do its best to do an immediate
-		// query for the data to get the most current value and return it.
+	// This non-location based resolution can only do its best to do an immediate
+	// query for the data to get the most current value and return it.
 	this.requestData();
 	return this._currentValue;
 };
@@ -290,22 +215,15 @@
  * be called back in the UI event thread.
  */
 /*public*/
-xap.data.controller.Binding.prototype.setData = function () {
-//		synchronized (
-//		this._session.getDocumentRegistry().getUiDocument().getDomSynchronizationObject()) {
+xap.data.controller.Binding.prototype.setData = function () {
 	for (var i = 0; i < this._targets.size(); i++) {
 		/* TargetLocation */
 		var target = this._targets.elementAt(i);
 		target.setData(this._currentValue, this._session);
-		if (this._bindingType == xap.data.controller.BindingType.ONE_TIME) {
-				// Dangerous...will we have to recast?---add method
-				// to whatever it actually is, as opposed to
-				// what (in Java) it was to be recast-to?
-				//	((XmlLocation)target).invalidate();
+		if (this._bindingType == xap.data.controller.BindingType.ONE_TIME) {
 			target.invalidate();
 		}
-	}
-//		} // end synchronization block
+	}
 };
 /**
  * Adds a formatter to the end of the formatter chain.
@@ -340,13 +258,13 @@
  **/
 xap.data.controller.Binding.prototype.removeBindTarget = function (target) {
 	this._targets.removeElement(target);
-		// if there are no targets left deregister from the data source associated
-		// with this binding.
-		// The data source is responsible for cleaning up one time bindings when
-		// the asynchronous call terminates, so never do that here.
+	// if there are no targets left deregister from the data source associated
+	// with this binding.
+	// The data source is responsible for cleaning up one time bindings when
+	// the asynchronous call terminates, so never do that here.
 	if (this._bindingType != xap.data.controller.BindingType.ONE_TIME && this._targets.size()
== 0) {
-			// IMPORTANT REVISIT revisit this.the source should probably handle listeners removing
themselves while
-			// it is looping through !!!
+		// IMPORTANT REVISIT revisit this.the source should probably handle listeners removing
themselves while
+		// it is looping through !!!
 		this._source.removeListener(this);
 	}
 };
@@ -368,18 +286,34 @@
 	this._currentValue = this._defaultValue;
 	if (data != null) {
 		try {
-// TODO at least get the formatting back in:
-			this._currentValue = this.formatObject(data) ;
-//			this._currentValue = "" + data;
+
+			//	Get the formatted object and check to see if it is null
+			//	if it is, there is no reason to convert it, just set it to the default value
+			//	convert formatted object to string, which may also come back as a null
+			//	as is the case with getFirstTextChild() of an Element.  If converted object
+			//	is null then also set to the default value.
+			var formattedObject = this.formatObject(data) ;
+			if (formattedObject){
+				this._currentValue = xap.util.TypeUtils.convertToString(formattedObject);
+
+				if (!this._currentValue){
+					this._currentValue = this._defaultValue;
+				}
+			}
+			else{
+				this._currentValue = this._defaultValue;
+			}
 		}
 		catch (dataException) { //DataException
 			this._session.handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE +
": no data retrieved: "+dataException, dataException);
-//			}catch ( conversionException ) { //TypeConversionException
-//				this._session.handleException(DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE, conversionException);
 		}
 	}
-	// TODO implement this
-	//this.setDataOnUiUpdateThread();
+	
+	//IMPORTANT if this was an asynch call we now need to stick this value into the UI!
+	//this is the right code (??) but setData doesn't work right now
+	this.setData();
+	
+	
 };
 /*public*/
 xap.data.controller.Binding.prototype.getBindingType = function () {
@@ -407,26 +341,7 @@
 		this._source.getData(this._select, this, this._context);
 	}
 };
-/*private*/
-xap.data.controller.Binding.prototype.setDataOnUiUpdateThread = function () {
-	throw new xap.util.Exception("setDataOnUiUpdateThread not implemented");
-	try {
-		/*UiUpdateQueue*/
-		var updateQueue = this.getSession().getUiUpdateQueue();
-		if (this.updateQueue.isUiUpdateThread()) {
-			this.setData();
-		} else {
-			this.updateQueue.invokeLater(this.setData, null);
-		}
-	}
-	catch (e) { //Exception
-		this._session.handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE +
": can't add data to update queue.", new xap.util.Exception(e));
-// TODO:  better exception
-//					new DataControllerException(
-//						DataControllerException.BINDING_SET_SCHEDULE_EXCEPTION,
-//							e));
-	}
-};
+
 /**
  * This method and isDataRetrievalListener
  * will be used by the data source to determine

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=475630&r1=475629&r2=475630
==============================================================================
--- incubator/xap/trunk/src/xap/data/controller/BindingResolver.js (original)
+++ incubator/xap/trunk/src/xap/data/controller/BindingResolver.js Thu Nov 16 00:18:42 2006
@@ -201,7 +201,7 @@
 		curToken += curChar ;
 	}
 	/*Binding*/
-	var binding = new xap.data.controller.Binding(this.getContextStack(), select, dataSource,
this._session, bindType, defaultValue);
+	var binding = xap.data.controller.Binding.createIteratorBinding(this.getContextStack(),
select, dataSource, this._session, bindType, defaultValue);
 	if (formatter != null) {
 		binding.setFormatter(formatter);
 	}



Mime
View raw message