incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r465723 - /incubator/xap/trunk/src/xap/taghandling/PluginDocumentHandler.js
Date Thu, 19 Oct 2006 18:56:04 GMT
Author: mturyn
Date: Thu Oct 19 11:56:03 2006
New Revision: 465723

URL: http://svn.apache.org/viewvc?view=rev&rev=465723
Log:
Implemented just-in-time loading for widget bridge classes; the only real change is that we
chaeck for the existence of a constructor before trying to use it, and if it's not around,
we'll try to load the code that should define it.

Modified:
    incubator/xap/trunk/src/xap/taghandling/PluginDocumentHandler.js

Modified: incubator/xap/trunk/src/xap/taghandling/PluginDocumentHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/taghandling/PluginDocumentHandler.js?view=diff&rev=465723&r1=465722&r2=465723
==============================================================================
--- incubator/xap/trunk/src/xap/taghandling/PluginDocumentHandler.js (original)
+++ incubator/xap/trunk/src/xap/taghandling/PluginDocumentHandler.js Thu Oct 19 11:56:03 2006
@@ -132,6 +132,39 @@
 	}
 }
 
+xap.taghandling.PluginDocumentHandler.prototype.obtainHandler = function(bridgeClassName){
+	var handlerConstructor = null ;
+	//now that we have the name of the bridge class, make a
+	//new one, loading its class first if necessary:
+	try {
+		// Note:  we could actually just do the require() without seeing
+		// if it's there yet, as require() checks first; still, it seems
+		// better (and less dependent on another behaviour working
+		// correctly) to check first:
+		handlerConstructor =  Xap.resolveConstructor(bridgeClassName ) ;
+		if (typeof handlerConstructor == "undefined" ){
+			Xap.require( bridgeClassName );
+			handlerConstructor =  Xap.resolveConstructor(bridgeClassName ) ;
+		}
+	} catch (classNotLoadableException){
+		xap.taghandling.PluginDocumentHandler.s_log.exception( "Exception while loading '" 	
+										+ bridgeClassName +"'"	
+										+ classNotLoadableException.toString() );
+									   
+		// If we didn't create a new handler just now,
+		// handler==null, so this.setHandlerForElement below
+		// will bomb on the xap.util.Hashtable.put(aKey,handler) that 
+		// it calls, and handler.setSession() below will also
+		// fail, so we might as well end it here:
+		throw classNotLoadableException ;				
+	
+	}
+	return new handlerConstructor() ;
+}
+
+
+
+
 /**
  * Parses an XML Element and returns a new instance of the tag-handling
  * bridge class that the tag name was mapped to. This is called whenever a 
@@ -173,10 +206,9 @@
 		}
 		var handler = null;
 		
-		//now that we have the name of the bridge class, make a
-		//new one
+		
 		try {
-			handler = eval( "new " + bridgeClass + "()" );
+			handler = this.obtainHandler( bridgeClass ) ;
 		} 
 		catch( ex ) {
 			xap.taghandling.PluginDocumentHandler.s_log.exception( "Exception during eval:" + 
@@ -194,7 +226,7 @@
 				if (lastPeriod>0){
 					bridgeClass = bridgeClass.substring(lastPeriod+1);
 				}
-				handler = eval( "new " + bridgeClass + "()" );
+				handler = this.obtainHandler( bridgeClass ) ;
 			}
 			catch(ex2){
 				xap.taghandling.PluginDocumentHandler.s_log.exception( "Exception during eval:" + 	



Mime
View raw message