EJB 2.0 requires that CMP fields be defined by the bean provider using
abstract methods, thusly:

public abstract class MyBean implements EntityBean {

    public abstract String getMyField();

    public abstract void setMyField(String value);
}

This approach suffers from two drawbacks:

1. Dynamic proxy implementations (such as JBoss) cannot extend the class
dynamically.

2. Name pollution. Suppose I want to check the validity of the argument to
setMyField() before storing it. I am forced to invent a new name
(getMyFieldUnchecked(), setMyFieldUnchecked()) in addition to getMyField()
and setMyField().

An possible solution would be to have the bean provider define an interface
for the abstract schema instead of abstract methods:

public class MyBean implements EntityBean {

    public interface MySchema extends AbstractSchema {
        // AbstractSchema is a marker interface

        String getMyField();
        void setMyField(String value);
    }

    // The 'schema' variable is set by the container. ejb-jar.xml
    // contains the name of the variable. The type is inferred.
    public MySchema schema;

    public void setMyField(String value) {
        if (value == null) value = "foobar";
        if (value.length() > 10) value = value.substring(0, 10);
        schema.setMyField(value);
        debugger.log("Done setting MyField to " + value);
    }

    public String getMyField() {
        return schema.getMyField();
    }

}

Any comments?

Also, does anyone know if such a change has a chance getting into 2.0 final?

- Avi
--
s/\be(\w+)/e-\1/g;

===========================================================================
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