PageRenderTime 515ms CodeModel.GetById 372ms app.highlight 2ms RepoModel.GetById 139ms app.codeStats 0ms

/wheels/vendor/memcached/com/util/JavaLoader.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 75 lines | 62 code | 10 blank | 3 comment | 3 complexity | 99b9cb6cbc0bbb28072ae0d7bfc1c679 MD5 | raw file
 1<cfcomponent name="JavaLoader" hint="Loads External Java Classes for Memcached">
 2	
 3	<cffunction name="init" hint="Constructor" access="public" returntype="JavaLoader" output="false">
 4		<cfargument name="serverFacade" type="any" required="Yes" hint="the server facade for the javaloader">
 5		<cfargument name="jarDir" type="string" required="false"  default="">
 6		<cfargument name="lockName" type="string" required="false"  default="memcached.server.JavaLoader">
 7		<cfscript>
 8			variables.instance = StructNew();
 9	
10			setServerFacade(arguments.serverFacade);
11		</cfscript>
12			
13		<!--- double check lock for safety --->
14		<cfif NOT getServerFacade().hasJavaLoader()>
15			<cflock name="#arguments.lockName#" throwontimeout="true" timeout="60">
16				<cfscript>
17					if(NOT getServerFacade().hasJavaLoader())
18					{
19						getServerFacade().setJavaLoader(createObject("component", "javaloader.JavaLoader").init(queryJars(arguments.jarDir), true));
20					}
21				</cfscript>
22			</cflock>
23		</cfif>
24	
25		<cfscript>
26			return this;
27		</cfscript>
28	</cffunction>
29	
30	<cffunction name="create" access="public" returntype="any" output="false" 
31			hint="Retrieves a reference to the java class. To create a instance, you must run init() on this object">
32		<cfargument name="className" type="string" required="Yes" hint="The name of the class to create">
33		<cfscript>
34			return getServerFacade().getJavaLoader().create(arguments.className);
35		</cfscript>
36	</cffunction>
37	
38	<cffunction name="queryJars" access="private" returntype="array" output="false" hint="pulls a query of all the jars in the /lib folder" >
39		<cfargument name="jarDir" type="string" required="false" default="">
40		<cfscript>
41			var qJars = 0;
42			//the path to my jar library
43			//var path = expandPath(arguments.jarDir);
44			var jarList = "";
45			var aJars = ArrayNew(1);
46			var libName = 0;
47		</cfscript>
48		<cfif len(trim(arguments.jardir)) gt 0 and directoryExists(arguments.jarDir)>
49			<cfdirectory action="list" name="qJars" directory="#arguments.jarDir#" filter="*.jar" sort="name desc"/>
50		
51			<cfloop query="qJars">
52				<cfscript>
53					libName = ListGetAt(name, 1, "-");
54					//let's not use the lib's that have the same name, but a lower datestamp
55					if(NOT ListFind(jarList, libName))
56					{
57						ArrayAppend(aJars, directory & "/" & name);
58						jarList = ListAppend(jarList, libName);
59					}
60				</cfscript>
61			</cfloop>
62		</cfif>
63		<cfreturn aJars>
64	</cffunction>
65	
66	<cffunction name="getServerFacade" access="private" returntype="any" output="false">
67		<cfreturn instance.serverFacade />
68	</cffunction>
69	
70	<cffunction name="setServerFacade" access="private" returntype="void" output="false">
71		<cfargument name="serverFacade" type="any" required="true">
72		<cfset instance.serverFacade = arguments.serverFacade />
73	</cffunction>
74
75</cfcomponent>