Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactoring

  • Loading branch information...
commit 18db051e6bf5ac2b21bdfc816e926c0a1c207a76 1 parent f30229c
billy authored
View
11 .project
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>cfmongo</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
View
269 Mongo.cfc
@@ -1,272 +1,11 @@
-<cfcomponent output="false">
+<cfcomponent output="false" hint="Convenience wrapper for MongoDB. @see components.MongoDB for wrapper details">
<cfscript>
-//This maybe should be a config object
-config = {
- server_name = 'localhost',
- server_port = 27017,
- db_name = 'default_db',
- collection_name = 'default_collection'
- };
-
-
-//maybe this goes in super class? Or make factory for returning mongos
-/*--------------------------------------------------------------------
- mongo1 = factory.createMongo(config);
---------------------------------------------------------------------*/
-mongo = createObject('java', 'com.mongodb.Mongo').init( variables.config.server_name , variables.config.server_port );
-db = mongo.getDb(config.db_name);
-collection = db.getCollection(config.collection_name);
-expression_builder = createObject('component', 'ExpressionBuilder') ;
-
- /*---------------------------------------------------------------------
-
- DSL for MongoDB searches:
-
- results = mongo.collection('blog').
- startsWith('name','foo'). //string
- endsWith('title','bar'). //string
- exists('field','value'). //string
- regex('field','value'). //string
- before('field', 'value'). //date
- after('field', 'value'). //date
- $eq('field','value'). //numeric
- $gt('field','value'). //numeric
- $gte('field','value'). //numeric
- $lte('field','value'). //numeric
- $in('field','value'). //array
- $nin('field','value'). //array
- $mod('field','value'). //numeric
- size('field','value'). //numeric
- search('title,author,date', limit, start);
-
- search(keys=list_of_keys_to_return,sort={field=direction},limit=num,start=num);
-
-
-
-
--------------------------------------------------------------------------------------*/
-
-builder = createObject('component','ExpressionBuilder');
-
-
-function getMongo(){
- return mongo;
-}
-
-//------------------------------------------------------------------------//
-function add(key,value,o){
- //add key value pair to object ... todo
-}
-
-
-function put(o){
- var doc = createObject('java', 'com.mongodb.BasicDBObject').init();
- var id = chr(0);
- doc.putAll(o);
- id = collection.insert(doc).get("_id");
- o._id = id; //add the _id object to the struct
- return id;
-}//end function
-
-
-
-function get(field,value){
- var q = createObject('java', 'com.mongodb.BasicDBObject').init(field,value);
- var cursor = collection.find(q);
- return cursor.next();
-} //end function
-
-
-//when only a string id is available
-function getById(id){
- var objId = createObject('java','com.mongodb.ObjectId').init(id);
- return get("_id", objId);
- } //en
-
-
-function count(){
- return collection.getCount();
-}
-
-
-function findOne(){
- return collection.findOne();
-} //
-
-
-function findAll(){
- var sort = {pub_date = -1};
- var sort_spec = createObject('java', 'com.mongodb.BasicDBObject').init(sort);
- return collection.find().sort( sort_spec ).toArray();
-} //end function
-
-
-function delete(o){
- var obj = get("_id", o._id);
- return collection.remove(obj); //id's of deleted items
-} //end function
-
-
-//Note the ObjectId object. This creates an ObjectId from
-//the string representation of
-
-function deleteById(id){
- var objId = createObject('java','com.mongodb.ObjectId').init(id);
- var obj = get("_id", objId);
- return collection.remove(obj); //id's of deleted items
-} //en
-
-
-function update(o){
- var obj = get("_id", o._id);
- var new_object = createObject('java', 'com.mongodb.BasicDBObject').init(o);
- return collection.update(obj, new_object, false, false);
-
-} //end function
-
-
-
-//swtich to or create database
-function getDB(db_name){
- return mongo.getDb(db_name);
-}
-
-
-//switch to or create collection
-function getCollection(collection_name){
- collection = db.getCollection(collection_name);
- return collection;
-}
-
-function collection(collection_name){
- collection = db.getCollection(collection_name);
- return this;
-}
-
-
-function listToStruct(list){
- var item = '';
- var s = {};
- var i = 1;
- for(i; i lte listlen(list); i++) {
- s.put(listgetat(list,i),1);
- }
- return s;
-}
-
-
-/*---------------------------------------------------------
- Expression Builder Wrappers
- ---------------------------------------------------------*/
-
-function startsWith(element, val){
- expression_builder.startsWith(element, val);
- return this;
-}
-
-function endsWith(element, val){
- expression_builder.endsWith(element, val);
- return this;
-}
-
-
-function exists(element, val){
- var regex = '.*' & val & '.*';
- expression_builder.exists( element, regex );
- return this;
-}
-
-function regex(element, val){
- var regex = val;
- expression_builder.regex( element, regex );
- return this;
-}
-
-function where( js_expression ){
- expression_builder.where( js_expression );
- return this;
-}
-
-function inArray(element, val){
- expression_builder.inArray( element, val );
- return this;
-}
-
- //vals should be list or array
-function $in(element,vals){
- expression_builder.$in(element,vals);
- return this;
-}
-
-function $nin(element,vals){
- expression_builder.$in(element,vals);
- return this;
-}
-
-
-function $eq(element,val){
- expression_builder.$eq(element,val);
- return this;
-}
-
-
-function $ne(element,val){
- expression_builder.$ne(element,val);
- return this;
-}
-
-
-function $lt(element,val){
- expression_builder.$lt(element,val);
- return this;
- }
-
-
-function $lte(element,val){
- expression_builder.$lte(element,val);
- return this;
-}
-
-
-function $gt(element,val){
- expression_builder.$gt(element,val);
- return this;
-}
-
-
-function $gte(element,val){
- expression_builder.$gte(element,val);
- return this;
-}
-
-function before(element,val){
- expression_builder.before(element,val);
- return this;
-}
-
-function after(element,val){
- expression_builder.after(element,val);
- return this;
-}
-
+ function init(){
+ return createObject('component','components.MongoDB');
+ }
</cfscript>
-<cffunction name="search">
- <cfargument name="keys" type="string" required="false" default="" hint="A list of keys to return" />
- <cfargument name="limit" type="numeric" required="false" default="0" hint="Number of the maximum items to return" />
- <cfargument name="sort" type="struct" required="false" default="#structNew()#" hint="A struct representing how the items are to be sorted" />
- <cfscript>
- var key_exp = listToStruct(arguments.keys);
- var _keys = createObject('java', 'com.mongodb.BasicDBObject').init(key_exp);
- var search_results = [];
- var criteria = expression_builder.get();
- var q = createObject('java', 'com.mongodb.BasicDBObject').init(criteria);
- search_results = collection.find(q,_keys).limit(limit);
- return search_results;
- </cfscript>
-</cffunction>
-
</cfcomponent>
View
0  components/Mongo.cfc → components/MongoDB.cfc
File renamed without changes
View
223 javaloader/JavaLoader.cfc
@@ -0,0 +1,223 @@
+<!--- Document Information -----------------------------------------------------
+
+Title: JavaLoader.cfc
+
+Author: Mark Mandel
+Email: mark@compoundtheory.com
+
+Website: http://www.compoundtheory.com
+
+Purpose: Utlitity class for loading Java Classes
+
+Usage:
+
+Modification Log:
+
+Name Date Description
+================================================================================
+Mark Mandel 08/05/2006 Created
+Mark Mandel 22/06/2006 Added verification that the path exists
+
+------------------------------------------------------------------------------->
+<cfcomponent name="JavaLoader" hint="Loads External Java Classes, while providing access to ColdFusion classes">
+
+<cfscript>
+ instance = StructNew();
+ instance.static.uuid = "A0608BEC-0AEB-B46A-0E1E1EC5F3CE7C9C";
+</cfscript>
+
+<!------------------------------------------- PUBLIC ------------------------------------------->
+
+<cffunction name="init" hint="Constructor" access="public" returntype="JavaLoader" output="false">
+ <cfargument name="loadPaths" hint="An array of directories of classes, or paths to .jar files to load" type="array" default="#ArrayNew(1)#" required="no">
+ <cfargument name="loadColdFusionClassPath" hint="Loads the ColdFusion libraries" type="boolean" required="No" default="false">
+ <cfargument name="parentClassLoader" hint="(Expert use only) The parent java.lang.ClassLoader to set when creating the URLClassLoader" type="any" default="" required="false">
+
+ <cfscript>
+ var iterator = arguments.loadPaths.iterator();
+ var file = 0;
+ var classLoader = 0;
+ var networkClassLoaderClass = 0;
+ var networkClassLoaderProxy = 0;
+
+ initUseJavaProxyCFC();
+
+ if(arguments.loadColdFusionClassPath)
+ {
+ //arguments.parentClassLoader = createObject("java", "java.lang.Thread").currentThread().getContextClassLoader();
+ //can't use above, as doesn't work in some... things
+
+ arguments.parentClassLoader = getPageContext().getClass().getClassLoader();
+
+ //arguments.parentClassLoader = createObject("java", "java.lang.ClassLoader").getSystemClassLoader();
+ //can't use the above, it doesn't have the CF stuff in it.
+ }
+
+ ensureNetworkClassLoaderOnServerScope();
+
+ //classLoader = createObject("java", "com.compoundtheory.classloader0.NetworkClassLoader").init();
+ networkClassLoaderClass = getServerURLClassLoader().loadClass("com.compoundtheory.classloader.NetworkClassLoader");
+
+ networkClassLoaderProxy = createJavaProxy(networkClassLoaderClass);
+
+ if(isObject(arguments.parentClassLoader))
+ {
+ classLoader = networkClassLoaderProxy.init(arguments.parentClassLoader);
+ }
+ else
+ {
+ classLoader = networkClassLoaderProxy.init();
+ }
+
+ while(iterator.hasNext())
+ {
+ file = createObject("java", "java.io.File").init(iterator.next());
+ if(NOT file.exists())
+ {
+ throw("PathNotFoundException", "The path you have specified could not be found", file.getAbsolutePath() & " does not exist");
+ }
+
+ classLoader.addUrl(file.toURL());
+ }
+
+ //pass in the system loader
+ setURLClassLoader(classLoader);
+
+ return this;
+ </cfscript>
+</cffunction>
+
+<cffunction name="create" hint="Retrieves a reference to the java class. To create a instance, you must run init() on this object" access="public" returntype="any" output="false">
+ <cfargument name="className" hint="The name of the class to create" type="string" required="Yes">
+ <cfscript>
+ var class = getURLClassLoader().loadClass(arguments.className);
+
+ return createJavaProxy(class);
+ </cfscript>
+</cffunction>
+
+<cffunction name="getURLClassLoader" hint="Returns the java.net.URLClassLoader in case you need access to it" access="public" returntype="any" output="false">
+ <cfreturn instance.ClassLoader />
+</cffunction>
+
+<cffunction name="getVersion" hint="Retrieves the version of the loader you are using" access="public" returntype="string" output="false">
+ <cfreturn "0.6">
+</cffunction>
+
+<!------------------------------------------- PACKAGE ------------------------------------------->
+
+<!------------------------------------------- PRIVATE ------------------------------------------->
+
+<cffunction name="ensureNetworkClassLoaderOnServerScope"
+ hint="makes sure there is a URL class loader on the server scope that can load me up some networkClassLoader goodness"
+ access="private" returntype="void" output="false">
+ <cfscript>
+ var Class = createObject("java", "java.lang.Class");
+ var Array = createObject("java", "java.lang.reflect.Array");
+ var jars = queryJars();
+ var iterator = jars.iterator();
+ var file = 0;
+ var urls = Array.newInstance(Class.forName("java.net.URL"), ArrayLen(jars));
+ var counter = 0;
+ var urlClassLoader = 0;
+ var key = instance.static.uuid & "." & getVersion();
+ //server scope uuid
+
+ //we have it already? escape.
+ if(StructKeyExists(server, key))
+ {
+ return;
+ }
+
+ while(iterator.hasNext())
+ {
+ Array.set(urls, counter, createObject("java", "java.io.File").init(iterator.next()).toURL());
+ counter = counter + 1;
+ }
+
+ urlClassLoader = createObject("java", "java.net.URLClassLoader").init(urls);
+
+ //put it on the server scope
+ server[key] = urlClassLoader;
+ </cfscript>
+</cffunction>
+
+<cffunction name="createJavaProxy" hint="create a javaproxy, dependent on CF server settings" access="private" returntype="any" output="false">
+ <cfargument name="class" hint="the java class to create the proxy with" type="any" required="Yes">
+ <cfscript>
+ if(getUseJavaProxyCFC())
+ {
+ return createObject("component", "JavaProxy")._init(arguments.class);
+ }
+
+ return createObject("java", "coldfusion.runtime.java.JavaProxy").init(arguments.class);
+ </cfscript>
+</cffunction>
+
+<cffunction name="initUseJavaProxyCFC" hint="initialise whether or not to use the JavaProxy CFC instead of the coldfusion java object" access="public" returntype="string" output="false">
+ <cfscript>
+ setUseJavaProxyCFC(false);
+
+ try
+ {
+ createObject("java", "coldfusion.runtime.java.JavaProxy");
+ }
+ catch(Object exc)
+ {
+ setUseJavaProxyCFC(true);
+ }
+ </cfscript>
+</cffunction>
+
+<cffunction name="queryJars" hint="pulls a query of all the jars in the /resources/lib folder" access="private" returntype="array" output="false">
+ <cfscript>
+ var qJars = 0;
+ //the path to my jar library
+ var path = getDirectoryFromPath(getMetaData(this).path) & "lib/";
+ var jarList = "";
+ var aJars = ArrayNew(1);
+ var libName = 0;
+ </cfscript>
+
+ <cfdirectory action="list" name="qJars" directory="#path#" filter="*.jar" sort="name desc"/>
+ <cfloop query="qJars">
+ <cfscript>
+ libName = ListGetAt(name, 1, "-");
+ //let's not use the lib's that have the same name, but a lower datestamp
+ if(NOT ListFind(jarList, libName))
+ {
+ ArrayAppend(aJars, path & "/" & name);
+ jarList = ListAppend(jarList, libName);
+ }
+ </cfscript>
+ </cfloop>
+
+ <cfreturn aJars>
+</cffunction>
+
+<cffunction name="getServerURLClassLoader" hint="returns the server URL class loader" access="private" returntype="any" output="false">
+ <cfreturn server[instance.static.uuid & "." & getVersion()] />
+</cffunction>
+
+<cffunction name="setURLClassLoader" access="private" returntype="void" output="false">
+ <cfargument name="ClassLoader" type="any" required="true">
+ <cfset instance.ClassLoader = arguments.ClassLoader />
+</cffunction>
+
+<cffunction name="getUseJavaProxyCFC" access="private" returntype="boolean" output="false">
+ <cfreturn instance.UseJavaProxyCFC />
+</cffunction>
+
+<cffunction name="setUseJavaProxyCFC" access="private" returntype="void" output="false">
+ <cfargument name="UseJavaProxyCFC" type="boolean" required="true">
+ <cfset instance.UseJavaProxyCFC = arguments.UseJavaProxyCFC />
+</cffunction>
+
+<cffunction name="throw" access="private" hint="Throws an Exception" output="false">
+ <cfargument name="type" hint="The type of exception" type="string" required="Yes">
+ <cfargument name="message" hint="The message to accompany the exception" type="string" required="Yes">
+ <cfargument name="detail" type="string" hint="The detail message for the exception" required="No" default="">
+ <cfthrow type="#arguments.type#" message="#arguments.message#" detail="#arguments.detail#">
+</cffunction>
+
+</cfcomponent>
View
354 javaloader/JavaProxy.cfc
@@ -0,0 +1,354 @@
+<!--- Document Information -----------------------------------------------------
+
+Title: JavaProxy.cfc
+
+Author: Mark Mandel
+Email: mark@compoundtheory.com
+
+Website: http://www.compoundtheory.com
+
+Purpose: JavaProxy to replace the ColdFusion one when you don't have access
+ to coldfusion.* packages due to CF8 settings.
+
+Usage:
+
+Modification Log:
+
+Name Date Description
+================================================================================
+Mark Mandel 27/08/2007 Created
+
+------------------------------------------------------------------------------->
+
+<cfcomponent output="false">
+
+<!---
+ All CF based methods have a _ in front, so that they don't interfere with the possible Java
+ calls
+ --->
+
+<cffunction name="_init" hint="Constructor" access="public" returntype="JavaProxy" output="false">
+ <cfargument name="class" hint="the java.lang.Class object this represents" type="any" required="Yes">
+ <cfscript>
+ var classLoader = createObject("java", "java.lang.ClassLoader").getSystemClassLoader();
+ var objectClass = classLoader.loadClass("java.lang.Object");
+
+ _setArray(createObject("java", "java.lang.reflect.Array"));
+
+ _setClassMethod(objectClass.getMethod("getClass", JavaCast("null", 0)));
+
+ _setObjectClass(objectClass);
+
+ _setClass(arguments.class);
+
+ _setModifier(createObject("java", "java.lang.reflect.Modifier"));
+
+ _setStaticFields();
+
+ _initMethodCollection();
+
+ return this;
+ </cfscript>
+</cffunction>
+
+<cffunction name="init" hint="create an instance of this object" access="public" returntype="any" output="false">
+ <cfscript>
+ var constructor = 0;
+ var instance = 0;
+
+ //make sure we only ever have one instance
+ if(_hasClassInstance())
+ {
+ return _getClassInstance();
+ }
+
+ constructor = _resolveMethodByParams("Constructor", _getClass().getConstructors(), arguments);
+
+ instance = constructor.newInstance(_buildArgumentArray(arguments));
+
+ _setClassInstance(instance);
+
+ return _getClassInstance();
+ </cfscript>
+</cffunction>
+
+<cffunction name="onMissingMethod" access="public" returntype="any" output="false" hint="wires the coldfusion invocation to the Java Object">
+ <cfargument name="missingMethodName" type="string" required="true" hint="" />
+ <cfargument name="missingMethodArguments" type="struct" required="true" hint=""/>
+
+ <cfscript>
+ var method = _findMethod(arguments.missingMethodName, arguments.missingMethodArguments);
+
+ if(_getModifier().isStatic(method.getModifiers()))
+ {
+ return method.invoke(JavaCast("null", 0), _buildArgumentArray(arguments.missingMethodArguments));
+ }
+ else
+ {
+ if(NOT _hasClassInstance())
+ {
+ //run the default constructor, just like in normal CF, if there is no instance
+ init();
+ }
+
+ return method.invoke(_getClassInstance(), _buildArgumentArray(arguments.missingMethodArguments));
+ }
+ </cfscript>
+</cffunction>
+
+<!------------------------------------------- PUBLIC ------------------------------------------->
+
+<!------------------------------------------- PACKAGE ------------------------------------------->
+
+<!------------------------------------------- PRIVATE ------------------------------------------->
+
+<cffunction name="_setStaticFields" hint="loops around all the fields and sets the static one to this scope" access="private" returntype="void" output="false">
+ <cfscript>
+ var fields = _getClass().getFields();
+ var counter = 1;
+ var len = ArrayLen(fields);
+ var field = 0;
+
+ for(; counter <= len; counter++)
+ {
+ field = fields[counter];
+ if(_getModifier().isStatic(field.getModifiers()))
+ {
+ this[field.getName()] = field.get(JavaCast("null", 0));
+ }
+ }
+ </cfscript>
+</cffunction>
+
+<cffunction name="_buildArgumentArray" hint="builds an argument array out of the arguments" access="private" returntype="array" output="false">
+ <cfargument name="arguments" hint="the arguments passed through" type="struct" required="Yes">
+ <cfscript>
+ var len = StructCount(arguments);
+ var objArray = _getArray().newInstance(_getObjectClass(), len);
+ var counter = 1;
+ var obj = 0;
+
+ for(; counter <= len; counter++)
+ {
+ obj = arguments[counter];
+ _getArray().set(objArray, counter - 1, obj);
+ }
+
+ return objArray;
+ </cfscript>
+</cffunction>
+
+<cffunction name="_findMethod" hint="finds the method that closest matches the signature" access="public" returntype="any" output="false">
+ <cfargument name="methodName" hint="the name of the method" type="string" required="Yes">
+ <cfargument name="methodArgs" hint="the arguments to look for" type="struct" required="Yes">
+ <cfscript>
+ var decision = 0;
+
+ if(StructKeyExists(_getMethodCollection(), arguments.methodName))
+ {
+ decision = StructFind(_getMethodCollection(), arguments.methodName);
+
+ //if there is only one option, try it, it's only going to throw a runtime exception if it doesn't work.
+ if(ArrayLen(decision) == 1)
+ {
+ return decision[1];
+ }
+ else
+ {
+ return _resolveMethodByParams(arguments.methodName, decision, arguments.methodArgs);
+ }
+ }
+
+ throw("JavaProxy.MethodNotFoundException", "Could not find the designated method", "Could not find the method '#arguments.methodName#' in the class #_getClass().getName()#");
+ </cfscript>
+</cffunction>
+
+<cffunction name="_resolveMethodByParams" hint="resolves the method to use by the parameters provided" access="private" returntype="any" output="false">
+ <cfargument name="methodName" hint="the name of the method" type="string" required="Yes">
+ <cfargument name="decision" hint="the array of methods to decide from" type="array" required="Yes">
+ <cfargument name="methodArgs" hint="the arguments to look for" type="struct" required="Yes">
+ <cfscript>
+ var decisionLen = ArrayLen(arguments.decision);
+ var method = 0;
+ var counter = 1;
+ var argLen = ArrayLen(arguments.methodArgs);
+ var parameters = 0;
+ var paramLen = 0;
+ var pCounter = 0;
+ var param = 0;
+ var class = 0;
+ var found = true;
+
+ for(; counter <= decisionLen; counter++)
+ {
+ method = arguments.decision[counter];
+ parameters = method.getParameterTypes();
+ paramLen = ArrayLen(parameters);
+
+ found = true;
+
+ if(argLen eq paramLen)
+ {
+ for(pCounter = 1; pCounter <= paramLen AND found; pCounter++)
+ {
+ param = parameters[pCounter];
+ class = _getClassMethod().invoke(arguments.methodArgs[pCounter], JavaCast("null", 0));
+
+ if(param.isAssignableFrom(class))
+ {
+ found = true;
+ }
+ else if(param.isPrimitive()) //if it's a primitive, it can be mapped to object primtive classes
+ {
+ if(param.getName() eq "boolean" AND class.getName() eq "java.lang.Boolean")
+ {
+ found = true;
+ }
+ else if(param.getName() eq "int" AND class.getName() eq "java.lang.Integer")
+ {
+ found = true;
+ }
+ else if(param.getName() eq "long" AND class.getName() eq "java.lang.Long")
+ {
+ found = true;
+ }
+ else if(param.getName() eq "float" AND class.getName() eq "java.lang.Float")
+ {
+ found = true;
+ }
+ else if(param.getName() eq "double" AND class.getName() eq "java.lang.Double")
+ {
+ found = true;
+ }
+ else if(param.getName() eq "char" AND class.getName() eq "java.lang.Character")
+ {
+ found = true;
+ }
+ else if(param.getName() eq "byte" AND class.getName() eq "java.lang.Byte")
+ {
+ found = true;
+ }
+ else if(param.getName() eq "short" AND class.getName() eq "java.lang.Short")
+ {
+ found = true;
+ }
+ else
+ {
+ found = false;
+ }
+ }
+ else
+ {
+ found = false;
+ }
+ }
+
+ if(found)
+ {
+ return method;
+ }
+ }
+ }
+
+ throw("JavaProxy.MethodNotFoundException", "Could not find the designated method", "Could not find the method '#arguments.methodName#' in the class #_getClass().getName()#");
+ </cfscript>
+</cffunction>
+
+<cffunction name="_initMethodCollection" hint="creates a method collection of all the methods that are available on the class (this may be cached externally later)" access="private" returntype="void" output="false">
+ <cfscript>
+ var methods = _getClass().getMethods();
+ var len = ArrayLen(methods);
+ var counter = 1;
+ var method = 0;
+
+ _setMethodCollection(StructNew());
+
+ for(; counter <= len; counter++)
+ {
+ method = methods[counter];
+
+ if(NOT StructKeyExists(_getMethodCollection(), method.getName()))
+ {
+ StructInsert(_getMethodCollection(), method.getName(), ArrayNew(1));
+ }
+
+ ArrayAppend(StructFind(_getMethodCollection(), method.getName()), method);
+ }
+ </cfscript>
+</cffunction>
+
+<cffunction name="_getMethodCollection" access="private" returntype="struct" output="false">
+ <cfreturn instance.MethodCollection />
+</cffunction>
+
+<cffunction name="_setMethodCollection" access="private" returntype="void" output="false">
+ <cfargument name="MethodCollection" type="struct" required="true">
+ <cfset instance.MethodCollection = arguments.MethodCollection />
+</cffunction>
+
+<cffunction name="_hasClassInstance" hint="if the proxy has an instance yet" access="private" returntype="boolean" output="false">
+ <cfreturn StructKeyExists(instance, "ClassInstance") />
+</cffunction>
+
+<cffunction name="_getClassInstance" access="private" returntype="any" output="false">
+ <cfreturn instance.ClassInstance />
+</cffunction>
+
+<cffunction name="_setClassInstance" access="private" returntype="void" output="false">
+ <cfargument name="ClassInstance" type="any" required="true">
+ <cfset instance.ClassInstance = arguments.ClassInstance />
+</cffunction>
+
+<cffunction name="_getObjectClass" access="private" returntype="any" output="false">
+ <cfreturn instance.ObjectClass />
+</cffunction>
+
+<cffunction name="_setObjectClass" access="private" returntype="void" output="false">
+ <cfargument name="ObjectClass" type="any" required="true">
+ <cfset instance.ObjectClass = arguments.ObjectClass />
+</cffunction>
+
+<cffunction name="_getArray" access="private" returntype="any" output="false">
+ <cfreturn instance.Array />
+</cffunction>
+
+<cffunction name="_setArray" access="private" returntype="void" output="false">
+ <cfargument name="Array" type="any" required="true">
+ <cfset instance.Array = arguments.Array />
+</cffunction>
+
+<cffunction name="_getClassMethod" access="private" returntype="any" output="false">
+ <cfreturn instance.ClassMethod />
+</cffunction>
+
+<cffunction name="_setClassMethod" access="private" returntype="void" output="false">
+ <cfargument name="ClassMethod" type="any" required="true">
+ <cfset instance.ClassMethod = arguments.ClassMethod />
+</cffunction>
+
+<cffunction name="_getClass" access="private" returntype="any" output="false">
+ <cfreturn instance.Class />
+</cffunction>
+
+<cffunction name="_setClass" access="private" returntype="void" output="false">
+ <cfargument name="Class" type="any" required="true">
+ <cfset instance.Class = arguments.Class />
+</cffunction>
+
+<cffunction name="_getModifier" access="private" returntype="any" output="false">
+ <cfreturn instance.Modifier />
+</cffunction>
+
+<cffunction name="_setModifier" access="private" returntype="void" output="false">
+ <cfargument name="Modifier" type="any" required="true">
+ <cfset instance.Modifier = arguments.Modifier />
+</cffunction>
+
+<cffunction name="throw" access="private" hint="Throws an Exception" output="false">
+ <cfargument name="type" hint="The type of exception" type="string" required="Yes">
+ <cfargument name="message" hint="The message to accompany the exception" type="string" required="Yes">
+ <cfargument name="detail" type="string" hint="The detail message for the exception" required="No" default="">
+ <cfthrow type="#arguments.type#" message="#arguments.message#" detail="#arguments.detail#">
+</cffunction>
+
+</cfcomponent>
View
BIN  javaloader/lib/classloader-20080514084644.jar
Binary file not shown
View
BIN  javaloader/lib/classloader-src.zip
Binary file not shown
View
213 javaloader/licence.txt
@@ -0,0 +1,213 @@
+Common Public License Version 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC
+LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
+CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+ a) in the case of the initial Contributor, the initial code and
+documentation distributed under this Agreement, and
+
+ b) in the case of each subsequent Contributor:
+
+ i) changes to the Program, and
+
+ ii) additions to the Program;
+
+ where such changes and/or additions to the Program originate from and are
+distributed by that particular Contributor. A Contribution 'originates' from a
+Contributor if it was added to the Program by such Contributor itself or anyone
+acting on such Contributor's behalf. Contributions do not include additions to
+the Program which: (i) are separate modules of software distributed in
+conjunction with the Program under their own license agreement, and (ii) are not
+derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are
+necessarily infringed by the use or sale of its Contribution alone or when
+combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement,
+including all Contributors.
+
+2. GRANT OF RIGHTS
+
+ a) Subject to the terms of this Agreement, each Contributor hereby grants
+Recipient a non-exclusive, worldwide, royalty-free copyright license to
+reproduce, prepare derivative works of, publicly display, publicly perform,
+distribute and sublicense the Contribution of such Contributor, if any, and such
+derivative works, in source code and object code form.
+
+ b) Subject to the terms of this Agreement, each Contributor hereby grants
+Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed
+Patents to make, use, sell, offer to sell, import and otherwise transfer the
+Contribution of such Contributor, if any, in source code and object code form.
+This patent license shall apply to the combination of the Contribution and the
+Program if, at the time the Contribution is added by the Contributor, such
+addition of the Contribution causes such combination to be covered by the
+Licensed Patents. The patent license shall not apply to any other combinations
+which include the Contribution. No hardware per se is licensed hereunder.
+
+ c) Recipient understands that although each Contributor grants the licenses
+to its Contributions set forth herein, no assurances are provided by any
+Contributor that the Program does not infringe the patent or other intellectual
+property rights of any other entity. Each Contributor disclaims any liability to
+Recipient for claims brought by any other entity based on infringement of
+intellectual property rights or otherwise. As a condition to exercising the
+rights and licenses granted hereunder, each Recipient hereby assumes sole
+responsibility to secure any other intellectual property rights needed, if any.
+For example, if a third party patent license is required to allow Recipient to
+distribute the Program, it is Recipient's responsibility to acquire that license
+before distributing the Program.
+
+ d) Each Contributor represents that to its knowledge it has sufficient
+copyright rights in its Contribution, if any, to grant the copyright license set
+forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its
+own license agreement, provided that:
+
+ a) it complies with the terms and conditions of this Agreement; and
+
+ b) its license agreement:
+
+ i) effectively disclaims on behalf of all Contributors all warranties and
+conditions, express and implied, including warranties or conditions of title and
+non-infringement, and implied warranties or conditions of merchantability and
+fitness for a particular purpose;
+
+ ii) effectively excludes on behalf of all Contributors all liability for
+damages, including direct, indirect, special, incidental and consequential
+damages, such as lost profits;
+
+ iii) states that any provisions which differ from this Agreement are offered
+by that Contributor alone and not by any other party; and
+
+ iv) states that source code for the Program is available from such
+Contributor, and informs licensees how to obtain it in a reasonable manner on or
+through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+ a) it must be made available under this Agreement; and
+
+ b) a copy of this Agreement must be included with each copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained within the
+Program.
+
+Each Contributor must identify itself as the originator of its Contribution, if
+any, in a manner that reasonably allows subsequent Recipients to identify the
+originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with
+respect to end users, business partners and the like. While this license is
+intended to facilitate the commercial use of the Program, the Contributor who
+includes the Program in a commercial product offering should do so in a manner
+which does not create potential liability for other Contributors. Therefore, if
+a Contributor includes the Program in a commercial product offering, such
+Contributor ("Commercial Contributor") hereby agrees to defend and indemnify
+every other Contributor ("Indemnified Contributor") against any losses, damages
+and costs (collectively "Losses") arising from claims, lawsuits and other legal
+actions brought by a third party against the Indemnified Contributor to the
+extent caused by the acts or omissions of such Commercial Contributor in
+connection with its distribution of the Program in a commercial product
+offering. The obligations in this section do not apply to any claims or Losses
+relating to any actual or alleged intellectual property infringement. In order
+to qualify, an Indemnified Contributor must: a) promptly notify the Commercial
+Contributor in writing of such claim, and b) allow the Commercial Contributor to
+control, and cooperate with the Commercial Contributor in, the defense and any
+related settlement negotiations. The Indemnified Contributor may participate in
+any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product
+offering, Product X. That Contributor is then a Commercial Contributor. If that
+Commercial Contributor then makes performance claims, or offers warranties
+related to Product X, those performance claims and warranties are such
+Commercial Contributor's responsibility alone. Under this section, the
+Commercial Contributor would have to defend claims against the other
+Contributors related to those performance claims and warranties, and if a court
+requires any other Contributor to pay any damages as a result, the Commercial
+Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
+IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE,
+NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each
+Recipient is solely responsible for determining the appropriateness of using and
+distributing the Program and assumes all risks associated with its exercise of
+rights under this Agreement, including but not limited to the risks and costs of
+program errors, compliance with applicable laws, damage to or loss of data,
+programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
+CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST
+PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS
+GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable
+law, it shall not affect the validity or enforceability of the remainder of the
+terms of this Agreement, and without further action by the parties hereto, such
+provision shall be reformed to the minimum extent necessary to make such
+provision valid and enforceable.
+
+If Recipient institutes patent litigation against a Contributor with respect to
+a patent applicable to software (including a cross-claim or counterclaim in a
+lawsuit), then any patent licenses granted by that Contributor to such Recipient
+under this Agreement shall terminate as of the date such litigation is filed. In
+addition, if Recipient institutes patent litigation against any entity
+(including a cross-claim or counterclaim in a lawsuit) alleging that the Program
+itself (excluding combinations of the Program with other software or hardware)
+infringes such Recipient's patent(s), then such Recipient's rights granted under
+Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to
+comply with any of the material terms or conditions of this Agreement and does
+not cure such failure in a reasonable period of time after becoming aware of
+such noncompliance. If all Recipient's rights under this Agreement terminate,
+Recipient agrees to cease use and distribution of the Program as soon as
+reasonably practicable. However, Recipient's obligations under this Agreement
+and any licenses granted by Recipient relating to the Program shall continue and
+survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in
+order to avoid inconsistency the Agreement is copyrighted and may only be
+modified in the following manner. The Agreement Steward reserves the right to
+publish new versions (including revisions) of this Agreement from time to time.
+No one other than the Agreement Steward has the right to modify this Agreement.
+IBM is the initial Agreement Steward. IBM may assign the responsibility to serve
+as the Agreement Steward to a suitable separate entity. Each new version of the
+Agreement will be given a distinguishing version number. The Program (including
+Contributions) may always be distributed subject to the version of the Agreement
+under which it was received. In addition, after a new version of the Agreement
+is published, Contributor may elect to distribute the Program (including its
+Contributions) under the new version. Except as expressly stated in Sections
+2(a) and 2(b) above, Recipient receives no rights or licenses to the
+intellectual property of any Contributor under this Agreement, whether
+expressly, by implication, estoppel or otherwise. All rights in the Program not
+expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the
+intellectual property laws of the United States of America. No party to this
+Agreement will bring a legal action under this Agreement more than one year
+after the cause of action arose. Each party waives its rights to a jury trial in
+any resulting litigation.
View
69 javaloader/readme.txt
@@ -0,0 +1,69 @@
+JavaLoader v0.5
+Author: Mark Mandel
+Date: 2nd October 2007
+
+Installation
+----------------
+To install the javaloader, either put the javaloader in the
+root of your web application, or make a mapping called
+'javaloader' to the javaloader folder.
+
+
+Utilisation
+----------------
+To access the JavaLoader CFC, you call createObject on it like so:
+
+createObject("component", "javaloader.JavaLoader").init(loadPaths,
+ [loadColdFusionClassPath,]
+ [parentClassLoader]);
+
+There are three arguments that possible to configure how and what the JavaLoader loads.
+
+* param: loadPaths
+An array of directories of classes, or paths to .jar files to load.
+
+An example would be:
+loadPaths = ArrayNew(1);
+loadPaths[1] = expandPath("icu4j.jar");
+loadPaths[2] = expandPath("log4j.jar");
+
+* param: loadColdFusionClassPath (default: false)
+Loads the ColdFusion libraries with the loaded libraries.
+This used to be on by default, however now you must implicitly set it to be true if
+you wish to access any of the libraries that ColdFusion loads at application startup.
+
+* parentClassLoader (null)
+(Expert use only) The parent java.lang.ClassLoader to set when creating the URLClassLoader.
+Note - when setting loadColdFusionClassPath to 'true', this value is overwritten with the
+ColdFusion classloader.
+
+
+To create an instance of a Java Class, you then only need to call:
+
+javaloader.create(className).init(arg1, arg2...);
+
+* param className
+The name of the Java Class to create.
+
+This works exactly the same as createObject("java", className), such that simply calling create(className)
+gives you access to the static properties of the class, but to get an instance through calling the
+Constructor you are required to call create(className).init();
+
+Example:
+javaloader.create("org.apache.log4j.Logger").init("my log");
+
+Memory Issues
+----------------
+Due to a bug in ColdFusion 7 that can cause URLClassLoaders not to be garbage collected,
+it is advised that instances of JavaLoader are stored in the Server scope, so that they
+never time out.
+
+
+Integration
+----------------
+Previously JavaLoader was a simple CFC that was very portable, and while JavaLoader
+now has dependencies, it can still be integrated into existing applications quite easily.
+
+The only dependency that much be maintained is that the /lib/ folder and its contents
+must sit in the same directory as JavaLoader.cfc Other than that, JavaLoader can be
+integrated into existing applications and frameworks quite easily.
View
BIN  lib/mongo-java-driver-1.2.jar
Binary file not shown
View
5 test/BaseTest.cfc
@@ -0,0 +1,5 @@
+<cfcomponent output="false" extends="mxunit.framework.TestCase">
+<cfscript>
+ mongo = createObject('component','cfmongodb.Mongo').init();
+ </cfscript>
+</cfcomponent>
View
6 test/ExpressionBuilderTest.cfc
@@ -1,6 +1,6 @@
-<cfcomponent extends="mxunit.framework.TestCase">
+<cfcomponent output="false" extends="BaseTest">
<cfscript>
- mongo = createObject('component','MongoDB');
+ mongo = createObject('component','cfmongodb.Mongo');
coll = mongo.getCollection('blog');
key_exp = {AUTHOR=1,TITLE=1,TS=1};
keys = createObject('java', 'com.mongodb.BasicDBObject').init(key_exp);
@@ -321,7 +321,7 @@ function testEndsWith(){
}
function setUp(){
- builder = createObject('component','ExpressionBuilder');
+ builder = createObject('component','cfmongodb.components.ExpressionBuilder');
}
View
4 test/MongoDBTest.cfc
@@ -1,4 +1,4 @@
-<cfcomponent output="false" extends="mxunit.framework.TestCase">
+<cfcomponent output="false" extends="BaseTest">
<cfscript>
@@ -87,7 +87,7 @@
function setUp(){
- mongo = createObject('component','MongoDB');
+ // mongo = createObject('component','MongoDB');
}
function tearDown(){
View
9 test/MongoSmokeTest.cfc
@@ -0,0 +1,9 @@
+<cfcomponent extends="BaseTest" output="false">
+<cfscript>
+function testThis(){
+
+ debug(mongo);
+
+}
+</cfscript>
+</cfcomponent>
View
4 test/SearchMongoTest.cfc
@@ -1,4 +1,4 @@
-<cfcomponent output="false" extends="mxunit.framework.TestCase">
+<cfcomponent output="false" extends="BaseTest">
<cfscript>
//this would be a good data driven test! pass in an arbitrary list of integers
@@ -103,7 +103,7 @@
function setUp(){
- mongo = createObject('component','MongoDB');
+ //mongo = createObject('component','MongoDB');
}
function tearDown(){
Please sign in to comment.
Something went wrong with that request. Please try again.