Newer
Older
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package ui;
import myutil.Conversion;
import myutil.TraceManager;
* Class AvatarSignal
* Signals in Avatar ...
* Creation: 08/04/2010
* @version 1.0 08/04/2010
* @author Ludovic APVRILLE
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
public class AvatarSignal extends AvatarMethod {
// Signa type
public final static int IN = 0;
public final static int OUT = 1;
private int inout;
public boolean attachedToARelation;
public AvatarSignal(int _inout, String _id, String _types[], String _typeIds[]) {
super(_id, _types, _typeIds);
inout = _inout;
}
public static AvatarSignal isAValidSignal(String _content) {
String tmp = _content.trim();
if (!((_content.startsWith("in ")) || (_content.startsWith("out ")))) {
return null;
}
int tmpinout;
if (_content.startsWith("in ")) {
tmpinout = IN;
} else {
tmpinout = OUT;
}
return isAValidSignal(tmpinout, tmp.substring(3, tmp.length()).trim());
}
public static AvatarSignal isAValidSignal(int _inout, String _content) {
if (!((_inout == IN) || (_inout == OUT))) {
return null;
}
AvatarMethod am = isAValidMethod(_content);
if (am == null) {
TraceManager.addDev("invalid signal: " + _content);
return null;
}
AvatarSignal as = new AvatarSignal(_inout, am.getId(), am.getTypes(), am.getTypeIds());
return as;
}
public static boolean isAValidUseSignal(String _content) {
if (_content.indexOf("()") == -1) {
_content = Conversion.replaceAllString(_content, "(", "#int ");
_content = Conversion.replaceAllString(_content, "#", "(");
_content = Conversion.replaceAllString(_content, ",", "#int ");
_content = Conversion.replaceAllString(_content, "#", ",");
_content = Conversion.replaceAllString(_content, ".", "");
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
}
TraceManager.addDev("content:" + _content);
return (isAValidMethod(_content) != null);
}
public int getInOut() {
return inout;
}
public static String getStringInOut(int _inout) {
switch(_inout) {
case IN:
return "in";
case OUT:
default:
return "out";
}
}
public String toBasicString() {
return super.toString();
}
public String toString() {
int cpt = 0;
String signal = getStringInOut(inout) + " ";
signal += super.toString();
return signal;
}
// Comparison on id only
public boolean equals(Object o) {
if (!(o instanceof AvatarSignal)) {
return false;
}
AvatarSignal as = (AvatarSignal)o;
return getId().equals(as.getId());
}
// Comparison on all fields
/*public int compareTo(Object o){
if (!(o instanceof AvatarMethod)) {
return 1;
}
AvatarMethod am = (AvatarMethod)o;
if (!(getId().equals(am.getId()))) {
return 1;
}
return 0;
}*/
public AvatarSignal makeClone() {
return isAValidSignal(inout, super.toString());
}
public boolean hasSamePrototype (AvatarSignal _as) {
String[] astypes = _as.getTypes();
if (astypes.length != types.length) {
return false;
}
for(int i=0; i<types.length; i++) {
if (!(types[i].compareTo(astypes[i]) == 0)) {
return false;
}
}
return true;
}
public boolean isCompatibleWith(AvatarSignal _as) {
if (_as.getInOut() == getInOut()) {
return false;
}
return this.hasSamePrototype (_as);
}
public static String getSignalNameFromFullSignalString(String _signal) {
String signal = _signal.trim();
int index0 = signal.indexOf(" ");
if (index0 != -1) {
signal = signal.substring(index0+1, signal.length()).trim();
}
index0 = signal.indexOf("(");
if (index0 != -1) {
signal = signal.substring(0, index0).trim();
}
return signal;
}
public static int getNbOfValues(String _value) {
int index = _value.indexOf('(');
if (index == -1) {
return -1;
}
int index0 = _value.indexOf(')');
if (index0 == -1) {
return -1;
}
String val = _value.substring(index+1, index0).trim();
if (val.length() == 0) {
return 0;
}
int nbChar = Conversion.nbChar(_value, ',');
return nbChar+1;
}
public static String getValue(String _value, int _index) {
int nbOfValues = getNbOfValues(_value);
if (nbOfValues < 1) {
return null;
}
if (_index >= nbOfValues) {
return null;
}
int index0 = _value.indexOf('(');
int index1 = _value.indexOf(')');
String val = _value.substring(index0+1, index1).trim();
String [] vals = val.split(",");
return vals[_index].trim();
}
}