-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSysMLClass.java
More file actions
324 lines (305 loc) · 10.3 KB
/
Copy pathSysMLClass.java
File metadata and controls
324 lines (305 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
108
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
package sysmlinjava.common;
import java.util.Optional;
import java.util.logging.Logger;
/**
* SysMLinJava representation of the base class of many SysML classes.
* <h2>Base class for most SysML classes</h2>The {@code SysMLClass} is an
* abstract class that provides the basic SysMLinJava class attributes such as a
* name and ID number as well as a logger. Virtually all of the other
* SysMLinJava elements such as {@code SysMLBlock}, {@code SysMLValueType},
* {@code SysMLSignal}, and all of the {@code SysMLStateMachine}-related
* elements are extensions of the {@code SysMLClass}.
* <h3>Create/initialize methods</h3> The {@code SysMLClass} provides a series
* of overrideable method calls to create any attributes and comments properties
* of the represented SysML class. The {@code SysMLClass} constructor
* automatically invokes these methods to create the attributes and comments
* (problems, rationalses, hyperlinks, etc) so that extensions to the
* {@code SysMLClass} need only override the {@code createXxxx()} methods for
* the applicable properties (fields) declared in the class to ensure the
* properties are created/initialized in the correct and complete sequence
* needed. The overridable {@code createXxxx()} methods provide a "reminder" to
* create and initialize the class's attributes and comments as well as a
* framework for their complete definition.
*
* @author ModelerOne
*
*/
public abstract class SysMLClass
{
/**
* Logger for this and inheriting classes
*/
protected Logger logger;
/**
* Optional name for this SysMLinJava object to be used in displays, logs, etc.
* as desired
*/
public Optional<String> name;
/**
* ID of this SysMLinJava object to be used to identify it as desired, e.g. as
* the index for this SysMLinJava object's location in an array of objects.
* Defaults to 0 if not specified or set.
*/
public Long id;
/**
* Constructor for logger only initialization, i.e. no name nor id
*/
public SysMLClass()
{
super();
logger = Logger.getLogger(this.getClass().getSimpleName());
this.name = Optional.empty();
this.id = 0L;
createAttributes();
createComments();
createProblems();
createRationales();
createHyperlinks();
}
/**
* Constructor for logger and name only initialization, i.e. no id
*
* @param name name for the class
*/
public SysMLClass(String name)
{
this();
this.name = Optional.of(name);
}
/**
* Constructor for logger, name, and id initialization.
*
* @param name name for the class
* @param id unique identifier of the class
*/
public SysMLClass(String name, Long id)
{
this(name);
this.id = id;
}
/**
* Constructor for copy
*
* @param copied instance this instance is to be copy of
*/
public SysMLClass(SysMLClass copied)
{
super();
logger = Logger.getLogger(this.getClass().getSimpleName());
this.name = copied.name;
this.id = copied.id;
}
/**
* Sets the name field that may or may not be unique, as needed
*
* @param name name of the class
*/
public void setName(String name)
{
this.name = Optional.of(name);
}
/**
* Sets the id field
*
* @param id Long number that may or may not be unique, as needed
*/
public void setID(Long id)
{
this.id = id;
}
/**
* Overridable operation for the identity String for this object for use in
* logging and other display outputs. This default implementation returns the
* object's {@code name}, if present, or the class's name if not. If the
* {@code id} is set to a value greater than 0, then the id is concatenated. (If
* the {@code id} is to be concatenated to the identity string, then set the
* {@code id} to an integer value greater than 0). If an array {@code index}
* value is present, the index (in square brackets) is concatenated to the
* string.
* <p>
* Extensions of the {@code SysMLClass} can override this operation to provide
* an arbitrarily formatted identity string as desired.
*
* @return the identity string for this {@code SysMLClass} object
*/
public String identityString()
{
String result;
if (name.isPresent())
{
if (id > 0)
result = String.format("%s%d", name.get(), id);
else
result = String.format("%s", name.get());
}
else
{
if (id > 0)
result = String.format("%s%d", getClass().getSimpleName(), id);
else
result = String.format("%s", getClass().getSimpleName());
}
return result;
}
/**
* Overridable operation that creates and initializes the attributes of the class.
* Extensions of the {@code SysMLClass} should override this operation to
* create/initialize any attributes as follows:
*
* <pre>
anAttribute = new AnAttribute(<params>, <params>, ...);
nextAttribute = new NextAttribute(<params>, <params>, ...);
* </pre>
*
* where the the target of the assignment operation is the name of a field
* annotated with the {@code @Attribute} annotation and the assigned value
* corresponds to a constructor for that field variable.
*/
protected void createAttributes()
{
}
/**
* Overridable operation that creates and initializes the class's comments. An
* example follows:
*
* <pre>
myFirstComment = new SysMLComment(<i>comment text</i>);
mySeondComment = new SysMLComment(<i>comment text</i>);
* </pre>
*
* where the the target of the assignment operation is the name of a field
* annotated with the {@code @Comment} annotation and of type
* {@code SysMLComment}. The assigned value is the {@code SysMLComment}'s
* constructor with initialization parameters as appropriate.
*/
protected void createComments()
{
}
/**
* Overridable operation that creates and initializes the class's problem
* comments. An example follows:
*
* <pre>
myFirstProblem = new SysMLProblem(<i>problem text</i>);
mySeondProblem = new SysMLProblem(<i>problem text</i>);
etc.}
* </pre>
* <p>
* where the the target of the assignment operation is the name of a field
* annotated with the {@code @Problem} annotation and of type
* {@code SysMLProblem}. The assigned value is the {@code SysMLProblem}'s
* constructor with initialization parameters as appropriate.
*/
protected void createProblems()
{
}
/**
* Overridable operation that creates and initializes the class's rationale
* comments. An example follows:
*
* <pre>
myFirstRationale = new SysMLRationale(<i>rationale text</i>);
mySeondRationale = new SysMLRationale(<i>rationale text</i>);
* </pre>
* <p>
* where the the target of the assignment operation is the name of a field
* annotated with the {@code @Rationale} annotation and of type
* {@code SysMLRationale}. The assigned value is the {@code SysMLRationale}'s
* constructor with initialization parameters as appropriate.
*/
protected void createRationales()
{
}
/**
* Overridable operation that creates and initializes the class's hyperlink
* comments. An example follows:
*
* <pre>
myFirstHyperlink = new SysMLHyperlink(<i>hyperlink args</i>);
mySeondHyperlink = new SysMLHyperlink(<i>hyperlink args</i>);
* </pre>
* <p>
* where the the target of the assignment operation is the name of a field
* annotated with the {@code @Hyperlink} annotation and of type
* {@code SysMLHyperlink}. The assigned value is the {@code SysMLHyperlink}'s
* constructor with initialization parameters as appropriate.
*/
protected void createHyperlinks()
{
}
/**
* Overridable operation that creates and initializes the class's element groups
* comments. An example follows:
*
* <pre>
myElementGroup = new SysMLElementGroup(<i>element group args</i>);
* </pre>
*
* where the the target of the assignment operation is the name of a field
* annotated with the {@code @ElementGroup} annotation and of type
* {@code SysMLElementGroup}. The assigned value is the
* {@code SysMLElementGroup}'s constructor with initialization parameters as
* appropriate.
*
*/
protected void createElementGroups()
{
}
/**
* Overridable operation that creates and initializes the class's constraint
* notes comments. An example follows:
*
* <pre>
myFirstConstraintNote = new SysMLConstraintNote(<i>constraint lambda expression</i>);
* </pre>
* <p>
* where the the target of the assignment operation is the name of a field
* annotated with the {@code @ConstraintNote} annotation and of type
* {@code SysMLConstraintNote}. The assigned value is the
* {@code SysMLConstraintNote}'s constructor with initialization parameters as
* appropriate.
*/
protected void createConstraintNotes()
{
}
/**
* Name of method to create attributes, used by SysMLinJava tools, typically not
* needed for modeling
*/
public static final String createAttributesMethodName = "createAttributes";
/**
* Name of method to create comments, used by SysMLinJava tools, typically not
* needed for modeling
*/
public static final String createCommentsMethodName = "createComments";
/**
* Name of method to create problems, used by SysMLinJava tools, typically not
* needed for modeling
*/
public static final String createProblemsMethodName = "createProblems";
/**
* Name of method to create rationales, used by SysMLinJava tools, typically not
* needed for modeling
*/
public static final String createRationalesMethodName = "createRationales";
/**
* Name of method to create hyperlinks, used by SysMLinJava tools, typically not
* needed for modeling
*/
public static final String createHyperlinksMethodName = "createHyperlinks";
/**
* Name of method to create element groups, used by SysMLinJava tools, typically
* not needed for modeling
*/
public static final String createElementGroupsMethodName = "createElementGroups";
/**
* Name of method to create constraint notes, used by SysMLinJava tools,
* typically not needed for modeling
*/
public static final String createConstraintNotesMethodName = "createConstraintNotes";
@Override
public String toString()
{
return String.format("%s [name=%s, id=%s]", getClass().getSimpleName(), name, id);
}
}