[mdr-users] RE: NullPointer Exception with MDR StandAlone
"ludger goeke" <[email protected]> Sat, 28 Jan 2006 10:32:55 +0100 (MET)
| Newsgroups | gmane.comp.java.netbeans.modules.mdr.user |
|---|---|
| Message-ID | <[email protected]> |
Hallo Luiz Felipe,
I think I had a similar problem. I have denoted the whole path of the
storage file. For example :
private String storageFile=
"C:\\myApplication\\mdrStorageFiles\\MDRStorage";
That works, but I must change it someday because it is not very elegant.
Another thing is that I sloved the access to the standalone NBMDR in
another way. Thereby I look about the example on the NBMDR site and the
source code of the UML2MOF tool that is also on the netbeans site.
I didn't use this constructor :
MDRepository repository = new NBMDRepositoryImpl(properties);
I use the following code to get access to the standalone nbmdr
// here I start the initalization
public void initMDR(){
manager=getMDRManager();
repository=manager.getDefaultRepository();
if((repository.getExtent(modelPackageName))==null){
instantiateModelPackage();
createExtent("Default");
}
}
// this is nearly the same code that was used in the uml2mof tool
public MDRManager getMDRManager() {
ClassLoader oldLoader = Thread.currentThread().
getContextClassLoader();
Thread.currentThread().setContextClassLoader( this.getClass().
getClassLoader() );
if ( storageFile != null ) {
System.getProperties().
put( "org.netbeans.mdr.persistence.Dir", storageFile );
}
MDRManager mm = MDRManager.getDefault();
Thread.currentThread().setContextClassLoader( oldLoader );
return mm;
}
// this method initializes the modelpackage
private void instantiateModelPackage(){
ModelPackage modelpackage;
try
{
repository.beginTrans( true );
try{
modelpackage = ( ModelPackage) repository.
createExtent(modelPackageName);
if(modelpackage!=null){
try{
XMIReader xmiReader =
XMIReaderFactory.getDefault().createXMIReader();
xmiReader.read( new File(metaModelFile).toURL().
toString(), repository.getExtent("MetaModel"));
}catch(Exception e){
System.out.println("The XMI file of the
MetaModel couldn`t be read "+e);
repository.endTrans(true);
}
}
}catch(CreationFailedException e){
System.out.println("The extent couldn´t be created "+e);
repository.endTrans(true);
}
}finally {
repository.endTrans();
}
}
/* with method creates the extent that I use for my application
public void createExtent(String name)
{
try
{
repository.beginTrans( true );
try
{
repository.createExtent(name, getModelPackage(modelPackageName));
System.out.println("The extent could be created");
}catch(CreationFailedException e)
{
System.out.println("The extent couldn´t be created "+e);
repository.endTrans(true);
}
} finally {
repository.endTrans();
}
}
Regards
Ludger
--
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner