[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.modeling.mdt.uml2.uml] Difficulty with profile API

Hi,
 
I am trying to use the following code to open a model and a profile in an eclipse plugin using the UML 2.1 API libraries. The libraries are added in the plugin.xml -> Runtime -> Classpath tab.
 
The following code to load a model, profile and check if profile is applied on model elements works fine in regular java i.e. non plugin evironment, but when I try to do this from within a plugin, the system hangs after ResourceSet resourceSet = new ResourceSetImpl();
 
Should the code change depending on whether its in a plugin context or not?
 
public static String verifyModel(String metaModelFile) throws IOException {
    ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.getPackageRegistry().put(UML2Package.eNS_URI,UML2Package.eINSTANCE);
    Map extensionToFactoryMap = resourceSet.getResourceFactoryRegistry()
            .getExtensionToFactoryMap();
    extensionToFactoryMap.put(UML2Resource.FILE_EXTENSION,UML2Resource.Factory.INSTANCE);
    URL prflURL = FileLocator.resolve(Platform.getBundle("UCSIM").getResource("resources/Profile.uml2"));
    String prflPath=prflURL.getFile();
    prflPath=prflPath.substring(1);

    Profile prfl = loadProfile(prflPath, resourceSet);
    Model model = loadModel(metaModelFile, resourceSet);
}
 
public static Model loadModel(String modelFile, ResourceSet resourceSet) {
    URI uri = URI.createFileURI(modelFile);
    Resource resource = resourceSet.getResource(uri, true);
    Model model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
            UML2Package.eINSTANCE.getModel());
 
    return model;
}
 
public static Profile loadProfile(String modelFile, ResourceSet resourceSet) {
    Profile profile = "">
 
    Resource inputResource = resourceSet.createResource(URI
            .createFileURI(modelFile));
    try {
        inputResource.load(null);
    } catch (IOException exception) {
        exception.printStackTrace();
    }
 
    Iterator iterator = inputResource.getAllContents();
    while (iterator.hasNext()) {
        Object currentObject = iterator.next();
        if (currentObject instanceof Profile) {
            profile = "" currentObject;
            break;
        }
    }
    return profile;
}