incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r428169 - /incubator/xap/trunk/src/xap/util/ObjectHierarchyAnalyzer.js
Date Wed, 02 Aug 2006 22:03:49 GMT
Author: mturyn
Date: Wed Aug  2 15:03:48 2006
New Revision: 428169

URL: http://svn.apache.org/viewvc?rev=428169&view=rev
Log:
Broke out object hierarchy analysis pieces of Xap into xap.util.ObjectHierarchyAnalyzer as
a first step of reducing Xap bloat.

Added:
    incubator/xap/trunk/src/xap/util/ObjectHierarchyAnalyzer.js

Added: incubator/xap/trunk/src/xap/util/ObjectHierarchyAnalyzer.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/ObjectHierarchyAnalyzer.js?rev=428169&view=auto
==============================================================================
--- incubator/xap/trunk/src/xap/util/ObjectHierarchyAnalyzer.js (added)
+++ incubator/xap/trunk/src/xap/util/ObjectHierarchyAnalyzer.js Wed Aug  2 15:03:48 2006
@@ -0,0 +1,161 @@
+/*
+ * 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.util.ObjectHierarchyAnalyzer = function () {}
+
+xap.util.ObjectHierarchyAnalyzer.getAllClasses = function (name, arr) {
+	var theArray = null;
+	if (!arr) {
+		theArray = new Array(0);
+	} else {
+		theArray = arr;
+	}
+	var pushClass = function () {
+		if (arguments[0][3]) {
+			theArray.push(arguments[0][1]);
+		}
+	}
+	// At each node
+	xap.util.ObjectHierarchyAnalyzer.walkClassTree(name, pushClass);
+	return theArray;
+}
+
+xap.util.ObjectHierarchyAnalyzer.walkClassTree = function (name, callbackFunction, level,
object) {
+	var theLevel = -1;
+	if (level) {
+		theLevel = level;
+	} else {
+		theLevel = 0;
+	}
+	var theObject = null;
+	if (object) {
+		theObject = object;
+	} else {
+		try {
+			theObject = eval(name);
+		}
+		catch (ee) {
+			return;
+		}
+	}
+	var args = [];
+	args.push(this);
+	args.push(name);
+	args.push(theObject);
+	if (theObject.prototype) {
+		// Let the callback know that this is a class, not a package node:
+		args.push(true);
+		callbackFunction.call(this, args);
+	} else {
+		for (var oo in theObject) {			
+		// Let the callback know that this is a package node, not a class
+			args.push(false);
+	 // Better in a different order?
+			callbackFunction.call(this, args);
+			xap.util.ObjectHierarchyAnalyzer.walkClassTree(name + "." + oo, callbackFunction, theLevel
+ 1);
+		}
+	}
+	return;
+}
+
+
+// Regular expressions for finding and manipulation Xap.require() or dojo.require()
+// statements in code:
+
+xap.util.ObjectHierarchyAnalyzer.allFullstopsRegexp = Xap.allFullstopsRegexp ;
+
+xap.util.ObjectHierarchyAnalyzer.require_startRegexp = /^.*require\S\s*['"]/;
+xap.util.ObjectHierarchyAnalyzer.require_endRegexp = /["'].*$/;
+// Exclude algorithmic .require() statements that aren't just quoted strings:
+xap.util.ObjectHierarchyAnalyzer.requireRegexp = /(Xap|dojo)\.require\(\s*['"]\S*?['"]\s*\)/mg;
+xap.util.ObjectHierarchyAnalyzer.getDependencies = function (className) {
+	var requirements = [];
+	if (!xap.util.ObjectHierarchyAnalyzer._requestService) {
+		xap.util.ObjectHierarchyAnalyzer._requestService = new xap.requestservice.RequestService(this);
+	}
+	
+	// Build a file path from a class name:
+	var filePath = "../../src/" + className.replace(xap.util.ObjectHierarchyAnalyzer.allFullstopsRegexp,
"/") + ".js";
+	
+	// Get the source for the class:
+	var classSource = xap.util.ObjectHierarchyAnalyzer._requestService.retrieve(filePath).responseText;
+	
+	// These are the lines that have a Xap.require() or a dojo.require() statement in them:
+	var requireLines = classSource.match(xap.util.ObjectHierarchyAnalyzer.requireRegexp);
+	if (!requireLines) {
+		return requirements;
+	}
+	for (var jj = 0; jj < requireLines.length; ++jj) {
+		// extract the argument to the .require():
+		var req = requireLines[jj].replace(xap.util.ObjectHierarchyAnalyzer.require_startRegexp,
"");
+		req = req.replace(xap.util.ObjectHierarchyAnalyzer.require_endRegexp, "");
+		requirements.push(req);
+		var bkp = -1;
+	}
+	return requirements;
+}
+
+xap.util.ObjectHierarchyAnalyzer.getAllDependencies = function (name, holder, level) {
+	var theLevel = -1;
+	if (level) {
+		theLevel = level;
+	} else {
+		theLevel = 0;
+	}
+	if (holder && holder[name]) {
+		return;
+	}
+	var theHolder = null;
+	if (!holder) {
+		theHolder = new Object();
+	} else {
+		theHolder = holder;
+	}
+	try {
+		var theObject = eval(name);
+	}
+	catch (ee) {
+		Xap._logString += ("Problem with getting dependencies for \"" + name + "\":\n" + ee);
+		return;
+	}
+	if (!theObject) {
+		return;
+	}
+	if (theObject.prototype) {
+		theHolder[name] = xap.util.ObjectHierarchyAnalyzer.getDependencies(name);
+		var nextLevel = 1 + theLevel;
+		for (var ii = 0; ii < theHolder[name].length; ++ii) {
+			xap.util.ObjectHierarchyAnalyzer.getAllDependencies((theHolder[name])[ii], theHolder,
nextLevel);
+		}
+	} else {
+		if (theLevel == 0) {
+			var clazzes = xap.util.ObjectHierarchyAnalyzer.getAllClasses("xap");
+			var nextLevel = 1 + theLevel;
+			for (var jj = 0; jj < clazzes.length; ++jj) {
+				xap.util.ObjectHierarchyAnalyzer.getAllDependencies(clazzes[jj], theHolder, nextLevel);
+			}
+			var arr = new Array(0);
+			for (key in theHolder) {
+				arr.push(key + "::" + theHolder[key].join(","));
+			}
+			prompt("", arr.join("^"));
+			return theHolder;
+		}
+	}
+}
+



Mime
View raw message