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 mt...@apache.org on 2006/09/25 16:26:57 UTC

svn commit: r449722 - in /incubator/xap/trunk: src/xap/session/DeclarativeArgumentParser.js testsrc/xap/mco/_TestDeclarativeArgumentParser.js

Author: mturyn
Date: Mon Sep 25 09:26:56 2006
New Revision: 449722

URL: http://svn.apache.org/viewvc?view=rev&rev=449722
Log:
Added a system container to DeclarativeArgumentParser, altered test so that the fake session used has a getSystemContainer() method.

Modified:
    incubator/xap/trunk/src/xap/session/DeclarativeArgumentParser.js
    incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js

Modified: incubator/xap/trunk/src/xap/session/DeclarativeArgumentParser.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/session/DeclarativeArgumentParser.js?view=diff&rev=449722&r1=449721&r2=449722
==============================================================================
--- incubator/xap/trunk/src/xap/session/DeclarativeArgumentParser.js (original)
+++ incubator/xap/trunk/src/xap/session/DeclarativeArgumentParser.js Mon Sep 25 09:26:56 2006
@@ -38,7 +38,7 @@
  * Creates a xap.session.DeclarativeArgumentParser
  * 
  * @class xap.session.DeclarativeArgumentParser is used to handle arguments in XML
- * declaritive method calls. For example:<br><br>
+ * declarative method calls. For example:<br><br>
  * <code>
  * onCommand=mco:myMco.doSomething( this.text, someOtherElement, true, 5)
  * </code>
@@ -84,6 +84,11 @@
 xap.session.DeclarativeArgumentParser = function( session ) {
 	this._session = session;
 	this._functionShortcuts = new xap.util.Hashtable() ;
+	//add ourselves to the system MCO container so that the data framework
+	//can look us up
+	// TODO:  Change this to "DeclarativeArgumentParser"?
+	// For now, keep older nomenclature:
+	this._session.getSystemContainer().put("McoArgumentParser",this);	
 }
 
 /** @private */
@@ -153,13 +158,13 @@
 			if (c==','){
 				xap.session.DeclarativeArgumentParser.s_log.debug("HIt a comma, returning arg" + arg);
 				parseResult._terminatingIndex = nextChar;
-				parseResult._parseStatus = ParseResult.COMMA_ENCOUNTERED;
+				parseResult._parseStatus = this._ParseResult.COMMA_ENCOUNTERED;
 				return parseResult;
 			}
 			else if (c==')'){
 				xap.session.DeclarativeArgumentParser.s_log.debug("HIt a close paren, returning arg" + arg);
 				parseResult._terminatingIndex = nextChar;
-				parseResult._parseStatus = ParseResult.CLOSING_PAREN;
+				parseResult._parseStatus = this._ParseResult.CLOSING_PAREN;
 				return parseResult;
 			}
 			else if (xap.util.Character.isWhiteSpace(c)){
@@ -202,22 +207,25 @@
 					mco = longcutText;
 				}
 
-//TODO we need to do more sharing of functionaltiy like checking validity of 
+//TODO we need to do more sharing of functionality like checking validity of 
 //container:name.method()
 				var containerIndex = mco.indexOf(":");
 				var containerName = null;
 				
-				if (containerIndex==-1){
-					throw new xap.util.Exception("Mmissing colon :" + mco);
+//				if (containerIndex==-1){
+//					throw new xap.util.Exception("Missing colon in: '" + mco+"'.");
+//				}
+// 	Default container will be system if there's no ":":
+				
+				if( containerIndex != -1 ){
+					containerName = mco.substring(0,containerIndex);
+					mco = mco.substring(containerIndex+1);
 				}
-
-				containerName = mco.substring(0,containerIndex);
-			   mco = mco.substring(containerIndex+1);
 				
 				var periodIndex = mco.lastIndexOf(".");
 				    
 				if (periodIndex==-1 || periodIndex==0 || periodIndex==mco.length-1){
-					throw new xap.util.Exception("Mmissing period:" + mco);
+					throw new xap.util.Exception("Missing period in: '" + mco+"'.");
 			    }
 				    
 				var mcoName = mco.substring(0,periodIndex);
@@ -229,7 +237,7 @@
 					
 				xap.session.DeclarativeArgumentParser.s_log.debug("Object event returned : " + callResult);
 				    
-				parseResult = new ParseResult(callResult,mcoCallResult._terminatingIndex);
+				parseResult = new this._ParseResult(callResult,mcoCallResult._terminatingIndex);
 				    
 				nextChar = mcoCallResult._terminatingIndex;
 			}
@@ -238,8 +246,8 @@
 			//if the literal is all whitespace this will throw an exception
 			else if (c==','){
 				xap.session.DeclarativeArgumentParser.s_log.debug("Hit comma after arg:" + arg);
-				return new ParseResult(this._stringToMcoArgument(arg, sourceElement, clientEvent),
-			                nextChar,ParseResult.COMMA_ENCOUNTERED);
+				return new this._ParseResult(this._stringToMcoArgument(arg, sourceElement, clientEvent),
+			                nextChar,this._ParseResult.COMMA_ENCOUNTERED);
 				//TODO check for all whitespace here or someplace else?
 				//_stringToMcoArgument should handle that?
 			}
@@ -258,11 +266,11 @@
 				//TODO try to detect this sort of thing better
 				//and don't allow myMco.do(x,y,) to pass
 				if (arg.trim().length==0){
-			  		return new ParseResult(null,nextChar,ParseResult.CLOSING_PAREN);
+			  		return new this._ParseResult(null,nextChar,this._ParseResult.CLOSING_PAREN);
 				}
 				else{
-					return new ParseResult(this._stringToMcoArgument(arg, sourceElement, clientEvent),
-				     	nextChar,ParseResult.CLOSING_PAREN);
+					return new this._ParseResult(this._stringToMcoArgument(arg, sourceElement, clientEvent),
+				     	nextChar,this._ParseResult.CLOSING_PAREN);
 			     	}
 			}
 			    
@@ -284,15 +292,15 @@
 	//text="{   }"
 	if (parseResult==null){
 		xap.session.DeclarativeArgumentParser.s_log.debug("Exited loop without a parse result at all");
-		return new ParseResult(this._stringToMcoArgument(arg,sourceElement, clientEvent),
-			args.length-1,ParseResult.END_OF_STRING);
+		return new this._ParseResult(this._stringToMcoArgument(arg,sourceElement, clientEvent),
+			args.length-1,this._ParseResult.END_OF_STRING);
 	}
 	
 	//if there was a parse result just set the terminating index up properly
 	else{
 		xap.session.DeclarativeArgumentParser.s_log.debug("Exited loop with a parse result");
 		parseResult._terminatingIndex = args.length-1;
-  		parseResult._parseStatus = ParseResult.END_OF_STRING;
+  		parseResult._parseStatus = this._ParseResult.END_OF_STRING;
    	return parseResult;
 	}
 }
@@ -320,7 +328,7 @@
 			args.push(result._resultObject);
 			xap.session.DeclarativeArgumentParser.s_log.debug("Push result: " + result._resultObject);
 			argumentStart = result._terminatingIndex;
-			if (result._parseStatus==ParseResult.CLOSING_PAREN){
+			if (result._parseStatus==this._ParseResult.CLOSING_PAREN){
  				break;
 			}
 		}
@@ -328,7 +336,7 @@
 		//if the result was null it could be because it ended with ')'
 		//or it could be end of string, which would be an error
 		else{
-			if (result._parseStatus!=ParseResult.CLOSING_PAREN){
+			if (result._parseStatus!=this._ParseResult.CLOSING_PAREN){
 				//TODO
 				throw new xap.util.Exception("Bad paramter string " + argumentsString);
 			}
@@ -337,7 +345,7 @@
 	}
 	
 	xap.session.DeclarativeArgumentParser.s_log.debug("Return parse result: " + args);
-	return new ParseResult(args,argumentStart);
+	return new this._ParseResult(args,argumentStart);
 }
 
 
@@ -387,17 +395,19 @@
 	  		//TODO
 			throw new xap.util.Exception("No bean with name: " + mcoName);
 	  	}
+
+	  	
 		return bean;
 	    //note that this RETURNS a macro and does not RUN it!
 	}
 	else if (arg=="true") {
 		xap.session.DeclarativeArgumentParser.s_log.debug("Found true");
 		//TODO do we have to do this sort of thing, can we rely on JS type conversion stuff?
-		return new Boolean(true);
+		return true ;
 	}
 	else if (arg=="false"){
 		xap.session.DeclarativeArgumentParser.s_log.debug("Found false");
-		return new Boolean(false);
+		return false ;
 	}
 	else{  
 		var num = parseFloat(arg);
@@ -465,13 +475,18 @@
 xap.session.DeclarativeArgumentParser.prototype._fireObjectEvent = function(containerName, mcoName,
 	methodName, args){
 	    
-	var container = this._session.getContainer(containerName);
+	var container =  this._session.getSystemContainer();
+	
+	if( (typeof containerName) != "undefined"
+			&& containerName != null
+			&& containerName.length > 0
+		){
+		container = this._session.getContainer(containerName) ;
+	}
 	
 	if (container==null){
-		
 		//TODO
-		throw new xap.util.Exception("Could not find container " + containerName);
-		
+		throw new xap.util.Exception("Could not find container " + containerName);	
 	}
 
 	var o  = container.get(mcoName);
@@ -514,7 +529,7 @@
 xap.session.DeclarativeArgumentParser.prototype._parseString = function(args, startIndex, terminatingCharacter){
 	
 	xap.session.DeclarativeArgumentParser.s_log.debug("Parse string :" + args + " at start index " + startIndex);
-	var result = new ParseResult(null,startIndex);
+	var result = new this._ParseResult(null,startIndex);
 	var arg = new String();
 	startIndex++; //first must be a " or '
 		
@@ -560,13 +575,28 @@
 	return result;
 }
 
+/**
+ * Adds a shortcut for a function call. When the shortcut is encountered
+ * before a '(' we replace it with the full text. For example
+ * addFunctionShortcut("*","Binding.bindTo") will make 
+ * *(..) the equivalent of Binding.bindTo(...)
+ * @param shortcut{String}
+ * @param fullText{String}
+ * @public
+ * @return {void}
+**/
+xap.session.DeclarativeArgumentParser.prototype.addFunctionShortcut = function(shortcut, fullText){
+	this._functionShortcuts.put(shortcut,fullText);
+}
 
 
 
 
 
 //TODO remove all these wrapper get/set methods?
-function ParseResult( resultObject, index, status ){
+// Hmmm...almost a private inner class---at least
+// you have to have a DAP around to get one of these:
+xap.session.DeclarativeArgumentParser.prototype._ParseResult = function( resultObject, index, status ){
 	
 	/** The result of the parse */
 	this._resultObject = resultObject;
@@ -578,8 +608,10 @@
 	this._parseStatus = status;
 }
 
-ParseResult.CLOSING_PAREN = 1;
-ParseResult.END_OF_STRING = 2;
-ParseResult.NO_INFORMATION = 0;
-ParseResult.COMMA_ENCOUNTERED = 3;
+
+
+xap.session.DeclarativeArgumentParser.prototype._ParseResult.CLOSING_PAREN = 1;
+xap.session.DeclarativeArgumentParser.prototype._ParseResult.END_OF_STRING = 2;
+xap.session.DeclarativeArgumentParser.prototype._ParseResult.NO_INFORMATION = 0;
+xap.session.DeclarativeArgumentParser.prototype._ParseResult.COMMA_ENCOUNTERED = 3;
 

Modified: incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js?view=diff&rev=449722&r1=449721&r2=449722
==============================================================================
--- incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js (original)
+++ incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js Mon Sep 25 09:26:56 2006
@@ -69,12 +69,14 @@
      addContainer: function(name, container) {this._namesToContainers.put(name, container)},
      getContainer: function(name) {return this._namesToContainers.get(name)},
      getDocumentContainer: function() {return this._documentContainer},
+     getSystemContainer: function() {return this._systemContainer},     
      initialize: function() {
-        this._declarativeArgumentParser = new xap.session.DeclarativeArgumentParser(this);
+		this._systemContainer = new xap.session.Container(this);
+		this._declarativeArgumentParser = new xap.session.DeclarativeArgumentParser(this);
         this._documentContainer = new xap.xml.DocumentContainer(this);
         this._namesToContainers = new xap.util.Hashtable(this);
         this._eventHandler = new xap.session.EventHandler(this);
-        this._mcoContainer = new xap.session.Container(this);
+        this._mcoContainer = new xap.session.Container(this);         
         this.addContainer('mco', this._mcoContainer); 
      }
    };
@@ -119,13 +121,16 @@
 
 function testContainer() {
  var session = {
+     getSystemContainer: function() {return this._systemContainer}, 
      getMcoContainer: function() {return this._mcoContainer},
      getEventHandler: function() {return this._eventHandler},
      getDeclarativeArgumentParser: function() {return this._declarativeArgumentParser},
      addContainer: function(name, container) {this._namesToContainers.put(name, container)},
      getContainer: function(name) {return this._namesToContainers.get(name)},
      getDocumentContainer: function() {return this._documentContainer},
+     getSystemContainer: function() {return this._systemContainer},     
      initialize: function() {
+     	this._systemContainer = new xap.session.Container(this);
         this._declarativeArgumentParser = new xap.session.DeclarativeArgumentParser(this);
         this._documentContainer = new xap.xml.DocumentContainer(this);
         this._namesToContainers = new xap.util.Hashtable(this);
@@ -343,8 +348,6 @@
    
    
 }
-
-