blob: 709dd08c603fa87750f0904d038d831fb19a1f8b (
plain) (
blame)
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
|
/*****************************************************************************
* Copyright (c) 2013 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* CEA LIST - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.moka.fuml.standardlibrary.library.io;
import java.util.List;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Object_;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.StringValue;
import org.eclipse.papyrus.moka.fuml.Semantics.Classes.Kernel.Value;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.Execution;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.OpaqueBehaviorExecution;
import org.eclipse.papyrus.moka.fuml.Semantics.CommonBehaviors.BasicBehaviors.ParameterValue;
import org.eclipse.papyrus.moka.fuml.debug.Debug;
import org.eclipse.papyrus.moka.fuml.registry.SystemServicesRegistryUtils;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.OpaqueBehavior;
import org.eclipse.uml2.uml.Operation;
public class StandardOutputChannelImpl extends Object_ {
protected static OpaqueBehavior writeLineMethod ;
protected static OpaqueBehavior writeMethod;
public StandardOutputChannelImpl(Class service) {
super() ;
this.types.add(service) ;
}
@Override
public Execution dispatch(Operation operation) {
if (operation.getName().equals("writeLine"))
return new WriteLineExecution(operation) ;
else if (operation.getName().equals("write"))
return new Write(operation) ;
// TODO complete with other operations
return null ;
}
protected class WriteLineExecution extends OpaqueBehaviorExecution {
protected Operation operation ;
public WriteLineExecution(Operation operation) {
this.operation = operation ;
}
@Override
public Value new_() {
return new WriteLineExecution(operation) ;
}
@Override
public void doBody(List<ParameterValue> inputParameters, List<ParameterValue> outputParameters) {
// Supposed to have only one input argument, corresponding to parameter 'value'
try {
String message = ((StringValue)inputParameters.get(0).values.get(0)).value;
System.out.println(message);
// This implementation does not produce errorStatus information.
} catch (Exception e) {
Debug.println("An error occured during the execution of writeLine " + e.getMessage());
}
}
@Override
public Behavior getBehavior() {
if (writeLineMethod == null) {
writeLineMethod = SystemServicesRegistryUtils.getInstance().generateOpaqueBehaviorSignature(operation) ;
}
return writeLineMethod ;
}
}
protected class Write extends OpaqueBehaviorExecution {
protected Operation operation ;
public Write(Operation operation) {
this.operation = operation ;
}
@Override
public Value new_() {
return new Write(operation) ;
}
@Override
public void doBody(List<ParameterValue> inputParameters, List<ParameterValue> outputParameters) {
// Supposed to have only one input argument, corresponding to parameter 'value'
try {
String message = inputParameters.get(0).values.get(0).toString();
System.out.print(message);
// This implementation does not produce errorStatus information.
} catch (Exception e) {
Debug.println("An error occured during the execution of write " + e.getMessage());
}
}
@Override
public Behavior getBehavior() {
if (writeMethod == null) {
writeMethod = SystemServicesRegistryUtils.getInstance().generateOpaqueBehaviorSignature(operation) ;
}
return writeMethod ;
}
}
}
|