1 6 7 package SOFA.Connector.ECG.SGenerator.Connectors; 8 9 import SOFA.Connector.ConnectorException; 10 import SOFA.Connector.LinkException; 11 import SOFA.Connector.Linkable; 12 import SOFA.Connector.Reference; 13 import SOFA.Connector.RoleBase; 14 import SOFA.Connector.RoleBaseImpl; 15 import SOFA.Connector.TaggedProfile; 16 import SOFA.Connector.EEG.Types.CRole; 17 import SOFA.Connector.EEG.Types.Distributor; 18 import SOFA.Connector.EEG.Types.Interceptor; 19 import SOFA.Connector.EEG.Types.SRole; 20 import SOFA.Connector.EEG.Types.Skeleton; 21 import SOFA.Connector.EEG.Types.Stub; 22 23 28 public class EventPassingImpl extends RoleBaseImpl implements SOFA.Connector.ECG.Types.EventPassing, SOFA.Connector.EEG.ConnectorManagerInterface { 29 30 protected SRole cRole; 31 protected Interceptor cInterceptor; 32 protected Skeleton skeleton[]; 33 34 protected CRole sRole; 35 protected Interceptor sInterceptor; 36 protected Distributor distributor; 37 protected java.util.LinkedList availableStubs; 39 40 public EventPassingImpl() { 41 } 42 43 static public RoleBase createConnector(SOFA.Connector.ECG.DeploymentDescriptor dd, ClassLoader cl) throws ConnectorException { 44 EventPassingImpl pc=new EventPassingImpl(); 45 RoleBase role=null; 46 if (dd.unit.equals("Supplier")) { 47 try { 48 Linkable last; 49 50 SOFA.Connector.EEG.ElementOutputDescriptor sRoleClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"sRole"); 51 pc.sRole=(CRole)Class.forName(sRoleClass.impl, true, cl).newInstance(); 52 pc.sRole.setManagerTie(pc); 53 last=pc.sRole; 54 55 SOFA.Connector.EEG.ElementOutputDescriptor sInterceptorClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"sInterceptor"); 56 if (sInterceptorClass!=null) { 57 pc.sInterceptor=(Interceptor)Class.forName(sInterceptorClass.impl, true, cl).newInstance(); 58 pc.sInterceptor.setManagerTie(pc); 59 last.link(pc.sInterceptor); 60 last=pc.sInterceptor; 61 } 62 63 SOFA.Connector.EEG.ElementOutputDescriptor distributorClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"distributor"); 64 pc.distributor=(Distributor)Class.forName(distributorClass.impl, true, cl).newInstance(); 65 pc.distributor.setManagerTie(pc); 66 last.link(pc.distributor); 67 68 pc.availableStubs=new java.util.LinkedList (); 69 70 for (int i=0;i<dd.elements.length;i++) { 71 if (dd.elements[i].name.equals("stub")) { 72 pc.availableStubs.add(Class.forName(dd.elements[i].impl, true, cl).newInstance()); 73 } 74 } 75 76 pc.setDeploymentDescriptor(dd); 77 78 role=pc.sRole; 79 } catch (Exception e) { 80 throw new ConnectorException("Can't instantiate sRole.",e); 81 } 82 } else if (dd.unit.equals("Consumer")) { 83 try { 84 Object last; 85 86 SOFA.Connector.EEG.ElementOutputDescriptor cRoleClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"cRole"); 87 pc.cRole=(SRole)Class.forName(cRoleClass.impl, true, cl).newInstance(); 88 pc.cRole.setManagerTie(pc); 89 last=pc.cRole; 90 91 SOFA.Connector.EEG.ElementOutputDescriptor cInterceptorClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"cInterceptor"); 92 if (cInterceptorClass!=null) { 93 pc.cInterceptor=(Interceptor)Class.forName(cInterceptorClass.impl, true, cl).newInstance(); 94 pc.cInterceptor.setManagerTie(pc); 95 pc.cInterceptor.link(last); 96 last=pc.cInterceptor; 97 } 98 99 int i, j, skelNum=0; 100 101 for (i=0;i<dd.elements.length;i++) { 102 if (dd.elements[i].name.equals("skeleton")) { 103 skelNum++; 104 } 105 } 106 107 pc.skeleton=new Skeleton[skelNum]; 108 java.util.LinkedList profiles=new java.util.LinkedList (); 109 110 skelNum=0; 111 for (i=0;i<dd.elements.length;i++) { 112 if (dd.elements[i].name.equals("skeleton")) { 113 pc.skeleton[skelNum]=(Skeleton)Class.forName(dd.elements[i].impl, true, cl).newInstance(); 114 pc.skeleton[skelNum].setManagerTie(pc); 115 pc.skeleton[skelNum].link(last); 116 117 TaggedProfile[] prf=pc.skeleton[skelNum].getProfiles(); 118 for (j=0;j<prf.length;j++) { 119 profiles.add(prf[j]); 120 } 121 skelNum++; 122 } 123 } 124 125 TaggedProfile[] prf=new TaggedProfile[profiles.size()]; 126 java.util.Iterator iter=profiles.iterator(); 127 for (i=0;iter.hasNext();i++) { 128 prf[i]=(TaggedProfile)iter.next(); 129 } 130 131 pc.setSOFAReference(new Reference(dd.impl,prf)); 132 pc.setDeploymentDescriptor(dd); 133 134 role=pc.cRole; 135 } catch (Exception e) { 136 throw new ConnectorException("Can't instantiate cRole.",e); 137 } 138 } else { 139 throw new ConnectorException("Unknown unit '"+dd.unit+"'."); 140 } 141 return role; 142 } 143 144 public void link(Object target) throws LinkException { 145 Reference ref=(Reference)target; 146 java.util.Iterator iter=availableStubs.iterator(); 147 148 while (iter.hasNext()) { 149 Stub st=(Stub)iter.next(); 150 String [] profileNames=(st).getSupportedProfiles(); 151 int i, j; 152 153 for (i=0;i<profileNames.length;i++) { 154 for (j=0;j<ref.profiles.length;j++) { 155 if (profileNames[i].equals(ref.profiles[j].tag)) { 156 try { 157 st=(Stub)st.getClass().newInstance(); 158 st.setManagerTie(this); 159 st.link(ref.profiles[j]); 160 distributor.link(st); 161 } catch (Exception e) { 162 throw new LinkException("Can't create stub ("+st.getClass()+").",e); 163 } 164 return; 165 } 166 } 167 } 168 } 169 } 170 171 public String getName() { 172 return getConnectorName(); 173 } 174 175 } 176 | Popular Tags |