package com.c2kernel.persistency; import java.util.HashMap; import java.util.StringTokenizer; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.AgentHelper; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.Item; import com.c2kernel.entity.ItemHelper; import com.c2kernel.lookup.ItemPath; import com.c2kernel.lookup.Lookup; import com.c2kernel.persistency.outcome.Outcome; import com.c2kernel.process.Gateway; import com.c2kernel.process.auth.Authenticator; 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(); Lookup lookup; @Override public void open(Authenticator auth) throws ClusterStorageException { lookup = Gateway.getLookup(); } @Override public void close() throws ClusterStorageException { } // introspection @Override public short queryClusterSupport(String clusterType) { return READ; } @Override public String getName() { return "Proxy Cluster Loader"; } @Override public String getId() { return "CORBA"; } // retrieve object by path @Override public C2KLocalObject get(ItemPath thisItem, String path) throws ClusterStorageException { try { Item thisEntity = getIOR(thisItem); String type = getClusterType(path); // fetch the xml from the item String queryData = thisEntity.queryData(path); if (Logger.doLog(6)) Logger.msg(6, "ProxyLoader - "+thisItem+":"+path+" = "+queryData); if (queryData != null) { if (type.equals(OUTCOME)) return new Outcome(path, queryData); else return (C2KLocalObject)Gateway.getMarshaller().unmarshall(queryData); } } catch (ObjectNotFoundException e) { return null; } catch (Exception e) { Logger.error(e); throw new ClusterStorageException(e.getMessage()); } return null; } // store object by path @Override public void put(ItemPath thisItem, C2KLocalObject obj) throws ClusterStorageException { // not supported throw new ClusterStorageException("Cannot write to items through the ProxyLoader"); } // delete cluster @Override public void delete(ItemPath thisItem, String path) throws ClusterStorageException { // not supported throw new ClusterStorageException("Cannot write to items through the ProxyLoader"); } /* navigation */ // directory listing @Override public String[] getClusterContents(ItemPath thisItem, String path) throws ClusterStorageException { try { Item thisEntity = getIOR(thisItem); String contents = thisEntity.queryData(path+"/all"); StringTokenizer tok = new StringTokenizer(contents, ","); String[] result = new String[tok.countTokens()]; for (int i=0; i