KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > CDL > DetectedConnector


1 /* $Id: DetectedConnector.java,v 1.2 2004/05/20 14:23:51 bures Exp $ */
2 package SOFA.SOFAnode.Made.CDL;
3
4
5 public class DetectedConnector {
6   public java.util.ArrayList JavaDoc cRoles; // list of CompBindOper
7
public java.util.ArrayList JavaDoc sRoles;
8   public String JavaDoc[] operations;
9   public int bindMode;
10
11   public String JavaDoc using;
12
13   public DetectedConnector(CompBindOper cR, CompBindOper sR, int bindMode, String JavaDoc using) {
14     this.using=using;
15     cRoles = new java.util.ArrayList JavaDoc();
16     sRoles = new java.util.ArrayList JavaDoc();
17     cRoles.add(cR);
18     sRoles.add(sR);
19     this.bindMode = bindMode;
20   }
21
22   private boolean isBothZeroOrIsBothNonZero(int a, int b) {
23     if (a==0 && b==0)
24       return true;
25     if (a!=0 && b!=0)
26       return true;
27     return false;
28   }
29
30   public boolean containsSameSRole(CompBindOper sR) {
31     for (int i=0;i<sRoles.size();i++) {
32       CompBindOper sRole = (CompBindOper) sRoles.get(i);
33       if (sRole.kind == sR.kind) {
34         CompBindType t1, t2;
35         /* FIXME, where is delegation? */
36         if (sRole.kind == CompBindOper.b_sub) {
37           sRole.subs.toFirst(); sR.subs.toFirst();
38           t1 = (CompBindType) sRole.subs.aktual();
39           t2 = (CompBindType) sR.subs.aktual();
40           if (t1.name.compareTo(t2.name)!=0) {
41             continue;
42           }
43           if (!isBothZeroOrIsBothNonZero(t1.exprs.size(), t2.exprs.size())) {
44             continue;
45           }
46         }
47         /* FIXME, possibly bad, this should be 'else' branch */
48         sRole.elements.toFirst(); sR.elements.toFirst();
49         t1 = (CompBindType) sRole.elements.aktual();
50         t2 = (CompBindType) sR.elements.aktual();
51         if (t1.name.compareTo(t2.name)!=0) {
52           continue;
53         }
54         if (!isBothZeroOrIsBothNonZero(t1.exprs.size(), t2.exprs.size())) {
55           continue;
56         }
57         return true;
58       } else {
59         continue;
60       }
61     } // ---- end of for
62
return false;
63   }
64
65   public boolean containsSameCRole(CompBindOper cR) {
66     for (int i=0;i<cRoles.size();i++) {
67       CompBindOper cRole = (CompBindOper) cRoles.get(i);
68       if (cRole.kind == cR.kind) {
69         CompBindType t1, t2;
70         /* FIXME, where is delegation? */
71         if (cRole.kind == CompBindOper.b_sub) {
72           cRole.subs.toFirst(); cR.subs.toFirst();
73           t1 = (CompBindType) cRole.subs.aktual();
74           t2 = (CompBindType) cR.subs.aktual();
75           if (t1.name.compareTo(t2.name)!=0) {
76             continue;
77           }
78           if (!isBothZeroOrIsBothNonZero(t1.exprs.size(), t2.exprs.size())) {
79             continue;
80           }
81         }
82         /* FIXME, possibly bad, this should be 'else' branch */
83         cRole.elements.toFirst(); cR.elements.toFirst();
84         t1 = (CompBindType) cRole.elements.aktual();
85         t2 = (CompBindType) cR.elements.aktual();
86         if (t1.name.compareTo(t2.name)!=0) {
87           continue;
88         }
89         if (!isBothZeroOrIsBothNonZero(t1.exprs.size(), t2.exprs.size())) {
90           continue;
91         }
92         return true;
93       } else {
94         continue;
95       }
96     } // ---- end of for
97
return false;
98   }
99
100   public int indexOfSRole(CompBindOper sR) {
101     for (int i=0;i<sRoles.size();i++) {
102       CompBindOper sRole = (CompBindOper) sRoles.get(i);
103       if (sRole.kind == sR.kind) {
104         CompBindType t1, t2;
105         if (sRole.kind == CompBindOper.b_sub) {
106           sRole.subs.toFirst(); sR.subs.toFirst();
107           t1 = (CompBindType) sRole.subs.aktual();
108           t2 = (CompBindType) sR.subs.aktual();
109           if (t1.name.compareTo(t2.name)!=0)
110             continue;
111           if (!isBothZeroOrIsBothNonZero(t1.exprs.size(), t2.exprs.size()))
112             continue;
113         }
114         sRole.elements.toFirst(); sR.elements.toFirst();
115         t1 = (CompBindType) sRole.elements.aktual();
116         t2 = (CompBindType) sR.elements.aktual();
117         if (t1.name.compareTo(t2.name)!=0)
118           continue;
119         if (!isBothZeroOrIsBothNonZero(t1.exprs.size(), t2.exprs.size()))
120           continue;
121         return i;
122       } else {
123         continue;
124       }
125     } // ---- end of for
126
return -1;
127   }
128
129   public int indexOfCRole(CompBindOper cR) {
130     for (int i=0;i<cRoles.size();i++) {
131       CompBindOper cRole = (CompBindOper) cRoles.get(i);
132       if (cRole.kind == cR.kind) {
133         CompBindType t1, t2;
134         if (cRole.kind == CompBindOper.b_sub) {
135           cRole.subs.toFirst(); cR.subs.toFirst();
136           t1 = (CompBindType) cRole.subs.aktual();
137           t2 = (CompBindType) cR.subs.aktual();
138           if (t1.name.compareTo(t2.name)!=0)
139             continue;
140           if (!isBothZeroOrIsBothNonZero(t1.exprs.size(), t2.exprs.size()))
141             continue;
142         }
143         cRole.elements.toFirst(); cR.elements.toFirst();
144         t1 = (CompBindType) cRole.elements.aktual();
145         t2 = (CompBindType) cR.elements.aktual();
146         if (t1.name.compareTo(t2.name)!=0)
147           continue;
148         if (!isBothZeroOrIsBothNonZero(t1.exprs.size(), t2.exprs.size()))
149           continue;
150         return i;
151       } else {
152         continue;
153       }
154     } // ---- end of for
155
return -1;
156   }
157
158   public void addSRole(CompBindOper sR) {
159     sRoles.add(sR);
160   }
161   
162   public void addCRole(CompBindOper cR) {
163     cRoles.add(cR);
164   }
165 }
166
Popular Tags