[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.mdt.uml2] Re: Continuing saga of the standalone app
|
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@xxxxxxxxxx> wrote in message
news:g62q94$8in$1@xxxxxxxxxxxxxxxxxxxx
> 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.METAMODELS_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@xxxxxxxxxxxxx> wrote in message
> news:g5rbqt$kmk$1@xxxxxxxxxxxxxxxxxxxx
>> 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@xxxxxxxxxx> wrote in message
>> news:g5q81a$42a$1@xxxxxxxxxxxxxxxxxxxx
>>> 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@xxxxxxxxxxxxxxx> wrote in message
>>> news:g5o96q$ph2$1@xxxxxxxxxxxxxxxxxxxx
>>>> 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.getImportedPackage(PackageImportImpl.java:204)
>>>>
>>>> at
>>>> org.eclipse.uml2.uml.internal.operations.NamespaceOperations.getImportedPackages(NamespaceOperations.java:207)
>>>>
>>>> at
>>>> org.eclipse.uml2.uml.internal.impl.NamespaceImpl.getImportedPackages(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.
>>>>
>>>
>>>
>>
>>
>>
>
>