2016-07-01 5 views

Répondre

2

Voulez-vous dire que vous voulez recharger votre fichier xmi spécifique avec un suffixe personnalisé?

Voici un exemple d'une méthode qui charge un fichier ecore à un endroit précis (chemin) et retourne votre EObject racine

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; 
}