Home » Modeling » UML2 » Same Model Load method returns different results
Same Model Load method returns different results [message #475856] |
Wed, 12 September 2007 21:50 |
Jerry Messages: 32 Registered: July 2009 |
Member |
|
|
Dear,
I have a uml model which is defined in Eclipse (let's say mymodel.uml, it
contains a model called "umltry"). There are profiles applied in this
model. Starting a new Eclipse, simply I would like to open that model and
extract information. I used the way given in the "instruction to UML"
profiles" article, but got strange results:
Case1) I use following referenced libararies
(Eclipse32)org.eclipse.osgi_3.2.0.V20060601.jar,
org.eclipse.uml2.common_1.2.3v200702141227.jar,
org.eclipse.uml2.uml.resources_2.0.3v20070214227.jar,
org.eclipse.emf.ecore.xmi_2.2.1v200701181044.jar,
org.eclipse.emf.ecore_2.2.2.v200701181044.jar... etc.
Case2) I use Eclipse 33 instead: org.eclipse.osgi_3.3.0.V20070530.jar,
org.eclipse.uml2.common_1.3.0v200706251652.jar,
org.eclipse.uml2.uml.resources_2.1.0v200706251652.jar,
org.eclipse.emf.ecore.xmi_2.3.0.v200706262000.jar,
org.eclipse.emf.ecore_2.3.0.v200706262000.jar... etc.
<<
public static void main(String[] arg){
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
URI uri = URI.createFileURI("C:\\mymodel.uml");
Model mymodels= (Model) load(uri);
//(**Here it returns null in debug in both Case1 and Case2. Why?**)
ResourceSet resSet=new ResourceSetImpl();
resSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Resource res = resSet.getResource(uri,true);
//(** In Case1:Here the first element of the content of the res
is: org.eclipse.uml2.uml.internal.impl.ModelImpl@18b995c (name: umltry,
visibility: <unset>) (visibility: public) (viewpoint: <unset>). BUT in
Case2, the first element in the content of res is:
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@e5ddd0 (eClass:
org.eclipse.emf.ecore.impl.EClassImpl@145959c (name: Model) **)
Model UMLmodel = (Model)res.getContents().get(0);
//(**if I continue with the above line, in Case1, I get the model
correctly. In Case2 I got Exception in thread "main"
java.lang.ClassCastException:
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl **)
//** Following is the load method used**
protected static org.eclipse.uml2.uml.Package load(URI uri) {
org.eclipse.uml2.uml.Package package_ = null;
org.eclipse.uml2.uml.Model model =null;
try {
Resource resource = RESOURCE_SET.getResource(uri, true);
package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
.getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE);
model = (Model)EcoreUtil.getObjectByType(resource.getContents(),
UMLPackage.Literals.MODEL);
}
catch (WrappedException we) {
err(we.getMessage());
System.exit(1);
}
return package_;
}
>>
Could you please explain this? How could I load the model and extract
information from it in Eclipse3.3?
Thank you very much!
|
|
|
Re: Same Model Load method returns different results [message #475860 is a reply to message #475856] |
Thu, 13 September 2007 13:55 |
james bruck Messages: 1724 Registered: July 2009 |
Senior Member |
|
|
Hi Jerry,
Have a look at this article :
http://www.eclipse.org/modeling/mdt/uml2/docs/guides/UML2_2. 0_Migration_Guide/guide.html
at the section entitled: "Programmatic Migration".
That will give more details on how to open up a .uml file in a 'standalone'
application, which it looks like you are doing ( I believe you are not
registering packages and pathmaps ).
If you try that and it still doesn't work, please repost a question.
Cheers,
- James.
"Jerry" <jianlin@md.kth.se> wrote in message
news:ca173502a7f931585427490018ff6284$1@www.eclipse.org...
> Dear,
>
> I have a uml model which is defined in Eclipse (let's say mymodel.uml, it
> contains a model called "umltry"). There are profiles applied in this
> model. Starting a new Eclipse, simply I would like to open that model and
> extract information. I used the way given in the "instruction to UML"
> profiles" article, but got strange results:
>
> Case1) I use following referenced libararies
> (Eclipse32)org.eclipse.osgi_3.2.0.V20060601.jar,
> org.eclipse.uml2.common_1.2.3v200702141227.jar,
> org.eclipse.uml2.uml.resources_2.0.3v20070214227.jar,
> org.eclipse.emf.ecore.xmi_2.2.1v200701181044.jar,
> org.eclipse.emf.ecore_2.2.2.v200701181044.jar... etc.
>
> Case2) I use Eclipse 33 instead: org.eclipse.osgi_3.3.0.V20070530.jar,
> org.eclipse.uml2.common_1.3.0v200706251652.jar,
> org.eclipse.uml2.uml.resources_2.1.0v200706251652.jar,
> org.eclipse.emf.ecore.xmi_2.3.0.v200706262000.jar,
> org.eclipse.emf.ecore_2.3.0.v200706262000.jar... etc.
> <<
> public static void main(String[] arg){
>
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResourc
e.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> URI uri = URI.createFileURI("C:\\mymodel.uml");
> Model mymodels= (Model) load(uri);
>
> //(**Here it returns null in debug in both Case1 and Case2.
Why?**)
>
> ResourceSet resSet=new ResourceSetImpl();
> resSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(UMLResour
ce.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> Resource res = resSet.getResource(uri,true);
>
> //(** In Case1:Here the first element of the content of the res
> is: org.eclipse.uml2.uml.internal.impl.ModelImpl@18b995c (name: umltry,
> visibility: <unset>) (visibility: public) (viewpoint: <unset>). BUT in
> Case2, the first element in the content of res is:
> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@e5ddd0 (eClass:
> org.eclipse.emf.ecore.impl.EClassImpl@145959c (name: Model) **)
>
> Model UMLmodel = (Model)res.getContents().get(0);
>
> //(**if I continue with the above line, in Case1, I get the model
> correctly. In Case2 I got Exception in thread "main"
> java.lang.ClassCastException:
> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl **)
> //** Following is the load method used**
> protected static org.eclipse.uml2.uml.Package load(URI uri) {
> org.eclipse.uml2.uml.Package package_ = null;
> org.eclipse.uml2.uml.Model model =null;
> try {
> Resource resource = RESOURCE_SET.getResource(uri, true);
> package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
> .getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE);
> model = (Model)EcoreUtil.getObjectByType(resource.getContents(),
> UMLPackage.Literals.MODEL);
> }
> catch (WrappedException we) {
> err(we.getMessage());
> System.exit(1);
> }
> return package_;
> }
>
> >>
> Could you please explain this? How could I load the model and extract
> information from it in Eclipse3.3?
> Thank you very much!
>
>
>
>
|
|
| |
Re: Same Model Load method returns different results [message #624751 is a reply to message #475856] |
Thu, 13 September 2007 13:55 |
james bruck Messages: 1724 Registered: July 2009 |
Senior Member |
|
|
Hi Jerry,
Have a look at this article :
http://www.eclipse.org/modeling/mdt/uml2/docs/guides/UML2_2. 0_Migration_Guide/guide.html
at the section entitled: "Programmatic Migration".
That will give more details on how to open up a .uml file in a 'standalone'
application, which it looks like you are doing ( I believe you are not
registering packages and pathmaps ).
If you try that and it still doesn't work, please repost a question.
Cheers,
- James.
"Jerry" <jianlin@md.kth.se> wrote in message
news:ca173502a7f931585427490018ff6284$1@www.eclipse.org...
> Dear,
>
> I have a uml model which is defined in Eclipse (let's say mymodel.uml, it
> contains a model called "umltry"). There are profiles applied in this
> model. Starting a new Eclipse, simply I would like to open that model and
> extract information. I used the way given in the "instruction to UML"
> profiles" article, but got strange results:
>
> Case1) I use following referenced libararies
> (Eclipse32)org.eclipse.osgi_3.2.0.V20060601.jar,
> org.eclipse.uml2.common_1.2.3v200702141227.jar,
> org.eclipse.uml2.uml.resources_2.0.3v20070214227.jar,
> org.eclipse.emf.ecore.xmi_2.2.1v200701181044.jar,
> org.eclipse.emf.ecore_2.2.2.v200701181044.jar... etc.
>
> Case2) I use Eclipse 33 instead: org.eclipse.osgi_3.3.0.V20070530.jar,
> org.eclipse.uml2.common_1.3.0v200706251652.jar,
> org.eclipse.uml2.uml.resources_2.1.0v200706251652.jar,
> org.eclipse.emf.ecore.xmi_2.3.0.v200706262000.jar,
> org.eclipse.emf.ecore_2.3.0.v200706262000.jar... etc.
> <<
> public static void main(String[] arg){
>
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResourc
e.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> URI uri = URI.createFileURI("C:\\mymodel.uml");
> Model mymodels= (Model) load(uri);
>
> //(**Here it returns null in debug in both Case1 and Case2.
Why?**)
>
> ResourceSet resSet=new ResourceSetImpl();
> resSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
>
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(UMLResour
ce.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> Resource res = resSet.getResource(uri,true);
>
> //(** In Case1:Here the first element of the content of the res
> is: org.eclipse.uml2.uml.internal.impl.ModelImpl@18b995c (name: umltry,
> visibility: <unset>) (visibility: public) (viewpoint: <unset>). BUT in
> Case2, the first element in the content of res is:
> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@e5ddd0 (eClass:
> org.eclipse.emf.ecore.impl.EClassImpl@145959c (name: Model) **)
>
> Model UMLmodel = (Model)res.getContents().get(0);
>
> //(**if I continue with the above line, in Case1, I get the model
> correctly. In Case2 I got Exception in thread "main"
> java.lang.ClassCastException:
> org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl **)
> //** Following is the load method used**
> protected static org.eclipse.uml2.uml.Package load(URI uri) {
> org.eclipse.uml2.uml.Package package_ = null;
> org.eclipse.uml2.uml.Model model =null;
> try {
> Resource resource = RESOURCE_SET.getResource(uri, true);
> package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
> .getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE);
> model = (Model)EcoreUtil.getObjectByType(resource.getContents(),
> UMLPackage.Literals.MODEL);
> }
> catch (WrappedException we) {
> err(we.getMessage());
> System.exit(1);
> }
> return package_;
> }
>
> >>
> Could you please explain this? How could I load the model and extract
> information from it in Eclipse3.3?
> Thank you very much!
>
>
>
>
|
|
| |
Goto Forum:
Current Time: Fri Apr 26 06:19:30 GMT 2024
Powered by FUDForum. Page generated in 0.03149 seconds
|