Re: [mdr-users] NullPointerException
Leonardo Gresta Paulino Murta <[email protected]> Tue, 19 Jul 2005 12:23:03 -0300
| Newsgroups | gmane.comp.java.netbeans.modules.mdr.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
You have just load the UML metamodel (M2). Now, you have to instantiate
this metamodel to create your UML model (M1). Try to do something like this:
repository.createExtent(name, modelPackage);
Where "name" is the name of your UML model and "modelPackage" is the M2
package ("UML" ou "Activity_Graphs", for example).
Leo
Cheng yong wrote:
> Hello, Leo and other MDR experts,
>
> I'm still litte confused about using MDR to create one activty graph in
> XMI.
>
> I tried to do following things:
>
> // connect to the repository
> MDRepository repository =
> MDRManager.getDefault().getDefaultRepository();
> ModelPackage modelPackage=null;
>
> // Init Repository with UML 1.4 metamodel (M2)
> try{
> modelPackage = (ModelPackage)repository.createExtent("TEST
> MODEL");
> URL xmiSpemMetamodel =
> this.getClass().getResource("01-02-15_Diff.xml");
> System.out.println( xmiSpemMetamodel.getContent().toString());
> XMIReader xmiReader =
> XMIReaderFactory.getDefault().createXMIReader();
> xmiReader.read(xmiSpemMetamodel.toString(),
> modelPackage);
> } catch(Exception e){
> e.printStackTrace();
> }
>
> According to the Leo's clues, I should init the activity model extent
> (M1), I found the MofPackage with the name "Activity_Graphs", but I
> don't know which resource file I should provide as metamodel. The
> metamodel is already included in 01-02-15_Diff.xml, istn't it? Why
> should do it again?
>
> I'm sorry to bother you with such questions. I hope that you can help me.
>
> regards
>
> lucia
>
>
> */Leonardo Gresta Paulino Murta <[email protected]>/* wrote:
>
> Hello,
>
> You need to load your metamodel first... Take a look on the following
> code (it uses SPEM metamodel, but the idea is almost the same for UML -
> In the case of UML you will need to search for a package named Model
> and
> instantiate it...):
>
> // Init Repository with SPEM metamodel (M2)
> ModelPackage modelPackage =
> (ModelPackage)repository.createExtent(METAMODEL_EXTENT);
> URL xmiSpemMetamodel = this.getClass().getResource(SPEM_METAMODEL);
> xmiReader.read(xmiSpemMetamodel.toString(), modelPackage);
>
> // Init the SPEM model extent (M1)
> Iterator iterator =
> modelPackage.getMofPackage().refAllOfClass().iterator();
> while (iterator.hasNext()) {
> MofPackage mofPackage = (MofPackage)iterator.next();
> if ("SPEM".equals(mofPackage.getName())) {
> spemPackage = (SpemPackage)repository.createExtent(MODEL_EXTENT,
> mofPackage);
> URL xmiSpemModel = this.getClass().getResource(SPEM_MODEL);
> xmiReader.read(xmiSpemModel.toString(), spemPackage);
> break;
> }
> }
>
> Leo
>
> Cheng yong wrote:
> > Hello, everyone,
> >
> > I'm now making my own example according to the online document
> and try
> > to figure out how the MDR works. Now I have got an
> NullPointerException
> > Error. Can anyone help me?
> >
> > What I did is as following:
> > 1. NetBeans IDE 3.5.1: imported Metadata UML 1.4
> (01-02-15_Diff.xml) and
> > generated the JMI Interfaces.
> > 2. Eclipse 3.1: created a new project, added all .jar files which
> I can
> > find in the installation folder, imported all generated files.
> > 3. Eclipse 3.1: created a new demo class,
> >
> > package demo;
> > import java.io.OutputStream;
> > import java.util.Iterator;
> > import org.netbeans.api.mdr.MDRManager;
> > import org.netbeans.api.mdr.MDRepository;
> > import org.netbeans.api.xmi.XMIWriterFactory;
> > import org.omg.uml.*;
> > import org.omg.uml.behavioralelements.activitygraphs.*;
> > public class Demo {
> >
> > public static void main(String[] args) {
> >
> > OutputStream out = null;
> >
> > MDRepository repository =
> > MDRManager.getDefault().getDefaultRepository();
> >
> > UmlPackage extent = (UmlPackage) repository.getExtent("Projects
> > metadata");
> > try{
> >
> >
> XMIWriterFactory.getDefault().createXMIWriter().write(out,extent,"1.2");
> > System.out.println(out.toString());
> > } catch(Exception e){
> > System.out.println("ERROR!");
> > }
> > }
> > }
> > 4. Eclipse 3.1: runed the demo, got the error:
> >
> > java.lang.NullPointerException
> > at
> >
> org.netbeans.modules.mdr.MDRManagerImpl.refreshChildren(MDRManagerImpl.java:61)
> > at
> org.netbeans.modules.mdr.MDRManagerImpl.init(MDRManagerImpl.java:84)
> > at
> >
> org.netbeans.modules.mdr.MDRManagerImpl.getRepository(MDRManagerImpl.java:94)
> > at
> >
> org.netbeans.modules.mdr.MDRManagerImpl.getDefaultRepository(MDRManagerImpl.java:105)
> > at demo.Demo.main(Demo.java:18)
> > Exception in thread "main"
> >
> > thanks
> >
> > Lucia
> >
> >
> ------------------------------------------------------------------------
> > Start your day with Yahoo! - make it your home page
> >
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>