Chris Harris wrote:
>
> My question is this: since these methods are abstract, how
> can I validate input coming in via a setXXX() method? Does
> this approach mean I can no longer put logic in my entity
> beans? Does this mean I am reduced to putting a session
> bean in front of the entities and putting my validation
> there (ugly)?

The first rule of CMP 2.0 is - don't expose CMR methods to the world
through remote interfaces. With this, there seems to be the flavour that
CMP fields also should not be directly exposed to remote users. The
emphasis seems to be very heavy on the new local interface capabilities
and keeping as much locally as possible. Though not directly stated,
when reading the spec and the tutorial snaps from Sun, that seems to be
the general direction they want programmers to head in.

The approach to this appears to be - have the remote interface provide a
method that does verification and then use the CMP methods to store the
checked values. Effectively you don't expose any of the CMP/CMR methods
through either the remote or local interface unless they are trivial and
require no range/value checking.

Say you had a stock counter variable that was being managed by the
container. Obviously, it does not make sense to let the value become
negative so some range checking is needed before storing the value. You
might end up with code like this:

public interface StockItem extends EJBObject {
  public void updateStockCount(int count)
    throws IllegalArgumentException;
}

public abstract class StockItemBean implements EntityBean {

  ...

  public abstract void setStockCount(int count);
  public abstract int getStockCount();

  public void updateStockCount(int count)
    throws IllegalArgumentException {

    if(count < 0)
      throw new IllegalArgumentException("Negative stock count");

    setStockCount(count);
  }
}

--
Justin Couch                         http://www.vlc.com.au/~justin/
Freelance Java Consultant                  http://www.yumetech.com/
Author, Java 3D FAQ Maintainer                  http://www.j3d.org/
-------------------------------------------------------------------
"Humanism is dead. Animals think, feel; so do machines now.
Neither man nor woman is the measure of all things. Every organism
processes data according to its domain, its environment; you, with
all your brains, would be useless in a mouse's universe..."
                                              - Greg Bear, Slant
-------------------------------------------------------------------

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