summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-01-23 12:09:30 +0100
committerAndrew Branson <andrew.branson@cern.ch>2014-01-23 12:09:30 +0100
commit8256917551c259df2b7e69e32cd74497e5394786 (patch)
tree068ec6e5acf41aabeb1538c6731c8e8f70d1ddb1
parent428d828ca640d1348979f9982d1c0bc0a489a3b4 (diff)
Refactored Resource into a new ResourceLoader interface, which allows
CRISTAL processes in other enviroments with complex class loading (e.g. OSGi) to supply their own resource and class loader to the kernel and its modules. Fixes #149
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/Activity.java3
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java4
-rw-r--r--src/main/java/com/c2kernel/lookup/LDAPLookup.java3
-rw-r--r--src/main/java/com/c2kernel/persistency/ClusterStorageManager.java4
-rw-r--r--src/main/java/com/c2kernel/process/Bootstrap.java9
-rw-r--r--src/main/java/com/c2kernel/process/ClientShell.java2
-rw-r--r--src/main/java/com/c2kernel/process/Gateway.java40
-rw-r--r--src/main/java/com/c2kernel/process/module/Module.java3
-rw-r--r--src/main/java/com/c2kernel/process/module/ModuleManager.java5
-rw-r--r--src/main/java/com/c2kernel/process/resource/Resource.java (renamed from src/main/java/com/c2kernel/utils/Resource.java)95
-rw-r--r--src/main/java/com/c2kernel/process/resource/ResourceLoader.java41
-rw-r--r--src/main/java/com/c2kernel/scripting/Script.java7
-rw-r--r--src/test/java/MainTest.java8
13 files changed, 158 insertions, 66 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java
index 889006c..064bd4d 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java
@@ -29,7 +29,6 @@ import com.c2kernel.process.Gateway;
import com.c2kernel.utils.DateUtility;
import com.c2kernel.utils.LocalObjectLoader;
import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.Resource;
/**
* @version $Revision: 1.222 $ $Date: 2005/10/05 07:39:37 $
* @author $Author: abranson $
@@ -87,7 +86,7 @@ public class Activity extends WfVertex
} catch (ObjectNotFoundException ex) {
if (name.equals(getDefaultSMName()) && version == 0) { // default state machine not imported yet. Fake it.
try {
- String marshalledSM = Resource.getTextResource(null, "boot/SM/"+getDefaultSMName()+".xml");
+ String marshalledSM = Gateway.getResource().getTextResource(null, "boot/SM/"+getDefaultSMName()+".xml");
StateMachine bootstrap = (StateMachine)Gateway.getMarshaller().unmarshall(marshalledSM);
bootstrap.validate();
machine = bootstrap;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java
index 9ab5793..1a966b5 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java
@@ -1,7 +1,7 @@
package com.c2kernel.lifecycle.instance.predefined.entitycreation;
import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.utils.Resource;
+import com.c2kernel.process.Gateway;
public class Outcome {
public String schema, viewname, path, data;
@@ -20,7 +20,7 @@ public class Outcome {
public String getData(String ns) throws ObjectNotFoundException {
if (data == null)
- data = Resource.getTextResource(ns, path);
+ data = Gateway.getResource().getTextResource(ns, path);
return data;
}
diff --git a/src/main/java/com/c2kernel/lookup/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/LDAPLookup.java
index 23d30d4..c6f86d0 100644
--- a/src/main/java/com/c2kernel/lookup/LDAPLookup.java
+++ b/src/main/java/com/c2kernel/lookup/LDAPLookup.java
@@ -18,7 +18,6 @@ import com.c2kernel.process.Gateway;
import com.c2kernel.property.PropertyDescription;
import com.c2kernel.property.PropertyDescriptionList;
import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.Resource;
import com.novell.ldap.LDAPAttributeSet;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPDN;
@@ -300,7 +299,7 @@ public class LDAPLookup
public void install() throws ObjectNotFoundException
{
createBootTree();
- initTree( Resource.getTextResource(null, "boot/LDAPboot.txt"));
+ initTree( Gateway.getResource().getTextResource(null, "boot/LDAPboot.txt"));
}
public void initTree(String bootFile)
diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java
index 16e942d..f7304b1 100644
--- a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java
+++ b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java
@@ -53,9 +53,9 @@ public class ClusterStorageManager {
String newStorageClass = tok.nextToken();
try {
try {
- newStorage = (ClusterStorage)(Class.forName(newStorageClass).newInstance());
+ newStorage = (ClusterStorage)(Gateway.getResource().getClassForName(newStorageClass).newInstance());
} catch (ClassNotFoundException ex2) {
- newStorage = (ClusterStorage)(Class.forName("com.c2kernel.persistency."+newStorageClass).newInstance());
+ newStorage = (ClusterStorage)(Gateway.getResource().getClassForName("com.c2kernel.persistency."+newStorageClass).newInstance());
}
newStorage.open();
Logger.msg(5, "ClusterStorageManager.init() - Cluster storage " + newStorageClass +
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java
index 51b98b0..5f23261 100644
--- a/src/main/java/com/c2kernel/process/Bootstrap.java
+++ b/src/main/java/com/c2kernel/process/Bootstrap.java
@@ -34,7 +34,6 @@ import com.c2kernel.property.PropertyDescriptionList;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.LocalObjectLoader;
import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.Resource;
/**
* @version $Revision: 1.25 $ $Date: 2006/01/10 09:48:32 $
@@ -86,7 +85,7 @@ public class Bootstrap
public static void verifyBootDataItems() throws Exception {
String bootItems;
Logger.msg(1, "Verifying kernel boot items");
- bootItems = FileStringUtility.url2String(Resource.getKernelResourceURL("boot/allbootitems.txt"));
+ bootItems = FileStringUtility.url2String(Gateway.getResource().getKernelResourceURL("boot/allbootitems.txt"));
verifyBootDataItems(bootItems, null, true);
Logger.msg(1, "Boot data items complete");
}
@@ -99,7 +98,7 @@ public class Bootstrap
String itemType = thisItem.substring(0,delim);
String itemName = thisItem.substring(delim+1);
try {
- String data = Resource.getTextResource(ns, "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"));
+ String data = Gateway.getResource().getTextResource(ns, "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"));
if (data == null)
Logger.die("No data found for "+getDataType(itemType)+" "+itemName);
verifyResource(ns, itemName, 0, itemType, data, reset);
@@ -169,7 +168,7 @@ public class Bootstrap
*/
private static ItemProxy createResourceItem(String itemType, String itemName, String ns) throws Exception {
// create props
- PropertyDescriptionList pdList = (PropertyDescriptionList)Gateway.getMarshaller().unmarshall(Resource.getTextResource(null, "boot/property/"+itemType+"Prop.xml"));
+ PropertyDescriptionList pdList = (PropertyDescriptionList)Gateway.getMarshaller().unmarshall(Gateway.getResource().getTextResource(null, "boot/property/"+itemType+"Prop.xml"));
PropertyArrayList props = new PropertyArrayList();
for (int i = 0; i < pdList.list.size(); i++) {
PropertyDescription pd = pdList.list.get(i);
@@ -300,7 +299,7 @@ public class Bootstrap
}
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Name", serverName, false), null);
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Type", "Server", false), null);
- Gateway.getStorage().put(serverEntity.getSysKey(), new Property("KernelVersion", Resource.getKernelVersion(), true), null);
+ Gateway.getStorage().put(serverEntity.getSysKey(), new Property("KernelVersion", Gateway.getKernelVersion(), true), null);
if (Gateway.getProperty("ItemServer.Proxy.port") != null)
Gateway.getStorage().put(serverEntity.getSysKey(),
new Property("ProxyPort", Gateway.getProperty("ItemServer.Proxy.port"), true), null);
diff --git a/src/main/java/com/c2kernel/process/ClientShell.java b/src/main/java/com/c2kernel/process/ClientShell.java
index f109155..6ca0970 100644
--- a/src/main/java/com/c2kernel/process/ClientShell.java
+++ b/src/main/java/com/c2kernel/process/ClientShell.java
@@ -39,7 +39,7 @@ public class ClientShell extends StandardClient {
public static void main(String[] args) throws Exception {
Gateway.init(readC2KArgs(args));
String authClassName = Gateway.getProperty("cli.auth");
- Class<?> authClass = Class.forName(authClassName);
+ Class<?> authClass = Gateway.getResource().getClassForName(authClassName);
Authenticator auth = (Authenticator)authClass.newInstance();
AgentProxy user = auth.authenticate(Gateway.getProperty("Name"));
ClientShell shell = new ClientShell(user);
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java
index 53fa36f..b57e91b 100644
--- a/src/main/java/com/c2kernel/process/Gateway.java
+++ b/src/main/java/com/c2kernel/process/Gateway.java
@@ -20,11 +20,12 @@ import com.c2kernel.lookup.LDAPProperties;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.TransactionManager;
import com.c2kernel.process.module.ModuleManager;
+import com.c2kernel.process.resource.Resource;
+import com.c2kernel.process.resource.ResourceLoader;
import com.c2kernel.utils.CastorXMLUtility;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Language;
import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.Resource;
/**************************************************************************
@@ -59,6 +60,7 @@ public class Gateway
static private CorbaServer mCorbaServer;
static private CastorXMLUtility mMarshaller;
static private AgentProxy mCurrentUser = null;
+ static private ResourceLoader mResource;
@@ -73,17 +75,32 @@ public class Gateway
* @throws InvalidDataException - invalid properties caused a failure in initialisation
*/
static public void init(Properties props) throws InvalidDataException {
+ init(props, null);
+ }
+
+ /**
+ * Initialises the Gateway and all of the client objects it holds, with
+ * the exception of the LDAPLookup, which is initialised during connect()
+ *
+ * @param props - java.util.Properties containing all application properties.
+ * If null, the java system properties are used
+ * @param res - ResourceLoader for the kernel to use to resolve all class resource requests
+ * such as for bootstrap descriptions and version information
+ * @throws InvalidDataException - invalid properties caused a failure in initialisation
+ */
+ static public void init(Properties props, ResourceLoader res) throws InvalidDataException {
// Init properties & resources
mC2KProps = new Properties();
- Resource.initKernelBaseURL();
+ mResource = res;
+ if (mResource == null) mResource = new Resource();
// report version info
- Logger.msg("Kernel version: "+Resource.getKernelVersion());
+ Logger.msg("Kernel version: "+getKernelVersion());
// load kernel mapfiles
try {
- mMarshaller = new CastorXMLUtility(Resource.getKernelResourceURL("mapFiles/"));
+ mMarshaller = new CastorXMLUtility(mResource.getKernelResourceURL("mapFiles/"));
} catch (MalformedURLException e1) {
throw new InvalidDataException("Invalid Resource Location", "");
}
@@ -381,6 +398,11 @@ public class Gateway
{
return mMarshaller;
}
+
+ static public ResourceLoader getResource()
+ {
+ return mResource;
+ }
static public EntityProxyManager getProxyManager()
{
@@ -417,5 +439,15 @@ public class Gateway
Logger.msg(" "+name+": "+getProperty(name));
}
}
+
+
+ static public String getKernelVersion() {
+ try {
+ return mResource.getTextResource(null, "textFiles/version.txt");
+ } catch (Exception ex) {
+ return "No version info found";
+ }
+
+ }
}
diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java
index 58cf503..fda4b1b 100644
--- a/src/main/java/com/c2kernel/process/module/Module.java
+++ b/src/main/java/com/c2kernel/process/module/Module.java
@@ -17,7 +17,6 @@ import com.c2kernel.process.Gateway;
import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.scripting.ScriptingEngineException;
import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.Resource;
public class Module {
@@ -79,7 +78,7 @@ public class Module {
for (ModuleResource thisRes : imports.getResources()) {
try {
- Bootstrap.verifyResource(ns, thisRes.name, thisRes.version, thisRes.resourceType, Resource.getTextResource(ns, thisRes.resourceLocation), reset);
+ Bootstrap.verifyResource(ns, thisRes.name, thisRes.version, thisRes.resourceType, Gateway.getResource().getTextResource(ns, thisRes.resourceLocation), reset);
} catch (Exception ex) {
Logger.error(ex);
}
diff --git a/src/main/java/com/c2kernel/process/module/ModuleManager.java b/src/main/java/com/c2kernel/process/module/ModuleManager.java
index f1d26fb..ca2e74b 100644
--- a/src/main/java/com/c2kernel/process/module/ModuleManager.java
+++ b/src/main/java/com/c2kernel/process/module/ModuleManager.java
@@ -17,7 +17,6 @@ import com.c2kernel.process.Gateway;
import com.c2kernel.scripting.ScriptingEngineException;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.Resource;
public class ModuleManager {
ArrayList<Module> modules = new ArrayList<Module>();
@@ -30,7 +29,7 @@ public class ModuleManager {
this.isServer = isServer;
try {
Schema moduleSchema = new Schema("Module", 0,
- FileStringUtility.url2String(Resource.getKernelResourceURL("boot/OD/Module.xsd")));
+ FileStringUtility.url2String(Gateway.getResource().getKernelResourceURL("boot/OD/Module.xsd")));
moduleValidator = new OutcomeValidator(moduleSchema);
} catch (InvalidDataException ex) {
Logger.error(ex);
@@ -48,7 +47,7 @@ public class ModuleManager {
if (errors.length() > 0)
throw new ModuleException("Module XML found at "+newModuleURL+" was not valid: "+errors);
Module newModule = (Module)Gateway.getMarshaller().unmarshall(moduleXML);
- if (newModule.resURL != null && newModule.resURL.length()>0) Resource.addModuleBaseURL(newModule.ns, newModule.resURL);
+ if (newModule.resURL != null && newModule.resURL.length()>0) Gateway.getResource().addModuleBaseURL(newModule.ns, newModule.resURL);
modules.add(newModule);
modulesXML.put(newModule.ns, moduleXML);
if (loadedModules.contains(newModule.getName())) throw new ModuleException("Module name clash: "+newModule.getName());
diff --git a/src/main/java/com/c2kernel/utils/Resource.java b/src/main/java/com/c2kernel/process/resource/Resource.java
index d24b8f8..4d07f35 100644
--- a/src/main/java/com/c2kernel/utils/Resource.java
+++ b/src/main/java/com/c2kernel/process/resource/Resource.java
@@ -1,4 +1,4 @@
-package com.c2kernel.utils;
+package com.c2kernel.process.resource;
//Java
import java.net.MalformedURLException;
@@ -8,58 +8,85 @@ import java.util.Hashtable;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.utils.FileStringUtility;
+import com.c2kernel.utils.Logger;
/**************************************************************************
*
* @author $Author: abranson $ $Date: 2005/10/05 07:39:36 $
* @version $Revision: 1.71 $
**************************************************************************/
-public class Resource {
- static private Hashtable<String, String> txtCache = new Hashtable<String, String>();
- static private URL baseURL;
- static private HashMap<String, URL> moduleBaseURLs = new HashMap<String, URL>();
- static private HashMap<String, URL> allBaseURLs = new HashMap<String, URL>();
+public class Resource implements ResourceLoader {
+ private final Hashtable<String, String> txtCache = new Hashtable<String, String>();
+ private final URL baseURL;
+ private final HashMap<String, URL> moduleBaseURLs = new HashMap<String, URL>();
+ private final HashMap<String, URL> allBaseURLs = new HashMap<String, URL>();
- public static void initKernelBaseURL() throws InvalidDataException {
+ public Resource() throws InvalidDataException {
baseURL = getURLorResURL("com/c2kernel/utils/resources/");
allBaseURLs.put(null, baseURL);
}
- public static URL getKernelBaseURL() {
+ /* (non-Javadoc)
+ * @see com.c2kernel.utils.ResourceLoader#getKernelBaseURL()
+ */
+ @Override
+ public URL getKernelBaseURL() {
return baseURL;
}
- public static URL getKernelResourceURL(String resName) throws MalformedURLException {
+ @Override
+ public Class<?> getClassForName(String name) throws ClassNotFoundException {
+ return Class.forName(name);
+ }
+
+ /* (non-Javadoc)
+ * @see com.c2kernel.utils.ResourceLoader#getKernelResourceURL(java.lang.String)
+ */
+ @Override
+ public URL getKernelResourceURL(String resName) throws MalformedURLException {
return new URL(baseURL, resName);
}
- public static void addModuleBaseURL(String ns, URL newBaseURL) {
+ /* (non-Javadoc)
+ * @see com.c2kernel.utils.ResourceLoader#addModuleBaseURL(java.lang.String, java.net.URL)
+ */
+ @Override
+ public void addModuleBaseURL(String ns, URL newBaseURL) {
moduleBaseURLs.put(ns, newBaseURL);
allBaseURLs.put(ns, newBaseURL);
Logger.msg("Adding resource URL for "+ns+": "+newBaseURL.toString());
}
- public static void addModuleBaseURL(String ns, String newBaseURL) throws InvalidDataException {
+ /* (non-Javadoc)
+ * @see com.c2kernel.utils.ResourceLoader#addModuleBaseURL(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void addModuleBaseURL(String ns, String newBaseURL) throws InvalidDataException {
addModuleBaseURL(ns, getURLorResURL(newBaseURL));
}
-
- public static URL getModuleBaseURL(String ns) {
- return moduleBaseURLs.get(ns);
- }
- public static HashMap<String, URL> getModuleBaseURLs() {
+ /* (non-Javadoc)
+ * @see com.c2kernel.utils.ResourceLoader#getModuleBaseURLs()
+ */
+ @Override
+ public HashMap<String, URL> getModuleBaseURLs() {
return moduleBaseURLs;
}
- public static HashMap<String, URL> getAllBaseURLs() {
+ private HashMap<String, URL> getAllBaseURLs() {
return allBaseURLs;
}
- static public URL getModuleResourceURL(String ns, String resName) throws MalformedURLException {
+ /* (non-Javadoc)
+ * @see com.c2kernel.utils.ResourceLoader#getModuleResourceURL(java.lang.String, java.lang.String)
+ */
+ @Override
+ public URL getModuleResourceURL(String ns, String resName) throws MalformedURLException {
return new URL(moduleBaseURLs.get(ns), resName);
}
- private static URL getURLorResURL(String newURL) throws InvalidDataException {
+ static private URL getURLorResURL(String newURL) throws InvalidDataException {
URL result;
try {
result = new URL(newURL);
@@ -74,11 +101,12 @@ public class Resource {
}
return result;
}
- /**************************************************************************
- * Gets any text resource files
- **************************************************************************/
+ /* (non-Javadoc)
+ * @see com.c2kernel.utils.ResourceLoader#findTextResource(java.lang.String)
+ */
- static public String findTextResource(String resName) {
+ @Override
+ public String findTextResource(String resName) {
for (String ns : getAllBaseURLs().keySet()) {
try {
return getTextResource(ns, resName);
@@ -88,7 +116,11 @@ public class Resource {
return null;
}
- static public HashMap<String, String> getAllTextResources(String resName) {
+ /* (non-Javadoc)
+ * @see com.c2kernel.utils.ResourceLoader#getAllTextResources(java.lang.String)
+ */
+ @Override
+ public HashMap<String, String> getAllTextResources(String resName) {
HashMap<String, String> results = new HashMap<String, String>();
for (String ns : getAllBaseURLs().keySet()) {
try {
@@ -98,7 +130,11 @@ public class Resource {
return results;
}
- static public String getTextResource(String ns, String resName) throws ObjectNotFoundException
+ /* (non-Javadoc)
+ * @see com.c2kernel.utils.ResourceLoader#getTextResource(java.lang.String, java.lang.String)
+ */
+ @Override
+ public String getTextResource(String ns, String resName) throws ObjectNotFoundException
// throws IOException
{
Logger.msg(8, "Resource::getTextResource() - Getting resource from "+ns+": " + resName);
@@ -124,13 +160,4 @@ public class Resource {
throw new ObjectNotFoundException(e.getMessage(),null);
}
}
-
- static public String getKernelVersion() {
- try {
- return FileStringUtility.url2String(getKernelResourceURL("textFiles/version.txt"));
- } catch (Exception ex) {
- return "No version info found";
- }
-
- }
}
diff --git a/src/main/java/com/c2kernel/process/resource/ResourceLoader.java b/src/main/java/com/c2kernel/process/resource/ResourceLoader.java
new file mode 100644
index 0000000..fdf2508
--- /dev/null
+++ b/src/main/java/com/c2kernel/process/resource/ResourceLoader.java
@@ -0,0 +1,41 @@
+package com.c2kernel.process.resource;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectNotFoundException;
+
+public interface ResourceLoader {
+
+ public URL getKernelBaseURL();
+
+ public URL getKernelResourceURL(String resName)
+ throws MalformedURLException;
+
+ public void addModuleBaseURL(String ns, URL newBaseURL);
+
+ public void addModuleBaseURL(String ns, String newBaseURL)
+ throws InvalidDataException;
+
+ public HashMap<String, URL> getModuleBaseURLs();
+
+ public URL getModuleResourceURL(String ns, String resName)
+ throws MalformedURLException;
+
+ /**************************************************************************
+ * Gets any text resource files
+ **************************************************************************/
+
+ public String findTextResource(String resName);
+
+ public HashMap<String, String> getAllTextResources(String resName);
+
+ public String getTextResource(String ns, String resName)
+ throws ObjectNotFoundException;
+
+ public Class<?> getClassForName(String name)
+ throws ClassNotFoundException;
+
+} \ No newline at end of file
diff --git a/src/main/java/com/c2kernel/scripting/Script.java b/src/main/java/com/c2kernel/scripting/Script.java
index 9166e2e..e3b4478 100644
--- a/src/main/java/com/c2kernel/scripting/Script.java
+++ b/src/main/java/com/c2kernel/scripting/Script.java
@@ -29,7 +29,6 @@ import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.LocalObjectLoader;
import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.Resource;
/**************************************************************************
*
@@ -159,7 +158,7 @@ public class Script
PrintWriter output = new PrintWriter(out);
context.setWriter(output);
context.setErrorWriter(output);
- HashMap<String, String> consoleScripts = Resource.getAllTextResources("textFiles/consoleScript."+lang+".txt");
+ HashMap<String, String> consoleScripts = Gateway.getResource().getAllTextResources("textFiles/consoleScript."+lang+".txt");
for (String ns : consoleScripts.keySet()) {
try {
engine.put(ScriptEngine.FILENAME, ns+" init script");
@@ -305,7 +304,7 @@ public class Script
{
try
{
- addInputParam(name, Class.forName(type));
+ addInputParam(name, Gateway.getResource().getClassForName(type));
}
catch (ClassNotFoundException ex)
{
@@ -351,7 +350,7 @@ public class Script
{
try
{
- addOutput(name, Class.forName(type));
+ addOutput(name, Gateway.getResource().getClassForName(type));
}
catch (ClassNotFoundException ex) {
throw new ParameterException("Output parameter " + name + " specifies class " + type + " which was not found.");
diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java
index 309f0cf..2029dc2 100644
--- a/src/test/java/MainTest.java
+++ b/src/test/java/MainTest.java
@@ -13,7 +13,6 @@ import com.c2kernel.process.Gateway;
import com.c2kernel.scripting.Script;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.Resource;
public class MainTest {
@@ -28,7 +27,6 @@ public class MainTest {
Logger.addLogStream(System.out, 1);
Properties props = FileStringUtility.loadConfigFile(MainTest.class.getResource("properties.conf").getPath());
Gateway.init(props);
- Resource.initKernelBaseURL();
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
}
@@ -41,7 +39,7 @@ public class MainTest {
validators.put("SM", new OutcomeValidator(getSchema("StateMachine", 0, "boot/OD/StateMachine.xsd")));
validators.put("OD", new SchemaValidator());
- String bootItems = FileStringUtility.url2String(Resource.getKernelResourceURL("boot/allbootitems.txt"));
+ String bootItems = FileStringUtility.url2String(Gateway.getResource().getKernelResourceURL("boot/allbootitems.txt"));
StringTokenizer str = new StringTokenizer(bootItems, "\n\r");
long castorTime=0;
while (str.hasMoreTokens()) {
@@ -50,7 +48,7 @@ public class MainTest {
int delim = thisItem.indexOf('/');
String itemType = thisItem.substring(0,delim);
OutcomeValidator validator = validators.get(itemType);
- String data = Resource.getTextResource(null, "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"));
+ String data = Gateway.getResource().getTextResource(null, "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"));
assert data!=null;
String errors = validator.validate(data);
if (errors.length() > 0) {
@@ -86,7 +84,7 @@ public class MainTest {
}
private static Schema getSchema(String name, int version, String resPath) throws ObjectNotFoundException {
- return new Schema(name, version, Resource.getTextResource(null, resPath));
+ return new Schema(name, version, Gateway.getResource().getTextResource(null, resPath));
}
public void testScriptParsing() throws Exception {