[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

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@xxxxxxxxxx> wrote in message 
news:g657k1$7c1$1@xxxxxxxxxxxxxxxxxxxx
> 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@xxxxxxxxxxxxxxx> wrote in message 
> news:g651sr$mg2$1@xxxxxxxxxxxxxxxxxxxx
>> 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@xxxxxxxxxx> wrote in message 
>> news:g64nml$1ha$1@xxxxxxxxxxxxxxxxxxxx
>>>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@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.
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>
>