1 2 package SOFA.Component; 3 4 import java.lang.reflect.Method ; 5 6 import SOFA.Connector.Reference; 7 import SOFA.Connector.RoleBase; 8 import SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor; 9 10 14 public abstract class ComponentManagerImpl implements ComponentManager, org.objectweb.fractal.api.Type { 15 16 17 protected NamedElementRegister provides; 18 19 protected NamedElementRegister requires; 20 21 protected NamedElementRegister subsumableRequires; 22 23 protected NamedElementRegister delegatedProvides; 24 25 protected NamedElementRegister subcomponents; 26 27 protected DeploymentDescriptor dd; 28 29 protected ThreadIDRegistry thrRegistry; 30 31 32 33 protected String node; 34 35 protected String dockName; 36 41 protected String releaseVersion; 42 43 protected SOFA.SOFAnode.Run.Deployment.DeplDock localdock; 44 45 46 protected String fullName; 47 48 49 protected String id; 50 51 52 public ComponentManagerImpl(DeploymentDescriptor _dd, String _node, String _dockName, SOFA.SOFAnode.Run.Deployment.DeplDock _localdock, String _id) { 53 dd = _dd; 54 localdock = _localdock; 55 releaseVersion = dd.getReleaseVersion(); 56 node = _node; 57 dockName = _dockName; 58 id = _id; 59 60 try { 61 thisRB = SOFA.Connector.Boot.DCUPComponentManagerConnector.createSrv(this, id); 62 } catch (SOFA.Connector.ConnectorException e) { 63 throw new ComponentLifecycleException("ConnectorException: "+e.getMessage(), e); 64 } 65 provides = new NamedElementRegister(); 68 requires = new NamedElementRegister(); 69 subsumableRequires = new NamedElementRegister(); 70 delegatedProvides = new NamedElementRegister(); 71 subcomponents = new NamedElementRegister(); 72 thrRegistry = new ThreadIDRegistryImpl(_node); 73 74 fullName = dd.getArchitectureAbsName()+"["+dd.getReleaseVersion()+"]"; 75 } 76 77 public void registerSubcomponent(String name, SOFA.Connector.Reference ref) throws NamingException, InstantiationException { 78 try { 79 RoleBase target = SOFA.Connector.Boot.DCUPComponentManagerConnector.createClt(ref); 80 subcomponents.registerElementNamed(name, target); 81 } catch (SOFA.Connector.ConnectorException e) { 82 throw new InstantiationException ("ConnectorException: "+e.getMessage()); 83 } 84 } 85 86 public void unregisterSubcomponent(String name) throws NamingException { 87 subcomponents.unregisterElementNamed(name); 88 } 89 90 95 public RoleBase getProvision(String name) throws NamingException { 96 return (RoleBase) provides.getElementNamed(name); 97 } 98 99 public Reference getProvisionReference(String name) throws NamingException { 100 return ((RoleBase) provides.getElementNamed(name)).getSOFAReference(); 101 } 102 103 public void setRequirement(String name, Reference ref) throws InstantiationException , NamingException { 104 RoleBase cRole = instantiateConnector(name); 105 try { 106 cRole.link(ref); 107 } catch (SOFA.Connector.LinkException e) { 108 throw new InstantiationException ("LinkException: "+e.getMessage(), e ); 109 } 110 requires.forceRegisterElementNamed(name, cRole); 111 } 112 113 120 public void setProvisionImpl(String name, Object prov) throws NamingException, InstantiationException { 121 try { 122 127 RoleBase ret = instantiateConnector(name); 128 ret.link(prov); 129 provides.registerElementNamed(name, ret); 133 } catch (SOFA.Connector.ConnectorException e) { 134 throw new InstantiationException ("ConnectorException: "+e.getMessage()); 135 } 136 } 137 138 145 public void reSetProvisionImpl(String name, Object prov) throws NamingException { 146 try { 147 RoleBase ret = (RoleBase) provides.getElementNamed(name); 148 ret.link(prov); 149 } catch (SOFA.Connector.ConnectorException e) { 150 throw new InstantiationException ("ConnectorException: "+e.getMessage()); 151 } 152 } 153 154 160 public void delegateProvision(String name, Reference ref) throws NamingException, InstantiationException { 161 try { 162 167 RoleBase ret = instantiateConnector("_delegate_"+name); 168 ret.link(ref); 169 delegatedProvides.registerElementNamed(name, ret); 170 } catch (SOFA.Connector.ConnectorException e) { 171 throw new InstantiationException ("ConnectorException: "+e.getMessage()); 172 } 173 } 174 175 180 public void createProvision(String name) throws NamingException, InstantiationException { 181 RoleBase ret = instantiateConnector(name); 182 provides.registerElementNamed(name, ret); 183 } 184 185 190 public void connectDelegated() throws NamingException, InstantiationException { 191 for (java.util.Enumeration e = provides.keys(); e.hasMoreElements(); ) { 192 String name = (String ) e.nextElement(); 193 RoleBase sRole = (RoleBase) provides.getElementNamed(name); 194 RoleBase cRole = (RoleBase) delegatedProvides.getElementNamed(name); 195 try { 196 sRole.link(cRole); 197 } catch (SOFA.Connector.LinkException ex) { 198 throw new InstantiationException ("LinkException: "+ex.getMessage() ); 199 } 200 } 201 } 202 203 209 public Reference createSubsumableRequirement(String name) throws NamingException, InstantiationException { 210 215 RoleBase ret = instantiateConnector("_subsume_"+name); 216 subsumableRequires.forceRegisterElementNamed(name, ret); 217 return ret.getSOFAReference(); 218 } 219 220 public void connectSubsumable() throws NamingException, InstantiationException { 221 for (java.util.Enumeration e = subsumableRequires.keys(); e.hasMoreElements(); ) { 222 String name = (String ) e.nextElement(); 223 RoleBase sRole = (RoleBase) subsumableRequires.getElementNamed(name); 224 RoleBase cRole = (RoleBase) requires.getElementNamed(name); 225 try { 226 sRole.link(cRole); 227 } catch (SOFA.Connector.LinkException ex) { 228 throw new InstantiationException ("LinkException: "+ex.getMessage() ); 229 } 230 } 231 } 232 233 236 private RoleBase instantiateConnector(String name) throws InstantiationException { 237 try { 238 SOFA.Connector.DeploymentDescriptor connDD = dd.getConnectorDeploymentDescriptor(name); 240 String type = connDD.getConnectorBuilder(); 241 Class cl = Class.forName(type, true, SOFA.SOFAnode.Run.SOFACompClassLoader.getCompClassLoader()); 242 Class [] par = new Class [2]; 243 par[0] = Class.forName("SOFA.Connector.ECG.DeploymentDescriptor"); 244 par[1] = Class.forName("java.lang.ClassLoader"); 245 Method m = cl.getMethod("createConnector", par); 246 Object [] arg = new Object [2]; 247 arg[0] = connDD; 248 arg[1] = SOFA.SOFAnode.Run.SOFACompClassLoader.getCompClassLoader(); 249 RoleBase conn = (RoleBase) m.invoke(null, arg); 250 conn.setThrIDRegistry(thrRegistry); 251 conn.setComponentManager(thisRB); 252 return conn; 253 254 258 } catch (ClassNotFoundException e) { 259 throw new InstantiationException ("ClassNotFoundException: "+e.getMessage(), e); 260 } catch (NoSuchMethodException e) { 261 throw new InstantiationException ("NoSuchMethodException: "+e.getMessage(), e); 262 } catch (IllegalAccessException e) { 263 throw new InstantiationException ("IllegalAccessException: "+e.getMessage(), e); 264 } catch (java.lang.reflect.InvocationTargetException e) { 265 throw new InstantiationException ("InvocationTargetException: "+e.getMessage(), e); 266 } 267 } 268 269 270 public SOFA.SOFAnode.Run.Deployment.DeplDock getLocalDeplDock() { 271 return localdock; 272 } 273 274 278 public Object getRequirement(String name) throws NamingException { 279 return requires.getElementNamed(name); 280 } 281 282 public String getFullName() { 283 return fullName; 284 } 285 286 293 public Class loadComponentClass(String name) throws ClassNotFoundException { 294 return SOFA.SOFAnode.Run.SOFACompClassLoader.loadComponentClass(name, releaseVersion); 295 } 296 297 298 private SOFA.Connector.RoleBase thisRB; 299 300 304 public void connToThisCM(SOFA.Connector.RoleBase rb) { 305 thisRB = rb; 306 } 307 308 312 public SOFA.Connector.RoleBase connToThisCM() { 313 return thisRB; 314 } 315 316 317 318 320 public Object [] getFcInterfaces() { 321 java.util.ArrayList ret = new java.util.ArrayList (); 322 for ( java.util.Enumeration e = provides.getAllNames(); e.hasMoreElements(); ) { 323 ret.add(e.nextElement()); 324 } 325 return ret.toArray(); 326 } 327 328 public Object getFcInterface(java.lang.String itfName) throws org.objectweb.fractal.api.NoSuchInterfaceException { 329 Object ret = null; 330 try { 331 ret = provides.getElementNamed(itfName); 332 } catch (NamingException e) { 333 throw new org.objectweb.fractal.api.NoSuchInterfaceException("No such interface", e); 334 } 335 return ret; 336 } 337 338 public org.objectweb.fractal.api.Type getFcType() { 339 return this; 340 } 341 342 public boolean isFcSubtypeOf(org.objectweb.fractal.api.Type t) { 344 return false; 346 } 347 } 348 | Popular Tags |