Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Continuing saga of the standalone app
Continuing saga of the standalone app [message #477617] Thu, 17 July 2008 20:14 Go to next message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

It is possible to find on this list a working code snippet showing how to
get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone app.

My problem occurs when that Package has an imported package that has a
"pathmap" URL.

I think what I should do is map the pathmap URL to the actual URL, like
this:
Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();

URI pathmap =
URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");

URI types = URI.createFileURI(new File(typesFilename).getAbsolutePath());

uriMap.put(pathmap, types);

But when I try to get the imported stuff, like this:
EList<Package> importList = model.getImportedPackages();

I get an exception:
java.lang.ClassCastException:
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
org.eclipse.uml2.uml.Package
at
org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)

at
org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)

at
org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)


(Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks like
it doesn't know that the imported package is UML.

Any help on this? Thanks.
Re: Continuing saga of the standalone app [message #477618 is a reply to message #477617] Fri, 18 July 2008 14:06 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Jeff,

It looks like you might be missing a trailing slash at the end of your
pathmap string. This is mentioned in the FAQ
http://wiki.eclipse.org/MDT-UML2-FAQ.
If that still doesn't work I can provide a code snippet that should load
your model (post a small section of the problematic model so I can test it
out the code ).

Cheers,
- James.


"Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
news:g5o96q$ph2$1@build.eclipse.org...
> It is possible to find on this list a working code snippet showing how to
> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone app.
>
> My problem occurs when that Package has an imported package that has a
> "pathmap" URL.
>
> I think what I should do is map the pathmap URL to the actual URL, like
> this:
> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>
> URI pathmap =
> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>
> URI types = URI.createFileURI(new File(typesFilename).getAbsolutePath());
>
> uriMap.put(pathmap, types);
>
> But when I try to get the imported stuff, like this:
> EList<Package> importList = model.getImportedPackages();
>
> I get an exception:
> java.lang.ClassCastException:
> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
> org.eclipse.uml2.uml.Package
> at
> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>
> at
> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>
> at
> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>
>
> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
> like it doesn't know that the imported package is UML.
>
> Any help on this? Thanks.
>
Re: Continuing saga of the standalone app [message #477621 is a reply to message #477618] Sat, 19 July 2008 00:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jeff.lansing.sbcglobal.net

Thanks, James. That stopped the exception. But somehow I thought that the
external package would magically be imported, and all of the references into
it would be resolved.

Which is not what is happening.

Here is the relevant code, and attached are the problematic models.

private Model getModel(String filename, String typesFilename) {
RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);

Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
URI pathmap =
URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
URI types = URI.createFileURI(new File(typesFilename).getAbsolutePath());
uriMap.put(pathmap, types);

URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
Model model = null;
try {
Resource resource = RESOURCE_SET.getResource(uri, true);
EcoreUtil.resolveAll(resource);

model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
UMLPackage.Literals.MODEL);
} catch (WrappedException we) {
System.err.println(we.getMessage());
}
return model;
}

"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g5q81a$42a$1@build.eclipse.org...
> Hi Jeff,
>
> It looks like you might be missing a trailing slash at the end of your
> pathmap string. This is mentioned in the FAQ
> http://wiki.eclipse.org/MDT-UML2-FAQ.
> If that still doesn't work I can provide a code snippet that should load
> your model (post a small section of the problematic model so I can test it
> out the code ).
>
> Cheers,
> - James.
>
>
> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
> news:g5o96q$ph2$1@build.eclipse.org...
>> It is possible to find on this list a working code snippet showing how to
>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>> app.
>>
>> My problem occurs when that Package has an imported package that has a
>> "pathmap" URL.
>>
>> I think what I should do is map the pathmap URL to the actual URL, like
>> this:
>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>
>> URI pathmap =
>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>
>> URI types = URI.createFileURI(new File(typesFilename).getAbsolutePath());
>>
>> uriMap.put(pathmap, types);
>>
>> But when I try to get the imported stuff, like this:
>> EList<Package> importList = model.getImportedPackages();
>>
>> I get an exception:
>> java.lang.ClassCastException:
>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>> org.eclipse.uml2.uml.Package
>> at
>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>
>> at
>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>
>> at
>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>
>>
>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
>> like it doesn't know that the imported package is UML.
>>
>> Any help on this? Thanks.
>>
>
>



Re: Continuing saga of the standalone app [message #477622 is a reply to message #477621] Mon, 21 July 2008 20:06 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Jeff,


The following code snippet will properly resolve the data type from the
library.
There was one little 'gotcha' that had me wondering what was going on.
Your XSDDataTypes.library.uml was not upgraded to the latest version. You
have at the top of the file ...
xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be

xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">


1. Change the nsURI in your library by either re-saving it out or edit with
a text editor.
2. Try the following code (pardon the hard-coded stuff):
3. You should notice the type of "breed" is not a proxy.


Cheers,...
- James.

protected static void registerPathmaps(URI umlResourcePluginURI) {


URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),

umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));


URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),

umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));


URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),

umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));


URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),

URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));



}

protected static void registerExtensions() {

Map<String, Object> extensionFactoryMap = Resource.Factory.Registry.INSTANCE

..getExtensionToFactoryMap();


extensionFactoryMap.put(UMLResource.FILE_EXTENSION,

UMLResource.Factory.INSTANCE);


extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,

Ecore2XMLResource.Factory.INSTANCE);


extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,

UML22UMLResource.Factory.INSTANCE);


}



protected static void registerPackages(ResourceSet resourceSet) {


Registry packageRegistry = resourceSet.getPackageRegistry();


packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);


packageRegistry.put(Ecore2XMLPackage.eNS_URI,

Ecore2XMLPackage.eINSTANCE);


packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);

}


public static Model getModel(URI resourceURI, URI umlPluginURI, URI
umlResourcePluginURI) {


ResourceSet resourceSet = new ResourceSetImpl();

registerPathmaps(umlResourcePluginURI);

registerPackages(resourceSet);

registerExtensions();


// Map references to legacy (1.x) model elements to their new locations.

Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();

resourceSet.getURIConverter().getURIMap().putAll(uriMap);


// Load a resource in the resource set.

try {

resourceSet.getResource(resourceURI, true);

} catch (Exception e) {

System.out.println(e.getMessage());

return null;

}


EList<Resource> resources = resourceSet.getResources();

EcoreUtil.resolveAll(resources.get(0));


Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)

..getContents(), UMLPackage.Literals.MODEL);



//

// Sanity check.

//

org.eclipse.uml2.uml.Package packageableElement =
(org.eclipse.uml2.uml.Package) model

..getPackagedElement("pets");

org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
packageableElement

..getOwnedMember("Animal");

org.eclipse.uml2.uml.Property breed = animal

..getAttribute("breed", null);


System.out.println("BreedType: " + breed.getType());


return model;


}



public static void main(String[] args) {


String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";

String umlPluginPath =
" C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";

String umlResourcePath =
" C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";


URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");

URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath

+ "!/");

getModel(URI.createFileURI(fileToOpen), umlPluginURI, umlResourcePluginURI);


}



"Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
news:g5rbqt$kmk$1@build.eclipse.org...
> Thanks, James. That stopped the exception. But somehow I thought that the
> external package would magically be imported, and all of the references
> into it would be resolved.
>
> Which is not what is happening.
>
> Here is the relevant code, and attached are the problematic models.
>
> private Model getModel(String filename, String typesFilename) {
> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
> URI pathmap =
> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
> URI types = URI.createFileURI(new File(typesFilename).getAbsolutePath());
> uriMap.put(pathmap, types);
>
> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
> Model model = null;
> try {
> Resource resource = RESOURCE_SET.getResource(uri, true);
> EcoreUtil.resolveAll(resource);
>
> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
> UMLPackage.Literals.MODEL);
> } catch (WrappedException we) {
> System.err.println(we.getMessage());
> }
> return model;
> }
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:g5q81a$42a$1@build.eclipse.org...
>> Hi Jeff,
>>
>> It looks like you might be missing a trailing slash at the end of your
>> pathmap string. This is mentioned in the FAQ
>> http://wiki.eclipse.org/MDT-UML2-FAQ.
>> If that still doesn't work I can provide a code snippet that should load
>> your model (post a small section of the problematic model so I can test
>> it
>> out the code ).
>>
>> Cheers,
>> - James.
>>
>>
>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>> news:g5o96q$ph2$1@build.eclipse.org...
>>> It is possible to find on this list a working code snippet showing how
>>> to
>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>>> app.
>>>
>>> My problem occurs when that Package has an imported package that has a
>>> "pathmap" URL.
>>>
>>> I think what I should do is map the pathmap URL to the actual URL, like
>>> this:
>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>
>>> URI pathmap =
>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>
>>> URI types = URI.createFileURI(new
>>> File(typesFilename).getAbsolutePath());
>>>
>>> uriMap.put(pathmap, types);
>>>
>>> But when I try to get the imported stuff, like this:
>>> EList<Package> importList = model.getImportedPackages();
>>>
>>> I get an exception:
>>> java.lang.ClassCastException:
>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>> org.eclipse.uml2.uml.Package
>>> at
>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>
>>> at
>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>
>>> at
>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>
>>>
>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
>>> like it doesn't know that the imported package is UML.
>>>
>>> Any help on this? Thanks.
>>>
>>
>>
>
>
>
Re: Continuing saga of the standalone app [message #477623 is a reply to message #477622] Tue, 22 July 2008 13:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jeff.lansing.sbcglobal.net

Thanks, James. Incredibly helpful.

Since it's a standalone app, I added:
URI umlResourcePluginURI = getJarURI("uml2.uml.resources");
....
protected static URI getJarURI(String key) {
for(String jarLoc : System.getProperty("java.class.path").split(";")) {
if(jarLoc.contains(key)) {
return URI.createURI("jar:file:/" + jarLoc.replace('\\', '/') + "!/");
}
}
return null;
}

"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g62q94$8in$1@build.eclipse.org...
> Hi Jeff,
>
>
> The following code snippet will properly resolve the data type from the
> library.
> There was one little 'gotcha' that had me wondering what was going on.
> Your XSDDataTypes.library.uml was not upgraded to the latest version. You
> have at the top of the file ...
> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>
> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>
>
> 1. Change the nsURI in your library by either re-saving it out or edit
> with a text editor.
> 2. Try the following code (pardon the hard-coded stuff):
> 3. You should notice the type of "breed" is not a proxy.
>
>
> Cheers,...
> - James.
>
> protected static void registerPathmaps(URI umlResourcePluginURI) {
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>
> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>
> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>
> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>
> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>
>
>
> }
>
> protected static void registerExtensions() {
>
> Map<String, Object> extensionFactoryMap =
> Resource.Factory.Registry.INSTANCE
>
> .getExtensionToFactoryMap();
>
>
> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>
> UMLResource.Factory.INSTANCE);
>
>
> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>
> Ecore2XMLResource.Factory.INSTANCE);
>
>
> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>
> UML22UMLResource.Factory.INSTANCE);
>
>
> }
>
>
>
> protected static void registerPackages(ResourceSet resourceSet) {
>
>
> Registry packageRegistry = resourceSet.getPackageRegistry();
>
>
> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>
>
> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>
> Ecore2XMLPackage.eINSTANCE);
>
>
> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>
> }
>
>
> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
> umlResourcePluginURI) {
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> registerPathmaps(umlResourcePluginURI);
>
> registerPackages(resourceSet);
>
> registerExtensions();
>
>
> // Map references to legacy (1.x) model elements to their new locations.
>
> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>
> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>
>
> // Load a resource in the resource set.
>
> try {
>
> resourceSet.getResource(resourceURI, true);
>
> } catch (Exception e) {
>
> System.out.println(e.getMessage());
>
> return null;
>
> }
>
>
> EList<Resource> resources = resourceSet.getResources();
>
> EcoreUtil.resolveAll(resources.get(0));
>
>
> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>
> .getContents(), UMLPackage.Literals.MODEL);
>
>
>
> //
>
> // Sanity check.
>
> //
>
> org.eclipse.uml2.uml.Package packageableElement =
> (org.eclipse.uml2.uml.Package) model
>
> .getPackagedElement("pets");
>
> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
> packageableElement
>
> .getOwnedMember("Animal");
>
> org.eclipse.uml2.uml.Property breed = animal
>
> .getAttribute("breed", null);
>
>
> System.out.println("BreedType: " + breed.getType());
>
>
> return model;
>
>
> }
>
>
>
> public static void main(String[] args) {
>
>
> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>
> String umlPluginPath =
> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>
> String umlResourcePath =
> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>
>
> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>
> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>
> + "!/");
>
> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
> umlResourcePluginURI);
>
>
> }
>
>
>
> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
> news:g5rbqt$kmk$1@build.eclipse.org...
>> Thanks, James. That stopped the exception. But somehow I thought that the
>> external package would magically be imported, and all of the references
>> into it would be resolved.
>>
>> Which is not what is happening.
>>
>> Here is the relevant code, and attached are the problematic models.
>>
>> private Model getModel(String filename, String typesFilename) {
>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>> UMLPackage.eINSTANCE);
>>
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>> UMLResource.Factory.INSTANCE);
>>
>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>> URI pathmap =
>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>> URI types = URI.createFileURI(new
>> File(typesFilename).getAbsolutePath());
>> uriMap.put(pathmap, types);
>>
>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>> Model model = null;
>> try {
>> Resource resource = RESOURCE_SET.getResource(uri, true);
>> EcoreUtil.resolveAll(resource);
>>
>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>> UMLPackage.Literals.MODEL);
>> } catch (WrappedException we) {
>> System.err.println(we.getMessage());
>> }
>> return model;
>> }
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:g5q81a$42a$1@build.eclipse.org...
>>> Hi Jeff,
>>>
>>> It looks like you might be missing a trailing slash at the end of your
>>> pathmap string. This is mentioned in the FAQ
>>> http://wiki.eclipse.org/MDT-UML2-FAQ.
>>> If that still doesn't work I can provide a code snippet that should load
>>> your model (post a small section of the problematic model so I can test
>>> it
>>> out the code ).
>>>
>>> Cheers,
>>> - James.
>>>
>>>
>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>> It is possible to find on this list a working code snippet showing how
>>>> to
>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>>>> app.
>>>>
>>>> My problem occurs when that Package has an imported package that has a
>>>> "pathmap" URL.
>>>>
>>>> I think what I should do is map the pathmap URL to the actual URL, like
>>>> this:
>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>
>>>> URI pathmap =
>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>
>>>> URI types = URI.createFileURI(new
>>>> File(typesFilename).getAbsolutePath());
>>>>
>>>> uriMap.put(pathmap, types);
>>>>
>>>> But when I try to get the imported stuff, like this:
>>>> EList<Package> importList = model.getImportedPackages();
>>>>
>>>> I get an exception:
>>>> java.lang.ClassCastException:
>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>> org.eclipse.uml2.uml.Package
>>>> at
>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>
>>>> at
>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>
>>>> at
>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>
>>>>
>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
>>>> like it doesn't know that the imported package is UML.
>>>>
>>>> Any help on this? Thanks.
>>>>
>>>
>>>
>>
>>
>>
>
>
Re: Continuing saga of the standalone app [message #477624 is a reply to message #477622] Tue, 22 July 2008 13:35 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
I should mention (for others reading this thread) that the recommendation to
"edit the nsURI with a text editor" would not be a general solution. It
would work for this very specific example but not in general (in this case
there was one DataType in the library). The migration guides on the wiki
explain in more detail how to properly migrate to newer versions.

Cheers,
- James.


"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g62q94$8in$1@build.eclipse.org...
> Hi Jeff,
>
>
> The following code snippet will properly resolve the data type from the
> library.
> There was one little 'gotcha' that had me wondering what was going on.
> Your XSDDataTypes.library.uml was not upgraded to the latest version. You
> have at the top of the file ...
> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>
> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>
>
> 1. Change the nsURI in your library by either re-saving it out or edit
> with a text editor.
> 2. Try the following code (pardon the hard-coded stuff):
> 3. You should notice the type of "breed" is not a proxy.
>
>
> Cheers,...
> - James.
>
> protected static void registerPathmaps(URI umlResourcePluginURI) {
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>
> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>
> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>
> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>
> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>
>
>
> }
>
> protected static void registerExtensions() {
>
> Map<String, Object> extensionFactoryMap =
> Resource.Factory.Registry.INSTANCE
>
> .getExtensionToFactoryMap();
>
>
> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>
> UMLResource.Factory.INSTANCE);
>
>
> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>
> Ecore2XMLResource.Factory.INSTANCE);
>
>
> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>
> UML22UMLResource.Factory.INSTANCE);
>
>
> }
>
>
>
> protected static void registerPackages(ResourceSet resourceSet) {
>
>
> Registry packageRegistry = resourceSet.getPackageRegistry();
>
>
> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>
>
> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>
> Ecore2XMLPackage.eINSTANCE);
>
>
> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>
> }
>
>
> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
> umlResourcePluginURI) {
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> registerPathmaps(umlResourcePluginURI);
>
> registerPackages(resourceSet);
>
> registerExtensions();
>
>
> // Map references to legacy (1.x) model elements to their new locations.
>
> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>
> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>
>
> // Load a resource in the resource set.
>
> try {
>
> resourceSet.getResource(resourceURI, true);
>
> } catch (Exception e) {
>
> System.out.println(e.getMessage());
>
> return null;
>
> }
>
>
> EList<Resource> resources = resourceSet.getResources();
>
> EcoreUtil.resolveAll(resources.get(0));
>
>
> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>
> .getContents(), UMLPackage.Literals.MODEL);
>
>
>
> //
>
> // Sanity check.
>
> //
>
> org.eclipse.uml2.uml.Package packageableElement =
> (org.eclipse.uml2.uml.Package) model
>
> .getPackagedElement("pets");
>
> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
> packageableElement
>
> .getOwnedMember("Animal");
>
> org.eclipse.uml2.uml.Property breed = animal
>
> .getAttribute("breed", null);
>
>
> System.out.println("BreedType: " + breed.getType());
>
>
> return model;
>
>
> }
>
>
>
> public static void main(String[] args) {
>
>
> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>
> String umlPluginPath =
> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>
> String umlResourcePath =
> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>
>
> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>
> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>
> + "!/");
>
> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
> umlResourcePluginURI);
>
>
> }
>
>
>
> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
> news:g5rbqt$kmk$1@build.eclipse.org...
>> Thanks, James. That stopped the exception. But somehow I thought that the
>> external package would magically be imported, and all of the references
>> into it would be resolved.
>>
>> Which is not what is happening.
>>
>> Here is the relevant code, and attached are the problematic models.
>>
>> private Model getModel(String filename, String typesFilename) {
>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>> UMLPackage.eINSTANCE);
>>
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>> UMLResource.Factory.INSTANCE);
>>
>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>> URI pathmap =
>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>> URI types = URI.createFileURI(new
>> File(typesFilename).getAbsolutePath());
>> uriMap.put(pathmap, types);
>>
>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>> Model model = null;
>> try {
>> Resource resource = RESOURCE_SET.getResource(uri, true);
>> EcoreUtil.resolveAll(resource);
>>
>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>> UMLPackage.Literals.MODEL);
>> } catch (WrappedException we) {
>> System.err.println(we.getMessage());
>> }
>> return model;
>> }
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:g5q81a$42a$1@build.eclipse.org...
>>> Hi Jeff,
>>>
>>> It looks like you might be missing a trailing slash at the end of your
>>> pathmap string. This is mentioned in the FAQ
>>> http://wiki.eclipse.org/MDT-UML2-FAQ.
>>> If that still doesn't work I can provide a code snippet that should load
>>> your model (post a small section of the problematic model so I can test
>>> it
>>> out the code ).
>>>
>>> Cheers,
>>> - James.
>>>
>>>
>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>> It is possible to find on this list a working code snippet showing how
>>>> to
>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>>>> app.
>>>>
>>>> My problem occurs when that Package has an imported package that has a
>>>> "pathmap" URL.
>>>>
>>>> I think what I should do is map the pathmap URL to the actual URL, like
>>>> this:
>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>
>>>> URI pathmap =
>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>
>>>> URI types = URI.createFileURI(new
>>>> File(typesFilename).getAbsolutePath());
>>>>
>>>> uriMap.put(pathmap, types);
>>>>
>>>> But when I try to get the imported stuff, like this:
>>>> EList<Package> importList = model.getImportedPackages();
>>>>
>>>> I get an exception:
>>>> java.lang.ClassCastException:
>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>> org.eclipse.uml2.uml.Package
>>>> at
>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>
>>>> at
>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>
>>>> at
>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>
>>>>
>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
>>>> like it doesn't know that the imported package is UML.
>>>>
>>>> Any help on this? Thanks.
>>>>
>>>
>>>
>>
>>
>>
>
>
Re: Continuing saga of the standalone app [message #477625 is a reply to message #477624] Tue, 22 July 2008 16:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

James,
This doesn't quite do what I hoped. Stuff in the external model that is
referenced "indirectly" doesn't get imported.

Attached is a refinement of the importing model that uses a generalization
that references the external model.
The new sanity check is the following, which gets null for the supertype:
//
// Sanity check.
//
org.eclipse.uml2.uml.Package packageableElement =
(org.eclipse.uml2.uml.Package) model.getPackagedElement("pets");
org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
packageableElement.getOwnedMember("Animal");
org.eclipse.uml2.uml.Property breed = animal.getAttribute("breed", null);
org.eclipse.uml2.uml.DataType breedType = (org.eclipse.uml2.uml.DataType)
breed.getType();
System.out.println("BreedType: " + breedType);
org.eclipse.uml2.uml.Generalization gen = ((org.eclipse.uml2.uml.DataType)
breedType).getGeneralizations().get(0);
org.eclipse.uml2.uml.Classifier general = gen.getGeneral();
System.out.println("BreedSuperType: " + general.getName());

"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g64nml$1ha$1@build.eclipse.org...
>I should mention (for others reading this thread) that the recommendation
>to
> "edit the nsURI with a text editor" would not be a general solution. It
> would work for this very specific example but not in general (in this case
> there was one DataType in the library). The migration guides on the wiki
> explain in more detail how to properly migrate to newer versions.
>
> Cheers,
> - James.
>
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:g62q94$8in$1@build.eclipse.org...
>> Hi Jeff,
>>
>>
>> The following code snippet will properly resolve the data type from the
>> library.
>> There was one little 'gotcha' that had me wondering what was going on.
>> Your XSDDataTypes.library.uml was not upgraded to the latest version.
>> You
>> have at the top of the file ...
>> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>>
>> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>>
>>
>> 1. Change the nsURI in your library by either re-saving it out or edit
>> with a text editor.
>> 2. Try the following code (pardon the hard-coded stuff):
>> 3. You should notice the type of "breed" is not a proxy.
>>
>>
>> Cheers,...
>> - James.
>>
>> protected static void registerPathmaps(URI umlResourcePluginURI) {
>>
>>
>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>>
>> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>>
>>
>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>>
>> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>>
>>
>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>>
>> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>>
>>
>> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>>
>> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>>
>>
>>
>> }
>>
>> protected static void registerExtensions() {
>>
>> Map<String, Object> extensionFactoryMap =
>> Resource.Factory.Registry.INSTANCE
>>
>> .getExtensionToFactoryMap();
>>
>>
>> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>>
>> UMLResource.Factory.INSTANCE);
>>
>>
>> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>>
>> Ecore2XMLResource.Factory.INSTANCE);
>>
>>
>> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>
>> UML22UMLResource.Factory.INSTANCE);
>>
>>
>> }
>>
>>
>>
>> protected static void registerPackages(ResourceSet resourceSet) {
>>
>>
>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>
>>
>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>
>>
>> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>>
>> Ecore2XMLPackage.eINSTANCE);
>>
>>
>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>
>> }
>>
>>
>> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
>> umlResourcePluginURI) {
>>
>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>>
>> registerPathmaps(umlResourcePluginURI);
>>
>> registerPackages(resourceSet);
>>
>> registerExtensions();
>>
>>
>> // Map references to legacy (1.x) model elements to their new locations.
>>
>> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>>
>> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>>
>>
>> // Load a resource in the resource set.
>>
>> try {
>>
>> resourceSet.getResource(resourceURI, true);
>>
>> } catch (Exception e) {
>>
>> System.out.println(e.getMessage());
>>
>> return null;
>>
>> }
>>
>>
>> EList<Resource> resources = resourceSet.getResources();
>>
>> EcoreUtil.resolveAll(resources.get(0));
>>
>>
>> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>>
>> .getContents(), UMLPackage.Literals.MODEL);
>>
>>
>>
>> //
>>
>> // Sanity check.
>>
>> //
>>
>> org.eclipse.uml2.uml.Package packageableElement =
>> (org.eclipse.uml2.uml.Package) model
>>
>> .getPackagedElement("pets");
>>
>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>> packageableElement
>>
>> .getOwnedMember("Animal");
>>
>> org.eclipse.uml2.uml.Property breed = animal
>>
>> .getAttribute("breed", null);
>>
>>
>> System.out.println("BreedType: " + breed.getType());
>>
>>
>> return model;
>>
>>
>> }
>>
>>
>>
>> public static void main(String[] args) {
>>
>>
>> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>>
>> String umlPluginPath =
>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>>
>> String umlResourcePath =
>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>>
>>
>> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>>
>> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>>
>> + "!/");
>>
>> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
>> umlResourcePluginURI);
>>
>>
>> }
>>
>>
>>
>> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
>> news:g5rbqt$kmk$1@build.eclipse.org...
>>> Thanks, James. That stopped the exception. But somehow I thought that
>>> the
>>> external package would magically be imported, and all of the references
>>> into it would be resolved.
>>>
>>> Which is not what is happening.
>>>
>>> Here is the relevant code, and attached are the problematic models.
>>>
>>> private Model getModel(String filename, String typesFilename) {
>>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>>> UMLPackage.eINSTANCE);
>>>
>>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>>> UMLResource.Factory.INSTANCE);
>>>
>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>> URI pathmap =
>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>>> URI types = URI.createFileURI(new
>>> File(typesFilename).getAbsolutePath());
>>> uriMap.put(pathmap, types);
>>>
>>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>>> Model model = null;
>>> try {
>>> Resource resource = RESOURCE_SET.getResource(uri, true);
>>> EcoreUtil.resolveAll(resource);
>>>
>>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>>> UMLPackage.Literals.MODEL);
>>> } catch (WrappedException we) {
>>> System.err.println(we.getMessage());
>>> }
>>> return model;
>>> }
>>>
>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>> news:g5q81a$42a$1@build.eclipse.org...
>>>> Hi Jeff,
>>>>
>>>> It looks like you might be missing a trailing slash at the end of your
>>>> pathmap string. This is mentioned in the FAQ
>>>> http://wiki.eclipse.org/MDT-UML2-FAQ.
>>>> If that still doesn't work I can provide a code snippet that should
>>>> load
>>>> your model (post a small section of the problematic model so I can test
>>>> it
>>>> out the code ).
>>>>
>>>> Cheers,
>>>> - James.
>>>>
>>>>
>>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>>> It is possible to find on this list a working code snippet showing how
>>>>> to
>>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>>>>> app.
>>>>>
>>>>> My problem occurs when that Package has an imported package that has a
>>>>> "pathmap" URL.
>>>>>
>>>>> I think what I should do is map the pathmap URL to the actual URL,
>>>>> like
>>>>> this:
>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>>
>>>>> URI pathmap =
>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>>
>>>>> URI types = URI.createFileURI(new
>>>>> File(typesFilename).getAbsolutePath());
>>>>>
>>>>> uriMap.put(pathmap, types);
>>>>>
>>>>> But when I try to get the imported stuff, like this:
>>>>> EList<Package> importList = model.getImportedPackages();
>>>>>
>>>>> I get an exception:
>>>>> java.lang.ClassCastException:
>>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>>> org.eclipse.uml2.uml.Package
>>>>> at
>>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>>
>>>>> at
>>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>>
>>>>> at
>>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>>
>>>>>
>>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
>>>>> like it doesn't know that the imported package is UML.
>>>>>
>>>>> Any help on this? Thanks.
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>
>


  • Attachment: petsplus.uml
    (Size: 6.36KB, Downloaded 275 times)
Re: Continuing saga of the standalone app [message #477626 is a reply to message #477625] Tue, 22 July 2008 18:06 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Jeff,

That seems to work fine for me. I'm seeing BreedType: Breed and
BreedSuperType: string.

What are the problems you are seeing?
Are you certain you are loading the new petsplus.uml and not the older
pets.uml. You would see an exception in that case since there would be no
generalizations of the DataType from the library.

I could zip up my small test class to send you if you want.

Cheers,
- James.


"Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
news:g651sr$mg2$1@build.eclipse.org...
> James,
> This doesn't quite do what I hoped. Stuff in the external model that is
> referenced "indirectly" doesn't get imported.
>
> Attached is a refinement of the importing model that uses a generalization
> that references the external model.
> The new sanity check is the following, which gets null for the supertype:
> //
> // Sanity check.
> //
> org.eclipse.uml2.uml.Package packageableElement =
> (org.eclipse.uml2.uml.Package) model.getPackagedElement("pets");
> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
> packageableElement.getOwnedMember("Animal");
> org.eclipse.uml2.uml.Property breed = animal.getAttribute("breed", null);
> org.eclipse.uml2.uml.DataType breedType = (org.eclipse.uml2.uml.DataType)
> breed.getType();
> System.out.println("BreedType: " + breedType);
> org.eclipse.uml2.uml.Generalization gen = ((org.eclipse.uml2.uml.DataType)
> breedType).getGeneralizations().get(0);
> org.eclipse.uml2.uml.Classifier general = gen.getGeneral();
> System.out.println("BreedSuperType: " + general.getName());
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:g64nml$1ha$1@build.eclipse.org...
>>I should mention (for others reading this thread) that the recommendation
>>to
>> "edit the nsURI with a text editor" would not be a general solution. It
>> would work for this very specific example but not in general (in this
>> case
>> there was one DataType in the library). The migration guides on the
>> wiki
>> explain in more detail how to properly migrate to newer versions.
>>
>> Cheers,
>> - James.
>>
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:g62q94$8in$1@build.eclipse.org...
>>> Hi Jeff,
>>>
>>>
>>> The following code snippet will properly resolve the data type from the
>>> library.
>>> There was one little 'gotcha' that had me wondering what was going on.
>>> Your XSDDataTypes.library.uml was not upgraded to the latest version.
>>> You
>>> have at the top of the file ...
>>> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>>>
>>> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>>>
>>>
>>> 1. Change the nsURI in your library by either re-saving it out or edit
>>> with a text editor.
>>> 2. Try the following code (pardon the hard-coded stuff):
>>> 3. You should notice the type of "breed" is not a proxy.
>>>
>>>
>>> Cheers,...
>>> - James.
>>>
>>> protected static void registerPathmaps(URI umlResourcePluginURI) {
>>>
>>>
>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>>>
>>> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>>>
>>>
>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>>>
>>> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>>>
>>>
>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>>>
>>> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>>>
>>>
>>> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>>>
>>> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>>>
>>>
>>>
>>> }
>>>
>>> protected static void registerExtensions() {
>>>
>>> Map<String, Object> extensionFactoryMap =
>>> Resource.Factory.Registry.INSTANCE
>>>
>>> .getExtensionToFactoryMap();
>>>
>>>
>>> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>>>
>>> UMLResource.Factory.INSTANCE);
>>>
>>>
>>> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>>>
>>> Ecore2XMLResource.Factory.INSTANCE);
>>>
>>>
>>> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>>
>>> UML22UMLResource.Factory.INSTANCE);
>>>
>>>
>>> }
>>>
>>>
>>>
>>> protected static void registerPackages(ResourceSet resourceSet) {
>>>
>>>
>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>>
>>>
>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>>
>>>
>>> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>>>
>>> Ecore2XMLPackage.eINSTANCE);
>>>
>>>
>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>>
>>> }
>>>
>>>
>>> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
>>> umlResourcePluginURI) {
>>>
>>>
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>
>>> registerPathmaps(umlResourcePluginURI);
>>>
>>> registerPackages(resourceSet);
>>>
>>> registerExtensions();
>>>
>>>
>>> // Map references to legacy (1.x) model elements to their new locations.
>>>
>>> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>>>
>>> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>>>
>>>
>>> // Load a resource in the resource set.
>>>
>>> try {
>>>
>>> resourceSet.getResource(resourceURI, true);
>>>
>>> } catch (Exception e) {
>>>
>>> System.out.println(e.getMessage());
>>>
>>> return null;
>>>
>>> }
>>>
>>>
>>> EList<Resource> resources = resourceSet.getResources();
>>>
>>> EcoreUtil.resolveAll(resources.get(0));
>>>
>>>
>>> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>>>
>>> .getContents(), UMLPackage.Literals.MODEL);
>>>
>>>
>>>
>>> //
>>>
>>> // Sanity check.
>>>
>>> //
>>>
>>> org.eclipse.uml2.uml.Package packageableElement =
>>> (org.eclipse.uml2.uml.Package) model
>>>
>>> .getPackagedElement("pets");
>>>
>>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>>> packageableElement
>>>
>>> .getOwnedMember("Animal");
>>>
>>> org.eclipse.uml2.uml.Property breed = animal
>>>
>>> .getAttribute("breed", null);
>>>
>>>
>>> System.out.println("BreedType: " + breed.getType());
>>>
>>>
>>> return model;
>>>
>>>
>>> }
>>>
>>>
>>>
>>> public static void main(String[] args) {
>>>
>>>
>>> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>>>
>>> String umlPluginPath =
>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>>>
>>> String umlResourcePath =
>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>>>
>>>
>>> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>>>
>>> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>>>
>>> + "!/");
>>>
>>> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
>>> umlResourcePluginURI);
>>>
>>>
>>> }
>>>
>>>
>>>
>>> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
>>> news:g5rbqt$kmk$1@build.eclipse.org...
>>>> Thanks, James. That stopped the exception. But somehow I thought that
>>>> the
>>>> external package would magically be imported, and all of the references
>>>> into it would be resolved.
>>>>
>>>> Which is not what is happening.
>>>>
>>>> Here is the relevant code, and attached are the problematic models.
>>>>
>>>> private Model getModel(String filename, String typesFilename) {
>>>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>>>> UMLPackage.eINSTANCE);
>>>>
>>>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>>>> UMLResource.Factory.INSTANCE);
>>>>
>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>> URI pathmap =
>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>>>> URI types = URI.createFileURI(new
>>>> File(typesFilename).getAbsolutePath());
>>>> uriMap.put(pathmap, types);
>>>>
>>>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>>>> Model model = null;
>>>> try {
>>>> Resource resource = RESOURCE_SET.getResource(uri, true);
>>>> EcoreUtil.resolveAll(resource);
>>>>
>>>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>>>> UMLPackage.Literals.MODEL);
>>>> } catch (WrappedException we) {
>>>> System.err.println(we.getMessage());
>>>> }
>>>> return model;
>>>> }
>>>>
>>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>>> news:g5q81a$42a$1@build.eclipse.org...
>>>>> Hi Jeff,
>>>>>
>>>>> It looks like you might be missing a trailing slash at the end of your
>>>>> pathmap string. This is mentioned in the FAQ
>>>>> http://wiki.eclipse.org/MDT-UML2-FAQ.
>>>>> If that still doesn't work I can provide a code snippet that should
>>>>> load
>>>>> your model (post a small section of the problematic model so I can
>>>>> test
>>>>> it
>>>>> out the code ).
>>>>>
>>>>> Cheers,
>>>>> - James.
>>>>>
>>>>>
>>>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>>>> It is possible to find on this list a working code snippet showing
>>>>>> how
>>>>>> to
>>>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>>>>>> app.
>>>>>>
>>>>>> My problem occurs when that Package has an imported package that has
>>>>>> a
>>>>>> "pathmap" URL.
>>>>>>
>>>>>> I think what I should do is map the pathmap URL to the actual URL,
>>>>>> like
>>>>>> this:
>>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>>>
>>>>>> URI pathmap =
>>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>>>
>>>>>> URI types = URI.createFileURI(new
>>>>>> File(typesFilename).getAbsolutePath());
>>>>>>
>>>>>> uriMap.put(pathmap, types);
>>>>>>
>>>>>> But when I try to get the imported stuff, like this:
>>>>>> EList<Package> importList = model.getImportedPackages();
>>>>>>
>>>>>> I get an exception:
>>>>>> java.lang.ClassCastException:
>>>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>>>> org.eclipse.uml2.uml.Package
>>>>>> at
>>>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>>>
>>>>>>
>>>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It
>>>>>> looks
>>>>>> like it doesn't know that the imported package is UML.
>>>>>>
>>>>>> Any help on this? Thanks.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
>
Re: Continuing saga of the standalone app [message #477627 is a reply to message #477626] Tue, 22 July 2008 20:18 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
.... the complete project attached ...



"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g657k1$7c1$1@build.eclipse.org...
> Hi Jeff,
>
> That seems to work fine for me. I'm seeing BreedType: Breed and
> BreedSuperType: string.
>
> What are the problems you are seeing?
> Are you certain you are loading the new petsplus.uml and not the older
> pets.uml. You would see an exception in that case since there would be no
> generalizations of the DataType from the library.
>
> I could zip up my small test class to send you if you want.
>
> Cheers,
> - James.
>
>
> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
> news:g651sr$mg2$1@build.eclipse.org...
>> James,
>> This doesn't quite do what I hoped. Stuff in the external model that is
>> referenced "indirectly" doesn't get imported.
>>
>> Attached is a refinement of the importing model that uses a
>> generalization
>> that references the external model.
>> The new sanity check is the following, which gets null for the supertype:
>> //
>> // Sanity check.
>> //
>> org.eclipse.uml2.uml.Package packageableElement =
>> (org.eclipse.uml2.uml.Package) model.getPackagedElement("pets");
>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>> packageableElement.getOwnedMember("Animal");
>> org.eclipse.uml2.uml.Property breed = animal.getAttribute("breed", null);
>> org.eclipse.uml2.uml.DataType breedType = (org.eclipse.uml2.uml.DataType)
>> breed.getType();
>> System.out.println("BreedType: " + breedType);
>> org.eclipse.uml2.uml.Generalization gen =
>> ((org.eclipse.uml2.uml.DataType)
>> breedType).getGeneralizations().get(0);
>> org.eclipse.uml2.uml.Classifier general = gen.getGeneral();
>> System.out.println("BreedSuperType: " + general.getName());
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:g64nml$1ha$1@build.eclipse.org...
>>>I should mention (for others reading this thread) that the recommendation
>>>to
>>> "edit the nsURI with a text editor" would not be a general solution.
>>> It
>>> would work for this very specific example but not in general (in this
>>> case
>>> there was one DataType in the library). The migration guides on the
>>> wiki
>>> explain in more detail how to properly migrate to newer versions.
>>>
>>> Cheers,
>>> - James.
>>>
>>>
>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>> news:g62q94$8in$1@build.eclipse.org...
>>>> Hi Jeff,
>>>>
>>>>
>>>> The following code snippet will properly resolve the data type from the
>>>> library.
>>>> There was one little 'gotcha' that had me wondering what was going on.
>>>> Your XSDDataTypes.library.uml was not upgraded to the latest version.
>>>> You
>>>> have at the top of the file ...
>>>> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>>>>
>>>> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>>>>
>>>>
>>>> 1. Change the nsURI in your library by either re-saving it out or edit
>>>> with a text editor.
>>>> 2. Try the following code (pardon the hard-coded stuff):
>>>> 3. You should notice the type of "breed" is not a proxy.
>>>>
>>>>
>>>> Cheers,...
>>>> - James.
>>>>
>>>> protected static void registerPathmaps(URI umlResourcePluginURI) {
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>>>>
>>>> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>>>>
>>>>
>>>>
>>>> }
>>>>
>>>> protected static void registerExtensions() {
>>>>
>>>> Map<String, Object> extensionFactoryMap =
>>>> Resource.Factory.Registry.INSTANCE
>>>>
>>>> .getExtensionToFactoryMap();
>>>>
>>>>
>>>> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>>>>
>>>> UMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>>>>
>>>> Ecore2XMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>>>
>>>> UML22UMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> protected static void registerPackages(ResourceSet resourceSet) {
>>>>
>>>>
>>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>>>
>>>>
>>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>>>
>>>>
>>>> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>>>>
>>>> Ecore2XMLPackage.eINSTANCE);
>>>>
>>>>
>>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>>>
>>>> }
>>>>
>>>>
>>>> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
>>>> umlResourcePluginURI) {
>>>>
>>>>
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>
>>>> registerPathmaps(umlResourcePluginURI);
>>>>
>>>> registerPackages(resourceSet);
>>>>
>>>> registerExtensions();
>>>>
>>>>
>>>> // Map references to legacy (1.x) model elements to their new
>>>> locations.
>>>>
>>>> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>>>>
>>>> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>>>>
>>>>
>>>> // Load a resource in the resource set.
>>>>
>>>> try {
>>>>
>>>> resourceSet.getResource(resourceURI, true);
>>>>
>>>> } catch (Exception e) {
>>>>
>>>> System.out.println(e.getMessage());
>>>>
>>>> return null;
>>>>
>>>> }
>>>>
>>>>
>>>> EList<Resource> resources = resourceSet.getResources();
>>>>
>>>> EcoreUtil.resolveAll(resources.get(0));
>>>>
>>>>
>>>> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>>>>
>>>> .getContents(), UMLPackage.Literals.MODEL);
>>>>
>>>>
>>>>
>>>> //
>>>>
>>>> // Sanity check.
>>>>
>>>> //
>>>>
>>>> org.eclipse.uml2.uml.Package packageableElement =
>>>> (org.eclipse.uml2.uml.Package) model
>>>>
>>>> .getPackagedElement("pets");
>>>>
>>>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>>>> packageableElement
>>>>
>>>> .getOwnedMember("Animal");
>>>>
>>>> org.eclipse.uml2.uml.Property breed = animal
>>>>
>>>> .getAttribute("breed", null);
>>>>
>>>>
>>>> System.out.println("BreedType: " + breed.getType());
>>>>
>>>>
>>>> return model;
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> public static void main(String[] args) {
>>>>
>>>>
>>>> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>>>>
>>>> String umlPluginPath =
>>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>>>>
>>>> String umlResourcePath =
>>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>>>>
>>>>
>>>> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>>>>
>>>> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>>>>
>>>> + "!/");
>>>>
>>>> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
>>>> umlResourcePluginURI);
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
>>>> news:g5rbqt$kmk$1@build.eclipse.org...
>>>>> Thanks, James. That stopped the exception. But somehow I thought that
>>>>> the
>>>>> external package would magically be imported, and all of the
>>>>> references
>>>>> into it would be resolved.
>>>>>
>>>>> Which is not what is happening.
>>>>>
>>>>> Here is the relevant code, and attached are the problematic models.
>>>>>
>>>>> private Model getModel(String filename, String typesFilename) {
>>>>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>>
>>>>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>>>>> UMLResource.Factory.INSTANCE);
>>>>>
>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>> URI pathmap =
>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>>>>> URI types = URI.createFileURI(new
>>>>> File(typesFilename).getAbsolutePath());
>>>>> uriMap.put(pathmap, types);
>>>>>
>>>>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>>>>> Model model = null;
>>>>> try {
>>>>> Resource resource = RESOURCE_SET.getResource(uri, true);
>>>>> EcoreUtil.resolveAll(resource);
>>>>>
>>>>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>>>>> UMLPackage.Literals.MODEL);
>>>>> } catch (WrappedException we) {
>>>>> System.err.println(we.getMessage());
>>>>> }
>>>>> return model;
>>>>> }
>>>>>
>>>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>>>> news:g5q81a$42a$1@build.eclipse.org...
>>>>>> Hi Jeff,
>>>>>>
>>>>>> It looks like you might be missing a trailing slash at the end of
>>>>>> your
>>>>>> pathmap string. This is mentioned in the FAQ
>>>>>> http://wiki.eclipse.org/MDT-UML2-FAQ.
>>>>>> If that still doesn't work I can provide a code snippet that should
>>>>>> load
>>>>>> your model (post a small section of the problematic model so I can
>>>>>> test
>>>>>> it
>>>>>> out the code ).
>>>>>>
>>>>>> Cheers,
>>>>>> - James.
>>>>>>
>>>>>>
>>>>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>>>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>>>>> It is possible to find on this list a working code snippet showing
>>>>>>> how
>>>>>>> to
>>>>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a
>>>>>>> standalone
>>>>>>> app.
>>>>>>>
>>>>>>> My problem occurs when that Package has an imported package that has
>>>>>>> a
>>>>>>> "pathmap" URL.
>>>>>>>
>>>>>>> I think what I should do is map the pathmap URL to the actual URL,
>>>>>>> like
>>>>>>> this:
>>>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>>>>
>>>>>>> URI pathmap =
>>>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>>>>
>>>>>>> URI types = URI.createFileURI(new
>>>>>>> File(typesFilename).getAbsolutePath());
>>>>>>>
>>>>>>> uriMap.put(pathmap, types);
>>>>>>>
>>>>>>> But when I try to get the imported stuff, like this:
>>>>>>> EList<Package> importList = model.getImportedPackages();
>>>>>>>
>>>>>>> I get an exception:
>>>>>>> java.lang.ClassCastException:
>>>>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>>>>> org.eclipse.uml2.uml.Package
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>>>>
>>>>>>>
>>>>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It
>>>>>>> looks
>>>>>>> like it doesn't know that the imported package is UML.
>>>>>>>
>>>>>>> Any help on this? Thanks.
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>
>


Re: Continuing saga of the standalone app [message #477628 is a reply to message #477626] Tue, 22 July 2008 20:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

James,
My misunderstanding.
I see now that the pathmap to the external library points, not to the
library itself, but to a directory called "libraries" that contains the
actual library file.
Once again, thanks for this great help.
Jeff


"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g657k1$7c1$1@build.eclipse.org...
> Hi Jeff,
>
> That seems to work fine for me. I'm seeing BreedType: Breed and
> BreedSuperType: string.
>
> What are the problems you are seeing?
> Are you certain you are loading the new petsplus.uml and not the older
> pets.uml. You would see an exception in that case since there would be no
> generalizations of the DataType from the library.
>
> I could zip up my small test class to send you if you want.
>
> Cheers,
> - James.
>
>
> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
> news:g651sr$mg2$1@build.eclipse.org...
>> James,
>> This doesn't quite do what I hoped. Stuff in the external model that is
>> referenced "indirectly" doesn't get imported.
>>
>> Attached is a refinement of the importing model that uses a
>> generalization that references the external model.
>> The new sanity check is the following, which gets null for the supertype:
>> //
>> // Sanity check.
>> //
>> org.eclipse.uml2.uml.Package packageableElement =
>> (org.eclipse.uml2.uml.Package) model.getPackagedElement("pets");
>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>> packageableElement.getOwnedMember("Animal");
>> org.eclipse.uml2.uml.Property breed = animal.getAttribute("breed", null);
>> org.eclipse.uml2.uml.DataType breedType = (org.eclipse.uml2.uml.DataType)
>> breed.getType();
>> System.out.println("BreedType: " + breedType);
>> org.eclipse.uml2.uml.Generalization gen =
>> ((org.eclipse.uml2.uml.DataType) breedType).getGeneralizations().get(0);
>> org.eclipse.uml2.uml.Classifier general = gen.getGeneral();
>> System.out.println("BreedSuperType: " + general.getName());
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:g64nml$1ha$1@build.eclipse.org...
>>>I should mention (for others reading this thread) that the recommendation
>>>to
>>> "edit the nsURI with a text editor" would not be a general solution.
>>> It
>>> would work for this very specific example but not in general (in this
>>> case
>>> there was one DataType in the library). The migration guides on the
>>> wiki
>>> explain in more detail how to properly migrate to newer versions.
>>>
>>> Cheers,
>>> - James.
>>>
>>>
>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>> news:g62q94$8in$1@build.eclipse.org...
>>>> Hi Jeff,
>>>>
>>>>
>>>> The following code snippet will properly resolve the data type from the
>>>> library.
>>>> There was one little 'gotcha' that had me wondering what was going on.
>>>> Your XSDDataTypes.library.uml was not upgraded to the latest version.
>>>> You
>>>> have at the top of the file ...
>>>> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>>>>
>>>> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>>>>
>>>>
>>>> 1. Change the nsURI in your library by either re-saving it out or edit
>>>> with a text editor.
>>>> 2. Try the following code (pardon the hard-coded stuff):
>>>> 3. You should notice the type of "breed" is not a proxy.
>>>>
>>>>
>>>> Cheers,...
>>>> - James.
>>>>
>>>> protected static void registerPathmaps(URI umlResourcePluginURI) {
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>>>>
>>>> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>>>>
>>>>
>>>>
>>>> }
>>>>
>>>> protected static void registerExtensions() {
>>>>
>>>> Map<String, Object> extensionFactoryMap =
>>>> Resource.Factory.Registry.INSTANCE
>>>>
>>>> .getExtensionToFactoryMap();
>>>>
>>>>
>>>> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>>>>
>>>> UMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>>>>
>>>> Ecore2XMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>>>
>>>> UML22UMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> protected static void registerPackages(ResourceSet resourceSet) {
>>>>
>>>>
>>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>>>
>>>>
>>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>>>
>>>>
>>>> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>>>>
>>>> Ecore2XMLPackage.eINSTANCE);
>>>>
>>>>
>>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>>>
>>>> }
>>>>
>>>>
>>>> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
>>>> umlResourcePluginURI) {
>>>>
>>>>
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>
>>>> registerPathmaps(umlResourcePluginURI);
>>>>
>>>> registerPackages(resourceSet);
>>>>
>>>> registerExtensions();
>>>>
>>>>
>>>> // Map references to legacy (1.x) model elements to their new
>>>> locations.
>>>>
>>>> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>>>>
>>>> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>>>>
>>>>
>>>> // Load a resource in the resource set.
>>>>
>>>> try {
>>>>
>>>> resourceSet.getResource(resourceURI, true);
>>>>
>>>> } catch (Exception e) {
>>>>
>>>> System.out.println(e.getMessage());
>>>>
>>>> return null;
>>>>
>>>> }
>>>>
>>>>
>>>> EList<Resource> resources = resourceSet.getResources();
>>>>
>>>> EcoreUtil.resolveAll(resources.get(0));
>>>>
>>>>
>>>> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>>>>
>>>> .getContents(), UMLPackage.Literals.MODEL);
>>>>
>>>>
>>>>
>>>> //
>>>>
>>>> // Sanity check.
>>>>
>>>> //
>>>>
>>>> org.eclipse.uml2.uml.Package packageableElement =
>>>> (org.eclipse.uml2.uml.Package) model
>>>>
>>>> .getPackagedElement("pets");
>>>>
>>>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>>>> packageableElement
>>>>
>>>> .getOwnedMember("Animal");
>>>>
>>>> org.eclipse.uml2.uml.Property breed = animal
>>>>
>>>> .getAttribute("breed", null);
>>>>
>>>>
>>>> System.out.println("BreedType: " + breed.getType());
>>>>
>>>>
>>>> return model;
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> public static void main(String[] args) {
>>>>
>>>>
>>>> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>>>>
>>>> String umlPluginPath =
>>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>>>>
>>>> String umlResourcePath =
>>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>>>>
>>>>
>>>> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>>>>
>>>> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>>>>
>>>> + "!/");
>>>>
>>>> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
>>>> umlResourcePluginURI);
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
>>>> news:g5rbqt$kmk$1@build.eclipse.org...
>>>>> Thanks, James. That stopped the exception. But somehow I thought that
>>>>> the
>>>>> external package would magically be imported, and all of the
>>>>> references
>>>>> into it would be resolved.
>>>>>
>>>>> Which is not what is happening.
>>>>>
>>>>> Here is the relevant code, and attached are the problematic models.
>>>>>
>>>>> private Model getModel(String filename, String typesFilename) {
>>>>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>>
>>>>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>>>>> UMLResource.Factory.INSTANCE);
>>>>>
>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>> URI pathmap =
>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>>>>> URI types = URI.createFileURI(new
>>>>> File(typesFilename).getAbsolutePath());
>>>>> uriMap.put(pathmap, types);
>>>>>
>>>>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>>>>> Model model = null;
>>>>> try {
>>>>> Resource resource = RESOURCE_SET.getResource(uri, true);
>>>>> EcoreUtil.resolveAll(resource);
>>>>>
>>>>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>>>>> UMLPackage.Literals.MODEL);
>>>>> } catch (WrappedException we) {
>>>>> System.err.println(we.getMessage());
>>>>> }
>>>>> return model;
>>>>> }
>>>>>
>>>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>>>> news:g5q81a$42a$1@build.eclipse.org...
>>>>>> Hi Jeff,
>>>>>>
>>>>>> It looks like you might be missing a trailing slash at the end of
>>>>>> your
>>>>>> pathmap string. This is mentioned in the FAQ
>>>>>> http://wiki.eclipse.org/MDT-UML2-FAQ.
>>>>>> If that still doesn't work I can provide a code snippet that should
>>>>>> load
>>>>>> your model (post a small section of the problematic model so I can
>>>>>> test
>>>>>> it
>>>>>> out the code ).
>>>>>>
>>>>>> Cheers,
>>>>>> - James.
>>>>>>
>>>>>>
>>>>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>>>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>>>>> It is possible to find on this list a working code snippet showing
>>>>>>> how
>>>>>>> to
>>>>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a
>>>>>>> standalone
>>>>>>> app.
>>>>>>>
>>>>>>> My problem occurs when that Package has an imported package that has
>>>>>>> a
>>>>>>> "pathmap" URL.
>>>>>>>
>>>>>>> I think what I should do is map the pathmap URL to the actual URL,
>>>>>>> like
>>>>>>> this:
>>>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>>>>
>>>>>>> URI pathmap =
>>>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>>>>
>>>>>>> URI types = URI.createFileURI(new
>>>>>>> File(typesFilename).getAbsolutePath());
>>>>>>>
>>>>>>> uriMap.put(pathmap, types);
>>>>>>>
>>>>>>> But when I try to get the imported stuff, like this:
>>>>>>> EList<Package> importList = model.getImportedPackages();
>>>>>>>
>>>>>>> I get an exception:
>>>>>>> java.lang.ClassCastException:
>>>>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>>>>> org.eclipse.uml2.uml.Package
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>>>>
>>>>>>>
>>>>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It
>>>>>>> looks
>>>>>>> like it doesn't know that the imported package is UML.
>>>>>>>
>>>>>>> Any help on this? Thanks.
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>
>
Re: Continuing saga of the standalone app [message #477701 is a reply to message #477618] Wed, 03 September 2008 02:06 Go to previous messageGo to next message
Victor Hugo is currently offline Victor HugoFriend
Messages: 20
Registered: July 2009
Junior Member
Hi Friends,

i have the same problem and try to solve using yours solutions by I obtain
this exception when i try to load model:

java.lang.ClassCastException:
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
org.eclipse.uml2.uml.Profile
at
org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.ge tAppliedProfile(ProfileApplicationImpl.java:182)
at
org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.eG et(ProfileApplicationImpl.java:410)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:100)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.scanNext(DerivedEObjectEList.java:66)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:109)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.next(DerivedEObjectEList.java:158)
at
org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.hasNext(EContentsEList.java:443)
at
org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.next(EContentsEList.java:561)
at
org.eclipse.emf.ecore.util.EcoreUtil.resolveCrossReferences( EcoreUtil.java:307)
at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.ja va:287)
at
br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:143)
at
br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:126)
at
br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:203)
at
br.ufrj.nce.crossmda.xmi.util.emf.EMF_XMIRepositoryImpl.load Model(EMF_XMIRepositoryImpl.java:227)
at br.ufrj.nce.crossmda.test.emf.TesteModelo.main(TesteModelo.j ava:248)



what should i do to resolve profiles?

thanks
Re: Continuing saga of the standalone app [message #477706 is a reply to message #477701] Thu, 04 September 2008 17:14 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Victor,

I don't think there is enough information here to figure out what the
problem is. Can you post your model and profile, or at least sections of
it, such that the exception can be reproduced ?

- James.


"Victor Hugo" <victorhcf@gmail.com> wrote in message
news:d05d6b4e49b96e4e3e7e108487524686$1@www.eclipse.org...
> Hi Friends,
>
> i have the same problem and try to solve using yours solutions by I obtain
> this exception when i try to load model:
>
> java.lang.ClassCastException:
> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
> org.eclipse.uml2.uml.Profile
> at
> org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.ge tAppliedProfile(ProfileApplicationImpl.java:182)
> at
> org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.eG et(ProfileApplicationImpl.java:410)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:100)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.scanNext(DerivedEObjectEList.java:66)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:109)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.next(DerivedEObjectEList.java:158)
> at
> org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.hasNext(EContentsEList.java:443)
> at
> org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.next(EContentsEList.java:561)
> at
> org.eclipse.emf.ecore.util.EcoreUtil.resolveCrossReferences( EcoreUtil.java:307)
> at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.ja va:287)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:143)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:126)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:203)
> at
> br.ufrj.nce.crossmda.xmi.util.emf.EMF_XMIRepositoryImpl.load Model(EMF_XMIRepositoryImpl.java:227)
> at br.ufrj.nce.crossmda.test.emf.TesteModelo.main(TesteModelo.j ava:248)
>
>
>
> what should i do to resolve profiles?
>
> thanks
>
Re: Continuing saga of the standalone app [message #477715 is a reply to message #477701] Wed, 10 September 2008 17:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

Victor,

This happened to me when I tried to use an older profile.

My solution was to open the profile with the UML Model Editor, select the
<Profile> element, then (in the top menu) click UML Editor | Profile |
Define.

The result is an up-to-date profile that can be loaded as
org.eclipse.uml2.uml.Profile instead of
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl .

It would be nice if this could be done programatically, though.

Jeff


"Victor Hugo" <victorhcf@gmail.com> wrote in message
news:d05d6b4e49b96e4e3e7e108487524686$1@www.eclipse.org...
> Hi Friends,
>
> i have the same problem and try to solve using yours solutions by I obtain
> this exception when i try to load model:
>
> java.lang.ClassCastException:
> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
> org.eclipse.uml2.uml.Profile
> at
> org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.ge tAppliedProfile(ProfileApplicationImpl.java:182)
> at
> org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.eG et(ProfileApplicationImpl.java:410)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:100)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.scanNext(DerivedEObjectEList.java:66)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:109)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.next(DerivedEObjectEList.java:158)
> at
> org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.hasNext(EContentsEList.java:443)
> at
> org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.next(EContentsEList.java:561)
> at
> org.eclipse.emf.ecore.util.EcoreUtil.resolveCrossReferences( EcoreUtil.java:307)
> at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.ja va:287)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:143)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:126)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:203)
> at
> br.ufrj.nce.crossmda.xmi.util.emf.EMF_XMIRepositoryImpl.load Model(EMF_XMIRepositoryImpl.java:227)
> at br.ufrj.nce.crossmda.test.emf.TesteModelo.main(TesteModelo.j ava:248)
>
>
>
> what should i do to resolve profiles?
>
> thanks
>
Re: Continuing saga of the standalone app [message #477737 is a reply to message #477715] Fri, 19 September 2008 06:30 Go to previous messageGo to next message
Victor Hugo is currently offline Victor HugoFriend
Messages: 20
Registered: July 2009
Junior Member
Hi Friends,

thanks for yours answers! but... my problem continue...

i tried to execute the Jeff's answer but without success!
and as James request...
My full application can be found in this link:
the profile in this:
http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/Profile_for_crossmda_profile-1.11.profile
the data model (bussiness):
http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/model_teste.uml
ths aspects model:
http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/model_aspects.uml
my java class thats load the model in this:
http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/sr c/test/Test.java

sorry about permission of directory to navigate into then, but i cannot
control this in server.


my problem is because i cannot load stereotypes that models has, i have to
apply profile before load model, how i can do this?


to simplify to yours here is the java code that i'm using to load models:

package test;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.EPackage.Registry;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.mapping.ecore2xml.Ecore2XMLPackage;
import org.eclipse.emf.mapping.ecore2xml.util.Ecore2XMLResource;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UML22UMLExtendedMetaData;
import org.eclipse.uml2.uml.resource.UML22UMLResource;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.eclipse.uml2.uml.resource.UML22UMLResource.Factory;

public class Test {

private ResourceSet resourceSet = null;
private Resource model = null;
private UMLResource uml2Resource = null;
private Profile profile = null;

@SuppressWarnings("unchecked")
protected void registerPathmaps(URI umlResourcePluginURI) {

String pathResource =
" /home/ceara/dev/mestrado/workspace/TesteLoadModels/lib/org.e clipse.uml2.uml.resources_2.2.0.v200805131030.jar ";
URI resourcePluginURI = URI.createURI("jar:file:/" + pathResource +
"!/");

resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Map uriMap = resourceSet.getURIConverter().getURIMap();

uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
resourcePluginURI.appendSegment("libraries").appendSegment( ""));

uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
resourcePluginURI.appendSegment("metamodels").appendSegment( ""));

uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
resourcePluginURI.appendSegment("profiles").appendSegment( ""));

}

protected void registerExtensions() {

Map<String, Object> extensionFactoryMap =
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( );

extensionFactoryMap.put(UMLResource.FILE_EXTENSION,UMLResour ce.Factory.INSTANCE);

extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,Eco re2XMLResource.Factory.INSTANCE);

extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,UML2 2UMLResource.Factory.INSTANCE);

}

protected void registerPackages(ResourceSet resourceSet) {

Registry packageRegistry = resourceSet.getPackageRegistry();
packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);

packageRegistry.put(Ecore2XMLPackage.eNS_URI,Ecore2XMLPackag e.eINSTANCE);

packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);

}

public Model getModel(URI resourceURI) {

resourceSet = new ResourceSetImpl();

registerPathmaps(null);
registerPackages(resourceSet);
registerExtensions();

Map<URI, URI> uriMap = UML22UMLExtendedMetaData.getURIMap();

resourceSet.getURIConverter().getURIMap().putAll(uriMap);

try {
model = resourceSet.getResource(resourceURI, true);
model.save(null);
EcoreUtil.resolveAll(model);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


if ( !(model instanceof UMLResource)) {
try {
throw new Exception("Modelo carregado esta inv&#65533;lido!");
} catch (Exception e) {
e.printStackTrace();
System.out.println( "OoOps..!" );
}
}

this.uml2Resource = (UMLResource) model;

return null;

}

public static void main(String[] args) {

String fileToOpen =
" /home/ceara/dev/mestrado/workspace/TesteLoadModels/models/mo del_teste.uml ";

Test t = new Test();
t.getModel(URI.createFileURI(fileToOpen));

}

public void displayAllElements() {
//Model o =
(Model)xmiutils.getUML2Resource().getContents().iterator().n ext();
Model o = (Model)uml2Resource.getContents().iterator().next();

EList<NamedElement> mbs = o.getMembers();
for( NamedElement mb : mbs ){
System.out.println( " NAMEDMEMBERS: " + mb.getClass() + mb.getName() );
}

EList<Profile> profiles = o.getAllAppliedProfiles();
for( Profile p : profiles ){
System.out.println( " \n\n\n PROFILE: " + p.getName() );
EList<Stereotype> stes = p.getAppliedStereotypes();
for(Stereotype ste : stes ){
System.out.println( "\n\n PROFILE STEREOTYPES: " + ste.getName() );
}
}

for(NamedElement ne : o.getOwnedMembers()){
System.out.println( ne.getClass() + " - " + ne.getName() );

if( ne instanceof org.eclipse.uml2.uml.Package ){
System.out.println("\n\nINSTANCE OF PACKAGE:");

EList<Stereotype> ste = ne.getAppliedStereotypes();
for( Stereotype s : ste ){
System.out.println("\n\n\nINSTANCE OF STEREOTYPES: " + s.getName());
}

}

}

}

private Profile reloadProfile() {
ResourceSet resourceSet = new ResourceSetImpl();

Resource inputResource = resourceSet.createResource(URI
.createFileURI("MyProfile.profile.uml"));
try {
inputResource.load(null);
} catch (IOException exception) {
exception.printStackTrace();
}

Iterator iterator = inputResource.getAllContents();
while (iterator.hasNext()) {
Object currentObject = iterator.next();
if (currentObject instanceof Profile) {
return (Profile) currentObject;
}
}
return null;
}




}


best regards!
=)
Re: Continuing saga of the standalone app [message #477744 is a reply to message #477737] Tue, 23 September 2008 19:25 Go to previous message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

Victor,
The link to the profile does not work.

"Victor Hugo" <victorhcf@gmail.com> wrote in message
news:9eac12420be6134540295db21a1db739$1@www.eclipse.org...
> Hi Friends,
>
> thanks for yours answers! but... my problem continue...
>
> i tried to execute the Jeff's answer but without success!
> and as James request...
> My full application can be found in this link:
> the profile in this:
> http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/Profile_for_crossmda_profile-1.11.profile
> the data model (bussiness):
> http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/model_teste.uml
> ths aspects model:
> http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/model_aspects.uml
> my java class thats load the model in this:
> http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/sr c/test/Test.java
>
> sorry about permission of directory to navigate into then, but i cannot
> control this in server.
>
>
> my problem is because i cannot load stereotypes that models has, i have to
> apply profile before load model, how i can do this?
>
>
> to simplify to yours here is the java code that i'm using to load models:
>
> package test;
>
> import java.io.IOException;
> import java.util.Iterator;
> import java.util.Map;
>
> import org.eclipse.emf.common.util.EList;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.EcorePackage;
> import org.eclipse.emf.ecore.EPackage.Registry;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.emf.mapping.ecore2xml.Ecore2XMLPackage;
> import org.eclipse.emf.mapping.ecore2xml.util.Ecore2XMLResource;
> import org.eclipse.uml2.uml.Model;
> import org.eclipse.uml2.uml.NamedElement;
> import org.eclipse.uml2.uml.Profile;
> import org.eclipse.uml2.uml.Stereotype;
> import org.eclipse.uml2.uml.UMLFactory;
> import org.eclipse.uml2.uml.UMLPackage;
> import org.eclipse.uml2.uml.resource.UML22UMLExtendedMetaData;
> import org.eclipse.uml2.uml.resource.UML22UMLResource;
> import org.eclipse.uml2.uml.resource.UMLResource;
> import org.eclipse.uml2.uml.resource.UML22UMLResource.Factory;
>
> public class Test {
>
> private ResourceSet resourceSet = null;
> private Resource model = null;
> private UMLResource uml2Resource = null;
> private Profile profile = null;
>
> @SuppressWarnings("unchecked")
> protected void registerPathmaps(URI umlResourcePluginURI) {
>
> String pathResource =
> " /home/ceara/dev/mestrado/workspace/TesteLoadModels/lib/org.e clipse.uml2.uml.resources_2.2.0.v200805131030.jar ";
> URI resourcePluginURI = URI.createURI("jar:file:/" + pathResource + "!/");
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> Map uriMap = resourceSet.getURIConverter().getURIMap();
>
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
> resourcePluginURI.appendSegment("libraries").appendSegment( ""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
> resourcePluginURI.appendSegment("metamodels").appendSegment( ""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
> resourcePluginURI.appendSegment("profiles").appendSegment( ""));
>
> }
>
> protected void registerExtensions() {
>
> Map<String, Object> extensionFactoryMap =
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( );
>
> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,UMLResour ce.Factory.INSTANCE);
>
> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,Eco re2XMLResource.Factory.INSTANCE);
>
> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,UML2 2UMLResource.Factory.INSTANCE);
>
> }
>
> protected void registerPackages(ResourceSet resourceSet) {
>
> Registry packageRegistry = resourceSet.getPackageRegistry();
> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>
> packageRegistry.put(Ecore2XMLPackage.eNS_URI,Ecore2XMLPackag e.eINSTANCE);
>
> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>
> }
>
> public Model getModel(URI resourceURI) {
>
> resourceSet = new ResourceSetImpl();
>
> registerPathmaps(null);
> registerPackages(resourceSet);
> registerExtensions();
>
> Map<URI, URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>
> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>
> try {
> model = resourceSet.getResource(resourceURI, true);
> model.save(null);
> EcoreUtil.resolveAll(model);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> if ( !(model instanceof UMLResource)) {
> try {
> throw new Exception("Modelo carregado esta inv&#65533;lido!");
> } catch (Exception e) {
> e.printStackTrace();
> System.out.println( "OoOps..!" );
> }
> }
>
> this.uml2Resource = (UMLResource) model;
>
> return null;
>
> }
>
> public static void main(String[] args) {
>
> String fileToOpen =
> " /home/ceara/dev/mestrado/workspace/TesteLoadModels/models/mo del_teste.uml ";
>
> Test t = new Test();
> t.getModel(URI.createFileURI(fileToOpen));
>
> }
>
> public void displayAllElements() {
> //Model o =
> (Model)xmiutils.getUML2Resource().getContents().iterator().n ext();
> Model o = (Model)uml2Resource.getContents().iterator().next();
>
> EList<NamedElement> mbs = o.getMembers();
> for( NamedElement mb : mbs ){
> System.out.println( " NAMEDMEMBERS: " + mb.getClass() + mb.getName() );
> }
>
> EList<Profile> profiles = o.getAllAppliedProfiles();
> for( Profile p : profiles ){
> System.out.println( " \n\n\n PROFILE: " + p.getName() );
> EList<Stereotype> stes = p.getAppliedStereotypes();
> for(Stereotype ste : stes ){
> System.out.println( "\n\n PROFILE STEREOTYPES: " + ste.getName() );
> }
> }
>
> for(NamedElement ne : o.getOwnedMembers()){
> System.out.println( ne.getClass() + " - " + ne.getName() );
>
> if( ne instanceof org.eclipse.uml2.uml.Package ){
> System.out.println("\n\nINSTANCE OF PACKAGE:");
>
> EList<Stereotype> ste = ne.getAppliedStereotypes();
> for( Stereotype s : ste ){
> System.out.println("\n\n\nINSTANCE OF STEREOTYPES: " + s.getName());
> }
>
> }
>
> }
>
> }
>
> private Profile reloadProfile() {
> ResourceSet resourceSet = new ResourceSetImpl();
>
> Resource inputResource = resourceSet.createResource(URI
> .createFileURI("MyProfile.profile.uml"));
> try {
> inputResource.load(null);
> } catch (IOException exception) {
> exception.printStackTrace();
> }
>
> Iterator iterator = inputResource.getAllContents();
> while (iterator.hasNext()) {
> Object currentObject = iterator.next();
> if (currentObject instanceof Profile) {
> return (Profile) currentObject;
> }
> }
> return null;
> }
>
>
>
>
> }
>
>
> best regards!
> =)
>
>
Re: Continuing saga of the standalone app [message #626809 is a reply to message #477617] Fri, 18 July 2008 14:06 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Jeff,

It looks like you might be missing a trailing slash at the end of your
pathmap string. This is mentioned in the FAQ
http://wiki.eclipse.org/MDT-UML2-FAQ
If that still doesn't work I can provide a code snippet that should load
your model (post a small section of the problematic model so I can test it
out the code ).

Cheers,
- James.


"Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
news:g5o96q$ph2$1@build.eclipse.org...
> It is possible to find on this list a working code snippet showing how to
> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone app.
>
> My problem occurs when that Package has an imported package that has a
> "pathmap" URL.
>
> I think what I should do is map the pathmap URL to the actual URL, like
> this:
> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>
> URI pathmap =
> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>
> URI types = URI.createFileURI(new File(typesFilename).getAbsolutePath());
>
> uriMap.put(pathmap, types);
>
> But when I try to get the imported stuff, like this:
> EList<Package> importList = model.getImportedPackages();
>
> I get an exception:
> java.lang.ClassCastException:
> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
> org.eclipse.uml2.uml.Package
> at
> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>
> at
> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>
> at
> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>
>
> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
> like it doesn't know that the imported package is UML.
>
> Any help on this? Thanks.
>
Re: Continuing saga of the standalone app [message #626812 is a reply to message #477618] Sat, 19 July 2008 00:17 Go to previous message
Eclipse UserFriend
Originally posted by: jeff.lansing.sbcglobal.net

Thanks, James. That stopped the exception. But somehow I thought that the
external package would magically be imported, and all of the references into
it would be resolved.

Which is not what is happening.

Here is the relevant code, and attached are the problematic models.

private Model getModel(String filename, String typesFilename) {
RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);

Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
URI pathmap =
URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
URI types = URI.createFileURI(new File(typesFilename).getAbsolutePath());
uriMap.put(pathmap, types);

URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
Model model = null;
try {
Resource resource = RESOURCE_SET.getResource(uri, true);
EcoreUtil.resolveAll(resource);

model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
UMLPackage.Literals.MODEL);
} catch (WrappedException we) {
System.err.println(we.getMessage());
}
return model;
}

"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g5q81a$42a$1@build.eclipse.org...
> Hi Jeff,
>
> It looks like you might be missing a trailing slash at the end of your
> pathmap string. This is mentioned in the FAQ
> http://wiki.eclipse.org/MDT-UML2-FAQ
> If that still doesn't work I can provide a code snippet that should load
> your model (post a small section of the problematic model so I can test it
> out the code ).
>
> Cheers,
> - James.
>
>
> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
> news:g5o96q$ph2$1@build.eclipse.org...
>> It is possible to find on this list a working code snippet showing how to
>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>> app.
>>
>> My problem occurs when that Package has an imported package that has a
>> "pathmap" URL.
>>
>> I think what I should do is map the pathmap URL to the actual URL, like
>> this:
>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>
>> URI pathmap =
>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>
>> URI types = URI.createFileURI(new File(typesFilename).getAbsolutePath());
>>
>> uriMap.put(pathmap, types);
>>
>> But when I try to get the imported stuff, like this:
>> EList<Package> importList = model.getImportedPackages();
>>
>> I get an exception:
>> java.lang.ClassCastException:
>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>> org.eclipse.uml2.uml.Package
>> at
>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>
>> at
>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>
>> at
>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>
>>
>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
>> like it doesn't know that the imported package is UML.
>>
>> Any help on this? Thanks.
>>
>
>



Re: Continuing saga of the standalone app [message #626813 is a reply to message #477621] Mon, 21 July 2008 20:06 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Jeff,


The following code snippet will properly resolve the data type from the
library.
There was one little 'gotcha' that had me wondering what was going on.
Your XSDDataTypes.library.uml was not upgraded to the latest version. You
have at the top of the file ...
xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be

xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">


1. Change the nsURI in your library by either re-saving it out or edit with
a text editor.
2. Try the following code (pardon the hard-coded stuff):
3. You should notice the type of "breed" is not a proxy.


Cheers,...
- James.

protected static void registerPathmaps(URI umlResourcePluginURI) {


URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),

umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));


URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),

umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));


URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),

umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));


URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),

URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));



}

protected static void registerExtensions() {

Map<String, Object> extensionFactoryMap = Resource.Factory.Registry.INSTANCE

..getExtensionToFactoryMap();


extensionFactoryMap.put(UMLResource.FILE_EXTENSION,

UMLResource.Factory.INSTANCE);


extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,

Ecore2XMLResource.Factory.INSTANCE);


extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,

UML22UMLResource.Factory.INSTANCE);


}



protected static void registerPackages(ResourceSet resourceSet) {


Registry packageRegistry = resourceSet.getPackageRegistry();


packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);


packageRegistry.put(Ecore2XMLPackage.eNS_URI,

Ecore2XMLPackage.eINSTANCE);


packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);

}


public static Model getModel(URI resourceURI, URI umlPluginURI, URI
umlResourcePluginURI) {


ResourceSet resourceSet = new ResourceSetImpl();

registerPathmaps(umlResourcePluginURI);

registerPackages(resourceSet);

registerExtensions();


// Map references to legacy (1.x) model elements to their new locations.

Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();

resourceSet.getURIConverter().getURIMap().putAll(uriMap);


// Load a resource in the resource set.

try {

resourceSet.getResource(resourceURI, true);

} catch (Exception e) {

System.out.println(e.getMessage());

return null;

}


EList<Resource> resources = resourceSet.getResources();

EcoreUtil.resolveAll(resources.get(0));


Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)

..getContents(), UMLPackage.Literals.MODEL);



//

// Sanity check.

//

org.eclipse.uml2.uml.Package packageableElement =
(org.eclipse.uml2.uml.Package) model

..getPackagedElement("pets");

org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
packageableElement

..getOwnedMember("Animal");

org.eclipse.uml2.uml.Property breed = animal

..getAttribute("breed", null);


System.out.println("BreedType: " + breed.getType());


return model;


}



public static void main(String[] args) {


String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";

String umlPluginPath =
" C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";

String umlResourcePath =
" C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";


URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");

URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath

+ "!/");

getModel(URI.createFileURI(fileToOpen), umlPluginURI, umlResourcePluginURI);


}



"Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
news:g5rbqt$kmk$1@build.eclipse.org...
> Thanks, James. That stopped the exception. But somehow I thought that the
> external package would magically be imported, and all of the references
> into it would be resolved.
>
> Which is not what is happening.
>
> Here is the relevant code, and attached are the problematic models.
>
> private Model getModel(String filename, String typesFilename) {
> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
> URI pathmap =
> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
> URI types = URI.createFileURI(new File(typesFilename).getAbsolutePath());
> uriMap.put(pathmap, types);
>
> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
> Model model = null;
> try {
> Resource resource = RESOURCE_SET.getResource(uri, true);
> EcoreUtil.resolveAll(resource);
>
> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
> UMLPackage.Literals.MODEL);
> } catch (WrappedException we) {
> System.err.println(we.getMessage());
> }
> return model;
> }
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:g5q81a$42a$1@build.eclipse.org...
>> Hi Jeff,
>>
>> It looks like you might be missing a trailing slash at the end of your
>> pathmap string. This is mentioned in the FAQ
>> http://wiki.eclipse.org/MDT-UML2-FAQ
>> If that still doesn't work I can provide a code snippet that should load
>> your model (post a small section of the problematic model so I can test
>> it
>> out the code ).
>>
>> Cheers,
>> - James.
>>
>>
>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>> news:g5o96q$ph2$1@build.eclipse.org...
>>> It is possible to find on this list a working code snippet showing how
>>> to
>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>>> app.
>>>
>>> My problem occurs when that Package has an imported package that has a
>>> "pathmap" URL.
>>>
>>> I think what I should do is map the pathmap URL to the actual URL, like
>>> this:
>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>
>>> URI pathmap =
>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>
>>> URI types = URI.createFileURI(new
>>> File(typesFilename).getAbsolutePath());
>>>
>>> uriMap.put(pathmap, types);
>>>
>>> But when I try to get the imported stuff, like this:
>>> EList<Package> importList = model.getImportedPackages();
>>>
>>> I get an exception:
>>> java.lang.ClassCastException:
>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>> org.eclipse.uml2.uml.Package
>>> at
>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>
>>> at
>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>
>>> at
>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>
>>>
>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
>>> like it doesn't know that the imported package is UML.
>>>
>>> Any help on this? Thanks.
>>>
>>
>>
>
>
>
Re: Continuing saga of the standalone app [message #626814 is a reply to message #477622] Tue, 22 July 2008 13:09 Go to previous message
Eclipse UserFriend
Originally posted by: jeff.lansing.sbcglobal.net

Thanks, James. Incredibly helpful.

Since it's a standalone app, I added:
URI umlResourcePluginURI = getJarURI("uml2.uml.resources");
....
protected static URI getJarURI(String key) {
for(String jarLoc : System.getProperty("java.class.path").split(";")) {
if(jarLoc.contains(key)) {
return URI.createURI("jar:file:/" + jarLoc.replace('\\', '/') + "!/");
}
}
return null;
}

"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g62q94$8in$1@build.eclipse.org...
> Hi Jeff,
>
>
> The following code snippet will properly resolve the data type from the
> library.
> There was one little 'gotcha' that had me wondering what was going on.
> Your XSDDataTypes.library.uml was not upgraded to the latest version. You
> have at the top of the file ...
> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>
> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>
>
> 1. Change the nsURI in your library by either re-saving it out or edit
> with a text editor.
> 2. Try the following code (pardon the hard-coded stuff):
> 3. You should notice the type of "breed" is not a proxy.
>
>
> Cheers,...
> - James.
>
> protected static void registerPathmaps(URI umlResourcePluginURI) {
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>
> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>
> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>
> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>
> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>
>
>
> }
>
> protected static void registerExtensions() {
>
> Map<String, Object> extensionFactoryMap =
> Resource.Factory.Registry.INSTANCE
>
> .getExtensionToFactoryMap();
>
>
> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>
> UMLResource.Factory.INSTANCE);
>
>
> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>
> Ecore2XMLResource.Factory.INSTANCE);
>
>
> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>
> UML22UMLResource.Factory.INSTANCE);
>
>
> }
>
>
>
> protected static void registerPackages(ResourceSet resourceSet) {
>
>
> Registry packageRegistry = resourceSet.getPackageRegistry();
>
>
> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>
>
> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>
> Ecore2XMLPackage.eINSTANCE);
>
>
> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>
> }
>
>
> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
> umlResourcePluginURI) {
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> registerPathmaps(umlResourcePluginURI);
>
> registerPackages(resourceSet);
>
> registerExtensions();
>
>
> // Map references to legacy (1.x) model elements to their new locations.
>
> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>
> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>
>
> // Load a resource in the resource set.
>
> try {
>
> resourceSet.getResource(resourceURI, true);
>
> } catch (Exception e) {
>
> System.out.println(e.getMessage());
>
> return null;
>
> }
>
>
> EList<Resource> resources = resourceSet.getResources();
>
> EcoreUtil.resolveAll(resources.get(0));
>
>
> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>
> .getContents(), UMLPackage.Literals.MODEL);
>
>
>
> //
>
> // Sanity check.
>
> //
>
> org.eclipse.uml2.uml.Package packageableElement =
> (org.eclipse.uml2.uml.Package) model
>
> .getPackagedElement("pets");
>
> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
> packageableElement
>
> .getOwnedMember("Animal");
>
> org.eclipse.uml2.uml.Property breed = animal
>
> .getAttribute("breed", null);
>
>
> System.out.println("BreedType: " + breed.getType());
>
>
> return model;
>
>
> }
>
>
>
> public static void main(String[] args) {
>
>
> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>
> String umlPluginPath =
> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>
> String umlResourcePath =
> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>
>
> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>
> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>
> + "!/");
>
> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
> umlResourcePluginURI);
>
>
> }
>
>
>
> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
> news:g5rbqt$kmk$1@build.eclipse.org...
>> Thanks, James. That stopped the exception. But somehow I thought that the
>> external package would magically be imported, and all of the references
>> into it would be resolved.
>>
>> Which is not what is happening.
>>
>> Here is the relevant code, and attached are the problematic models.
>>
>> private Model getModel(String filename, String typesFilename) {
>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>> UMLPackage.eINSTANCE);
>>
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>> UMLResource.Factory.INSTANCE);
>>
>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>> URI pathmap =
>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>> URI types = URI.createFileURI(new
>> File(typesFilename).getAbsolutePath());
>> uriMap.put(pathmap, types);
>>
>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>> Model model = null;
>> try {
>> Resource resource = RESOURCE_SET.getResource(uri, true);
>> EcoreUtil.resolveAll(resource);
>>
>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>> UMLPackage.Literals.MODEL);
>> } catch (WrappedException we) {
>> System.err.println(we.getMessage());
>> }
>> return model;
>> }
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:g5q81a$42a$1@build.eclipse.org...
>>> Hi Jeff,
>>>
>>> It looks like you might be missing a trailing slash at the end of your
>>> pathmap string. This is mentioned in the FAQ
>>> http://wiki.eclipse.org/MDT-UML2-FAQ
>>> If that still doesn't work I can provide a code snippet that should load
>>> your model (post a small section of the problematic model so I can test
>>> it
>>> out the code ).
>>>
>>> Cheers,
>>> - James.
>>>
>>>
>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>> It is possible to find on this list a working code snippet showing how
>>>> to
>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>>>> app.
>>>>
>>>> My problem occurs when that Package has an imported package that has a
>>>> "pathmap" URL.
>>>>
>>>> I think what I should do is map the pathmap URL to the actual URL, like
>>>> this:
>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>
>>>> URI pathmap =
>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>
>>>> URI types = URI.createFileURI(new
>>>> File(typesFilename).getAbsolutePath());
>>>>
>>>> uriMap.put(pathmap, types);
>>>>
>>>> But when I try to get the imported stuff, like this:
>>>> EList<Package> importList = model.getImportedPackages();
>>>>
>>>> I get an exception:
>>>> java.lang.ClassCastException:
>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>> org.eclipse.uml2.uml.Package
>>>> at
>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>
>>>> at
>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>
>>>> at
>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>
>>>>
>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
>>>> like it doesn't know that the imported package is UML.
>>>>
>>>> Any help on this? Thanks.
>>>>
>>>
>>>
>>
>>
>>
>
>
Re: Continuing saga of the standalone app [message #626815 is a reply to message #477622] Tue, 22 July 2008 13:35 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
I should mention (for others reading this thread) that the recommendation to
"edit the nsURI with a text editor" would not be a general solution. It
would work for this very specific example but not in general (in this case
there was one DataType in the library). The migration guides on the wiki
explain in more detail how to properly migrate to newer versions.

Cheers,
- James.


"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g62q94$8in$1@build.eclipse.org...
> Hi Jeff,
>
>
> The following code snippet will properly resolve the data type from the
> library.
> There was one little 'gotcha' that had me wondering what was going on.
> Your XSDDataTypes.library.uml was not upgraded to the latest version. You
> have at the top of the file ...
> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>
> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>
>
> 1. Change the nsURI in your library by either re-saving it out or edit
> with a text editor.
> 2. Try the following code (pardon the hard-coded stuff):
> 3. You should notice the type of "breed" is not a proxy.
>
>
> Cheers,...
> - James.
>
> protected static void registerPathmaps(URI umlResourcePluginURI) {
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>
> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>
> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>
> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>
>
> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>
> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>
>
>
> }
>
> protected static void registerExtensions() {
>
> Map<String, Object> extensionFactoryMap =
> Resource.Factory.Registry.INSTANCE
>
> .getExtensionToFactoryMap();
>
>
> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>
> UMLResource.Factory.INSTANCE);
>
>
> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>
> Ecore2XMLResource.Factory.INSTANCE);
>
>
> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>
> UML22UMLResource.Factory.INSTANCE);
>
>
> }
>
>
>
> protected static void registerPackages(ResourceSet resourceSet) {
>
>
> Registry packageRegistry = resourceSet.getPackageRegistry();
>
>
> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>
>
> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>
> Ecore2XMLPackage.eINSTANCE);
>
>
> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>
> }
>
>
> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
> umlResourcePluginURI) {
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> registerPathmaps(umlResourcePluginURI);
>
> registerPackages(resourceSet);
>
> registerExtensions();
>
>
> // Map references to legacy (1.x) model elements to their new locations.
>
> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>
> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>
>
> // Load a resource in the resource set.
>
> try {
>
> resourceSet.getResource(resourceURI, true);
>
> } catch (Exception e) {
>
> System.out.println(e.getMessage());
>
> return null;
>
> }
>
>
> EList<Resource> resources = resourceSet.getResources();
>
> EcoreUtil.resolveAll(resources.get(0));
>
>
> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>
> .getContents(), UMLPackage.Literals.MODEL);
>
>
>
> //
>
> // Sanity check.
>
> //
>
> org.eclipse.uml2.uml.Package packageableElement =
> (org.eclipse.uml2.uml.Package) model
>
> .getPackagedElement("pets");
>
> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
> packageableElement
>
> .getOwnedMember("Animal");
>
> org.eclipse.uml2.uml.Property breed = animal
>
> .getAttribute("breed", null);
>
>
> System.out.println("BreedType: " + breed.getType());
>
>
> return model;
>
>
> }
>
>
>
> public static void main(String[] args) {
>
>
> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>
> String umlPluginPath =
> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>
> String umlResourcePath =
> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>
>
> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>
> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>
> + "!/");
>
> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
> umlResourcePluginURI);
>
>
> }
>
>
>
> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
> news:g5rbqt$kmk$1@build.eclipse.org...
>> Thanks, James. That stopped the exception. But somehow I thought that the
>> external package would magically be imported, and all of the references
>> into it would be resolved.
>>
>> Which is not what is happening.
>>
>> Here is the relevant code, and attached are the problematic models.
>>
>> private Model getModel(String filename, String typesFilename) {
>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>> UMLPackage.eINSTANCE);
>>
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>> UMLResource.Factory.INSTANCE);
>>
>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>> URI pathmap =
>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>> URI types = URI.createFileURI(new
>> File(typesFilename).getAbsolutePath());
>> uriMap.put(pathmap, types);
>>
>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>> Model model = null;
>> try {
>> Resource resource = RESOURCE_SET.getResource(uri, true);
>> EcoreUtil.resolveAll(resource);
>>
>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>> UMLPackage.Literals.MODEL);
>> } catch (WrappedException we) {
>> System.err.println(we.getMessage());
>> }
>> return model;
>> }
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:g5q81a$42a$1@build.eclipse.org...
>>> Hi Jeff,
>>>
>>> It looks like you might be missing a trailing slash at the end of your
>>> pathmap string. This is mentioned in the FAQ
>>> http://wiki.eclipse.org/MDT-UML2-FAQ
>>> If that still doesn't work I can provide a code snippet that should load
>>> your model (post a small section of the problematic model so I can test
>>> it
>>> out the code ).
>>>
>>> Cheers,
>>> - James.
>>>
>>>
>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>> It is possible to find on this list a working code snippet showing how
>>>> to
>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>>>> app.
>>>>
>>>> My problem occurs when that Package has an imported package that has a
>>>> "pathmap" URL.
>>>>
>>>> I think what I should do is map the pathmap URL to the actual URL, like
>>>> this:
>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>
>>>> URI pathmap =
>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>
>>>> URI types = URI.createFileURI(new
>>>> File(typesFilename).getAbsolutePath());
>>>>
>>>> uriMap.put(pathmap, types);
>>>>
>>>> But when I try to get the imported stuff, like this:
>>>> EList<Package> importList = model.getImportedPackages();
>>>>
>>>> I get an exception:
>>>> java.lang.ClassCastException:
>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>> org.eclipse.uml2.uml.Package
>>>> at
>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>
>>>> at
>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>
>>>> at
>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>
>>>>
>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
>>>> like it doesn't know that the imported package is UML.
>>>>
>>>> Any help on this? Thanks.
>>>>
>>>
>>>
>>
>>
>>
>
>
Re: Continuing saga of the standalone app [message #626816 is a reply to message #477624] Tue, 22 July 2008 16:29 Go to previous message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

James,
This doesn't quite do what I hoped. Stuff in the external model that is
referenced "indirectly" doesn't get imported.

Attached is a refinement of the importing model that uses a generalization
that references the external model.
The new sanity check is the following, which gets null for the supertype:
//
// Sanity check.
//
org.eclipse.uml2.uml.Package packageableElement =
(org.eclipse.uml2.uml.Package) model.getPackagedElement("pets");
org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
packageableElement.getOwnedMember("Animal");
org.eclipse.uml2.uml.Property breed = animal.getAttribute("breed", null);
org.eclipse.uml2.uml.DataType breedType = (org.eclipse.uml2.uml.DataType)
breed.getType();
System.out.println("BreedType: " + breedType);
org.eclipse.uml2.uml.Generalization gen = ((org.eclipse.uml2.uml.DataType)
breedType).getGeneralizations().get(0);
org.eclipse.uml2.uml.Classifier general = gen.getGeneral();
System.out.println("BreedSuperType: " + general.getName());

"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g64nml$1ha$1@build.eclipse.org...
>I should mention (for others reading this thread) that the recommendation
>to
> "edit the nsURI with a text editor" would not be a general solution. It
> would work for this very specific example but not in general (in this case
> there was one DataType in the library). The migration guides on the wiki
> explain in more detail how to properly migrate to newer versions.
>
> Cheers,
> - James.
>
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:g62q94$8in$1@build.eclipse.org...
>> Hi Jeff,
>>
>>
>> The following code snippet will properly resolve the data type from the
>> library.
>> There was one little 'gotcha' that had me wondering what was going on.
>> Your XSDDataTypes.library.uml was not upgraded to the latest version.
>> You
>> have at the top of the file ...
>> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>>
>> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>>
>>
>> 1. Change the nsURI in your library by either re-saving it out or edit
>> with a text editor.
>> 2. Try the following code (pardon the hard-coded stuff):
>> 3. You should notice the type of "breed" is not a proxy.
>>
>>
>> Cheers,...
>> - James.
>>
>> protected static void registerPathmaps(URI umlResourcePluginURI) {
>>
>>
>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>>
>> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>>
>>
>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>>
>> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>>
>>
>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>>
>> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>>
>>
>> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>>
>> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>>
>>
>>
>> }
>>
>> protected static void registerExtensions() {
>>
>> Map<String, Object> extensionFactoryMap =
>> Resource.Factory.Registry.INSTANCE
>>
>> .getExtensionToFactoryMap();
>>
>>
>> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>>
>> UMLResource.Factory.INSTANCE);
>>
>>
>> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>>
>> Ecore2XMLResource.Factory.INSTANCE);
>>
>>
>> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>
>> UML22UMLResource.Factory.INSTANCE);
>>
>>
>> }
>>
>>
>>
>> protected static void registerPackages(ResourceSet resourceSet) {
>>
>>
>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>
>>
>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>
>>
>> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>>
>> Ecore2XMLPackage.eINSTANCE);
>>
>>
>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>
>> }
>>
>>
>> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
>> umlResourcePluginURI) {
>>
>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>>
>> registerPathmaps(umlResourcePluginURI);
>>
>> registerPackages(resourceSet);
>>
>> registerExtensions();
>>
>>
>> // Map references to legacy (1.x) model elements to their new locations.
>>
>> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>>
>> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>>
>>
>> // Load a resource in the resource set.
>>
>> try {
>>
>> resourceSet.getResource(resourceURI, true);
>>
>> } catch (Exception e) {
>>
>> System.out.println(e.getMessage());
>>
>> return null;
>>
>> }
>>
>>
>> EList<Resource> resources = resourceSet.getResources();
>>
>> EcoreUtil.resolveAll(resources.get(0));
>>
>>
>> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>>
>> .getContents(), UMLPackage.Literals.MODEL);
>>
>>
>>
>> //
>>
>> // Sanity check.
>>
>> //
>>
>> org.eclipse.uml2.uml.Package packageableElement =
>> (org.eclipse.uml2.uml.Package) model
>>
>> .getPackagedElement("pets");
>>
>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>> packageableElement
>>
>> .getOwnedMember("Animal");
>>
>> org.eclipse.uml2.uml.Property breed = animal
>>
>> .getAttribute("breed", null);
>>
>>
>> System.out.println("BreedType: " + breed.getType());
>>
>>
>> return model;
>>
>>
>> }
>>
>>
>>
>> public static void main(String[] args) {
>>
>>
>> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>>
>> String umlPluginPath =
>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>>
>> String umlResourcePath =
>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>>
>>
>> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>>
>> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>>
>> + "!/");
>>
>> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
>> umlResourcePluginURI);
>>
>>
>> }
>>
>>
>>
>> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
>> news:g5rbqt$kmk$1@build.eclipse.org...
>>> Thanks, James. That stopped the exception. But somehow I thought that
>>> the
>>> external package would magically be imported, and all of the references
>>> into it would be resolved.
>>>
>>> Which is not what is happening.
>>>
>>> Here is the relevant code, and attached are the problematic models.
>>>
>>> private Model getModel(String filename, String typesFilename) {
>>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>>> UMLPackage.eINSTANCE);
>>>
>>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>>> UMLResource.Factory.INSTANCE);
>>>
>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>> URI pathmap =
>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>>> URI types = URI.createFileURI(new
>>> File(typesFilename).getAbsolutePath());
>>> uriMap.put(pathmap, types);
>>>
>>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>>> Model model = null;
>>> try {
>>> Resource resource = RESOURCE_SET.getResource(uri, true);
>>> EcoreUtil.resolveAll(resource);
>>>
>>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>>> UMLPackage.Literals.MODEL);
>>> } catch (WrappedException we) {
>>> System.err.println(we.getMessage());
>>> }
>>> return model;
>>> }
>>>
>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>> news:g5q81a$42a$1@build.eclipse.org...
>>>> Hi Jeff,
>>>>
>>>> It looks like you might be missing a trailing slash at the end of your
>>>> pathmap string. This is mentioned in the FAQ
>>>> http://wiki.eclipse.org/MDT-UML2-FAQ
>>>> If that still doesn't work I can provide a code snippet that should
>>>> load
>>>> your model (post a small section of the problematic model so I can test
>>>> it
>>>> out the code ).
>>>>
>>>> Cheers,
>>>> - James.
>>>>
>>>>
>>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>>> It is possible to find on this list a working code snippet showing how
>>>>> to
>>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>>>>> app.
>>>>>
>>>>> My problem occurs when that Package has an imported package that has a
>>>>> "pathmap" URL.
>>>>>
>>>>> I think what I should do is map the pathmap URL to the actual URL,
>>>>> like
>>>>> this:
>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>>
>>>>> URI pathmap =
>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>>
>>>>> URI types = URI.createFileURI(new
>>>>> File(typesFilename).getAbsolutePath());
>>>>>
>>>>> uriMap.put(pathmap, types);
>>>>>
>>>>> But when I try to get the imported stuff, like this:
>>>>> EList<Package> importList = model.getImportedPackages();
>>>>>
>>>>> I get an exception:
>>>>> java.lang.ClassCastException:
>>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>>> org.eclipse.uml2.uml.Package
>>>>> at
>>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>>
>>>>> at
>>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>>
>>>>> at
>>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>>
>>>>>
>>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It looks
>>>>> like it doesn't know that the imported package is UML.
>>>>>
>>>>> Any help on this? Thanks.
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>
>


  • Attachment: petsplus.uml
    (Size: 6.36KB, Downloaded 251 times)
Re: Continuing saga of the standalone app [message #626817 is a reply to message #477625] Tue, 22 July 2008 18:06 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Jeff,

That seems to work fine for me. I'm seeing BreedType: Breed and
BreedSuperType: string.

What are the problems you are seeing?
Are you certain you are loading the new petsplus.uml and not the older
pets.uml. You would see an exception in that case since there would be no
generalizations of the DataType from the library.

I could zip up my small test class to send you if you want.

Cheers,
- James.


"Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
news:g651sr$mg2$1@build.eclipse.org...
> James,
> This doesn't quite do what I hoped. Stuff in the external model that is
> referenced "indirectly" doesn't get imported.
>
> Attached is a refinement of the importing model that uses a generalization
> that references the external model.
> The new sanity check is the following, which gets null for the supertype:
> //
> // Sanity check.
> //
> org.eclipse.uml2.uml.Package packageableElement =
> (org.eclipse.uml2.uml.Package) model.getPackagedElement("pets");
> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
> packageableElement.getOwnedMember("Animal");
> org.eclipse.uml2.uml.Property breed = animal.getAttribute("breed", null);
> org.eclipse.uml2.uml.DataType breedType = (org.eclipse.uml2.uml.DataType)
> breed.getType();
> System.out.println("BreedType: " + breedType);
> org.eclipse.uml2.uml.Generalization gen = ((org.eclipse.uml2.uml.DataType)
> breedType).getGeneralizations().get(0);
> org.eclipse.uml2.uml.Classifier general = gen.getGeneral();
> System.out.println("BreedSuperType: " + general.getName());
>
> "James Bruck" <jbruck@ca.ibm.com> wrote in message
> news:g64nml$1ha$1@build.eclipse.org...
>>I should mention (for others reading this thread) that the recommendation
>>to
>> "edit the nsURI with a text editor" would not be a general solution. It
>> would work for this very specific example but not in general (in this
>> case
>> there was one DataType in the library). The migration guides on the
>> wiki
>> explain in more detail how to properly migrate to newer versions.
>>
>> Cheers,
>> - James.
>>
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:g62q94$8in$1@build.eclipse.org...
>>> Hi Jeff,
>>>
>>>
>>> The following code snippet will properly resolve the data type from the
>>> library.
>>> There was one little 'gotcha' that had me wondering what was going on.
>>> Your XSDDataTypes.library.uml was not upgraded to the latest version.
>>> You
>>> have at the top of the file ...
>>> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>>>
>>> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>>>
>>>
>>> 1. Change the nsURI in your library by either re-saving it out or edit
>>> with a text editor.
>>> 2. Try the following code (pardon the hard-coded stuff):
>>> 3. You should notice the type of "breed" is not a proxy.
>>>
>>>
>>> Cheers,...
>>> - James.
>>>
>>> protected static void registerPathmaps(URI umlResourcePluginURI) {
>>>
>>>
>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>>>
>>> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>>>
>>>
>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>>>
>>> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>>>
>>>
>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>>>
>>> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>>>
>>>
>>> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>>>
>>> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>>>
>>>
>>>
>>> }
>>>
>>> protected static void registerExtensions() {
>>>
>>> Map<String, Object> extensionFactoryMap =
>>> Resource.Factory.Registry.INSTANCE
>>>
>>> .getExtensionToFactoryMap();
>>>
>>>
>>> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>>>
>>> UMLResource.Factory.INSTANCE);
>>>
>>>
>>> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>>>
>>> Ecore2XMLResource.Factory.INSTANCE);
>>>
>>>
>>> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>>
>>> UML22UMLResource.Factory.INSTANCE);
>>>
>>>
>>> }
>>>
>>>
>>>
>>> protected static void registerPackages(ResourceSet resourceSet) {
>>>
>>>
>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>>
>>>
>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>>
>>>
>>> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>>>
>>> Ecore2XMLPackage.eINSTANCE);
>>>
>>>
>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>>
>>> }
>>>
>>>
>>> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
>>> umlResourcePluginURI) {
>>>
>>>
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>
>>> registerPathmaps(umlResourcePluginURI);
>>>
>>> registerPackages(resourceSet);
>>>
>>> registerExtensions();
>>>
>>>
>>> // Map references to legacy (1.x) model elements to their new locations.
>>>
>>> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>>>
>>> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>>>
>>>
>>> // Load a resource in the resource set.
>>>
>>> try {
>>>
>>> resourceSet.getResource(resourceURI, true);
>>>
>>> } catch (Exception e) {
>>>
>>> System.out.println(e.getMessage());
>>>
>>> return null;
>>>
>>> }
>>>
>>>
>>> EList<Resource> resources = resourceSet.getResources();
>>>
>>> EcoreUtil.resolveAll(resources.get(0));
>>>
>>>
>>> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>>>
>>> .getContents(), UMLPackage.Literals.MODEL);
>>>
>>>
>>>
>>> //
>>>
>>> // Sanity check.
>>>
>>> //
>>>
>>> org.eclipse.uml2.uml.Package packageableElement =
>>> (org.eclipse.uml2.uml.Package) model
>>>
>>> .getPackagedElement("pets");
>>>
>>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>>> packageableElement
>>>
>>> .getOwnedMember("Animal");
>>>
>>> org.eclipse.uml2.uml.Property breed = animal
>>>
>>> .getAttribute("breed", null);
>>>
>>>
>>> System.out.println("BreedType: " + breed.getType());
>>>
>>>
>>> return model;
>>>
>>>
>>> }
>>>
>>>
>>>
>>> public static void main(String[] args) {
>>>
>>>
>>> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>>>
>>> String umlPluginPath =
>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>>>
>>> String umlResourcePath =
>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>>>
>>>
>>> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>>>
>>> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>>>
>>> + "!/");
>>>
>>> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
>>> umlResourcePluginURI);
>>>
>>>
>>> }
>>>
>>>
>>>
>>> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
>>> news:g5rbqt$kmk$1@build.eclipse.org...
>>>> Thanks, James. That stopped the exception. But somehow I thought that
>>>> the
>>>> external package would magically be imported, and all of the references
>>>> into it would be resolved.
>>>>
>>>> Which is not what is happening.
>>>>
>>>> Here is the relevant code, and attached are the problematic models.
>>>>
>>>> private Model getModel(String filename, String typesFilename) {
>>>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>>>> UMLPackage.eINSTANCE);
>>>>
>>>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>>>> UMLResource.Factory.INSTANCE);
>>>>
>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>> URI pathmap =
>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>>>> URI types = URI.createFileURI(new
>>>> File(typesFilename).getAbsolutePath());
>>>> uriMap.put(pathmap, types);
>>>>
>>>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>>>> Model model = null;
>>>> try {
>>>> Resource resource = RESOURCE_SET.getResource(uri, true);
>>>> EcoreUtil.resolveAll(resource);
>>>>
>>>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>>>> UMLPackage.Literals.MODEL);
>>>> } catch (WrappedException we) {
>>>> System.err.println(we.getMessage());
>>>> }
>>>> return model;
>>>> }
>>>>
>>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>>> news:g5q81a$42a$1@build.eclipse.org...
>>>>> Hi Jeff,
>>>>>
>>>>> It looks like you might be missing a trailing slash at the end of your
>>>>> pathmap string. This is mentioned in the FAQ
>>>>> http://wiki.eclipse.org/MDT-UML2-FAQ
>>>>> If that still doesn't work I can provide a code snippet that should
>>>>> load
>>>>> your model (post a small section of the problematic model so I can
>>>>> test
>>>>> it
>>>>> out the code ).
>>>>>
>>>>> Cheers,
>>>>> - James.
>>>>>
>>>>>
>>>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>>>> It is possible to find on this list a working code snippet showing
>>>>>> how
>>>>>> to
>>>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a standalone
>>>>>> app.
>>>>>>
>>>>>> My problem occurs when that Package has an imported package that has
>>>>>> a
>>>>>> "pathmap" URL.
>>>>>>
>>>>>> I think what I should do is map the pathmap URL to the actual URL,
>>>>>> like
>>>>>> this:
>>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>>>
>>>>>> URI pathmap =
>>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>>>
>>>>>> URI types = URI.createFileURI(new
>>>>>> File(typesFilename).getAbsolutePath());
>>>>>>
>>>>>> uriMap.put(pathmap, types);
>>>>>>
>>>>>> But when I try to get the imported stuff, like this:
>>>>>> EList<Package> importList = model.getImportedPackages();
>>>>>>
>>>>>> I get an exception:
>>>>>> java.lang.ClassCastException:
>>>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>>>> org.eclipse.uml2.uml.Package
>>>>>> at
>>>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>>>
>>>>>>
>>>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It
>>>>>> looks
>>>>>> like it doesn't know that the imported package is UML.
>>>>>>
>>>>>> Any help on this? Thanks.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
>
Re: Continuing saga of the standalone app [message #626818 is a reply to message #477626] Tue, 22 July 2008 20:18 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
.... the complete project attached ...



"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g657k1$7c1$1@build.eclipse.org...
> Hi Jeff,
>
> That seems to work fine for me. I'm seeing BreedType: Breed and
> BreedSuperType: string.
>
> What are the problems you are seeing?
> Are you certain you are loading the new petsplus.uml and not the older
> pets.uml. You would see an exception in that case since there would be no
> generalizations of the DataType from the library.
>
> I could zip up my small test class to send you if you want.
>
> Cheers,
> - James.
>
>
> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
> news:g651sr$mg2$1@build.eclipse.org...
>> James,
>> This doesn't quite do what I hoped. Stuff in the external model that is
>> referenced "indirectly" doesn't get imported.
>>
>> Attached is a refinement of the importing model that uses a
>> generalization
>> that references the external model.
>> The new sanity check is the following, which gets null for the supertype:
>> //
>> // Sanity check.
>> //
>> org.eclipse.uml2.uml.Package packageableElement =
>> (org.eclipse.uml2.uml.Package) model.getPackagedElement("pets");
>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>> packageableElement.getOwnedMember("Animal");
>> org.eclipse.uml2.uml.Property breed = animal.getAttribute("breed", null);
>> org.eclipse.uml2.uml.DataType breedType = (org.eclipse.uml2.uml.DataType)
>> breed.getType();
>> System.out.println("BreedType: " + breedType);
>> org.eclipse.uml2.uml.Generalization gen =
>> ((org.eclipse.uml2.uml.DataType)
>> breedType).getGeneralizations().get(0);
>> org.eclipse.uml2.uml.Classifier general = gen.getGeneral();
>> System.out.println("BreedSuperType: " + general.getName());
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:g64nml$1ha$1@build.eclipse.org...
>>>I should mention (for others reading this thread) that the recommendation
>>>to
>>> "edit the nsURI with a text editor" would not be a general solution.
>>> It
>>> would work for this very specific example but not in general (in this
>>> case
>>> there was one DataType in the library). The migration guides on the
>>> wiki
>>> explain in more detail how to properly migrate to newer versions.
>>>
>>> Cheers,
>>> - James.
>>>
>>>
>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>> news:g62q94$8in$1@build.eclipse.org...
>>>> Hi Jeff,
>>>>
>>>>
>>>> The following code snippet will properly resolve the data type from the
>>>> library.
>>>> There was one little 'gotcha' that had me wondering what was going on.
>>>> Your XSDDataTypes.library.uml was not upgraded to the latest version.
>>>> You
>>>> have at the top of the file ...
>>>> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>>>>
>>>> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>>>>
>>>>
>>>> 1. Change the nsURI in your library by either re-saving it out or edit
>>>> with a text editor.
>>>> 2. Try the following code (pardon the hard-coded stuff):
>>>> 3. You should notice the type of "breed" is not a proxy.
>>>>
>>>>
>>>> Cheers,...
>>>> - James.
>>>>
>>>> protected static void registerPathmaps(URI umlResourcePluginURI) {
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>>>>
>>>> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>>>>
>>>>
>>>>
>>>> }
>>>>
>>>> protected static void registerExtensions() {
>>>>
>>>> Map<String, Object> extensionFactoryMap =
>>>> Resource.Factory.Registry.INSTANCE
>>>>
>>>> .getExtensionToFactoryMap();
>>>>
>>>>
>>>> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>>>>
>>>> UMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>>>>
>>>> Ecore2XMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>>>
>>>> UML22UMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> protected static void registerPackages(ResourceSet resourceSet) {
>>>>
>>>>
>>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>>>
>>>>
>>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>>>
>>>>
>>>> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>>>>
>>>> Ecore2XMLPackage.eINSTANCE);
>>>>
>>>>
>>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>>>
>>>> }
>>>>
>>>>
>>>> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
>>>> umlResourcePluginURI) {
>>>>
>>>>
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>
>>>> registerPathmaps(umlResourcePluginURI);
>>>>
>>>> registerPackages(resourceSet);
>>>>
>>>> registerExtensions();
>>>>
>>>>
>>>> // Map references to legacy (1.x) model elements to their new
>>>> locations.
>>>>
>>>> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>>>>
>>>> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>>>>
>>>>
>>>> // Load a resource in the resource set.
>>>>
>>>> try {
>>>>
>>>> resourceSet.getResource(resourceURI, true);
>>>>
>>>> } catch (Exception e) {
>>>>
>>>> System.out.println(e.getMessage());
>>>>
>>>> return null;
>>>>
>>>> }
>>>>
>>>>
>>>> EList<Resource> resources = resourceSet.getResources();
>>>>
>>>> EcoreUtil.resolveAll(resources.get(0));
>>>>
>>>>
>>>> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>>>>
>>>> .getContents(), UMLPackage.Literals.MODEL);
>>>>
>>>>
>>>>
>>>> //
>>>>
>>>> // Sanity check.
>>>>
>>>> //
>>>>
>>>> org.eclipse.uml2.uml.Package packageableElement =
>>>> (org.eclipse.uml2.uml.Package) model
>>>>
>>>> .getPackagedElement("pets");
>>>>
>>>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>>>> packageableElement
>>>>
>>>> .getOwnedMember("Animal");
>>>>
>>>> org.eclipse.uml2.uml.Property breed = animal
>>>>
>>>> .getAttribute("breed", null);
>>>>
>>>>
>>>> System.out.println("BreedType: " + breed.getType());
>>>>
>>>>
>>>> return model;
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> public static void main(String[] args) {
>>>>
>>>>
>>>> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>>>>
>>>> String umlPluginPath =
>>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>>>>
>>>> String umlResourcePath =
>>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>>>>
>>>>
>>>> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>>>>
>>>> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>>>>
>>>> + "!/");
>>>>
>>>> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
>>>> umlResourcePluginURI);
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
>>>> news:g5rbqt$kmk$1@build.eclipse.org...
>>>>> Thanks, James. That stopped the exception. But somehow I thought that
>>>>> the
>>>>> external package would magically be imported, and all of the
>>>>> references
>>>>> into it would be resolved.
>>>>>
>>>>> Which is not what is happening.
>>>>>
>>>>> Here is the relevant code, and attached are the problematic models.
>>>>>
>>>>> private Model getModel(String filename, String typesFilename) {
>>>>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>>
>>>>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>>>>> UMLResource.Factory.INSTANCE);
>>>>>
>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>> URI pathmap =
>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>>>>> URI types = URI.createFileURI(new
>>>>> File(typesFilename).getAbsolutePath());
>>>>> uriMap.put(pathmap, types);
>>>>>
>>>>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>>>>> Model model = null;
>>>>> try {
>>>>> Resource resource = RESOURCE_SET.getResource(uri, true);
>>>>> EcoreUtil.resolveAll(resource);
>>>>>
>>>>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>>>>> UMLPackage.Literals.MODEL);
>>>>> } catch (WrappedException we) {
>>>>> System.err.println(we.getMessage());
>>>>> }
>>>>> return model;
>>>>> }
>>>>>
>>>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>>>> news:g5q81a$42a$1@build.eclipse.org...
>>>>>> Hi Jeff,
>>>>>>
>>>>>> It looks like you might be missing a trailing slash at the end of
>>>>>> your
>>>>>> pathmap string. This is mentioned in the FAQ
>>>>>> http://wiki.eclipse.org/MDT-UML2-FAQ
>>>>>> If that still doesn't work I can provide a code snippet that should
>>>>>> load
>>>>>> your model (post a small section of the problematic model so I can
>>>>>> test
>>>>>> it
>>>>>> out the code ).
>>>>>>
>>>>>> Cheers,
>>>>>> - James.
>>>>>>
>>>>>>
>>>>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>>>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>>>>> It is possible to find on this list a working code snippet showing
>>>>>>> how
>>>>>>> to
>>>>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a
>>>>>>> standalone
>>>>>>> app.
>>>>>>>
>>>>>>> My problem occurs when that Package has an imported package that has
>>>>>>> a
>>>>>>> "pathmap" URL.
>>>>>>>
>>>>>>> I think what I should do is map the pathmap URL to the actual URL,
>>>>>>> like
>>>>>>> this:
>>>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>>>>
>>>>>>> URI pathmap =
>>>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>>>>
>>>>>>> URI types = URI.createFileURI(new
>>>>>>> File(typesFilename).getAbsolutePath());
>>>>>>>
>>>>>>> uriMap.put(pathmap, types);
>>>>>>>
>>>>>>> But when I try to get the imported stuff, like this:
>>>>>>> EList<Package> importList = model.getImportedPackages();
>>>>>>>
>>>>>>> I get an exception:
>>>>>>> java.lang.ClassCastException:
>>>>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>>>>> org.eclipse.uml2.uml.Package
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>>>>
>>>>>>>
>>>>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It
>>>>>>> looks
>>>>>>> like it doesn't know that the imported package is UML.
>>>>>>>
>>>>>>> Any help on this? Thanks.
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>
>


Re: Continuing saga of the standalone app [message #626819 is a reply to message #477626] Tue, 22 July 2008 20:41 Go to previous message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

James,
My misunderstanding.
I see now that the pathmap to the external library points, not to the
library itself, but to a directory called "libraries" that contains the
actual library file.
Once again, thanks for this great help.
Jeff


"James Bruck" <jbruck@ca.ibm.com> wrote in message
news:g657k1$7c1$1@build.eclipse.org...
> Hi Jeff,
>
> That seems to work fine for me. I'm seeing BreedType: Breed and
> BreedSuperType: string.
>
> What are the problems you are seeing?
> Are you certain you are loading the new petsplus.uml and not the older
> pets.uml. You would see an exception in that case since there would be no
> generalizations of the DataType from the library.
>
> I could zip up my small test class to send you if you want.
>
> Cheers,
> - James.
>
>
> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
> news:g651sr$mg2$1@build.eclipse.org...
>> James,
>> This doesn't quite do what I hoped. Stuff in the external model that is
>> referenced "indirectly" doesn't get imported.
>>
>> Attached is a refinement of the importing model that uses a
>> generalization that references the external model.
>> The new sanity check is the following, which gets null for the supertype:
>> //
>> // Sanity check.
>> //
>> org.eclipse.uml2.uml.Package packageableElement =
>> (org.eclipse.uml2.uml.Package) model.getPackagedElement("pets");
>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>> packageableElement.getOwnedMember("Animal");
>> org.eclipse.uml2.uml.Property breed = animal.getAttribute("breed", null);
>> org.eclipse.uml2.uml.DataType breedType = (org.eclipse.uml2.uml.DataType)
>> breed.getType();
>> System.out.println("BreedType: " + breedType);
>> org.eclipse.uml2.uml.Generalization gen =
>> ((org.eclipse.uml2.uml.DataType) breedType).getGeneralizations().get(0);
>> org.eclipse.uml2.uml.Classifier general = gen.getGeneral();
>> System.out.println("BreedSuperType: " + general.getName());
>>
>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>> news:g64nml$1ha$1@build.eclipse.org...
>>>I should mention (for others reading this thread) that the recommendation
>>>to
>>> "edit the nsURI with a text editor" would not be a general solution.
>>> It
>>> would work for this very specific example but not in general (in this
>>> case
>>> there was one DataType in the library). The migration guides on the
>>> wiki
>>> explain in more detail how to properly migrate to newer versions.
>>>
>>> Cheers,
>>> - James.
>>>
>>>
>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>> news:g62q94$8in$1@build.eclipse.org...
>>>> Hi Jeff,
>>>>
>>>>
>>>> The following code snippet will properly resolve the data type from the
>>>> library.
>>>> There was one little 'gotcha' that had me wondering what was going on.
>>>> Your XSDDataTypes.library.uml was not upgraded to the latest version.
>>>> You
>>>> have at the top of the file ...
>>>> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"> which should be
>>>>
>>>> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML">
>>>>
>>>>
>>>> 1. Change the nsURI in your library by either re-saving it out or edit
>>>> with a text editor.
>>>> 2. Try the following code (pardon the hard-coded stuff):
>>>> 3. You should notice the type of "breed" is not a proxy.
>>>>
>>>>
>>>> Cheers,...
>>>> - James.
>>>>
>>>> protected static void registerPathmaps(URI umlResourcePluginURI) {
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("libraries").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("metamodels").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
>>>>
>>>> umlResourcePluginURI.appendSegment("profiles").appendSegment( ""));
>>>>
>>>>
>>>> URIConverter.URI_MAP.put(URI.createURI("pathmap://XMLmodeling_LIBRARIES/"),
>>>>
>>>> URI.createFileURI("C:/UMLDevelopment/NewsGroupIssue").appendSegment( "libraries").appendSegment(""));
>>>>
>>>>
>>>>
>>>> }
>>>>
>>>> protected static void registerExtensions() {
>>>>
>>>> Map<String, Object> extensionFactoryMap =
>>>> Resource.Factory.Registry.INSTANCE
>>>>
>>>> .getExtensionToFactoryMap();
>>>>
>>>>
>>>> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,
>>>>
>>>> UMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,
>>>>
>>>> Ecore2XMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,
>>>>
>>>> UML22UMLResource.Factory.INSTANCE);
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> protected static void registerPackages(ResourceSet resourceSet) {
>>>>
>>>>
>>>> Registry packageRegistry = resourceSet.getPackageRegistry();
>>>>
>>>>
>>>> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>>>>
>>>>
>>>> packageRegistry.put(Ecore2XMLPackage.eNS_URI,
>>>>
>>>> Ecore2XMLPackage.eINSTANCE);
>>>>
>>>>
>>>> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>>>>
>>>> }
>>>>
>>>>
>>>> public static Model getModel(URI resourceURI, URI umlPluginURI, URI
>>>> umlResourcePluginURI) {
>>>>
>>>>
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>
>>>> registerPathmaps(umlResourcePluginURI);
>>>>
>>>> registerPackages(resourceSet);
>>>>
>>>> registerExtensions();
>>>>
>>>>
>>>> // Map references to legacy (1.x) model elements to their new
>>>> locations.
>>>>
>>>> Map<URI,URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>>>>
>>>> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>>>>
>>>>
>>>> // Load a resource in the resource set.
>>>>
>>>> try {
>>>>
>>>> resourceSet.getResource(resourceURI, true);
>>>>
>>>> } catch (Exception e) {
>>>>
>>>> System.out.println(e.getMessage());
>>>>
>>>> return null;
>>>>
>>>> }
>>>>
>>>>
>>>> EList<Resource> resources = resourceSet.getResources();
>>>>
>>>> EcoreUtil.resolveAll(resources.get(0));
>>>>
>>>>
>>>> Model model = (Model) EcoreUtil.getObjectByType(resources.get(0)
>>>>
>>>> .getContents(), UMLPackage.Literals.MODEL);
>>>>
>>>>
>>>>
>>>> //
>>>>
>>>> // Sanity check.
>>>>
>>>> //
>>>>
>>>> org.eclipse.uml2.uml.Package packageableElement =
>>>> (org.eclipse.uml2.uml.Package) model
>>>>
>>>> .getPackagedElement("pets");
>>>>
>>>> org.eclipse.uml2.uml.Class animal = (org.eclipse.uml2.uml.Class)
>>>> packageableElement
>>>>
>>>> .getOwnedMember("Animal");
>>>>
>>>> org.eclipse.uml2.uml.Property breed = animal
>>>>
>>>> .getAttribute("breed", null);
>>>>
>>>>
>>>> System.out.println("BreedType: " + breed.getType());
>>>>
>>>>
>>>> return model;
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> public static void main(String[] args) {
>>>>
>>>>
>>>> String fileToOpen = "C:/UMLDevelopment/NewsGroupIssue/pets.uml";
>>>>
>>>> String umlPluginPath =
>>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml_2.2.0.v200805141133.jar ";
>>>>
>>>> String umlResourcePath =
>>>> " C:/UMLDevelopment/Download_Zips/Eclipse_Downloads/Eclipse3.4
>>>> final/eclipse-SDK-3.4-win32/eclipse/plugins/org.eclipse.uml2 .uml.resources_2.2.0.v200805131030.jar ";
>>>>
>>>>
>>>> URI umlPluginURI = URI.createURI("jar:file:/" + umlPluginPath + "!/");
>>>>
>>>> URI umlResourcePluginURI = URI.createURI("jar:file:/" + umlResourcePath
>>>>
>>>> + "!/");
>>>>
>>>> getModel(URI.createFileURI(fileToOpen), umlPluginURI,
>>>> umlResourcePluginURI);
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> "Jeff Lansing" <jeff.lansing@sbcglobal.net> wrote in message
>>>> news:g5rbqt$kmk$1@build.eclipse.org...
>>>>> Thanks, James. That stopped the exception. But somehow I thought that
>>>>> the
>>>>> external package would magically be imported, and all of the
>>>>> references
>>>>> into it would be resolved.
>>>>>
>>>>> Which is not what is happening.
>>>>>
>>>>> Here is the relevant code, and attached are the problematic models.
>>>>>
>>>>> private Model getModel(String filename, String typesFilename) {
>>>>> RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI,
>>>>> UMLPackage.eINSTANCE);
>>>>>
>>>>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
>>>>> UMLResource.Factory.INSTANCE);
>>>>>
>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>> URI pathmap =
>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml/");
>>>>> URI types = URI.createFileURI(new
>>>>> File(typesFilename).getAbsolutePath());
>>>>> uriMap.put(pathmap, types);
>>>>>
>>>>> URI uri = URI.createFileURI(new File(filename).getAbsolutePath());
>>>>> Model model = null;
>>>>> try {
>>>>> Resource resource = RESOURCE_SET.getResource(uri, true);
>>>>> EcoreUtil.resolveAll(resource);
>>>>>
>>>>> model = (Model) EcoreUtil.getObjectByType(resource.getContents(),
>>>>> UMLPackage.Literals.MODEL);
>>>>> } catch (WrappedException we) {
>>>>> System.err.println(we.getMessage());
>>>>> }
>>>>> return model;
>>>>> }
>>>>>
>>>>> "James Bruck" <jbruck@ca.ibm.com> wrote in message
>>>>> news:g5q81a$42a$1@build.eclipse.org...
>>>>>> Hi Jeff,
>>>>>>
>>>>>> It looks like you might be missing a trailing slash at the end of
>>>>>> your
>>>>>> pathmap string. This is mentioned in the FAQ
>>>>>> http://wiki.eclipse.org/MDT-UML2-FAQ
>>>>>> If that still doesn't work I can provide a code snippet that should
>>>>>> load
>>>>>> your model (post a small section of the problematic model so I can
>>>>>> test
>>>>>> it
>>>>>> out the code ).
>>>>>>
>>>>>> Cheers,
>>>>>> - James.
>>>>>>
>>>>>>
>>>>>> "Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
>>>>>> news:g5o96q$ph2$1@build.eclipse.org...
>>>>>>> It is possible to find on this list a working code snippet showing
>>>>>>> how
>>>>>>> to
>>>>>>> get an org.eclipse.uml2.uml.Package from a .uml file, in a
>>>>>>> standalone
>>>>>>> app.
>>>>>>>
>>>>>>> My problem occurs when that Package has an imported package that has
>>>>>>> a
>>>>>>> "pathmap" URL.
>>>>>>>
>>>>>>> I think what I should do is map the pathmap URL to the actual URL,
>>>>>>> like
>>>>>>> this:
>>>>>>> Map<URI, URI> uriMap = RESOURCE_SET.getURIConverter().getURIMap();
>>>>>>>
>>>>>>> URI pathmap =
>>>>>>> URI.createURI("pathmap://XMLmodeling_LIBRARIES/XSDDataTypes.library.uml");
>>>>>>>
>>>>>>> URI types = URI.createFileURI(new
>>>>>>> File(typesFilename).getAbsolutePath());
>>>>>>>
>>>>>>> uriMap.put(pathmap, types);
>>>>>>>
>>>>>>> But when I try to get the imported stuff, like this:
>>>>>>> EList<Package> importList = model.getImportedPackages();
>>>>>>>
>>>>>>> I get an exception:
>>>>>>> java.lang.ClassCastException:
>>>>>>> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
>>>>>>> org.eclipse.uml2.uml.Package
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.impl.PackageImportImpl.getImpo rtedPackage(PackageImportImpl.java:204)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations .getImportedPackages(NamespaceOperations.java:207)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImported Packages(NamespaceImpl.java:552)
>>>>>>>
>>>>>>>
>>>>>>> (Similarly if I try to use EcoreUtil.resolveAll(resource); ). It
>>>>>>> looks
>>>>>>> like it doesn't know that the imported package is UML.
>>>>>>>
>>>>>>> Any help on this? Thanks.
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>
>
Re: Continuing saga of the standalone app [message #626895 is a reply to message #477618] Wed, 03 September 2008 02:06 Go to previous message
Victor Hugo is currently offline Victor HugoFriend
Messages: 20
Registered: July 2009
Junior Member
Hi Friends,

i have the same problem and try to solve using yours solutions by I obtain
this exception when i try to load model:

java.lang.ClassCastException:
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
org.eclipse.uml2.uml.Profile
at
org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.ge tAppliedProfile(ProfileApplicationImpl.java:182)
at
org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.eG et(ProfileApplicationImpl.java:410)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:100)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.scanNext(DerivedEObjectEList.java:66)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:109)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
at
org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.next(DerivedEObjectEList.java:158)
at
org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.hasNext(EContentsEList.java:443)
at
org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.next(EContentsEList.java:561)
at
org.eclipse.emf.ecore.util.EcoreUtil.resolveCrossReferences( EcoreUtil.java:307)
at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.ja va:287)
at
br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:143)
at
br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:126)
at
br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:203)
at
br.ufrj.nce.crossmda.xmi.util.emf.EMF_XMIRepositoryImpl.load Model(EMF_XMIRepositoryImpl.java:227)
at br.ufrj.nce.crossmda.test.emf.TesteModelo.main(TesteModelo.j ava:248)



what should i do to resolve profiles?

thanks
Re: Continuing saga of the standalone app [message #626900 is a reply to message #477701] Thu, 04 September 2008 17:14 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Victor,

I don't think there is enough information here to figure out what the
problem is. Can you post your model and profile, or at least sections of
it, such that the exception can be reproduced ?

- James.


"Victor Hugo" <victorhcf@gmail.com> wrote in message
news:d05d6b4e49b96e4e3e7e108487524686$1@www.eclipse.org...
> Hi Friends,
>
> i have the same problem and try to solve using yours solutions by I obtain
> this exception when i try to load model:
>
> java.lang.ClassCastException:
> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
> org.eclipse.uml2.uml.Profile
> at
> org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.ge tAppliedProfile(ProfileApplicationImpl.java:182)
> at
> org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.eG et(ProfileApplicationImpl.java:410)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:100)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.scanNext(DerivedEObjectEList.java:66)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:109)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.next(DerivedEObjectEList.java:158)
> at
> org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.hasNext(EContentsEList.java:443)
> at
> org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.next(EContentsEList.java:561)
> at
> org.eclipse.emf.ecore.util.EcoreUtil.resolveCrossReferences( EcoreUtil.java:307)
> at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.ja va:287)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:143)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:126)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:203)
> at
> br.ufrj.nce.crossmda.xmi.util.emf.EMF_XMIRepositoryImpl.load Model(EMF_XMIRepositoryImpl.java:227)
> at br.ufrj.nce.crossmda.test.emf.TesteModelo.main(TesteModelo.j ava:248)
>
>
>
> what should i do to resolve profiles?
>
> thanks
>
Re: Continuing saga of the standalone app [message #626909 is a reply to message #477701] Wed, 10 September 2008 17:27 Go to previous message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

Victor,

This happened to me when I tried to use an older profile.

My solution was to open the profile with the UML Model Editor, select the
<Profile> element, then (in the top menu) click UML Editor | Profile |
Define.

The result is an up-to-date profile that can be loaded as
org.eclipse.uml2.uml.Profile instead of
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl .

It would be nice if this could be done programatically, though.

Jeff


"Victor Hugo" <victorhcf@gmail.com> wrote in message
news:d05d6b4e49b96e4e3e7e108487524686$1@www.eclipse.org...
> Hi Friends,
>
> i have the same problem and try to solve using yours solutions by I obtain
> this exception when i try to load model:
>
> java.lang.ClassCastException:
> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl cannot be cast to
> org.eclipse.uml2.uml.Profile
> at
> org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.ge tAppliedProfile(ProfileApplicationImpl.java:182)
> at
> org.eclipse.uml2.uml.internal.impl.ProfileApplicationImpl.eG et(ProfileApplicationImpl.java:410)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:100)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.scanNext(DerivedEObjectEList.java:66)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.prepareNext(DerivedEObjectEList.java:109)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.hasNext(DerivedEObjectEList.java:149)
> at
> org.eclipse.uml2.common.util.DerivedEObjectEList$DerivedList Iterator.next(DerivedEObjectEList.java:158)
> at
> org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.hasNext(EContentsEList.java:443)
> at
> org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.next(EContentsEList.java:561)
> at
> org.eclipse.emf.ecore.util.EcoreUtil.resolveCrossReferences( EcoreUtil.java:307)
> at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.ja va:287)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:143)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:126)
> at
> br.ufrj.nce.crossmda.xml.util.EMFUML2RepositoryFacade.readMo del(EMFUML2RepositoryFacade.java:203)
> at
> br.ufrj.nce.crossmda.xmi.util.emf.EMF_XMIRepositoryImpl.load Model(EMF_XMIRepositoryImpl.java:227)
> at br.ufrj.nce.crossmda.test.emf.TesteModelo.main(TesteModelo.j ava:248)
>
>
>
> what should i do to resolve profiles?
>
> thanks
>
Re: Continuing saga of the standalone app [message #626936 is a reply to message #477715] Fri, 19 September 2008 06:30 Go to previous message
Victor Hugo is currently offline Victor HugoFriend
Messages: 20
Registered: July 2009
Junior Member
Hi Friends,

thanks for yours answers! but... my problem continue...

i tried to execute the Jeff's answer but without success!
and as James request...
My full application can be found in this link:
the profile in this:
http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/Profile_for_crossmda_profile-1.11.profile
the data model (bussiness):
http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/model_teste.uml
ths aspects model:
http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/model_aspects.uml
my java class thats load the model in this:
http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/sr c/test/Test.java

sorry about permission of directory to navigate into then, but i cannot
control this in server.


my problem is because i cannot load stereotypes that models has, i have to
apply profile before load model, how i can do this?


to simplify to yours here is the java code that i'm using to load models:

package test;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.EPackage.Registry;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.mapping.ecore2xml.Ecore2XMLPackage;
import org.eclipse.emf.mapping.ecore2xml.util.Ecore2XMLResource;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UML22UMLExtendedMetaData;
import org.eclipse.uml2.uml.resource.UML22UMLResource;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.eclipse.uml2.uml.resource.UML22UMLResource.Factory;

public class Test {

private ResourceSet resourceSet = null;
private Resource model = null;
private UMLResource uml2Resource = null;
private Profile profile = null;

@SuppressWarnings("unchecked")
protected void registerPathmaps(URI umlResourcePluginURI) {

String pathResource =
" /home/ceara/dev/mestrado/workspace/TesteLoadModels/lib/org.e clipse.uml2.uml.resources_2.2.0.v200805131030.jar ";
URI resourcePluginURI = URI.createURI("jar:file:/" + pathResource +
"!/");

resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Map uriMap = resourceSet.getURIConverter().getURIMap();

uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
resourcePluginURI.appendSegment("libraries").appendSegment( ""));

uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
resourcePluginURI.appendSegment("metamodels").appendSegment( ""));

uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
resourcePluginURI.appendSegment("profiles").appendSegment( ""));

}

protected void registerExtensions() {

Map<String, Object> extensionFactoryMap =
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( );

extensionFactoryMap.put(UMLResource.FILE_EXTENSION,UMLResour ce.Factory.INSTANCE);

extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,Eco re2XMLResource.Factory.INSTANCE);

extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,UML2 2UMLResource.Factory.INSTANCE);

}

protected void registerPackages(ResourceSet resourceSet) {

Registry packageRegistry = resourceSet.getPackageRegistry();
packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);

packageRegistry.put(Ecore2XMLPackage.eNS_URI,Ecore2XMLPackag e.eINSTANCE);

packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);

}

public Model getModel(URI resourceURI) {

resourceSet = new ResourceSetImpl();

registerPathmaps(null);
registerPackages(resourceSet);
registerExtensions();

Map<URI, URI> uriMap = UML22UMLExtendedMetaData.getURIMap();

resourceSet.getURIConverter().getURIMap().putAll(uriMap);

try {
model = resourceSet.getResource(resourceURI, true);
model.save(null);
EcoreUtil.resolveAll(model);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


if ( !(model instanceof UMLResource)) {
try {
throw new Exception("Modelo carregado esta inv&#65533;lido!");
} catch (Exception e) {
e.printStackTrace();
System.out.println( "OoOps..!" );
}
}

this.uml2Resource = (UMLResource) model;

return null;

}

public static void main(String[] args) {

String fileToOpen =
" /home/ceara/dev/mestrado/workspace/TesteLoadModels/models/mo del_teste.uml ";

Test t = new Test();
t.getModel(URI.createFileURI(fileToOpen));

}

public void displayAllElements() {
//Model o =
(Model)xmiutils.getUML2Resource().getContents().iterator().n ext();
Model o = (Model)uml2Resource.getContents().iterator().next();

EList<NamedElement> mbs = o.getMembers();
for( NamedElement mb : mbs ){
System.out.println( " NAMEDMEMBERS: " + mb.getClass() + mb.getName() );
}

EList<Profile> profiles = o.getAllAppliedProfiles();
for( Profile p : profiles ){
System.out.println( " \n\n\n PROFILE: " + p.getName() );
EList<Stereotype> stes = p.getAppliedStereotypes();
for(Stereotype ste : stes ){
System.out.println( "\n\n PROFILE STEREOTYPES: " + ste.getName() );
}
}

for(NamedElement ne : o.getOwnedMembers()){
System.out.println( ne.getClass() + " - " + ne.getName() );

if( ne instanceof org.eclipse.uml2.uml.Package ){
System.out.println("\n\nINSTANCE OF PACKAGE:");

EList<Stereotype> ste = ne.getAppliedStereotypes();
for( Stereotype s : ste ){
System.out.println("\n\n\nINSTANCE OF STEREOTYPES: " + s.getName());
}

}

}

}

private Profile reloadProfile() {
ResourceSet resourceSet = new ResourceSetImpl();

Resource inputResource = resourceSet.createResource(URI
.createFileURI("MyProfile.profile.uml"));
try {
inputResource.load(null);
} catch (IOException exception) {
exception.printStackTrace();
}

Iterator iterator = inputResource.getAllContents();
while (iterator.hasNext()) {
Object currentObject = iterator.next();
if (currentObject instanceof Profile) {
return (Profile) currentObject;
}
}
return null;
}




}


best regards!
=)
Re: Continuing saga of the standalone app [message #626943 is a reply to message #477737] Tue, 23 September 2008 19:25 Go to previous message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

Victor,
The link to the profile does not work.

"Victor Hugo" <victorhcf@gmail.com> wrote in message
news:9eac12420be6134540295db21a1db739$1@www.eclipse.org...
> Hi Friends,
>
> thanks for yours answers! but... my problem continue...
>
> i tried to execute the Jeff's answer but without success!
> and as James request...
> My full application can be found in this link:
> the profile in this:
> http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/Profile_for_crossmda_profile-1.11.profile
> the data model (bussiness):
> http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/model_teste.uml
> ths aspects model:
> http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/mo dels/model_aspects.uml
> my java class thats load the model in this:
> http://www.info.ufrn.br/~victorhugo//uml2/TesteLoadModels/sr c/test/Test.java
>
> sorry about permission of directory to navigate into then, but i cannot
> control this in server.
>
>
> my problem is because i cannot load stereotypes that models has, i have to
> apply profile before load model, how i can do this?
>
>
> to simplify to yours here is the java code that i'm using to load models:
>
> package test;
>
> import java.io.IOException;
> import java.util.Iterator;
> import java.util.Map;
>
> import org.eclipse.emf.common.util.EList;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.EcorePackage;
> import org.eclipse.emf.ecore.EPackage.Registry;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.emf.mapping.ecore2xml.Ecore2XMLPackage;
> import org.eclipse.emf.mapping.ecore2xml.util.Ecore2XMLResource;
> import org.eclipse.uml2.uml.Model;
> import org.eclipse.uml2.uml.NamedElement;
> import org.eclipse.uml2.uml.Profile;
> import org.eclipse.uml2.uml.Stereotype;
> import org.eclipse.uml2.uml.UMLFactory;
> import org.eclipse.uml2.uml.UMLPackage;
> import org.eclipse.uml2.uml.resource.UML22UMLExtendedMetaData;
> import org.eclipse.uml2.uml.resource.UML22UMLResource;
> import org.eclipse.uml2.uml.resource.UMLResource;
> import org.eclipse.uml2.uml.resource.UML22UMLResource.Factory;
>
> public class Test {
>
> private ResourceSet resourceSet = null;
> private Resource model = null;
> private UMLResource uml2Resource = null;
> private Profile profile = null;
>
> @SuppressWarnings("unchecked")
> protected void registerPathmaps(URI umlResourcePluginURI) {
>
> String pathResource =
> " /home/ceara/dev/mestrado/workspace/TesteLoadModels/lib/org.e clipse.uml2.uml.resources_2.2.0.v200805131030.jar ";
> URI resourcePluginURI = URI.createURI("jar:file:/" + pathResource + "!/");
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> Map uriMap = resourceSet.getURIConverter().getURIMap();
>
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
> resourcePluginURI.appendSegment("libraries").appendSegment( ""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
> resourcePluginURI.appendSegment("metamodels").appendSegment( ""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
> resourcePluginURI.appendSegment("profiles").appendSegment( ""));
>
> }
>
> protected void registerExtensions() {
>
> Map<String, Object> extensionFactoryMap =
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( );
>
> extensionFactoryMap.put(UMLResource.FILE_EXTENSION,UMLResour ce.Factory.INSTANCE);
>
> extensionFactoryMap.put(Ecore2XMLResource.FILE_EXTENSION,Eco re2XMLResource.Factory.INSTANCE);
>
> extensionFactoryMap.put(UML22UMLResource.FILE_EXTENSION,UML2 2UMLResource.Factory.INSTANCE);
>
> }
>
> protected void registerPackages(ResourceSet resourceSet) {
>
> Registry packageRegistry = resourceSet.getPackageRegistry();
> packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>
> packageRegistry.put(Ecore2XMLPackage.eNS_URI,Ecore2XMLPackag e.eINSTANCE);
>
> packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>
> }
>
> public Model getModel(URI resourceURI) {
>
> resourceSet = new ResourceSetImpl();
>
> registerPathmaps(null);
> registerPackages(resourceSet);
> registerExtensions();
>
> Map<URI, URI> uriMap = UML22UMLExtendedMetaData.getURIMap();
>
> resourceSet.getURIConverter().getURIMap().putAll(uriMap);
>
> try {
> model = resourceSet.getResource(resourceURI, true);
> model.save(null);
> EcoreUtil.resolveAll(model);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> if ( !(model instanceof UMLResource)) {
> try {
> throw new Exception("Modelo carregado esta inv&#65533;lido!");
> } catch (Exception e) {
> e.printStackTrace();
> System.out.println( "OoOps..!" );
> }
> }
>
> this.uml2Resource = (UMLResource) model;
>
> return null;
>
> }
>
> public static void main(String[] args) {
>
> String fileToOpen =
> " /home/ceara/dev/mestrado/workspace/TesteLoadModels/models/mo del_teste.uml ";
>
> Test t = new Test();
> t.getModel(URI.createFileURI(fileToOpen));
>
> }
>
> public void displayAllElements() {
> //Model o =
> (Model)xmiutils.getUML2Resource().getContents().iterator().n ext();
> Model o = (Model)uml2Resource.getContents().iterator().next();
>
> EList<NamedElement> mbs = o.getMembers();
> for( NamedElement mb : mbs ){
> System.out.println( " NAMEDMEMBERS: " + mb.getClass() + mb.getName() );
> }
>
> EList<Profile> profiles = o.getAllAppliedProfiles();
> for( Profile p : profiles ){
> System.out.println( " \n\n\n PROFILE: " + p.getName() );
> EList<Stereotype> stes = p.getAppliedStereotypes();
> for(Stereotype ste : stes ){
> System.out.println( "\n\n PROFILE STEREOTYPES: " + ste.getName() );
> }
> }
>
> for(NamedElement ne : o.getOwnedMembers()){
> System.out.println( ne.getClass() + " - " + ne.getName() );
>
> if( ne instanceof org.eclipse.uml2.uml.Package ){
> System.out.println("\n\nINSTANCE OF PACKAGE:");
>
> EList<Stereotype> ste = ne.getAppliedStereotypes();
> for( Stereotype s : ste ){
> System.out.println("\n\n\nINSTANCE OF STEREOTYPES: " + s.getName());
> }
>
> }
>
> }
>
> }
>
> private Profile reloadProfile() {
> ResourceSet resourceSet = new ResourceSetImpl();
>
> Resource inputResource = resourceSet.createResource(URI
> .createFileURI("MyProfile.profile.uml"));
> try {
> inputResource.load(null);
> } catch (IOException exception) {
> exception.printStackTrace();
> }
>
> Iterator iterator = inputResource.getAllContents();
> while (iterator.hasNext()) {
> Object currentObject = iterator.next();
> if (currentObject instanceof Profile) {
> return (Profile) currentObject;
> }
> }
> return null;
> }
>
>
>
>
> }
>
>
> best regards!
> =)
>
>
Previous Topic:[Announce] MDT UML2 2.2.1 is available
Next Topic:[Announce] MDT UML2 3.0.0M2 is available
Goto Forum:
  


Current Time: Thu Apr 18 13:42:45 GMT 2024

Powered by FUDForum. Page generated in 0.04130 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top