Re: Re: MDR use problem

Martin Matula <[email protected]> Mon, 24 May 2004 22:30:43 +0200
Newsgroups gmane.comp.java.netbeans.modules.mdr.devel
Message-ID <[email protected]>
Hi,
I am confused by your messages. In the first message you wrote:

[sam adam] I have downloaded the MDR-standalone and copied the example 
“Projects metadata”. When I compiled and run the ProjectCreationDemo (as 
it is), I got the message: [Exception in thread "main" 
java.lang.NullPointerException ] returned by the getExtent method. I 
have noticed the files mdr.btd, mdr.btb and mdr.btx were though created.


But then you say that you also instantiated the metamodel in MDR 
browser. We are probably not in-sync on what we mean by "instantiation". 
Generating Java interafaces from the metamodel is one thing, but then 
you also have to create a new extent in MDR from the Projects package - 
this will create a new "sub-repository" capable of storing the metadata 
described by the projects metamodel.

In your first e-mail you also wrote:

[sam adam] I have then tried to test on the nullity of the extent and I 
tried to use the createExtent method as follows:

[ if (extent==null)

extent= (ProjectsPackage) repository.createExtent("Projects metadata"); ]

but I got the error message [unreported exception 
org.netbeans.api.mdr.CreationFailedException; must be caught or declared 
to be thrown

extent= (ProjectsPackage) repository.createExtent("Projects metadata");]


The error above (at the createExtent method) is a compilation error - 
all it says is that you have to wrap the createExtent method call by 
try-catch clause to catch CreationFailedException if thrown.
Anyway, the code is still wrong since it tries to create an extent named 
"Project metadata" but does not pass the metamodel package that the 
extent should conform to - this will result in creating an instance of 
MOF Model package rather than Projects package, so when running the code 
you will get ClassCastException when trying to cast the result to 
ProjectsPackage.
You probably figured this out, because the code in your second e-mail 
looks better:

sam adam wrote:

>
> MDRepository repository = MDRManager.getDefault().getDefaultRepository();
> ProjectsPackage extent= (ProjectsPackage) 
> repository.createExtent("projects metadata",projects); ]

But I do not know what you have in "projects" variable. So I am not able 
to tell whether your code is right or not. Does your code load metamodel 
of projects (using XMI)? Does it then find the Projects package in this 
loaded metamodel and pass it to "projects" variable? If so, then the 
code above should work. If you do not know how to load the metamodel and 
find the package, you can look at the Main class in UML2MOF tool (under 
mdr/extras/uml2mof in the cvs) - there you can find a similar code for 
loading and instantiating of UML 1.4 metamodel.
Regards,
Martin