KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Connector > ECG > SGenerator > Connectors > CSProcCallImpl


1 /*
2  * CSProcCallImpl.java
3  *
4  * Created on 5. duben 2002, 13:50
5  */

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.Interceptor;
18 import SOFA.Connector.EEG.Types.SRole;
19 import SOFA.Connector.EEG.Types.Skeleton;
20 import SOFA.Connector.EEG.Types.Stub;
21
22 /**
23  *
24  * @author ghort
25  * @version
26  */

27 public class CSProcCallImpl extends RoleBaseImpl implements SOFA.Connector.ECG.Types.CSProcCall, SOFA.Connector.EEG.ConnectorManagerInterface {
28
29     protected CRole cRole;
30     protected Interceptor cInterceptor;
31     protected Stub stub;
32
33     protected SRole sRole;
34     protected Interceptor sInterceptor;
35     protected Skeleton skeleton[];
36     
37     /** Creates new CSProcCallImpl */
38     public CSProcCallImpl() {
39     }
40
41     static public RoleBase createConnector(SOFA.Connector.ECG.DeploymentDescriptor dd, ClassLoader JavaDoc cl) throws ConnectorException {
42 // ClassLoader cl = ClassLoader.getSystemClassLoader();
43
//ClassLoader cl = getClass().getClassLoader();
44
CSProcCallImpl pc=new CSProcCallImpl();
45         RoleBase role=null;
46         if (dd.unit.equals("Client")) {
47             try {
48                 Linkable last;
49
50                 SOFA.Connector.EEG.ElementOutputDescriptor cRoleClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"cRole");
51 // pc.cRole=(CRole)Class.forName(cRoleClass.impl,true, new SOFA.SOFAnode.Run.SOFASystemClassLoader()).newInstance();
52
pc.cRole=(CRole)Class.forName(cRoleClass.impl, true, cl).newInstance();
53                 pc.cRole.setManagerTie(pc);
54                 last=pc.cRole;
55
56                 SOFA.Connector.EEG.ElementOutputDescriptor cInterceptorClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"cInterceptor");
57                 if (cInterceptorClass!=null) {
58                     pc.cInterceptor=(Interceptor)Class.forName(cInterceptorClass.impl, true, cl).newInstance();
59                     pc.cInterceptor.setManagerTie(pc);
60                     last.link(pc.cInterceptor);
61                     last=pc.cInterceptor;
62                 }
63                 
64                 SOFA.Connector.EEG.ElementOutputDescriptor stubClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"stub");
65                 pc.stub=(Stub)Class.forName(stubClass.impl,true, cl).newInstance();
66                 pc.stub.setManagerTie(pc);
67                 last.link(pc.stub);
68                 
69                 pc.setDeploymentDescriptor(dd);
70
71                 role=pc.cRole;
72             } catch (Exception JavaDoc e) {
73                 throw new ConnectorException("Can't instantiate cRole.",e);
74             }
75         } else if (dd.unit.equals("Server")) {
76             try {
77                 Object JavaDoc last;
78
79                 SOFA.Connector.EEG.ElementOutputDescriptor sRoleClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"sRole");
80                 pc.sRole=(SRole)Class.forName(sRoleClass.impl,true, cl).newInstance();
81 // pc.sRole=(SRole)Class.forName(sRoleClass.impl).newInstance();
82
pc.sRole.setManagerTie(pc);
83                 last=pc.sRole;
84                 
85                 SOFA.Connector.EEG.ElementOutputDescriptor sInterceptorClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"sInterceptor");
86                 if (sInterceptorClass!=null) {
87                     pc.sInterceptor=(Interceptor)Class.forName(sInterceptorClass.impl, true, cl).newInstance();
88                     pc.sInterceptor.setManagerTie(pc);
89                     pc.sInterceptor.link(last);
90                     last=pc.sInterceptor;
91                 }
92
93                 int i, skelNum=0;
94                 for (i=0;i<dd.elements.length;i++) {
95                     if (dd.elements[i].name.equals("skeleton")) {
96                         skelNum++;
97                     }
98                 }
99
100                 pc.skeleton=new Skeleton[skelNum];
101                 java.util.LinkedList JavaDoc profiles=new java.util.LinkedList JavaDoc();
102
103                 skelNum=0;
104                 for (i=0;i<dd.elements.length;i++) {
105                     if (dd.elements[i].name.equals("skeleton")) {
106                         pc.skeleton[skelNum]=(Skeleton)Class.forName(dd.elements[i].impl,true, cl).newInstance();
107                         pc.skeleton[skelNum].setManagerTie(pc);
108                         pc.skeleton[skelNum].link(last);
109                         
110                         TaggedProfile[] prf=pc.skeleton[skelNum].getProfiles();
111                         for (int j=0;j<prf.length;j++) {
112                             profiles.add(prf[j]);
113                         }
114                         skelNum++;
115                     }
116                 }
117
118                 TaggedProfile[] prf=new TaggedProfile[profiles.size()];
119                 java.util.Iterator JavaDoc iter=profiles.iterator();
120                 for (i=0;iter.hasNext();i++) {
121                     prf[i]=(TaggedProfile)iter.next();
122                 }
123                 
124                 pc.setSOFAReference(new Reference(dd.impl,prf));
125                 pc.setDeploymentDescriptor(dd);
126                 
127                 role=pc.sRole;
128             } catch (Exception JavaDoc e) {
129                 throw new ConnectorException("Can't instantiate sRole.",e);
130             }
131         } else {
132             throw new ConnectorException("Unknown unit '"+dd.unit+"'.");
133         }
134         return role;
135     }
136
137     public void link(Object JavaDoc target) throws LinkException {
138         Reference ref=(Reference)target;
139         String JavaDoc[] profileNames=stub.getSupportedProfiles();
140         int i, j;
141
142         for (i=0;i<profileNames.length;i++) {
143             for (j=0;j<ref.profiles.length;j++) {
144                 if (profileNames[i].equals(ref.profiles[j].tag)) {
145                     stub.link(ref.profiles[j]);
146                     return;
147                 }
148             }
149         }
150     }
151
152         public String JavaDoc getName() {
153           return getConnectorName();
154         }
155
156 }
157
Popular Tags