0
我使用modelio生成了一個UML文件。 我在我的課上應用了刻板印象。使用UML2解析XMI文件,如何處理定型
我.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);
一切工作正常,但我不能讓我的班associed定型。 (對於爲例,這個代碼給我空數組:)
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());
我想也許我忘掉一個人一步,但我沒有看到它。
我希望有人能幫助我:)