diff options
| author | ogattaz <olivier@gattaz.com> | 2014-06-05 16:51:07 +0200 |
|---|---|---|
| committer | ogattaz <olivier@gattaz.com> | 2014-06-05 16:51:07 +0200 |
| commit | 2fd193d7936084de91eae46e8c2763914d87ab71 (patch) | |
| tree | b136ed97e535f11d4b3433d16c26570c89430ce4 /src/main/java/com/c2kernel/utils | |
| parent | 1225792532f77e6e8f4a9addfc0c0a6cf56e89b8 (diff) | |
| parent | e73468fd08cc27aa31f76a27c916e45d5987c628 (diff) | |
Merge branch 'master' of ssh://dev.cccs.uwe.ac.uk:22/var/git/cristal-kernel
Diffstat (limited to 'src/main/java/com/c2kernel/utils')
5 files changed, 50 insertions, 11 deletions
diff --git a/src/main/java/com/c2kernel/utils/ActDefCache.java b/src/main/java/com/c2kernel/utils/ActDefCache.java index ab2bd90..66695f5 100644 --- a/src/main/java/com/c2kernel/utils/ActDefCache.java +++ b/src/main/java/com/c2kernel/utils/ActDefCache.java @@ -34,6 +34,7 @@ public class ActDefCache extends DescriptionObjectCache<ActivityDef> { }
try {
thisActDef = (ActivityDef)Gateway.getMarshaller().unmarshall(marshalledAct);
+ thisActDef.getProperties().put("Version", version);
} catch (Exception ex) {
Logger.error(ex);
throw new InvalidDataException("Could not unmarshall '"+name+"' v"+version+": "+ex.getMessage(), "");
diff --git a/src/main/java/com/c2kernel/utils/DescriptionObject.java b/src/main/java/com/c2kernel/utils/DescriptionObject.java index 4d7d108..f8ba72d 100644 --- a/src/main/java/com/c2kernel/utils/DescriptionObject.java +++ b/src/main/java/com/c2kernel/utils/DescriptionObject.java @@ -4,5 +4,8 @@ public interface DescriptionObject { public String getName();
public int getVersion();
+
+ public void setName(String name);
+ public void setVersion(int version);
}
diff --git a/src/main/java/com/c2kernel/utils/DescriptionObjectCache.java b/src/main/java/com/c2kernel/utils/DescriptionObjectCache.java index d5382da..d7c5ec1 100644 --- a/src/main/java/com/c2kernel/utils/DescriptionObjectCache.java +++ b/src/main/java/com/c2kernel/utils/DescriptionObjectCache.java @@ -5,7 +5,7 @@ package com.c2kernel.utils; import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.proxy.EntityProxyObserver;
+import com.c2kernel.entity.proxy.ProxyObserver;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.entity.proxy.MemberSubscription;
import com.c2kernel.persistency.ClusterStorage;
@@ -37,7 +37,7 @@ public abstract class DescriptionObjectCache<D extends DescriptionObject> { public abstract D loadObject(String name, int version, ItemProxy proxy) throws ObjectNotFoundException, InvalidDataException;
- public void removeAct(String id) {
+ public void removeObject(String id) {
synchronized(cache) {
if (cache.keySet().contains(id)) {
Logger.msg(7, "ActDefCache: Removing activity def "+id+" from cache");
@@ -46,7 +46,7 @@ public abstract class DescriptionObjectCache<D extends DescriptionObject> { }
}
- public class CacheEntry<E extends DescriptionObject> implements EntityProxyObserver<Viewpoint> {
+ public class CacheEntry<E extends DescriptionObject> implements ProxyObserver<Viewpoint> {
public String id;
public ItemProxy proxy;
public E def;
@@ -60,17 +60,17 @@ public abstract class DescriptionObjectCache<D extends DescriptionObject> { }
@Override
public void finalize() {
- parent.removeAct(id);
+ parent.removeObject(id);
proxy.unsubscribe(this);
}
@Override
public void add(Viewpoint contents) {
- parent.removeAct(id);
+ parent.removeObject(id);
}
@Override
public void remove(String oldId) {
- parent.removeAct(oldId);
+ parent.removeObject(oldId);
}
@Override
diff --git a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java index aef7b96..f0d8928 100644 --- a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java +++ b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java @@ -1,11 +1,14 @@ package com.c2kernel.utils;
+import java.util.Iterator;
+
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lifecycle.ActivityDef;
import com.c2kernel.lifecycle.instance.stateMachine.StateMachine;
import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.lookup.Path;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Schema;
@@ -20,8 +23,29 @@ public class LocalObjectLoader { throws ObjectNotFoundException
{
DomainPath defRoot = new DomainPath(root);
- DomainPath defPath = (DomainPath)defRoot.find(name);
- return (ItemProxy)Gateway.getProxyManager().getProxy(defPath);
+ Iterator<Path> e = Gateway.getLookup().search(defRoot, name);
+ ItemProxy defProxy = null; int currentLayer = -1;
+ while (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 (defProxy == null)
+ throw new ObjectNotFoundException("No match for "+name+" in "+root, "");
+ return defProxy;
}
static public String getScript(String scriptName, int scriptVersion) throws ObjectNotFoundException {
diff --git a/src/main/java/com/c2kernel/utils/ObjectProperties.java b/src/main/java/com/c2kernel/utils/ObjectProperties.java index 79aee78..731b009 100644 --- a/src/main/java/com/c2kernel/utils/ObjectProperties.java +++ b/src/main/java/com/c2kernel/utils/ObjectProperties.java @@ -144,13 +144,24 @@ public class ObjectProperties extends Properties { }
public void dumpProps(int logLevel) {
- if (!Logger.doLog(logLevel)) return;
Logger.msg(logLevel, "Properties:");
for (Enumeration<?> e = propertyNames(); e.hasMoreElements();) {
String name = (String) e.nextElement();
- Logger.msg(" "+name+": "+getProperty(name));
+ Logger.msg(" "+name+" ("+getObject(name).getClass().getSimpleName()+"): "+getObject(name).toString());
}
}
-
+
+ public Object getInstance(String propName, Object defaultVal) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+ Object prop = getObject(propName, defaultVal);
+ if (prop == null || prop.equals(""))
+ throw new InstantiationException("Property '"+propName+"' was not defined. Cannot instantiate.");
+ if (prop instanceof String)
+ return Class.forName((String)prop).newInstance();
+ return prop;
+ }
+
+ public Object getInstance(String propName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+ return getInstance(propName, null);
+ }
}
|
