Floyd Marinescu wrote:
>
> A good idea when designing entity beans is to keeping bulk accessors of
> entity beans (ie: Value Object factory methods) separate from the entity
> bean itself.
>
> ...
>       Does anyone have any ideas on how to extract value object creation
> from an entity bean?

How about the following. Add two methods to your remote interface:

public class MyEntityImpl ...
{
    void setValueObject(String name, Object value)
    {
        String factoryName = 
_context.getEJBObject().getEJBHome().getMetaData().getRemoteInterfaceClass().getName()
                             + name;
        Class factoryClass = getClassLoader().loadClass(factoryName, true);
        ValueObjectFactory factory = (ValueObjectFactory)factoryClass.newInstance();
        factory.set(this, value);
    }

    Object getValueObject(String name)
    {
        String factoryName = 
_context.getEJBObject().getEJBHome().getMetaData().getRemoteInterfaceClass().getName()
                             + name;
        Class factoryClass = getClassLoader().loadClass(factoryName, true);
        ValueObjectFactory factory = (ValueObjectFactory)factoryClass.newInstance();
        return factory.get(this, name);
    }
}

public interface ValueObjectFactory
{
    public void set(EntityBean entity, Object value);
    public Object get(EntityBean entity);
}

Now if you create a new value object called MyEntityDetails, you
could use (from a client):

    MyEntityDetails details = (MyEntityDetails)entity.getValueObject("Details");

and so on.

When you implement the ValueObjectFactory class for MyEntityDetails, note that
you can access the entity instance directly instead of through remote calls.
________________________________________________________________________________

Evan Ireland              Sybase EAServer Engineering        [EMAIL PROTECTED]
                            Wellington, New Zealand               +64 4 934-5856

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to