KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * DataStreamImpl.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.EEG.Types.CRole;
16 import SOFA.Connector.EEG.Types.Interceptor;
17 import SOFA.Connector.EEG.Types.Receiver;
18 import SOFA.Connector.EEG.Types.SRole;
19 import SOFA.Connector.EEG.Types.Sender;
20
21 /**
22  *
23  * @author ghort
24  * @version
25  */

26 public class DataStreamImpl extends RoleBaseImpl implements SOFA.Connector.ECG.Types.DataStream, SOFA.Connector.EEG.ConnectorManagerInterface {
27
28     protected CRole pushSRole;
29     protected SRole pullSRole;
30     protected Interceptor pushSInterceptor;
31     protected Interceptor pullSInterceptor;
32     protected Sender sender;
33
34     protected SRole pushRRole;
35     protected CRole pullRRole;
36     protected Interceptor pushRInterceptor;
37     protected Interceptor pullRInterceptor;
38     protected Receiver receiver;
39
40     protected final static int pullMode=0;
41     protected final static int pushMode=1;
42     
43     /** Creates new DataStreamImpl */
44     public DataStreamImpl() {
45     }
46
47     static public RoleBase createConnector(SOFA.Connector.ECG.DeploymentDescriptor dd, ClassLoader JavaDoc cl) throws ConnectorException {
48         int sMode, rMode;
49         String JavaDoc mode=SOFA.Connector.Property.findFirst(dd.params,"senderMode");
50         if (mode!=null) {
51             if (mode.equals("push")) {
52                 sMode=pushMode;
53             } else if (mode.equals("pull")) {
54                 sMode=pullMode;
55             } else {
56                 throw new ConnectorException("Parameter senderMode is incorrect '"+mode+"'.");
57             }
58         } else {
59             throw new ConnectorException("Parameter senderMode is not specified");
60         }
61
62         mode=SOFA.Connector.Property.findFirst(dd.params,"receiverMode");
63         if (mode!=null) {
64             if (mode.equals("push")) {
65                 rMode=pushMode;
66             } else if (mode.equals("pull")) {
67                 rMode=pullMode;
68             } else {
69                 throw new ConnectorException("Parameter receiverMode is incorrect '"+mode+"'.");
70             }
71         } else {
72             throw new ConnectorException("Parameter receiverMode is not specified");
73         }
74         
75         DataStreamImpl pc=new DataStreamImpl();
76         RoleBase role=null;
77         if (dd.unit.equals("Sender")) {
78             try {
79                 Linkable last;
80
81                 if (sMode==pushMode) {
82                     SOFA.Connector.EEG.ElementOutputDescriptor pushSRoleClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"pushSRole");
83                     pc.pushSRole=(CRole)Class.forName(pushSRoleClass.impl, true, cl).newInstance();
84                     pc.pushSRole.setManagerTie(pc);
85                     last=pc.pushSRole;
86
87                     SOFA.Connector.EEG.ElementOutputDescriptor pushSInterceptorClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"pushSInterceptor");
88                     if (pushSInterceptorClass!=null) {
89                         pc.pushSInterceptor=(Interceptor)Class.forName(pushSInterceptorClass.impl, true, cl).newInstance();
90                         pc.pushSInterceptor.setManagerTie(pc);
91                         last.link(pc.pushSInterceptor);
92                         last=pc.pushSInterceptor;
93                     }
94                 
95                     SOFA.Connector.EEG.ElementOutputDescriptor senderClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"sender");
96                     pc.sender=(Sender)Class.forName(senderClass.impl, true, cl).newInstance();
97                     pc.sender.setManagerTie(pc);
98                     last.link(pc.sender);
99
100                     role=pc.pushSRole;
101                 } else {
102                     SOFA.Connector.EEG.ElementOutputDescriptor senderClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"sender");
103                     pc.sender=(Sender)Class.forName(senderClass.impl, true, cl).newInstance();
104                     pc.sender.setManagerTie(pc);
105                     last=(Linkable)pc.sender;
106
107                     SOFA.Connector.EEG.ElementOutputDescriptor pullSInterceptorClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"pullSInterceptor");
108                     if (pullSInterceptorClass!=null) {
109                         pc.pullSInterceptor=(Interceptor)Class.forName(pullSInterceptorClass.impl, true, cl).newInstance();
110                         pc.pullSInterceptor.setManagerTie(pc);
111                         last.link(pc.pullSInterceptor);
112                         last=pc.pullSInterceptor;
113                     }
114                 
115                     SOFA.Connector.EEG.ElementOutputDescriptor pullSRoleClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"pullSRole");
116                     pc.pullSRole=(SRole)Class.forName(pullSRoleClass.impl, true, cl).newInstance();
117                     pc.pullSRole.setManagerTie(pc);
118                     last.link(pc.pullSRole);
119
120                     role=pc.pullSRole;
121                 }
122                 
123                 pc.setDeploymentDescriptor(dd);
124             } catch (Exception JavaDoc e) {
125                 throw new ConnectorException("Can't instantiate senderRole.",e);
126             }
127         } else if (dd.unit.equals("Receiver")) {
128             try {
129                 Linkable last;
130
131                 if (rMode==pushMode) {
132                     SOFA.Connector.EEG.ElementOutputDescriptor receiverClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"receiver");
133                     pc.receiver=(Receiver)Class.forName(receiverClass.impl, true, cl).newInstance();
134                     pc.receiver.setManagerTie(pc);
135                     last=(Linkable)pc.receiver;
136
137                     SOFA.Connector.EEG.ElementOutputDescriptor pushRInterceptorClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"pushRInterceptor");
138                     if (pushRInterceptorClass!=null) {
139                         pc.pushRInterceptor=(Interceptor)Class.forName(pushRInterceptorClass.impl, true, cl).newInstance();
140                         pc.pushRInterceptor.setManagerTie(pc);
141                         last.link(pc.pushRInterceptor);
142                         last=pc.pushRInterceptor;
143                     }
144                 
145                     SOFA.Connector.EEG.ElementOutputDescriptor pushRRoleClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"pushRRole");
146                     pc.pushRRole=(SRole)Class.forName(pushRRoleClass.impl, true, cl).newInstance();
147                     pc.pushRRole.setManagerTie(pc);
148                     last.link(pc.pushRRole);
149
150                     role=pc.pushRRole;
151                 } else {
152                     SOFA.Connector.EEG.ElementOutputDescriptor pullRRoleClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"pullRRole");
153                     pc.pullRRole=(CRole)Class.forName(pullRRoleClass.impl, true, cl).newInstance();
154                     pc.pullRRole.setManagerTie(pc);
155                     last=pc.pullRRole;
156
157                     SOFA.Connector.EEG.ElementOutputDescriptor pullRInterceptorClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"pullRInterceptor");
158                     if (pullRInterceptorClass!=null) {
159                         pc.pullRInterceptor=(Interceptor)Class.forName(pullRInterceptorClass.impl, true, cl).newInstance();
160                         pc.pullRInterceptor.setManagerTie(pc);
161                         last.link(pc.pullRInterceptor);
162                         last=pc.pullRInterceptor;
163                     }
164                 
165                     SOFA.Connector.EEG.ElementOutputDescriptor receiverClass=SOFA.Connector.EEG.ElementOutputDescriptor.findFirst(dd.elements,"receiver");
166                     pc.receiver=(Receiver)Class.forName(receiverClass.impl, true, cl).newInstance();
167                     pc.receiver.setManagerTie(pc);
168                     last.link(pc.receiver);
169
170                     role=pc.pullRRole;
171                 }
172
173                 pc.setSOFAReference(new Reference(dd.impl,pc.receiver.getProfiles()));
174                 pc.setDeploymentDescriptor(dd);
175             } catch (Exception JavaDoc e) {
176                 throw new ConnectorException("Can't instantiate receiverRole.",e);
177             }
178         } else {
179             throw new ConnectorException("Unknown unit '"+dd.unit+"'.");
180         }
181         return role;
182     }
183
184     public void link(Object JavaDoc target) throws LinkException {
185         Reference ref=(Reference)target;
186         String JavaDoc[] profileNames=sender.getSupportedProfiles();
187         int i, j;
188
189         for (i=0;i<profileNames.length;i++) {
190             for (j=0;j<ref.profiles.length;j++) {
191                 if (profileNames[i].equals(ref.profiles[j].tag)) {
192                     sender.link(ref.profiles[j]);
193                     return;
194                 }
195             }
196         }
197     }
198
199         public String JavaDoc getName() {
200           return getConnectorName();
201         }
202
203 }
204
Popular Tags