How to call createObject from within an OzoneObject?
Arjen van der Meijden <[email protected]>
| Newsgroups | gmane.comp.java.ozone.user |
|---|---|
| Message-ID | <[email protected]> |
Hi list,
I've been playing around with Ozone, but ran into a small problem:
When I create an Object via database.createObject and that newly created
object wants to create another OzoneObject (say an OzoneMap), that fails
in my current code.
Below in the example-code is a marker, and there the code fails, the
Ozone-database doesn't know about any OzonePlugIn (actually it is the
org.apache.struts.plugin.PlugIn it doesn't know about).
But even if this code would work, my object would reference the database
"it is being created in" via some external, client-side, reference...
So, what is the best way to retrieve some local reference, to the
database the object is being created in and use that reference to create
member-objects?
My current implementation is something like this:
class OzonePlugIn extends PlugIn // struts plugin
{
private static ExternalDatabase db;
public static ExternalDatabase getDatabase()
{
return db;
}
public void init()
{
db = ExternalDatabase.openDatabase(...);
}
}
class OzoneAccess
{
public static OzoneObject createObject(Class objectClass)
{
return OzonePlugIn.getDatabase().createObject(objectClass);
}
public static OzoneMap createNodeMap()
{
return (OzoneMap) createObject(OzoneNodeTreeMapImpl.class);
}
}
interface Foo extends OzoneRemote
{}
class FooImpl extends OzoneObject
{
private Map datastore;
public FooImpl
{
datastore = OzoneAccess.createNodeMap();
}
}
class Client
{
public void doSomething()
{
// MARKER
Foo foo = OzoneAccess.createObject(FooImpl.class);
}
}
Best regards,
Arjen van der Meijden
-------------------------------------------------------
This SF.Net email is sponsored by Sleepycat Software
Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to deliver
higher performing products faster, at low TCO.
http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3