|
Re: UML save to *.uml file [message #998706 is a reply to message #998692] |
Thu, 10 January 2013 14:34 |
|
Hi, Florian,
Does your code run in the context of an Eclipse instance? If so, then
you don't need to manage any resource factory registrations. If not,
then the UMLResourcesUtil::init(ResourceSet) method will set up the
proper resource factories and other configuration of your ResourceSet.
In particular, you are missing the registration of the UMLResource
implementation, which provides the UTF-8 encoding, XMI IDs, etc.
BTW, your code probably has a memory leak: You're putting the Package
into a resource in a resource set. These will all be retained in
memory by the static CacheAdapter, along with the entire contents of
the package. When working with UML models, you *must* always maintain
your UML resources explicitly in a ResourceSet and ensure that you
unload all of your UML resources and clear the adapters of your
ResourceSet when you have finished with them.
HTH,
Christian
On 2013-01-10 14:15:12 +0000, Florian Wartenberg said:
> I am currently using the following method to save my UML Model.
>
>
> public static void saveModel(org.eclipse.uml2.uml.Package package_,
> URI uri)
> {
> Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new
> XMIResourceFactoryImpl());
>
> Resource resource = new ResourceSetImpl().createResource(uri);
> resource.getContents().add(package_);
> try {
> resource.save(null);
> } catch (IOException ioe) {
> }
> }
>
> It is working fine but I recently discovered that it is slightly
> different from *.uml files created with Papyrus or Topcased:
>
> 1. The File Header changes from <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmi:id="_qb8akM37EdqwVrslYOdUDA" name="eShopModel" viewpoint="">
>
> to
> <?xml version="1.0" encoding="ASCII"?>
> <uml:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" name="eShopModel"
> viewpoint="">
>
> 2. <subvertex xmi:type="uml:State" xmi:id="_mq2sED0qEeKGTJtY_dTOTg"
> name="Product Selection">
> changes to
> <subvertex xsi:type="uml:State" name="Product Selection">
> Especially the lost id's and the different file encoding are problems.
>
> Is there a chance to configure this?
>
> regards
> F. Wartenberg
|
|
|
|
|
|
|
Re: UML save to *.uml file [message #1000776 is a reply to message #1000728] |
Tue, 15 January 2013 12:19 |
|
Hi, Florian,
Your resource is null because the resource set couldn't create it.
Most likely it didn't find a suitable resource factory for the URI that
you specified. Because you initialized the resource set, probably the
URI doesn't have the *.uml file extension? What is the URI that you
are using?
HTH,
Christian
On 2013-01-15 10:40:35 +0000, Florian Wartenberg said:
> I am now using this method to save the model as suggested here:
> http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Getting_Started_with_UML2/article.html
>
>
>
> public static void saveModel(org.eclipse.uml2.uml.Package package_,
> URI uri) {
> ResourceSet resourceSet = new ResourceSetImpl();
> UMLResourcesUtil.init(resourceSet); // MDT/UML2 4.0.0 (Juno)
> Resource resource = resourceSet.createResource(uri);
> resource.getContents().add(package_);
>
> try {
> resource.save(null);
> } catch (IOException ioe) {
> }
> }
>
>
> But I always get this error: Exception in thread "main"
> java.lang.NullPointerException
> at <packagename>.UMLModelSaver.saveModel(UMLModelSaver.java:36)
>
> Line 36 is this line of Code:
> resource.getContents().add(package_);
>
> What am I not taking into account or overlooking?
>
> Regards
>
> Florian
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03177 seconds