我使用 modelio 生成了一个 UML 文件。我在课堂上应用了刻板印象。
我的 .uml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:LocalProfile="http:///schemas/LocalProfile/_TS6FwP2iEeKR1arwT6_zsA/0" xmlns:default="http:///schemas/default/_TTEd0P2iEeKR1arwT6_zsA/0" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xsi:schemaLocation="http:///schemas/LocalProfile/_TS6FwP2iEeKR1arwT6_zsA/0 LocalProfile.profile.uml#_TUTM5v2iEeKR1arwT6_zsA http:///schemas/default/_TTEd0P2iEeKR1arwT6_zsA/0 default.profile.uml#_TUkSp_2iEeKR1arwT6_zsA">
<uml:Model xmi:id="_TSufkP2iEeKR1arwT6_zsA" name="xmitojava">
<eAnnotations xmi:id="_TSufkf2iEeKR1arwT6_zsA" source="Objing">
<contents xmi:type="uml:Property" xmi:id="_TSufkv2iEeKR1arwT6_zsA" name="exporterVersion">
<defaultValue xmi:type="uml:LiteralString" xmi:id="_TSufk_2iEeKR1arwT6_zsA" value="2.2"/>
</contents>
</eAnnotations>
<ownedComment xmi:id="_TSuflP2iEeKR1arwT6_zsA">
<body></body>
</ownedComment>
<packagedElement xmi:type="uml:Package" xmi:id="_TSuflf2iEeKR1arwT6_zsA" name="com.imcfr.pkg">
<packagedElement xmi:type="uml:Class" xmi:id="_TSuflv2iEeKR1arwT6_zsA" name="Group">
<ownedAttribute xmi:id="_TSufl_2iEeKR1arwT6_zsA" name="label" visibility="private" isUnique="false" isReadOnly="true">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
</ownedAttribute>
</packagedElement>
<packagedElement xmi:type="uml:Association" xmi:id="_TSufmP2iEeKR1arwT6_zsA" memberEnd="_TSufmf2iEeKR1arwT6_zsA _TSufn_2iEeKR1arwT6_zsA">
<ownedEnd xmi:id="_TSufmf2iEeKR1arwT6_zsA" type="_TSufnP2iEeKR1arwT6_zsA" association="_TSufmP2iEeKR1arwT6_zsA">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_TSufmv2iEeKR1arwT6_zsA" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_TSufm_2iEeKR1arwT6_zsA"/>
</ownedEnd>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_TSufnP2iEeKR1arwT6_zsA" name="User">
<ownedAttribute xmi:id="_TSufnf2iEeKR1arwT6_zsA" name="login" visibility="protected" isUnique="false" isReadOnly="true">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
</ownedAttribute>
<ownedAttribute xmi:id="_TSufnv2iEeKR1arwT6_zsA" name="password" visibility="protected" isUnique="false" isReadOnly="true">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
</ownedAttribute>
<ownedAttribute xmi:id="_TSufn_2iEeKR1arwT6_zsA" name="group" type="_TSuflv2iEeKR1arwT6_zsA" isReadOnly="true" aggregation="shared" association="_TSufmP2iEeKR1arwT6_zsA">
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_TSufoP2iEeKR1arwT6_zsA"/>
</ownedAttribute>
</packagedElement>
</packagedElement>
<profileApplication xmi:id="_TVRdQP2iEeKR1arwT6_zsA">
<eAnnotations xmi:id="_TVT5gP2iEeKR1arwT6_zsA" source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage" href="LocalProfile.profile.uml#_TUTM5v2iEeKR1arwT6_zsA"/>
</eAnnotations>
<appliedProfile href="LocalProfile.profile.uml#_TUSl0P2iEeKR1arwT6_zsA"/>
</profileApplication>
<profileApplication xmi:id="_TVUgkP2iEeKR1arwT6_zsA">
<eAnnotations xmi:id="_TVUgkf2iEeKR1arwT6_zsA" source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage" href="default.profile.uml#_TUkSp_2iEeKR1arwT6_zsA"/>
</eAnnotations>
<appliedProfile href="default.profile.uml#_TUkSoP2iEeKR1arwT6_zsA"/>
</profileApplication>
</uml:Model>
<LocalProfile:Stereo xmi:id="_TVWVwP2iEeKR1arwT6_zsA" base_Class="_TSuflv2iEeKR1arwT6_zsA"/>
<default:metaclass xmi:id="_TVW80P2iEeKR1arwT6_zsA" base_Classifier="_TSufnP2iEeKR1arwT6_zsA"/>
</xmi:XMI>
我default.profile.uml
和LocalProfil.profile.uml
我的文件在同一个文件夹中.uml
。
我使用此代码来获取我的 UML2 模型:
URI typesUri = URI.createFileURI(path);
ResourceSet set = new ResourceSetImpl();
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
set.createResource(typesUri);
Map<URI, URI> uriMap = set.getURIConverter().getURIMap();
URI uri = URI.createURI("jar:file:/C:/Users/ffischer/Desktop/org.eclipse.uml2.uml.resources_3.1.1.v201008191505.jar!/");
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
Resource r = set.getResource(typesUri, true);
Model m = (Model) EcoreUtil.getObjectByType(r.getContents(), UMLPackage.Literals.MODEL);
一切都很好,除了我无法获得与我的课程相关的刻板印象。(例如,此代码向我发送空数组:)
ClassImpl _c = (ClassImpl) el;
System.out.println(_c.getName() + " stereotypes :");
System.out.println(_c.getStereotypeApplications());
System.out.println(_c.getApplicableStereotypes());
System.out.println(_c.getAppliedStereotypes());
我想也许我忘了做一步,但我看不出是哪一步。
我希望有一个人可以帮助我 :)