Skip to content

Commit 025aa64

Browse files
committed
Added readReal and writeReal ops to i/o channels. (OMG Issue FUML13-21)
1 parent 05a2b2d commit 025aa64

5 files changed

Lines changed: 161 additions & 7 deletions

File tree

org.modeldriven.fuml/src/main/java/org/modeldriven/fuml/library/channel/StandardInputChannelObject.java

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
* Copyright 2011-2017 Data Access Technologies, Inc. (Model Driven Solutions)
3+
*
4+
* Licensed under the Academic Free License version 3.0
5+
* (http://www.opensource.org/licenses/afl-3.0.php), except as stated
6+
* in the file entitled Licensing-Information.
7+
*/
8+
19
package org.modeldriven.fuml.library.channel;
210

311
import java.io.BufferedReader;
@@ -224,6 +232,86 @@ public Integer readInteger(Status errorStatus) {
224232
}
225233
}
226234

235+
@Override
236+
public Float readReal(Status errorStatus) {
237+
if (!this.isOpen()) {
238+
errorStatus.setStatus("StandardInputChannel", -1, "Not open");
239+
return null;
240+
} else {
241+
try {
242+
StringBuilder image = new StringBuilder();
243+
244+
this.reader.mark(2);
245+
int c = this.reader.read();
246+
if (c == ((char)'+') || c == ((char)'-')) {
247+
image.append((char)c);
248+
c = this.reader.read();
249+
}
250+
251+
if (!readDigits(c, image)) {
252+
if (c < 0) {
253+
errorStatus.setStatus("StandardInputChannel", -2, "No Input");
254+
} else {
255+
errorStatus.setStatus("StandardInputChannel", -3, "Cannot convert");
256+
}
257+
this.reader.reset();
258+
return null;
259+
} else {
260+
this.reader.mark(1);
261+
c = this.reader.read();
262+
if (c != ((char)'.')) {
263+
this.reader.reset();
264+
} else {
265+
image.append('.');
266+
this.reader.mark(2);
267+
this.readDigits(this.reader.read(), image);
268+
}
269+
this.reader.mark(3);
270+
c = this.reader.read();
271+
if (c != ((char)'E') && c != ((char)'e')) {
272+
this.reader.reset();
273+
} else {
274+
image.append('E');
275+
c = this.reader.read();
276+
if (c == ((char)'+') || c == ((char)'-')) {
277+
image.append((char)c);
278+
c = this.reader.read();
279+
}
280+
if (!readDigits(c, image)) {
281+
image.append('0');
282+
}
283+
}
284+
return Float.valueOf(image.toString());
285+
}
286+
287+
} catch (IOException e) {
288+
errorStatus.setStatus("StandardInputChannel", -100, e.getMessage());
289+
return null;
290+
}
291+
}
292+
}
293+
294+
private boolean readDigits(int c, StringBuilder s) throws IOException {
295+
if (c < ((int)'0') || c > ((int)'9')) {
296+
this.reader.reset();
297+
return false;
298+
} else {
299+
s.append((char)c);
300+
301+
while (true) {
302+
this.reader.mark(1);
303+
c = this.reader.read();
304+
305+
if (c >= ((int)'0') && c <= ((int)'9')) {
306+
s.append((char)c);
307+
} else {
308+
this.reader.reset();
309+
return true;
310+
}
311+
}
312+
}
313+
}
314+
227315
@Override
228316
public UnlimitedNatural readUnlimitedNatural(Status errorStatus) {
229317
UnlimitedNatural u = null;
@@ -283,7 +371,7 @@ private Integer readNatural(int c, Status errorStatus) {
283371
return null;
284372
}
285373
}
286-
374+
287375
@Override
288376
public Value new_() {
289377
return (Value)new StandardInputChannelObject();

org.modeldriven.fuml/src/main/java/org/modeldriven/fuml/library/channel/TextInputChannelObject.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
* Copyright 2011 Data Access Technologies, Inc. (Model Driven Solutions)
2+
* Copyright 2011-2017 Data Access Technologies, Inc. (Model Driven Solutions)
3+
*
34
* Licensed under the Academic Free License version 3.0
45
* (http://www.opensource.org/licenses/afl-3.0.php), except as stated
56
* in the file entitled Licensing-Information.
@@ -15,6 +16,7 @@
1516
import fUML.Semantics.Classes.Kernel.BooleanValue;
1617
import fUML.Semantics.Classes.Kernel.IntegerValue;
1718
import fUML.Semantics.Classes.Kernel.PrimitiveValue;
19+
import fUML.Semantics.Classes.Kernel.RealValue;
1820
import fUML.Semantics.Classes.Kernel.StringValue;
1921
import fUML.Semantics.Classes.Kernel.UnlimitedNaturalValue;
2022

@@ -24,6 +26,7 @@ public abstract class TextInputChannelObject extends InputChannelObject {
2426
public abstract String peekCharacter(Status errorStatus);
2527
public abstract String readLine(Status errorStatus);
2628
public abstract Integer readInteger(Status errorStatus);
29+
public abstract Float readReal(Status errorStatus);
2730
public abstract Boolean readBoolean(Status errorStatus);
2831
public abstract UnlimitedNatural readUnlimitedNatural(Status errorStatus);
2932

@@ -65,6 +68,14 @@ public void execute(OperationExecution execution) {
6568
((IntegerValue)resultValue).value = result;
6669
}
6770
this.updateStatus(execution, status);
71+
} else if (name.equals("readReal")) {
72+
Float result = this.readReal(status);
73+
if (result != null) {
74+
resultValue = new RealValue();
75+
resultValue.type = this.locus.factory.getBuiltInType("Real");
76+
((RealValue)resultValue).value = result;
77+
}
78+
this.updateStatus(execution, status);
6879
} else if (name.equals("readBoolean")) {
6980
Boolean result = this.readBoolean(status);
7081
if (result != null) {

org.modeldriven.fuml/src/main/java/org/modeldriven/fuml/library/channel/TextOutputChannelObject.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/*
22
* Copyright 2008 Lockheed Martin Corporation, except as stated in the file
33
* entitled Licensing-Information.
4-
* All modifications copyright 2009-2011 Data Access Technologies, Inc.
4+
*
5+
* All modifications copyright 2009-2017 Data Access Technologies, Inc.
6+
*
57
* Licensed under the Academic Free License
68
* version 3.0 (http://www.opensource.org/licenses/afl-3.0.php), except as stated
79
* in the file entitled Licensing-Information.
8-
*
9-
* Contributors:
10-
* MDS - initial API and implementation
11-
*
1210
*/
1311

1412
package org.modeldriven.fuml.library.channel;
@@ -18,6 +16,7 @@
1816

1917
import fUML.Semantics.Classes.Kernel.BooleanValue;
2018
import fUML.Semantics.Classes.Kernel.IntegerValue;
19+
import fUML.Semantics.Classes.Kernel.RealValue;
2120
import fUML.Semantics.Classes.Kernel.StringValue;
2221
import fUML.Semantics.Classes.Kernel.UnlimitedNaturalValue;
2322
import fUML.Semantics.CommonBehaviors.BasicBehaviors.ParameterValue;
@@ -36,6 +35,10 @@ public void writeInteger(int value, Status errorStatus) {
3635
this.writeString(Integer.toString(value), errorStatus);
3736
}
3837

38+
public void writeReal(float value, Status errorStatus) {
39+
this.writeString(Float.toString(value), errorStatus);
40+
}
41+
3942
public void writeBoolean(boolean value, Status errorStatus) {
4043
this.writeString(Boolean.toString(value), errorStatus);
4144
}
@@ -75,6 +78,9 @@ public void execute(OperationExecution execution) {
7578
} else if (name.equals("writeInteger")) {
7679
this.writeInteger(((IntegerValue) (parameterValue.values.getValue(0))).value, status);
7780
this.updateStatus(execution, status);
81+
} else if (name.equals("writeReal")) {
82+
this.writeReal(((RealValue) (parameterValue.values.getValue(0))).value, status);
83+
this.updateStatus(execution, status);
7884
} else if (name.equals("writeBoolean")) {
7985
this.writeBoolean(((BooleanValue) (parameterValue.values.getValue(0))).value, status);
8086
this.updateStatus(execution, status);

org.modeldriven.fuml/src/main/java/org/modeldriven/fuml/library/common/Status.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ static public void setStatusType(DataType type) {
3535
statusType = type;
3636
}
3737

38+
public Status() {
39+
40+
}
41+
3842
public Status(Locus locus, String context, int code, String description) {
3943
this.setPrimitiveTypes(locus);
4044
this.setStatus(context, code, description);
@@ -60,6 +64,18 @@ public void setStatus(String context, int code, String description) {
6064
this.description = description;
6165
}
6266

67+
public String getContext() {
68+
return this.context;
69+
}
70+
71+
public int getCode() {
72+
return this.code;
73+
}
74+
75+
public String getDescription() {
76+
return this.description;
77+
}
78+
6379
public Value getValue() {
6480
DataValue value = new DataValue();
6581
DataType statusType = getStatusType();

org.modeldriven.fuml/src/main/resources/org/modeldriven/fuml/library/fUML_Library.xmi

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,24 @@
12821282
/>
12831283
</ownedParameter>
12841284
</ownedOperation>
1285+
<ownedOperation xmi:type="uml:Operation"
1286+
xmi:id="BasicInputOutput-TextInputChannel-readReal" name="readReal">
1287+
<ownedParameter xmi:type="uml:Parameter"
1288+
xmi:id="BasicInputOutput-TextInputChannel-readReal-ReturnResult"
1289+
name="ReturnResult" direction="return">
1290+
<type href="http://www.omg.org/spec/UML/20110701/PrimitiveTypes.xmi#Real"/>
1291+
<lowerValue xmi:type="uml:LiteralInteger"
1292+
xmi:id="BasicInputOutput-TextInputChannel-readReal-ReturnResult-_lowerValue"
1293+
/>
1294+
</ownedParameter>
1295+
<ownedParameter xmi:type="uml:Parameter"
1296+
xmi:id="BasicInputOutput-TextInputChannel-readReal-errorStatus"
1297+
name="errorStatus" direction="out" type="Common-Status">
1298+
<lowerValue xmi:type="uml:LiteralInteger"
1299+
xmi:id="BasicInputOutput-TextInputChannel-readReal-errorStatus-_lowerValue"
1300+
/>
1301+
</ownedParameter>
1302+
</ownedOperation>
12851303
<ownedOperation xmi:type="uml:Operation"
12861304
xmi:id="BasicInputOutput-TextInputChannel-readBoolean" name="readBoolean">
12871305
<ownedParameter xmi:type="uml:Parameter"
@@ -1382,6 +1400,21 @@
13821400
/>
13831401
</ownedParameter>
13841402
</ownedOperation>
1403+
<ownedOperation xmi:type="uml:Operation"
1404+
xmi:id="BasicInputOutput-TextOutputChannel-writeReal" name="writeReal">
1405+
<ownedParameter xmi:type="uml:Parameter"
1406+
xmi:id="BasicInputOutput-TextOutputChannel-writeReal-value" name="value">
1407+
<type href="http://www.omg.org/spec/UML/20110701/PrimitiveTypes.xmi#Real"
1408+
/>
1409+
</ownedParameter>
1410+
<ownedParameter xmi:type="uml:Parameter"
1411+
xmi:id="BasicInputOutput-TextOutputChannel-writeReal-errorStatus"
1412+
name="errorStatus" direction="out" type="Common-Status">
1413+
<lowerValue xmi:type="uml:LiteralInteger"
1414+
xmi:id="BasicInputOutput-TextOutputChannel-writeReal-errorStatus-_lowerValue"
1415+
/>
1416+
</ownedParameter>
1417+
</ownedOperation>
13851418
<ownedOperation xmi:type="uml:Operation"
13861419
xmi:id="BasicInputOutput-TextOutputChannel-writeBoolean" name="writeBoolean">
13871420
<ownedParameter xmi:type="uml:Parameter"

0 commit comments

Comments
 (0)