summaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorogattaz <olivier@gattaz.com>2014-08-28 11:05:51 +0200
committerogattaz <olivier@gattaz.com>2014-08-28 11:05:51 +0200
commitd0e42f669232987359ae3431b310530dc588fc6f (patch)
tree1e0d4cdf4344b3328dca8777ce7c23d7a498aab8 /src/main/java/com
parentacc72802a1e5374b9654c865c9843fd70e544d35 (diff)
pull master devs
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/package-info.java56
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java45
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java15
-rw-r--r--src/main/java/com/c2kernel/process/AbstractMain.java25
-rw-r--r--src/main/java/com/c2kernel/process/Bootstrap.java41
-rw-r--r--src/main/java/com/c2kernel/process/ClientShell.java5
-rw-r--r--src/main/java/com/c2kernel/process/Gateway.java6
-rw-r--r--src/main/java/com/c2kernel/process/module/Module.java3
-rw-r--r--src/main/java/com/c2kernel/process/module/ModuleInfo.java1
-rw-r--r--src/main/java/com/c2kernel/scripting/Script.java26
-rw-r--r--src/main/java/com/c2kernel/utils/CastorXMLUtility.java74
-rw-r--r--src/main/java/com/c2kernel/utils/LocalObjectLoader.java27
12 files changed, 176 insertions, 148 deletions
diff --git a/src/main/java/com/c2kernel/entity/proxy/package-info.java b/src/main/java/com/c2kernel/entity/proxy/package-info.java
new file mode 100644
index 0000000..404ca07
--- /dev/null
+++ b/src/main/java/com/c2kernel/entity/proxy/package-info.java
@@ -0,0 +1,56 @@
+/**
+ * The Proxy API is a major part of the client-side functionality of the
+ * CRISTAL API, which provides client-side proxy objects that represent the
+ * Items and Agents on the server. It is the main entry point for many
+ * components, such as Scripts and Job execution. An AgentProxy is returned on
+ * login, and should be used as the root for all user-based CRISTAL interactions.
+ *
+ * <p>The Proxy API provides the following functionality:
+ *
+ * <ul>
+ * <li><b>Transparent storage integration</b> - Combines direct database access
+ * with remote calls to data retrieval methods on the Items. This allows client
+ * processes to load Item data directly from databases whenever possible
+ * without bothering the CRISTAL server. For example, the LDAP Lookup
+ * implementation allows client processes to load Item Properties directly from
+ * the LDAP server.</li>
+ *
+ * <li><b>Data object browsing and loading</b> - The proxy objects allow client
+ * processes to browse through the storage cluster structure beneath the Item,
+ * and access the objects directly without having to unmarshall their XML forms.
+ * All object types have their own get methods, so there's no need to construct
+ * their paths nor cast.</b>
+ *
+ * <li><b>Item object and directory change notification</b> - When a proxy
+ * object is created, it notifies the CRISTAL server that its Item is located
+ * on, and it notified of all additions, deletions and modifications of objects
+ * within that Item so it can remain up-to-date. Client applications may use
+ * the {@link ProxyObserver} interface to be notified of changes, using
+ * {@link MemberSubscription} instances to set up push subscriptions to cluster
+ * contents. It also provides a mechanism for subscribing to directory paths,
+ * so that domain tree browsers can implement asynchronous loading and update
+ * themselves when the tree changes.</li>
+ *
+ * <li><b>Job querying</b> - Job objects may be retrieved directly from an
+ * ItemProxy, and may also be filtered by Activity name.</li>
+ *
+ * <li><b>Job execution</b> - The {@link AgentProxy} provides the main
+ * execution method for Jobs. This method performs outcome validation and
+ * executes required CRISTAL Scripts in the client process before the execution
+ * is requested on the server. Additional execution methods to call Predefined
+ * Steps are also available.
+ *
+ * <li><b>Utility methods for resolution and marshalling</b> - The AgentProxy
+ * provides utility methods for finding Items in the directory by name, path,
+ * or system key, and gives access to the Castor XML marshalling system to
+ * transform CRISTAL objects to XML and back again.</li>
+ * </ul>
+ * <p>The core object of the Proxy API is the ProxyManager, which is initialized
+ * as a static member of the Gateway on initialization. This object can be used
+ * to create a Proxy object from a Path from the directory, and maintains a
+ * connection to the server called the Proxy Update Notification Channel,
+ * through which it subscribes to Items it holds proxies for so it can be
+ * informed of changes to Item data through {@link ProxyMessage} objects.
+ *
+ */
+package com.c2kernel.entity.proxy; \ No newline at end of file
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java
index f311dc1..a7971f3 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java
@@ -14,11 +14,12 @@ package com.c2kernel.lifecycle.instance.predefined.agent;
import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.CorbaServer;
import com.c2kernel.entity.agent.ActiveEntity;
import com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.lookup.RolePath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -34,27 +35,36 @@ public class CreateAgentFromDescription extends CreateItemFromDescription
super();
}
- //requestdata is xmlstring
+ /**
+ * Params:
+ * <ol><li>1: new Agent name</li>
+ * <li>2...: Roles to assign to the agent. Must already exist.
+ * @see com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(com.c2kernel.lookup.AgentPath, int, int, java.lang.String)
+ */
@Override
protected String runActivityLogic(AgentPath agent, int itemSysKey,
int transitionID, String requestData) throws InvalidDataException {
String[] input = getDataList(requestData);
String newName = input[0];
- String domPath = input[1];
- String wfDefName = null;
- int wfDefVer = -1;
- if (input.length > 2) // override wf
- wfDefName = input[2];
Logger.msg(1, "CreateAgentFromDescription::request() - Starting.");
try {
+
+ if (input.length < 2)
+ throw new InvalidDataException("Agent should have at least one Role defined on creation");
+ // check if given roles exist
+ for(int i=1; i<input.length; i++) {
+ RolePath thisRole = new RolePath(input[i]);
+ if (!thisRole.exists()) throw new InvalidDataException("Role "+input[i]+" does not exist");
+ }
+
// check if the path is already taken
- DomainPath context = new DomainPath(new DomainPath(domPath), newName);
- Logger.debug(8,"context "+context.getSysKey()+" "+context.getPath()+" "+context.getString());
- if (context.getSysKey()!=-1)
- throw new ObjectAlreadyExistsException("The agent name " +newName+ " exists already.", "");
+ try {
+ Gateway.getLookup().getAgentPath(newName);
+ throw new ObjectAlreadyExistsException("The agent name " +newName+ " exists already.", "");
+ } catch (ObjectNotFoundException ex) { }
// generate new entity key
Logger.msg(6, "CreateItemFromDescription - Requesting new sysKey");
@@ -70,7 +80,6 @@ public class CreateAgentFromDescription extends CreateItemFromDescription
ActiveEntity newAgent = (ActiveEntity)factory.createEntity(newAgentPath);
Gateway.getLookupManager().add(newAgentPath);
-
// initialise it with its properties and workflow
Logger.msg(3, "CreateItemFromDescription - Initializing Item");
@@ -78,14 +87,16 @@ public class CreateAgentFromDescription extends CreateItemFromDescription
newAgent.initialise(
agent.getSysKey(),
Gateway.getMarshaller().marshall(getNewProperties(itemSysKey, newName, agent)),
- Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey, wfDefName, wfDefVer)),
+ Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey)),
Gateway.getMarshaller().marshall(getNewCollections(itemSysKey))
);
+
+ // add roles if given
+
+ for(int i=1; i<input.length; i++) {
+ newAgent.addRole(input[i]);
+ }
- // add its domain path
- Logger.msg(3, "CreateItemFromDescription - Creating "+context);
- context.setEntity(newAgentPath);
- Gateway.getLookupManager().add(context);
return requestData;
} catch (Exception e) {
Logger.error(e);
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java
index f63c188..728631c 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java
@@ -59,10 +59,6 @@ public class CreateItemFromDescription extends PredefinedStep
String[] input = getDataList(requestData);
String newName = input[0];
String domPath = input[1];
- String wfDefName = null;
- int wfDefVer = -1;
- if (input.length > 2) // override wf
- wfDefName = input[2];
Logger.msg(1, "CreateItemFromDescription - Starting.");
@@ -99,7 +95,7 @@ public class CreateItemFromDescription extends PredefinedStep
newItem.initialise(
agent.getSysKey(),
Gateway.getMarshaller().marshall(getNewProperties(itemSysKey, newName, agent)),
- Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey, wfDefName, wfDefVer)),
+ Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey)),
Gateway.getMarshaller().marshall(getNewCollections(itemSysKey))
);
@@ -132,11 +128,12 @@ public class CreateItemFromDescription extends PredefinedStep
return props;
}
- protected CompositeActivity getNewWorkflow(int itemSysKey, String wfDefName, int wfDefVer) throws ClusterStorageException, ObjectNotFoundException, InvalidDataException {
+ protected CompositeActivity getNewWorkflow(int itemSysKey) throws ClusterStorageException, ObjectNotFoundException, InvalidDataException {
// loop through collections, collecting instantiated descriptions and finding the default workflow def
String[] collNames = Gateway.getStorage().getClusterContents(itemSysKey, ClusterStorage.COLLECTION);
+ String wfDefName = null; Integer wfDefVer = null;
for (String collName : collNames) {
- if (collName.equalsIgnoreCase("workflow") && wfDefName == null) {
+ if (collName.equalsIgnoreCase("workflow")) {
Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>)Gateway.getStorage().get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null);
ArrayList<? extends CollectionMember> members = thisCol.getMembers().list;
// get the first member from the wf collection
@@ -154,14 +151,14 @@ public class CreateItemFromDescription extends PredefinedStep
// load workflow def
if (wfDefName == null)
throw new InvalidDataException("No workflow given or defined", "");
- if (wfDefVer == -1)
+ if (wfDefVer == null)
throw new InvalidDataException("No workflow def version given","");
try {
CompositeActivityDef wfDef = (CompositeActivityDef)LocalObjectLoader.getActDef(wfDefName, wfDefVer);
return (CompositeActivity)wfDef.instantiate();
} catch (ObjectNotFoundException ex) {
- throw new InvalidDataException("Workflow def '"+wfDefName+"' item not found", "");
+ throw new InvalidDataException("Workflow def '"+wfDefName+"'v"+wfDefVer+" not found", "");
} catch (ClassCastException ex) {
throw new InvalidDataException("Activity def '"+wfDefName+"' was not Composite", "");
}
diff --git a/src/main/java/com/c2kernel/process/AbstractMain.java b/src/main/java/com/c2kernel/process/AbstractMain.java
index ad21b78..0baf9ce 100644
--- a/src/main/java/com/c2kernel/process/AbstractMain.java
+++ b/src/main/java/com/c2kernel/process/AbstractMain.java
@@ -36,25 +36,6 @@ abstract public class AbstractMain
public static String MAIN_ARG_LOGLEVEL = "logLevel";
public static String MAIN_ARG_LOGFILE = "logFile";
public static String MAIN_ARG_CONNECT = "connect";
- public static String MAIN_ARG_HELP = "help";
- public static String MAIN_ARG_HELPSHORT = "h";
-
- /**
- *
- * -noNewLogStream: if present no new Logstream is added to the logger (
- * considers that the Logger is already configured)
- *
- * @return help informations
- */
- public static String usageHelp() {
-
- return "USAGE: com.c2kernel.process.AbstractMain \n"
- + " -config <server/client config file> \n"
- + " [-connect <LC connect file> ] (or LocalCentre in conf)\n"
- + " [-h] [-help] \n" + " [-logLevel 0-19] \n"
- + " [-logFile <path to log file>]"
- + " [-noNewLogStream ]";
- }
@@ -122,12 +103,12 @@ abstract public class AbstractMain
Logger.addLogStream(logStream, logLevel);
}
- Logger.msg(0, String.format(
- "AbstractMain.readC2KArgs(): New logStream added = [%b]",
- wMustAddNewLogStream));
+ if (wMustAddNewLogStream) Logger.msg(
+ String.format("New logStream added at logLevel %d: %s", logLevel, logStream.getClass().getName()));
// Dump params if log high enough
+
if (Logger.doLog(3)) for (Enumeration<?> e = argProps.propertyNames(); e.hasMoreElements();) {
String next = (String)e.nextElement();
System.out.println("AbstractMain: Param "+next+": "+argProps.getProperty(next));
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java
index bc93676..46e2cb6 100644
--- a/src/main/java/com/c2kernel/process/Bootstrap.java
+++ b/src/main/java/com/c2kernel/process/Bootstrap.java
@@ -106,7 +106,7 @@ public class Bootstrap
String itemName = thisItem.substring(delim+1);
try {
String location = "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml");
- verifyResource(ns, itemName, 0, itemType, location, 0, reset);
+ verifyResource(ns, itemName, 0, itemType, location, reset);
} catch (Exception e) {
Logger.error(e);
Logger.die("Error importing bootstrap items. Unsafe to continue.");
@@ -115,7 +115,7 @@ public class Bootstrap
}
- public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, String dataLocation, int layer, boolean reset) throws Exception {
+ public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, String dataLocation, boolean reset) throws Exception {
if (version == null) version = 0;
LookupManager lookupManager = Gateway.getLookupManager();
ResourceImportHandler typeImpHandler = getHandler(itemType);
@@ -127,7 +127,7 @@ public class Bootstrap
Iterator<Path> en = Gateway.getLookup().search(typeImpHandler.getTypeRoot(), itemName);
if (!en.hasNext()) {
Logger.msg("Bootstrap.verifyResource() - "+typeImpHandler.getName()+" "+itemName+" not found. Creating new.");
- thisProxy = createResourceItem(typeImpHandler, itemName, layer, ns);
+ thisProxy = createResourceItem(typeImpHandler, itemName, ns);
}
else {
DomainPath path = (DomainPath)en.next();
@@ -151,15 +151,6 @@ public class Bootstrap
Gateway.getStorage().put(thisProxy.getSystemKey(), new Property("Module", moduleName, false), thisProxy);
}
- // overwrite layer if different
- int currentLayer = -1;
- try {
- String layerProp = thisProxy.getProperty("Layer");
- currentLayer = Integer.parseInt(layerProp);
- } catch (Exception e) { }
- if (currentLayer != layer)
- Gateway.getStorage().put(thisProxy.getSystemKey(), new Property("Layer", String.valueOf(layer), false), thisProxy);
-
if (!modDomPath.equals(path)) { // move item to module subtree
Logger.msg("Module item "+itemName+" found with path "+path.toString()+". Moving to "+modDomPath.toString());
modDomPath.setEntity(new ItemPath(thisProxy.getSystemKey()));
@@ -195,13 +186,15 @@ public class Bootstrap
}
// data was missing or doesn't match
- // validate it
- OutcomeValidator validator = OutcomeValidator.getValidator(LocalObjectLoader.getSchema(newOutcome.getSchemaType(), newOutcome.getSchemaVersion()));
- String error = validator.validate(newOutcome.getData());
- if (error.length() > 0) {
- Logger.error("Outcome not valid: \n " + error);
- throw new InvalidDataException(error, "");
- }
+ // validate it (but not for kernel objects because we need those to validate the rest)
+ if (ns!= null) {
+ OutcomeValidator validator = OutcomeValidator.getValidator(LocalObjectLoader.getSchema(newOutcome.getSchemaType(), newOutcome.getSchemaVersion()));
+ String error = validator.validate(newOutcome.getData());
+ if (error.length() > 0) {
+ Logger.error("Outcome not valid: \n " + error);
+ throw new InvalidDataException(error, "");
+ }
+ }
// store
Logger.msg("Bootstrap.verifyResource() - Writing new "+newOutcome.getSchemaType()+" v"+version+" to "+typeImpHandler.getName()+" "+itemName);
@@ -246,10 +239,9 @@ public class Bootstrap
/**
* @param itemType
* @param itemName
- * @param layer
* @param data
*/
- private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, int layer, String ns) throws Exception {
+ private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, String ns) throws Exception {
// create props
PropertyDescriptionList pdList = impHandler.getPropDesc();
PropertyArrayList props = new PropertyArrayList();
@@ -258,12 +250,7 @@ public class Bootstrap
for (int i = 0; i < pdList.list.size(); i++) {
PropertyDescription pd = pdList.list.get(i);
String propName = pd.getName();
- String propVal;
- if (propName.equals("Name"))
- propVal = itemName;
- else if (propName.equals("Layer"))
- propVal = String.valueOf(layer);
- else propVal = pd.getDefaultValue();
+ String propVal = propName.equals("Name")?itemName:pd.getDefaultValue();
props.list.add(new Property(propName, propVal, pd.getIsMutable()));
}
diff --git a/src/main/java/com/c2kernel/process/ClientShell.java b/src/main/java/com/c2kernel/process/ClientShell.java
index 9f1d3ab..eeeb07f 100644
--- a/src/main/java/com/c2kernel/process/ClientShell.java
+++ b/src/main/java/com/c2kernel/process/ClientShell.java
@@ -5,6 +5,7 @@ import java.util.Scanner;
import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.process.auth.ProxyLogin;
import com.c2kernel.scripting.Script;
+import com.c2kernel.scripting.ScriptParsingException;
public class ClientShell extends StandardClient {
@@ -21,13 +22,15 @@ public class ClientShell extends StandardClient {
System.out.print("> ");
while (scan.hasNextLine()) {
String command = scan.nextLine();
- console.setScript(command);
try {
+ console.setScript(command);
Object response = console.execute();
if (response == null)
System.out.println("Ok");
else
System.out.println(response);
+ } catch (ScriptParsingException e) {
+ System.err.println("Syntax error: "+e.getMessage());
} catch (Throwable ex) {
ex.printStackTrace();
}
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java
index cd76d0e..85262e8 100644
--- a/src/main/java/com/c2kernel/process/Gateway.java
+++ b/src/main/java/com/c2kernel/process/Gateway.java
@@ -108,7 +108,11 @@ public class Gateway
// load kernel mapfiles giving the resourse loader and the properties of
// the application to be able to configure castor
- mMarshaller = new CastorXMLUtility(mResource, props, "mapFiles/");
+ try {
+ mMarshaller = new CastorXMLUtility(mResource, props, mResource.getKernelResourceURL("mapFiles/"));
+ } catch (MalformedURLException e1) {
+ throw new InvalidDataException("Invalid Resource Location", "");
+ }
// init module manager
diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java
index 195c883..1272026 100644
--- a/src/main/java/com/c2kernel/process/module/Module.java
+++ b/src/main/java/com/c2kernel/process/module/Module.java
@@ -57,7 +57,6 @@ public class Module {
moduleItem.properties.add(new com.c2kernel.property.Property("Namespace", ns, false));
moduleItem.properties.add(new com.c2kernel.property.Property("Name", name, false));
moduleItem.properties.add(new com.c2kernel.property.Property("Type", "Module", false));
- moduleItem.properties.add(new com.c2kernel.property.Property("Layer", String.valueOf(info.layer), true));
moduleItem.properties.add(new com.c2kernel.property.Property("Version", info.version, true));
// Add dependency for all children
ImportDependency children = new ImportDependency("Contents");
@@ -81,7 +80,7 @@ public class Module {
for (ModuleResource thisRes : imports.getResources()) {
try {
thisRes.path = Bootstrap.verifyResource(ns, thisRes.name, thisRes.version,
- thisRes.resourceType, thisRes.resourceLocation, info.layer, reset);
+ thisRes.resourceType, thisRes.resourceLocation, reset);
} catch (Exception ex) {
Logger.error(ex);
Logger.die("Error importing module resources. Unsafe to continue.");
diff --git a/src/main/java/com/c2kernel/process/module/ModuleInfo.java b/src/main/java/com/c2kernel/process/module/ModuleInfo.java
index 646a915..55e02c9 100644
--- a/src/main/java/com/c2kernel/process/module/ModuleInfo.java
+++ b/src/main/java/com/c2kernel/process/module/ModuleInfo.java
@@ -6,7 +6,6 @@ public class ModuleInfo {
public String desc;
public String version;
- public int layer = 0;
public ArrayList<String> dependency = new ArrayList<String>();
public ModuleInfo() {
diff --git a/src/main/java/com/c2kernel/scripting/Script.java b/src/main/java/com/c2kernel/scripting/Script.java
index 83849d9..d8ccee2 100644
--- a/src/main/java/com/c2kernel/scripting/Script.java
+++ b/src/main/java/com/c2kernel/scripting/Script.java
@@ -7,6 +7,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import javax.script.Bindings;
+import javax.script.Compilable;
+import javax.script.CompiledScript;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
@@ -41,6 +43,7 @@ import com.c2kernel.utils.Logger;
public class Script
{
String mScript = "";
+ CompiledScript mCompScript = null;
String mName;
Integer mVersion;
HashMap<String, Parameter> mInputParams = new HashMap<String, Parameter>();
@@ -55,7 +58,8 @@ public class Script
* @throws ScriptParsingException
* @throws ParameterException
*/
- public Script(String xml) throws ScriptParsingException, ParameterException {
+ public Script(String name, int version, String xml) throws ScriptParsingException, ParameterException {
+ mName = name; mVersion = version;
parseScriptXML(xml);
}
/**
@@ -93,7 +97,7 @@ public class Script
setScriptEngine(lang);
mVersion = null;
addOutput(null, returnType);
- mScript = expr;
+ setScript(expr);
}
/**
@@ -292,7 +296,7 @@ public class Script
if (scriptChildNodes.getLength() != 1)
throw new ScriptParsingException("More than one child element found under script tag. Script characters may need escaping - suggest convert to CDATA section");
if (scriptChildNodes.item(0) instanceof Text)
- mScript = ((Text) scriptChildNodes.item(0)).getData();
+ setScript(((Text) scriptChildNodes.item(0)).getData());
else
throw new ScriptParsingException("Child element of script tag was not text");
Logger.msg(6, "Script.parseScriptXML() - script:" + mScript);
@@ -475,7 +479,10 @@ public class Script
if (engine == null)
throw new ScriptingEngineException("Script engine not set. Cannot execute scripts.");
engine.put(ScriptEngine.FILENAME, mName);
- returnValue = engine.eval(mScript);
+ if (mCompScript != null)
+ returnValue = mCompScript.eval();
+ else
+ returnValue = engine.eval(mScript);
Logger.msg(7, "Script.execute() - script returned \"" + returnValue + "\"");
}
catch (Throwable ex)
@@ -516,8 +523,17 @@ public class Script
return outputs;
}
- public void setScript(String script) {
+ public void setScript(String script) throws ScriptParsingException {
mScript = script;
+ if (engine instanceof Compilable) {
+ try {
+ Logger.msg(1, "Compiling script "+mName);
+ engine.put(ScriptEngine.FILENAME, mName);
+ mCompScript = ((Compilable)engine).compile(mScript);
+ } catch (ScriptException e) {
+ throw new ScriptParsingException(e.getMessage());
+ }
+ }
}
static public void main(String[] args) {
diff --git a/src/main/java/com/c2kernel/utils/CastorXMLUtility.java b/src/main/java/com/c2kernel/utils/CastorXMLUtility.java
index c7d37dd..c5c2499 100644
--- a/src/main/java/com/c2kernel/utils/CastorXMLUtility.java
+++ b/src/main/java/com/c2kernel/utils/CastorXMLUtility.java
@@ -29,11 +29,11 @@ import com.c2kernel.process.resource.ResourceLoader;
* @author $Author: abranson $ $Date: 2004/10/20 14:10:21 $
* @version $Revision: 1.12 $
**************************************************************************/
-public class CastorXMLUtility{
+public class CastorXMLUtility
+{
public static final String CASTOR_XML_SERIALIZER_FACTORY = "org.exolab.castor.xml.serializer.factory";
-
- private XMLContext pCastorContext;
+ private XMLContext mappingContext;
/**
* Looks for a file called 'index.xml' at the given URL, and loads every
@@ -42,89 +42,77 @@ public class CastorXMLUtility{
* @param aResourceLoader
* the resource loader able to return the right class loader
* @param aAppProperties
- * the application properties containint optionnal castor
+ * the application properties containing optional castor
* configuration
- * @param aMapsSubPath
- * the map root sub path (in the kernel path)
+ * @param mapURL
+ * the root URL for the mapfiles
* @throws InvalidDataException
*/
public CastorXMLUtility(final ResourceLoader aResourceLoader,
- final Properties aAppProperties, final String aMapsSubPath)
+ final Properties aAppProperties, final URL mapURL)
throws InvalidDataException {
- // build base url
- URL wMapsURL ;
- try {
- wMapsURL = aResourceLoader.getKernelResourceURL(aMapsSubPath);
- } catch (MalformedURLException e) {
- throw new InvalidDataException(String.format(
- "Invalid Resource Location [%s]. Cause:%s", aMapsSubPath,
- e.getLocalizedMessage()));
- }
-
+
// load index
- Logger.msg(3,String.format( "CastorXMLUtility.<init> Loading maps from [%s]",wMapsURL));
+ Logger.msg(3,String.format( "CastorXMLUtility.<init> Loading maps from [%s]",mapURL));
String index;
try {
- index = FileStringUtility.url2String( new URL(wMapsURL, "index") );
+ index = FileStringUtility.url2String( new URL(mapURL, "index") );
} catch (Exception e) {
- throw new InvalidDataException(String.format("Could not load map index from [%s]",wMapsURL));
+ throw new InvalidDataException(String.format("Could not load map index from [%s]",mapURL));
}
// retrieve the class loader of the class "CastorXMLUtility"
- ClassLoader wKernelClassLoader = aResourceLoader
+ ClassLoader defaultClassLoader = aResourceLoader
.getClassLoader(CastorXMLUtility.class.getName());
Logger.msg(3, String.format(
- "CastorXMLUtility.<init>: iuse KernelClassLoader=[%s]",
- wKernelClassLoader));
+ "CastorXMLUtility.<init>: defaultClassLoader=[%s]",
+ defaultClassLoader));
StringTokenizer sTokenizer = new StringTokenizer(index);
int wNbMap = sTokenizer.countTokens();
// init the castor mapping using the classloader of the class "CastorXMLUtility"
- Mapping wCastorMapping = new Mapping(wKernelClassLoader);
+ Mapping thisMapping = new Mapping(defaultClassLoader);
HashSet<URL> loadedMapURLs = new HashSet<URL>();
try {
int wMapIdx=0;
while( sTokenizer.hasMoreTokens() ) {
- String wCurrentMap = sTokenizer.nextToken();
- URL wCurrentMapURL = new URL(wMapsURL, wCurrentMap);
+ String thisMap = sTokenizer.nextToken();
+ URL thisMapURL = new URL(mapURL, thisMap);
wMapIdx++;
- if( !loadedMapURLs.contains(wCurrentMapURL) ) {
- Logger.msg(
- 3,
- String.format(
- "CastorXMLUtility.<init>: Adding mapping file (%d/%d):[%s]",
- wMapIdx, wNbMap, wCurrentMapURL));
- wCastorMapping.loadMapping( wCurrentMapURL );
- loadedMapURLs.add( wCurrentMapURL );
+ if( !loadedMapURLs.contains(thisMapURL) ) {
+ Logger.msg( 3,
+ String.format("CastorXMLUtility.<init>: Adding mapping file (%d/%d):[%s]", wMapIdx, wNbMap, thisMapURL));
+ thisMapping.loadMapping( thisMapURL );
+ loadedMapURLs.add( thisMapURL );
}
else {
- Logger.msg(3,"Map file already loaded:"+wCurrentMapURL);
+ Logger.msg(3,"Map file already loaded:"+thisMapURL);
}
}
- pCastorContext = new XMLContext();
+ mappingContext = new XMLContext();
- pCastorContext.setClassLoader(wKernelClassLoader);
+ mappingContext.setClassLoader(defaultClassLoader);
// if the aAppProperties contains castor properties then
if (aAppProperties.contains(CASTOR_XML_SERIALIZER_FACTORY)) {
- pCastorContext.setProperty(CASTOR_XML_SERIALIZER_FACTORY,
+ mappingContext.setProperty(CASTOR_XML_SERIALIZER_FACTORY,
aAppProperties
.getProperty(CASTOR_XML_SERIALIZER_FACTORY));
Logger.msg(3, String.format(
"CastorXMLUtility.<init>: castor prop: %s=[%s]",
- CASTOR_XML_SERIALIZER_FACTORY, pCastorContext
+ CASTOR_XML_SERIALIZER_FACTORY, mappingContext
.getProperty(CASTOR_XML_SERIALIZER_FACTORY)));
}
- pCastorContext.addMapping(wCastorMapping);
+ mappingContext.addMapping(thisMapping);
} catch (MappingException ex) {
Logger.error(ex);
throw new InvalidDataException("XML Mapping files are not valid: "+ex.getMessage(), "");
@@ -136,7 +124,7 @@ public class CastorXMLUtility{
throw new InvalidDataException("Could not read XML mapping files: "+ex.getMessage(), "");
}
- Logger.msg(1, String.format("Loaded [%d] maps from [%s]",loadedMapURLs.size(),wMapsURL));
+ Logger.msg(1, String.format("Loaded [%d] maps from [%s]", loadedMapURLs.size(), mapURL));
}
/**************************************************************************
@@ -153,7 +141,7 @@ public class CastorXMLUtility{
if (obj instanceof Outcome)
return ((Outcome)obj).getData();
StringWriter sWriter = new StringWriter();
- Marshaller marshaller = pCastorContext.createMarshaller();
+ Marshaller marshaller = mappingContext.createMarshaller();
marshaller.setWriter(sWriter);
marshaller.setMarshalAsDocument( false );
@@ -174,7 +162,7 @@ public class CastorXMLUtility{
{
if (data.equals("<NULL/>")) return null;
StringReader sReader = new StringReader( data );
- Unmarshaller unmarshaller = pCastorContext.createUnmarshaller();
+ Unmarshaller unmarshaller = mappingContext.createUnmarshaller();
return unmarshaller.unmarshal( sReader );
}
}
diff --git a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java
index f0d8928..503e951 100644
--- a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java
+++ b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java
@@ -1,5 +1,5 @@
package com.c2kernel.utils;
-
+
import java.util.Iterator;
import com.c2kernel.common.InvalidDataException;
@@ -24,28 +24,15 @@ public class LocalObjectLoader {
{
DomainPath defRoot = new DomainPath(root);
Iterator<Path> e = Gateway.getLookup().search(defRoot, name);
- ItemProxy defProxy = null; int currentLayer = -1;
- while (e.hasNext()) {
+ if (e.hasNext()) {
DomainPath defPath = (DomainPath)e.next();
- ItemProxy thisProxy = Gateway.getProxyManager().getProxy(defPath);
- int thisLayer;
- try {
- String thisLayerProp = thisProxy.getProperty("Layer");
- thisLayer = Integer.parseInt(thisLayerProp);
- } catch (Exception ex) {
- thisLayer = 0;
- }
- if (thisLayer > currentLayer) {
- currentLayer = thisLayer;
- defProxy = thisProxy;
- }
- else if (thisLayer == currentLayer) {
- throw new ObjectNotFoundException("Duplicate definition for "+name+" in "+root+" found in Layer "+thisLayer, "");
- }
+ if (e.hasNext()) throw new ObjectNotFoundException("Too many matches for "+name+" in "+root, "");
+ return Gateway.getProxyManager().getProxy(defPath);
}
- if (defProxy == null)
+ else {
throw new ObjectNotFoundException("No match for "+name+" in "+root, "");
- return defProxy;
+ }
+
}
static public String getScript(String scriptName, int scriptVersion) throws ObjectNotFoundException {