Regarding Christian Ruediger's post, Damjan S. Vujnovic wrote:
> Can you specify your design goal more precisely, so we can help you?

Yes, that would help us help you. Can you explain exactly the reason you
are trying to use inheritance here? In my case, I created a base entity
bean (BaseEntityEJB) that all my entity beans extend. However, I
specified that the base bean had no interfaces or homes generated for
it. Further, the base class only implemented the
EJB-infrastructure-related methods (context, activate, passivate, store,
load and remove) and some other helper methods (getEjbName, trimName,
getPk and getNamePk). Thus no CMP fields nor business methods were
inherited.

If this is your goal, it's doable. I've included the code here in hopes
that it helps someone along the way. :) If not, describe what it is
you're trying to do.

David Harkness
Sr. Software Engineer
Sony Pictures Digital Networks
(310) 482-4756

---------- 8< ---------------------------------------- 8< ----------

package dd.ejb.entity.identity;


import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;

import dd.util.LogManager;
import org.apache.log4j.Logger;


/**
 * Base class for all entity beans.
 *
 * @ejb.bean
 *      generate="False"
 *      view-type="local"
 *      type="CMP"
 *      cmp-version="2.x"
 *
 * @ejb.interface
 *      generate="false"
 *
 * @ejb.home
 *      generate="false"
 *
 * @ejb.transaction
 *      type="Supports"
 *
 * @weblogic.transaction-isolation TRANSACTION_READ_COMMITTED
 *
 * @weblogic.delay-database-insert-until ejbPostCreate
 *
 * @weblogic.persistence
 *      finders-load-bean="False"
 *
 * @weblogic.cache
 *      concurrency-strategy="Database"
 *      cache-between-transactions="False"
 */
public abstract class BaseEntityEJB implements EntityBean
{
//-- LOGGING ------------------------------------------------------
LOGGING --

  /** Used for logging messages */
  private static Logger logger =
LogManager.getLogger(BaseEntityEJB.class);

  /** Returns <tt>true</tt> if debugging is enabled for this class's
logger. */
  private static boolean debugging ( ) { return logger.isDebugEnabled();
}

  /** Logs the given debug message to this class's logger. */
  private static void debug ( String msg ) { logger.debug(msg); }


//-- MEMBERS ------------------------------------------------------
MEMBERS --

  protected EntityContext context = null;

  private String ejbName = null;


//-- EJB METHODS ---------------------------------------------- EJB
METHODS --

  public void setEntityContext ( EntityContext ctx )
  {
    if ( debugging() ) debug("setEntityContext: " + getEjbName());
    context = ctx;
  }

  public void unsetEntityContext ( )
  {
    if ( debugging() ) debug("unsetEntityContext: " + getEjbName());
    context = null;
  }


  public void ejbActivate ( )
  {
    if ( debugging() ) debug("ejbActivate: " + getEjbName());
  }

  public void ejbPassivate ( )
  {
    if ( debugging() ) debug("ejbPassivate: " + getEjbName());
  }

  public void ejbLoad ( )
  {
    if ( debugging() ) debug("ejbLoad: " + getEjbName() + " " +
context.getPrimaryKey());
  }

  public void ejbStore ( )
  {
    if ( debugging() ) debug("ejbStore: " + getEjbName() + " " +
context.getPrimaryKey());
  }

  public void ejbRemove ( )
  throws RemoveException
  {
    if ( debugging() ) debug("ejbRemove: " + getEjbName() + " " +
context.getPrimaryKey());
  }


//-- UTILITY METHODS -------------------------------------- UTILITY
METHODS --

  /**
   * Returns the name of this bean's local interface class.
   *
   * @return  the name of this bean's local interface class.
   *
   * @ejb.interface-method
   * @ejb.transaction type="Supports"
   */
  public String getEjbName ( )
  {
    if ( null != ejbName ) {
      return ejbName;
    }
    
    return context == null ? null :
trimName(context.getEJBLocalObject().getClass().getName());
  }

  /**
   * Returns a trimmed form of the given class name; the package name
and
   * suffix (EJB, CMP or Bean) are removed.
   *
   * @return  a trimmed form of the given class name
   */
  public static String trimName ( String name )
  {
    int lastDotPos = name.lastIndexOf(".");
    int suffixPos = name.indexOf("EJB");
    if ( -1 == suffixPos ) {
        suffixPos = name.indexOf("CMP");
    }
    if ( -1 == suffixPos ) {
        suffixPos = name.indexOf("Bean");
    }
    
    if ( -1 == suffixPos ) {
        if ( -1 == lastDotPos ) {
          // No trimming needed
          return name;
        }
        
        // Just trim the package
        return name.substring(lastDotPos + 1);
    }
    
    // If there's no prefix, lastDotPos + 1 will be 0 which is ok
    // Otherwise, trim both packaage and suffix
    return name.substring(lastDotPos + 1, suffixPos);
  }

  /**
   * Returns this bean's primary key. Clearly, this assumes the PK is an
Integer.
   *
   * @return  this bean's primary key
   *
   * @ejb.interface-method
   * @ejb.transaction type="Supports"
   */
  public Integer getPk ( )
  {
    return context == null ? null : (Integer) context.getPrimaryKey();
  }

  /**
   * Returns this bean's name and primary key as a String.
   *
   * @return  this bean's name and primary key
   *
   * @ejb.interface-method
   * @ejb.transaction type="Supports"
   */
  public String getNamePk ( )
  {
    return getEjbName() + " " + getPk();
  }
}


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user

Reply via email to