00001 package cast.server;
00002
00003 import Ice.Current;
00004 import Ice.Identity;
00005 import Ice.Object;
00006 import Ice.ObjectAdapter;
00007 import Ice.ObjectPrx;
00008 import cast.ComponentCreationException;
00009 import cast.cdl.CASTRELEASESTRING;
00010 import cast.core.CASTUtils;
00011 import cast.interfaces.CASTComponentPrx;
00012 import cast.interfaces.CASTComponentPrxHelper;
00013 import cast.interfaces.ManagedComponentPrx;
00014 import cast.interfaces.ManagedComponentPrxHelper;
00015 import cast.interfaces.TaskManagerPrx;
00016 import cast.interfaces.TaskManagerPrxHelper;
00017 import cast.interfaces.UnmanagedComponentPrx;
00018 import cast.interfaces.UnmanagedComponentPrxHelper;
00019 import cast.interfaces.WorkingMemoryPrx;
00020 import cast.interfaces.WorkingMemoryPrxHelper;
00021 import cast.interfaces._ComponentFactoryDisp;
00022
00030 public class CASTComponentFactory extends _ComponentFactoryDisp {
00031
00035 private static final long serialVersionUID = 1L;
00036
00037 public CASTComponentPrx newComponent(String _id, String _type, boolean _newProcess,
00038 Current __current) throws ComponentCreationException {
00039 ObjectPrx base = createBase(_id, _type, _newProcess, __current);
00040 CASTComponentPrx prx = CASTComponentPrxHelper.checkedCast(base);
00041 if (prx == null) {
00042 throw new ComponentCreationException(_type
00043 + " cannot be cast to a CASTComponentPrx");
00044 }
00045 return prx;
00046 }
00047
00048 public ManagedComponentPrx newManagedComponent(String _id, String _type, boolean _newProcess,
00049 Current __current) throws ComponentCreationException {
00050 ObjectPrx base = createBase(_id, _type, _newProcess, __current);
00051 ManagedComponentPrx prx = ManagedComponentPrxHelper.checkedCast(base);
00052 if (prx == null) {
00053 throw new ComponentCreationException(_type
00054 + " cannot be cast to a ManagaedComponentPrx");
00055 }
00056 return prx;
00057
00058 }
00059
00060 public TaskManagerPrx newTaskManager(String _id, String _type, boolean _newProcess,
00061 Current __current) throws ComponentCreationException {
00062 ObjectPrx base = createBase(_id, _type, _newProcess, __current);
00063 TaskManagerPrx prx = TaskManagerPrxHelper.checkedCast(base);
00064 if (prx == null) {
00065 throw new ComponentCreationException(_type
00066 + " cannot be cast to a TaskManagerPrx");
00067 }
00068 return prx;
00069
00070 }
00071
00072 public UnmanagedComponentPrx newUnmanagedComponent(String _id,
00073 String _type, boolean _newProcess, Current __current) throws ComponentCreationException {
00074 ObjectPrx base = createBase(_id, _type, _newProcess, __current);
00075 UnmanagedComponentPrx prx = UnmanagedComponentPrxHelper
00076 .checkedCast(base);
00077 if (prx == null) {
00078 throw new ComponentCreationException(_type
00079 + " cannot be cast to a UmanagedComponentPrx");
00080 }
00081 return prx;
00082
00083 }
00084
00085 public WorkingMemoryPrx newWorkingMemory(String _id, String _type, boolean _newProcess,
00086 Current __current) throws ComponentCreationException {
00087 ObjectPrx base = createBase(_id, _type, _newProcess, __current);
00088 WorkingMemoryPrx prx = WorkingMemoryPrxHelper.checkedCast(base);
00089 if (prx == null) {
00090 throw new ComponentCreationException(_type
00091 + " cannot be cast to a WorkingMemoryPrx");
00092 }
00093 return prx;
00094
00095 }
00096
00097 private ObjectPrx createBase(String _id, String _type, boolean _newProcess, Current __current)
00098 throws ComponentCreationException {
00099 try {
00100 ObjectAdapter adapter = __current.adapter;
00101 Identity id = new Identity(_id, _type);
00102 Object servant = CASTUtils.createServant(id, adapter);
00103 ObjectPrx base = adapter.add(servant, id);
00104 assert (base != null);
00105 return base;
00106 } catch (ClassNotFoundException e) {
00107 ComponentCreationException cce = new ComponentCreationException(
00108 "Unable to create component: Cannot find class "
00109 + e.getMessage());
00110 cce.initCause(e);
00111 throw cce;
00112 } catch (Exception e) {
00113 ComponentCreationException cce = new ComponentCreationException(
00114 "Unable to create component: " + e.getClass() + ": "
00115 + e.getMessage());
00116 cce.initCause(e);
00117 throw cce;
00118 }
00119 }
00120
00121 public String getVersionString(Current __current) {
00122 return CASTRELEASESTRING.value;
00123 }
00124
00125
00126
00127
00128
00129
00130 }