The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

st_clair (8) [Avatar] Offline
#1
Hello,

Hello,

In a previous post an author gave the following as a method of setting Neodatis classloader as the Groovy classloader thus allowing persistence of Groovy classses in Neodatis:

// Gets the Groovy ClassLoader
GroovyClassLoader gcl = new GroovyClassLoader();

new GroovyScriptEngine( "", gcl );

// Sets the Groovy ClassLoader as the default NeoDatis Odb ClassLoader
Configuration.setClassLoader( gcl );

// Loads Groovy classes in the Groovy ClassLoader
gcl.parseClass( new File( "scripts\Costumer.groovy" ) );

I am trying to load an an OSGi service which I have done successfully. In the OSGi plugin I have accessed the service and called getters and setters successfully.

However, I am having problems storing the service class or objects which are part of the service graphy in Neodatis ODB.

I am sure it is because the Neodatis class loader is not set for the service properly, but I cannot solve it.

I cannot parse the src file as shown above:

gcl.parseClass( new File( "scripts\Costumer.groovy" ) );

bacause it is a service and I am actually calling the class using the current plugin BundleContext.

So, how can this be done?

Below is the code of my Plugin with the code that generates a CNFE for both the Name and Patient classes:

=======================================================================================================

package biz.epims.reg.ui;


import groovy.lang.GroovyClassLoader;

import groovy.util.GroovyScriptEngine;

import biz.epims.db.core.odb.nodb.connection.NODBConnection;

import biz.epims.reg.core.groovy.model.service.IPatient;

import biz.epims.reg.core.groovy.model.service.demography.IName;

import org.eclipse.jface.resource.ImageDescriptor;

import org.eclipse.ui.plugin.AbstractUIPlugin;

import org.neodatis.odb.Configuration;
import org.neodatis.odb.ODB;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;



public class RegUIPlugin extends AbstractUIPlugin
{


//The shared instance.
private static RegUIPlugin plugin;


/** The nODB ODB @tag DOCUMENT -date=February 3, 2009. */
public ODB nODB = null;

private IPatient patient;
private NODBConnection nODBConxn;
private ServiceReference nODBConxnSrvcRef;
private ServiceReference patientSrvcRef;


public RegUIPlugin()
{
plugin = this;

} // end ctor RegUIPlugin



public void start( BundleContext context ) throws Exception
{
super.start( context );

patientSrvcRef = context.getServiceReference( IPatient.class.getName() );
patient = ( IPatient ) context.getService( patientSrvcRef );


nODBConxnSrvcRef = context.getServiceReference( NODBConnection.class.getName() );
nODBConxn = ( NODBConnection ) context.getService( nODBConxnSrvcRef );
nODBConxn.isLocalModeUsed();


// Set Groovy classloader as Neodatis default classloader before the database is opened.

// Gets the Groovy ClassLoader
GroovyClassLoader gcl = new GroovyClassLoader();

new GroovyScriptEngine( "", gcl );

// Sets the Groovy ClassLoader as the default NeoDatis Odb ClassLoader
Configuration.setClassLoader( gcl );

// Loads Groovy classes in the Groovy ClassLoader
gcl.parseClass( new File( "scripts\Costumer.groovy" ) );


nODB = NODBConnection.open();


ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();

try
{
IName name = patient.getName();

name.setFirstName( "St Clair" );
name.setLastName( "Clarke" );
name.setMiddleName( "Seymour" );
name.setGender( "Male" );
name.setSuffix( "Sr" );
name.setTitle( "Dr" );

patient.setName( name );

// gcl.parseClass( name );

System.out.println( name );

// CULPRIT: patient CANNOT BE FOUND
nODB.store( patient );

}
finally
{
Thread.currentThread().setContextClassLoader( originalClassLoader );

} // end try-finally

} // end method start


public void stop( BundleContext context ) throws Exception
{
super.stop( context );

context.ungetService( patientSrvcRef );
context.ungetService( nODBConxnSrvcRef );

plugin = null;

} // end method stop


public static RegUIPlugin getDefault()
{
return( plugin );

} // end method getDefault



public static ImageDescriptor getImageDescriptor( String path )
{
return( AbstractUIPlugin.imageDescriptorFromPlugin( "biz.epims.reg.ui", path ) );

} // end method getImageDescriptor

} // end class RegUIPlugin


=======================================================================================================

The exception stacktrace is shown below:

=======================================================================================================

!ENTRY org.eclipse.osgi 4 0 2009-02-10 18:34:32.498
!MESSAGE Application error
!STACK 1
org.eclipse.core.runtime.CoreException: Plug-in biz.epims.reg.ui was unable to load class biz.epims.reg.ui.Application.
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:180)
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:162)
at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:867)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:51)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:18smilie
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Caused by: org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter$TerminatingClassNotFoundException: An error occurred while automatically activating bundle biz.epims.reg.ui (4).
at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:125)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:427)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:193)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:36smilie
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:444)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:397)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:385)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:313)
at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:227)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1274)
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:160)
... 16 more
Caused by: org.osgi.framework.BundleException: Exception in biz.epims.reg.ui.RegUIPlugin.start() of bundle biz.epims.reg.ui.
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:102smilie
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:984)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:265)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:400)
at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:111)
... 28 more
Caused by: org.neodatis.odb.ODBRuntimeException:
ODB Release : 491 - 17-12-2008-23-39-15 - th=main
228:Error while creating (reflection) class biz.epims.reg.core.groovy.model.domain.Patient
at org.neodatis.odb.impl.core.layers.layer2.instance.ODBClassPool.getClass(ODBClassPool.java:64)
at org.neodatis.odb.impl.core.layers.layer1.introspector.AbstractClassIntrospector.getSuperClasses(AbstractClassIntrospector.java:359)
at org.neodatis.odb.impl.core.layers.layer1.introspector.AbstractClassIntrospector.getAllFields(AbstractClassIntrospector.java:397)
at org.neodatis.odb.impl.core.layers.layer1.introspector.AbstractClassIntrospector.internalIntrospect(AbstractClassIntrospector.java:27smilie
at org.neodatis.odb.impl.core.layers.layer1.introspector.AbstractClassIntrospector.introspect(AbstractClassIntrospector.java:243)
at org.neodatis.odb.core.layers.layer3.engine.AbstractStorageEngine.internalStore(AbstractStorageEngine.java:475)
at org.neodatis.odb.core.layers.layer3.engine.AbstractStorageEngine.store(AbstractStorageEngine.java:416)
at org.neodatis.odb.core.layers.layer3.engine.AbstractStorageEngine.store(AbstractStorageEngine.java:39smilie
at org.neodatis.odb.impl.main.ODBAdapter.store(ODBAdapter.java:9smilie
at biz.epims.reg.ui.RegUIPlugin.start(RegUIPlugin.java:165)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:1009)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1003)
... 33 more
Caused by: java.lang.ClassNotFoundException: biz.epims.reg.core.groovy.model.domain.Patient
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:18smilie
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:637)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:720)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at org.neodatis.odb.impl.core.layers.layer2.instance.ODBClassPool.getClass(ODBClassPool.java:62)
... 45 more
=======================================================================================================


I hope someone can help.
richard.hall (87) [Avatar] Offline
#2
Re: Classloader problem using Neodatis database
Wouldn't this question be better directed at a wider forum, like the Felix users mailing list?