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

Praveen,
 
There is no UML2 2.2 yet, since UML2 2.1 is still under development. So, are you saying that you are using UML2 2.0 with Eclipse 3.2 and EMF 2.2? I'd suggest selecting the 'Help > About Eclipse SDK' to confirm which versions of the UML2 plug-ins are installed.
 
So no errors are appearing in the platform log?
 
Kenn
Hi Kenn,
 
I am using UML 2.1 and not UML 2.2 with eclipse 3.2 and EMF 2.2.
 
How should I check the configuration? The exact same code and the libraries work fine in standalone java programs.
 
Thanks Praveen.
"Kenn Hussey" <khussey@xxxxxxxxxx> wrote in message news:enma4r$92u$1@xxxxxxxxxxxxxxxxx...
Praveen,
 
No, code that works stand-alone should also work in a workbench. Are you seeing any exceptions in the platform log?
 
Are you sure you are using UML2 2.x? I wouldn't expect to see references to UML2Package or UML2Resource in code based on the latest API (they were replaced with UMLPackage and UMLResource as of UML2 2.0)... Could there be a problem with your configuration?
 
Kenn
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;
}