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/11/07 17:50:15 UTC

svn commit: r472178 - in /incubator/xap/trunk: WebContent/examples/widgets/AttributeTester.js WebContent/examples/widgets/combobox.html WebContent/examples/widgets/combobox.xal src/xap/Xap.js src/xap/mco/McoNamespaceHandler.js

Author: mturyn
Date: Tue Nov  7 09:50:11 2006
New Revision: 472178

URL: http://svn.apache.org/viewvc?view=rev&rev=472178
Log:
Added handling for a "path" attribute for MCO's---if the mco "src" doesn't resolve
to a valid constructor, we look for a "path" attribute for the MCO, and if found, load
from the URI indicated there (usual restrictions on XmlHttpRequests in mozilla apply).

If there's no path, or if the source obtained still hasn't provided a constructor,
we attempt a Xap.require(<src>); there seems to be some problem with resolving the path 
here, so this is more of a placeholder than anything else.

Xap has been altered to return a boolean depending on the success or failure in 
its 'require()' call; this is necessary for the nascent behaviour above, but is a good
idea anyway---we should know when our loads work.

The combobox example has been altered to test these changes:  the <script/> tag loading
AttributeTester has been removed from the html file, and a path to Attribute.js supplied
to the mco declaration in the xal file.  AttributeTester.js has been altered in a minor way 
--the xal file's source is AttributeTesterAlias instead of AttributeTester---in order to
test that we don't have any accidental file resolution going on anywhere.

Modified:
    incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js
    incubator/xap/trunk/WebContent/examples/widgets/combobox.html
    incubator/xap/trunk/WebContent/examples/widgets/combobox.xal
    incubator/xap/trunk/src/xap/Xap.js
    incubator/xap/trunk/src/xap/mco/McoNamespaceHandler.js

Modified: incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js?view=diff&rev=472178&r1=472177&r2=472178
==============================================================================
--- incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js (original)
+++ incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js Tue Nov  7 09:50:11 2006
@@ -1,5 +1,8 @@
 function AttributeTester() { }
 
+// Used in checking MCO reolution:
+AttributeTesterAlias = AttributeTester ;
+
 AttributeTester.prototype = new Object() ;
 
 AttributeTester.prototype.setAttribute = function(element, name, value){

Modified: incubator/xap/trunk/WebContent/examples/widgets/combobox.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/widgets/combobox.html?view=diff&rev=472178&r1=472177&r2=472178
==============================================================================
--- incubator/xap/trunk/WebContent/examples/widgets/combobox.html (original)
+++ incubator/xap/trunk/WebContent/examples/widgets/combobox.html Tue Nov  7 09:50:11 2006
@@ -28,7 +28,6 @@
 		</script>
 		
 		<script language="JavaScript" type="text/javascript" src="../../xapcore.js"></script>
-	    <script language="JavaScript" type="text/javascript" src="AttributeTester.js"></script>    
 	    								
 		<script language="JavaScript">
 		<!-- must do this before we load the actual application: -->						

Modified: incubator/xap/trunk/WebContent/examples/widgets/combobox.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/widgets/combobox.xal?view=diff&rev=472178&r1=472177&r2=472178
==============================================================================
--- incubator/xap/trunk/WebContent/examples/widgets/combobox.xal (original)
+++ incubator/xap/trunk/WebContent/examples/widgets/combobox.xal Tue Nov  7 09:50:11 2006
@@ -1,7 +1,12 @@
 <xal xmlns="http://www.openxal.org/xal" xmlns:dojo="http://www.dojotoolkit.org/">
 
 
-	<mco:mco xmlns:mco="http://www.openxal.org/mco" id="attributeSetter" src="AttributeTester" />
+	<mco:mco 
+		xmlns:mco="http://www.openxal.org/mco" 
+		id="attributeSetter" 
+		src="AttributeTesterAlias" 
+		path="../widgets/AttributeTester.js"
+	/>
 
 
 

Modified: incubator/xap/trunk/src/xap/Xap.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/Xap.js?view=diff&rev=472178&r1=472177&r2=472178
==============================================================================
--- incubator/xap/trunk/src/xap/Xap.js (original)
+++ incubator/xap/trunk/src/xap/Xap.js Tue Nov  7 09:50:11 2006
@@ -91,9 +91,13 @@
  * Method is used to require a class be loaded.  This 
  * works similar to a Java:
  * import com.nexaweb.MyClass;
+ * @return true if the desired class can be loaded, false 
+ * otherwise.
  * 
  */
 Xap.require = function(){
+	var result = false ;
+	
 	if( !xap || !xap.util || ! xap.util.Debug ){
 		dojo.require("xap.util.Debug") ;
 	}
@@ -105,28 +109,33 @@
 	var alreadyLoaded = (Xap.ourLoadedClasses[toLoad])?true:false ;
 	if( alreadyLoaded ){
 		Xap._logString += "\nRedundant load attempt: "+toLoad ;
-		return ;
-	}
-
-	// do we need to reload this file?
-	//---is it in the "debuggables" list?--are we reloading everything?
-	var needToDebugLoad = notModule && 
-	                        (xap.util.Debug._debugAll || 
-	                        	(xap.util.Debug._debugLoad  //
-	                        		&& xap.util.Debug._debuggables[toLoad] //this is one to load
-	                        		)
-	                        );
+		// We've already loaded this, so it's loadable:
+		result = true;
+	} else {
 
-	try {		
-		dojo.require.apply(dojo,arguments) ;
-		if(needToDebugLoad){
-			xap.util.Debug.addDebuggables([toLoad]) ;	
-			Xap.ourLoadedClasses[toLoad] = true ;			
+		// do we need to reload this file?
+		//---is it in the "debuggables" list?--are we reloading everything?
+		var needToDebugLoad = notModule && 
+		                        (xap.util.Debug._debugAll || 
+		                        	(xap.util.Debug._debugLoad  //
+		                        		&& xap.util.Debug._debuggables[toLoad] //this is one to load
+		                        		)
+		                        );
+	
+		try {		
+			dojo.require.apply(dojo,arguments) ;
+			if(needToDebugLoad){
+				xap.util.Debug.addDebuggables([toLoad]) ;	
+				Xap.ourLoadedClasses[toLoad] = true ;			
+			}
+			result = true ;
+		} catch (ee) {
+			Xap._logString += '\n'+ee ;
+			result = false ;
 		}
-	} catch (ee) {
-		Xap._logString += '\n'+ee ;
 	}
-
+	
+	return result ;
 }
 
 Xap.resolveConstructor = function(aString){

Modified: incubator/xap/trunk/src/xap/mco/McoNamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/mco/McoNamespaceHandler.js?view=diff&rev=472178&r1=472177&r2=472178
==============================================================================
--- incubator/xap/trunk/src/xap/mco/McoNamespaceHandler.js (original)
+++ incubator/xap/trunk/src/xap/mco/McoNamespaceHandler.js Tue Nov  7 09:50:11 2006
@@ -93,10 +93,69 @@
 					   	   element.toXml( true ))));
 	}
 	
+	// See if the 'src' describes a valid constructor:
+	var mcoConstructor = Xap.resolveConstructor(src) ;
+	// ...returned an object if it's there, else null.
+	// If there is no constructor, try the path---do it this
+	// way because we don't want to reload the source file
+	// every time we define an mco using the constructor:
+	if( !mcoConstructor ){
+		// If there's a path to code to evaluate first---if there is, evaluate it:
+		var path = element.getAttribute( "path" );
+		if( path ){
+			var sourceString = null ;
+			try {
+				var theRetriever = this._session.getRequestService() ;
+				sourceString = theRetriever.retrieve( path ).responseText;
+			} catch (eRetrieve){
+				throw new xap.util.Exception(
+											"Problem getting data from location "
+											+ path
+											+";\n"+eRetrieve
+												) ;
+			}
+			try {
+				dj_global.eval(sourceString) ;
+			} catch ( eEvaluation ){
+				throw new xap.util.Exception(
+											"Problem evaluating data from location "
+											+ path
+											+":\n"
+											+ sourceString
+											+"\n"+eEvaluation
+												) ;				
+			}		
+		}
+	}
+	
 	xap.mco.McoNamespaceHandler.s_log.debug( "Creating mco id: ["+ id + "] from source: [" 
 									 + src + "]");
+									 
+	mcoConstructor = Xap.resolveConstructor(src) ;
+	if( mcoConstructor == null ){
+		//Last-ditch:
+		// (Doesn't even seem to work well yet---some
+		// problem getting the proper path for the require()
+		// statement, doesn't get right root for (at least)
+		// "xap"
+		// TODO:  Get this right.
+		var success = Xap.require(src) ;
+		if( !success ){
+			throw new xap.util.Exception("Cannot load constructor for "
+										+ " MCO object"
+										+ " using Xap.require('"+src+"')"
+										+ "'.") ;
+		}	
+	
+		throw new xap.util.Exception("Cannot create an MCO object"
+										+ " from the constructor '"
+										+ src
+										+ "'.") ;	
+	
+	}									 
 	try {
-		var mco = eval("new " + src + "()");
+		// We can do the following because we're argless:
+		var mco = new mcoConstructor ;
 		xap.mco.McoNamespaceHandler.s_log.debug("Created mco: " + mco);
 		//TODO info if replacing existing macro?
 		session.getMcoContainer().put( id, mco );