我是 eclipse UML2 的新手,遇到了以下问题。
我定义了一个具有两个原型的配置文件:ServiceRequest 和 TransitionEdge。ServiceRequest 使用两个附加属性(cpu、内存)扩展了 Action 元类,TransitionEdge 使用称为“概率”的附加属性扩展了 ActivityEdge 元类。所有这些属性都是定义为 PrimitiveType 的 float 类型。
我创建了一个应用了配置文件和原型的活动图。在活动图中,每条边都是配置文件中定义的一个TransitionEdge,并且已经为概率属性分配了一个值。
有了配置文件和活动模型,我使用以下 Java 代码来加载它们。
// Load the profile
URI profileUri = URI.createURI(PROFILE_NAME);
ResourceSet profileSet = new ResourceSetImpl();
profileSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
profileSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
profileSet.createResource(profileUri);
Resource profileResource = profileSet.getResource(profileUri, true);
Profile profile = (Profile)EcoreUtil.getObjectByType(profileResource.getContents(), UMLPackage.Literals.PROFILE);
Profile sopraProfile = (Profile)profile.getOwnedMember(PROFILE_NAME);
Stereotype serviceRequestStereotype = (Stereotype)sopraProfile.getOwnedMember(STEREOTYPE_SERVICE_REQUEST);
Stereotype transitionEdgeStereotype = (Stereotype)sopraProfile.getOwnedMember(STEREOTYPE_TRANSITION_EDGE);
// Load the model
URI modelUri = URI.createURI(MODEL_NAME);
ResourceSet modelSet = new ResourceSetImpl();
modelSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
modelSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
modelSet.createResource(modelUri);
Resource modelResource = modelSet.getResource(modelUri, true);
Model model = (Model)EcoreUtil.getObjectByType(modelResource.getContents(), UMLPackage.Literals.MODEL);
EList<Element> elements = model.getOwnedElements();
for(Element e : elements){
if(e instanceof Activity){
Activity activity = (Activity)e;
EList<ActivityEdge> edges = activity.getEdges();
for(ActivityEdge edge : edges){
System.out.println(edge.getValue(transitionEdgeStereotype, "probability"));
}
}
}
对元素调用 getValue 方法时会引发异常。以下是错误信息:
org.eclipse.uml2.uml.internal.impl.PropertyImpl@7a6d6a3f (name: base_ActivityEdge, visibility: <unset>) (isLeaf: false) (isStatic: false) (isOrdered: false, isUnique: true, isReadOnly: false) (aggregation: none, isDerived: false, isDerivedUnion: false, isID: false)
org.eclipse.uml2.uml.internal.impl.PropertyImpl@255a8ce4 (name: probability, visibility: public) (isLeaf: false) (isStatic: false) (isOrdered: false, isUnique: true, isReadOnly: false) (aggregation: none, isDerived: false, isDerivedUnion: false, isID: false)
Exception in thread "main" java.lang.IllegalArgumentException: org.eclipse.uml2.uml.internal.impl.StereotypeImpl@442f4161 (name: TransitionEdge, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
at org.eclipse.uml2.uml.internal.operations.ElementOperations.getValue(ElementOperations.java:527)
at org.eclipse.uml2.uml.internal.impl.ElementImpl.getValue(ElementImpl.java:296)
at test.Test.main(Test.java:68)
我无法弄清楚发生了什么事。有什么建议么?非常感谢!!