2016-07-01 7 views

답변

2

사용자 지정 접미어로 특정 xmi 파일을 다시로드 하시겠습니까? 여기

는 루트 EObject를을 특정 위치 (경로)에서는 Ecore 파일을로드하고 반환하는 방법의 예입니다

public static EObject loadYourModel(String path) { 
    /*Initialzie Models*/ 
    YourPackage.eINSTANCE.eClass(); 

    /*register your xmi resources*/ 
    final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; 
    final Map<String, Object> m = reg.getExtensionToFactoryMap(); 
    /*put all your different ecore file suffixes in the map; suffix = YourPackage.eNAME*/ 
    m.put(YourPackage.eNAME, new XMIResourceFactoryImpl()); 
    /*you can put all different package names here*/ 

    /*Create a new Resource set to store the EObjects from the file*/ 
    ResourceSet resSet = new ResourceSetImpl(); 

    /*get the resource of your ecore file*/ 
    Resource resource = resSet.getResource(URI.createURI(path), true); 
    /*Get the first element = root of your model hierachy*/ 
    EObject root = resource.getContents().get(0); 
    return root; 
}