summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/persistency/ProxyLoader.java
diff options
context:
space:
mode:
Diffstat (limited to 'source/com/c2kernel/persistency/ProxyLoader.java')
-rwxr-xr-xsource/com/c2kernel/persistency/ProxyLoader.java124
1 files changed, 124 insertions, 0 deletions
diff --git a/source/com/c2kernel/persistency/ProxyLoader.java b/source/com/c2kernel/persistency/ProxyLoader.java
new file mode 100755
index 0000000..d20fb2d
--- /dev/null
+++ b/source/com/c2kernel/persistency/ProxyLoader.java
@@ -0,0 +1,124 @@
+package com.c2kernel.persistency;
+import java.util.HashMap;
+import java.util.StringTokenizer;
+
+import com.c2kernel.entity.AgentHelper;
+import com.c2kernel.entity.C2KLocalObject;
+import com.c2kernel.entity.ItemHelper;
+import com.c2kernel.entity.ManageableEntity;
+import com.c2kernel.lookup.EntityPath;
+import com.c2kernel.lookup.LDAPLookup;
+import com.c2kernel.persistency.outcome.Outcome;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+/** Used by proxies to load clusters by queryData from the Entity.
+* Last client storage - only used if not cached elsewhere
+*/
+
+public class ProxyLoader extends ClusterStorage {
+ HashMap entities = new HashMap();
+ LDAPLookup lookup;
+
+ public void open() throws ClusterStorageException {
+ lookup = Gateway.getLDAPLookup();
+ }
+
+ public void close() throws ClusterStorageException {
+ }
+ // introspection
+ public short queryClusterSupport(String clusterType) {
+ return READ;
+ }
+
+ public String getName() {
+ return "Proxy Cluster Loader";
+ }
+
+ public String getId() {
+ return "CORBA";
+ }
+
+ // retrieve object by path
+ public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
+ try {
+ ManageableEntity thisEntity = getIOR(sysKey);
+ String type = getClusterType(path);
+
+ // fetch the xml from the item
+ String queryData = thisEntity.queryData(path);
+
+ if (queryData != null) {
+ if (type.equals(OUTCOME))
+ return new Outcome(path, queryData);
+ else
+ return (C2KLocalObject)CastorXMLUtility.unmarshall(queryData);
+ }
+ } catch (Exception e) {
+ //Logger.error(e);
+ throw new ClusterStorageException(e.getMessage());
+ }
+ return null;
+ }
+
+ // store object by path
+ public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
+ // not supported
+ throw new ClusterStorageException("Cannot write to items through the ProxyLoader");
+ }
+ // delete cluster
+ public void delete(Integer sysKey, String path) throws ClusterStorageException {
+ // not supported
+ throw new ClusterStorageException("Cannot write to items through the ProxyLoader");
+ }
+
+ /* navigation */
+
+ // directory listing
+ public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
+ try {
+ ManageableEntity thisEntity = getIOR(sysKey);
+ String contents = thisEntity.queryData(path+"/all");
+ StringTokenizer tok = new StringTokenizer(contents, ",");
+ String[] result = new String[tok.countTokens()];
+ for (int i=0; i<result.length; i++)
+ result[i] = tok.nextToken();
+
+ return result;
+ } catch (Exception e) {
+ throw new ClusterStorageException(e.getMessage());
+ }
+ }
+
+ private ManageableEntity getIOR(Integer sysKey) throws ClusterStorageException {
+ if (entities.containsKey(sysKey)) {
+ // check the cache
+ Logger.msg(7, "ProxyLoader.getIOR() - "+sysKey+" cached.");
+ return (ManageableEntity)entities.get(sysKey);
+ }
+
+ try {
+ Logger.msg(7, "ProxyLoader.getIOR() - Resolving "+sysKey+".");
+
+ org.omg.CORBA.Object ior = lookup.getIOR(new EntityPath(sysKey.intValue()));
+
+ ManageableEntity thisEntity = null;
+ try {
+ thisEntity = ItemHelper.narrow(ior);
+ } catch (org.omg.CORBA.BAD_PARAM ex) {
+ try {
+ thisEntity = AgentHelper.narrow(ior);
+ } catch (org.omg.CORBA.BAD_PARAM ex2) {
+ throw new ClusterStorageException ("Could not narrow "+sysKey+" as a known Entity type");
+ }
+ }
+
+ Logger.msg(7, "ProxyLoader.getIOR() - Found "+sysKey+".");
+ entities.put(sysKey, thisEntity);
+ return thisEntity;
+ } catch (Exception e) {
+ throw new ClusterStorageException("Error narrowing "+sysKey+": "+e.getMessage());
+ }
+ }
+}