Changeset 1908 for trunk/autoquest-plugin-uml
- Timestamp:
- 03/11/15 15:43:03 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java
r1900 r1908 40 40 import org.eclipse.uml2.uml.Connector; 41 41 import org.eclipse.uml2.uml.ConnectorEnd; 42 import org.eclipse.uml2.uml.DataType; 42 43 import org.eclipse.uml2.uml.Element; 44 import org.eclipse.uml2.uml.Expression; 45 import org.eclipse.uml2.uml.InstanceSpecification; 46 import org.eclipse.uml2.uml.InstanceValue; 43 47 import org.eclipse.uml2.uml.Interaction; 44 48 import org.eclipse.uml2.uml.InteractionFragment; 45 49 import org.eclipse.uml2.uml.Interface; 46 50 import org.eclipse.uml2.uml.Lifeline; 51 import org.eclipse.uml2.uml.LiteralBoolean; 52 import org.eclipse.uml2.uml.LiteralInteger; 53 import org.eclipse.uml2.uml.LiteralReal; 54 import org.eclipse.uml2.uml.LiteralString; 47 55 import org.eclipse.uml2.uml.Message; 48 56 import org.eclipse.uml2.uml.MessageOccurrenceSpecification; … … 51 59 import org.eclipse.uml2.uml.Operation; 52 60 import org.eclipse.uml2.uml.Package; 61 import org.eclipse.uml2.uml.Parameter; 62 import org.eclipse.uml2.uml.ParameterDirectionKind; 53 63 import org.eclipse.uml2.uml.Port; 64 import org.eclipse.uml2.uml.PrimitiveType; 54 65 import org.eclipse.uml2.uml.Profile; 55 66 import org.eclipse.uml2.uml.Property; 56 67 import org.eclipse.uml2.uml.Region; 68 import org.eclipse.uml2.uml.Slot; 57 69 import org.eclipse.uml2.uml.StateMachine; 58 70 import org.eclipse.uml2.uml.Stereotype; … … 138 150 "Found the following services and operations in the usage data: "); 139 151 for (Entry<String, Set<String>> entry : calledMethods.entrySet()) { 140 Console.trace(Level.INFO, "\tService \"" + entry.getKey() + "\": "); 141 Iterator<String> iter = entry.getValue().iterator(); 142 StringBuilder strBld = new StringBuilder(); 143 while (iter.hasNext()) { 144 strBld.append(iter.next()); 145 if (iter.hasNext()) { 146 strBld.append(", "); 147 } 148 } 149 Console.traceln(Level.INFO, strBld.toString()); 152 Console.traceln(Level.INFO, "\tService \"" + entry.getKey() + "\": "); 153 for(String method : entry.getValue()) { 154 Console.traceln(Level.INFO, "\t\t"+method); 155 } 150 156 } 151 157 … … 197 203 "\tFound the following realized interfaces for the service \"" + 198 204 serviceName + "\": "); 199 Iterator<Interface> iter = interfaces.iterator(); 200 while (iter.hasNext()) { 201 String interfaceName = iter.next().getName(); 202 StringBuilder strBld = new StringBuilder(); 203 strBld.append(interfaceName); 204 if (iter.hasNext()) { 205 strBld.append(", "); 205 for( Interface intface : interfaces ) { 206 Console.traceln(Level.INFO, "\t" + intface.getName()); 207 for( Operation operation : intface.getAllOperations() ) { 208 Console.traceln(Level.INFO, "\t\t" + operation.getName()); 206 209 } 207 Console.traceln(Level.INFO, strBld.toString());208 210 } 209 211 for (String methodName : methodNames) { … … 221 223 Console.traceln(Level.SEVERE, "\tCould not find operation: " + 222 224 methodName); 223 Console224 .traceln(Level.SEVERE,225 "\tHint: check if operation is present and spelled correctly");226 225 } 227 226 } … … 568 567 // create call 569 568 Message callMessage = interaction.createMessage(methodName); 570 callMessage.setSignature(calledOperation); 569 callMessage.setSignature(calledOperation); 570 setMessageParameters(callMessage, calledOperation, event); 571 571 callMessage.setConnector(inferConnector(msgSourceLifeline, msgTargetLifeline)); 572 572 callMessage.setSendEvent(callSendFragment); … … 630 630 } 631 631 } 632 633 632 634 633 635 /** … … 958 960 return null; 959 961 } 962 963 private static void setMessageParameters(Message callMessage, Operation calledOperation, Event event) { 964 // Set parameters of operation 965 for( Parameter param : calledOperation.getOwnedParameters() ) { 966 Expression argument = (Expression) callMessage.createArgument(param.getName(), param.getType(), UMLPackage.Literals.EXPRESSION); 967 968 if( param.getDirection()==ParameterDirectionKind.IN_LITERAL || param.getDirection()==ParameterDirectionKind.INOUT_LITERAL) { 969 if( param.getType() instanceof DataType ) { 970 InstanceSpecification instSpec = createInstanceSpecification((DataType) param.getType(), event); 971 972 InstanceValue value = (InstanceValue) argument.createOperand(null, param.getType(), UMLPackage.Literals.INSTANCE_VALUE); 973 value.setInstance(instSpec); 974 } 975 else if( param.getType() instanceof PrimitiveType ) { 976 if( "String".equals(param.getType().getName()) ) { 977 LiteralString spec = (LiteralString) argument.createOperand(param.getName(), null, UMLPackage.Literals.LITERAL_STRING); 978 spec.setValue("foobar"); // TODO needs to be real value 979 } 980 else if( "Integer".equals(param.getType().getName()) ) { 981 LiteralInteger spec = (LiteralInteger) argument.createOperand(param.getName(), null, UMLPackage.Literals.LITERAL_INTEGER); 982 spec.setValue(42); // TODO needs to be real value 983 } 984 else if( "Boolean".equals(param.getType().getName()) ) { 985 LiteralBoolean spec = (LiteralBoolean) argument.createOperand(param.getName(), null, UMLPackage.Literals.LITERAL_BOOLEAN); 986 spec.setValue(true); // TODO needs to be real value 987 } 988 else if( "Real".equals(param.getType().getName()) ) { 989 LiteralReal spec = (LiteralReal) argument.createOperand(param.getName(), null, UMLPackage.Literals.LITERAL_REAL); 990 spec.setValue(3.14); // TODO needs to be real value 991 } 992 } 993 } else { 994 // set literalNull for out and return parameters 995 argument.createOperand(null, param.getType(), UMLPackage.Literals.LITERAL_NULL); 996 } 997 } 998 } 999 1000 public static InstanceSpecification createInstanceSpecification(DataType type, Event event) { 1001 String pkgUBTInstSpecs = "UBT_InstanceSpecifications"; 1002 Model model = type.getModel(); 1003 Package ubtInstSpecPkg = (Package) model.getOwnedMember(pkgUBTInstSpecs); 1004 if( ubtInstSpecPkg==null ) { 1005 ubtInstSpecPkg = (Package) type.getModel().createPackagedElement(pkgUBTInstSpecs, UMLPackage.Literals.PACKAGE); 1006 } 1007 String serviceName = ((SOAPEventType) event.getType()).getServiceName(); 1008 Package serviceInstSpecPkg = (Package) ubtInstSpecPkg.getOwnedMember(serviceName); 1009 if( serviceInstSpecPkg==null ) { 1010 serviceInstSpecPkg = (Package) ubtInstSpecPkg.createPackagedElement(serviceName, UMLPackage.Literals.PACKAGE); 1011 } 1012 1013 InstanceSpecification instSpec = (InstanceSpecification) serviceInstSpecPkg.createPackagedElement("instspec_"+type.getName(), UMLPackage.Literals.INSTANCE_SPECIFICATION); 1014 instSpec.getClassifiers().add(type); 1015 System.out.println(type.getName()); 1016 for( Property prop : type.getAllAttributes() ) { 1017 // TODO handle multiplicity 1018 //int lowerBound = prop.getLower(); 1019 //int upperBound = prop.getUpper(); 1020 1021 Slot slot = instSpec.createSlot(); 1022 slot.setDefiningFeature(prop); 1023 if( prop.getType() instanceof PrimitiveType ) { 1024 if( "String".equals(prop.getType().getName()) ) { 1025 LiteralString value = (LiteralString) slot.createValue(prop.getName(), null, UMLPackage.Literals.LITERAL_STRING); 1026 value.setValue("foobar"); // TODO needs to be real value 1027 } 1028 else if( "Integer".equals(prop.getType().getName()) ) { 1029 LiteralInteger value = (LiteralInteger) slot.createValue(prop.getName(), null, UMLPackage.Literals.LITERAL_INTEGER); 1030 value.setValue(42); // TODO needs to be real value 1031 } 1032 else if( "Boolean".equals(prop.getType().getName()) ) { 1033 LiteralBoolean value = (LiteralBoolean) slot.createValue(prop.getName(), null, UMLPackage.Literals.LITERAL_BOOLEAN); 1034 value.setValue(true); // TODO needs to be real value 1035 } 1036 else if( "Real".equals(prop.getType().getName()) ) { 1037 LiteralReal value = (LiteralReal) slot.createValue(prop.getName(), null, UMLPackage.Literals.LITERAL_REAL); 1038 value.setValue(3.14); // TODO needs to be real value 1039 } 1040 } 1041 else if( prop.getType() instanceof DataType ) { 1042 InstanceValue value = (InstanceValue) slot.createValue(prop.getName(), prop.getType(), UMLPackage.Literals.INSTANCE_VALUE); 1043 value.setInstance(createInstanceSpecification((DataType) prop.getType(), event)); 1044 } 1045 } 1046 return instSpec; 1047 } 960 1048 }
Note: See TracChangeset
for help on using the changeset viewer.