문제 설명
Eclipse UML2를 사용하여 Visual Paradigm 생성 XMI 파일 구문 분석 (Using Eclipse UML2 to parse a Visual Paradigm generated XMI file)
Visual Paradigm 8로 클래스 다이어그램을 그리고 프로젝트를 XMI 2.1 파일로 내보냈습니다(UML2용 내보내기). 따라서 두 개의 파일(test.xmi.uml
및 test.xmi.profile.uml
)이 있습니다. test.xmi.uml
을 구문 분석하기 위해 eclipse uml2 및 emf를 사용하여 이 Java 코드를 작성했습니다.
ResourceSet set = new ResourceSetImpl();
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource res = set.getResource(URI.createFileURI("C:\\test.xmi.uml"), true);
EObject eobj = res.getContents().get(0);
그러나 출력 개체(eobj
)는 AnyTypeImpl
잘 읽을 수 없습니다. 이 파일을 구문 분석하여 org.eclipse.uml2.uml.Model
객체와 같은 올바른 형식의 객체를 얻으려면 어떻게 해야 합니까?
참조 솔루션
방법 1:
I have finally found my answer: Using org.eclipse.uml2.uml.resources.util.UMLResourcesUtil.init()
to initialize the parameters needed to parse the .uml
file. So the code must be like this:
ResourceSet set = new ResourceSetImpl();
UMLResourcesUtil.init(set);
Resource res = set.getResource(typesUri, true);
EObject eobj = res.getContents().get(0);
the eobj
is an instance of org.eclipse.uml2.uml.Model
which is a well‑formed object.
(by Ehsan Soleimani、Ehsan Soleimani)