Hi all,

I'm thinking about an easier way for declaring and looking up entries in
a bean's environment JNDI Name space ("java:comp/env"). i.e.
env-entries, ejb-ref's, ...

I would like to expand the current tags to method and field level. The
developer has only to declare protected fields or abstract methods with
XDoclet tags for the environment stuff. The lookup is done in the
technical bean generated with the session, entitybmp, entitycmp and mdb
subtasks.

The lookup is done in the container callback method for the ejb context
(i.e. setSessionContext()). For field-level tags, the value is assigned
 directly to the field in setXxxContext(). For method-level tags, the
value is assigned to a private member of the technical bean in
setXxxContext() for caching. The implementation of the abstract method
simply returns the cached value.

i.e. the developer declares those members and tags:

/**
 * @ejb.env-entry
 *  value = "true"
 */
protected boolean aPrimitiveFieldEnvEntry;

/**
 * @ejb.env-entry
 *      value = "123.456"
 */
protected abstract Double aMethodEnvEntry();

/**
 * @ejb.resource-ref
 *  res-auth = "Container"
 *  res-sharing-scope = "Shareable"
 */
protected DataSource aFieldResRefWithDefaultName;

And the rest is handled by the deploymentdescriptor subtask and the
technical bean generated with the session subtask.

See the attached files for a session bean sample. The issue for this is
XDT-1325. IMHO, this makes the handling of the ejb environment stuff a
lot easier and the user has already some ejb3-like features when using
ejb2 with XDoclet :-)

Backward-compatibility is guaranted because the existing tags are just
expanded to method and field level. Template code dupplication is
avoided with a special tags handler for the ejb environment tags.

What do you think about this?

Regards,
Matthias

-- 
Matthias Germann <[EMAIL PROTECTED]>
/*
 * Created on 24.12.2004
 */
import javax.ejb.SessionBean;
import javax.jms.QueueConnectionFactory;
import javax.jms.TopicConnectionFactory;
import javax.sql.DataSource;

/**
 * @ejb.bean 
 *   name = "MySessionX"
 *   type = "Stateless"
 *   view-type = "remote"
 *   jndi-name = "SBXR"
 *   local-jndi-name = "SBXL"
 * 
 * @ejb.env-entry 
 *  description = "A class-level env-entry with all parameters"
 *  name = "aClassEnvEntry1"
 *  type = "java.lang.Integer"
 *  value = "100"
 *
 * @ejb.env-entry 
 *  name = "aClassEnvEntry2"
 * 
 * @ejb.resource-ref 
 *  res-ref-name = "jdbc/aClassResRef"
 *  res-type = "javax.sql.DataSource"
 *  res-auth = "Container"
 *  res-sharing-scope = "Shareable"
 * 
 * 
 */
public abstract class MySessionXBean implements SessionBean {
	
	/**
	 * @ejb.env-entry
	 *  description = "A field-level env-entry with all parameters. This env-entry is assigned it's value before setSessionContext is called"
     *  name = "myNameForThisFieldEnvEntry"
	 * 	value = "10"
	 */
	protected Long aFieldEnvEntry1;
	
	/**
	 * @ejb.env-entry
	 */
	protected String aFieldEnvEntryWithDefaultName;

	/**
	 * @ejb.resource-ref 
	 *  res-ref-name = "jms/myNameForThisFieldResRef"
	 *  res-auth = "Container"
	 *  res-sharing-scope = "Shareable"
	 */
	protected QueueConnectionFactory aFieldResRef1;
	
	/**
	 * @ejb.resource-ref 
	 *  res-auth = "Container"
	 *  res-sharing-scope = "Shareable"
	 */
	protected DataSource aFieldResRefWithDefaultName;

	/**
	 * @ejb.env-entry
	 *  description = "A primitive-type field-level env-entry. This env-entry's type is java.lang.Boolean and it's value is automatically converted to the primitive type after the lookup"
	 *  value = "true"
	 */
	protected boolean aPrimitiveFieldEnvEntry;

	/**
	 * @ejb.env-entry
	 *  description = A method-level env-entry with all parameters. This env-entry's value is cached in the session object.
     *  name = "myNameForThisMethodEnvEntry"
	 * 	value = "123.456"
	 */
	protected abstract Double aMethodEnvEntry();
	
	/**
	 * @ejb.env-entry
	 */
	protected abstract Character aMethodEnvEntryWithDefaultName();

	/**
	 * @ejb.env-entry
	 *  description = "A primitive-type method-level env-entry. This env-entry's type is java.lang.Float and it's value is automatically converted to the primitive type after the lookup"
	 *  value = "true"
	 */
	protected abstract float aPrimitiveMethodEnvEntry();


	/**
	 * @ejb.resource-ref 
	 *  res-ref-name = "jms/myNameForThisMethodResRef"
	 *  res-auth = "Container"
	 *  res-sharing-scope = "Shareable"
	 */
	protected abstract QueueConnectionFactory aMethodResRef();
	
	/**
	 * @ejb.resource-ref 
	 *  res-auth = "Container"
	 *  res-sharing-scope = "Shareable"
	 */
	protected abstract TopicConnectionFactory aMethodResRefWithDefaultName();
	
}
/*
 * Generated by XDoclet - Do not edit!
 */

/**
 * Session layer for MySessionX.
 */
public class MySessionXSession
   extends MySessionXBean
   implements javax.ejb.SessionBean
{
   public void ejbActivate() 
   {
   }

   public void ejbPassivate() 
   {
   }

   public void setSessionContext(javax.ejb.SessionContext ctx) 
   {
      javax.naming.Context namingCtx = null;
      try 
      {
         namingCtx = new javax.naming.InitialContext();
         aMethodEnvEntry = ((java.lang.Double) namingCtx.lookup("java:comp/env/aMethodEnvEntry"));       
         aMethodEnvEntryWithDefaultName = ((java.lang.Character) namingCtx.lookup("java:comp/env/aMethodEnvEntryWithDefaultName"));       
         aPrimitiveMethodEnvEntry = ((java.lang.Float) namingCtx.lookup("java:comp/env/aPrimitiveMethodEnvEntry")).floatValue();       
         aFieldEnvEntry1 = ((java.lang.Long) namingCtx.lookup("java:comp/env/myNameForThisFieldEnvEntry"));       
         aFieldEnvEntryWithDefaultName = ((java.lang.String) namingCtx.lookup("java:comp/env/aFieldEnvEntryWithDefaultName"));       
         aPrimitiveFieldEnvEntry = ((java.lang.Boolean) namingCtx.lookup("java:comp/env/aPrimitiveFieldEnvEntry")).booleanValue();       
         aMethodResRef = ((javax.jms.QueueConnectionFactory) namingCtx.lookup("java:comp/env/aMethodResRef"));       
         aMethodResRefWithDefaultName = ((javax.jms.TopicConnectionFactory) namingCtx.lookup("java:comp/env/aMethodResRefWithDefaultName"));       
         aFieldResRef1 = ((javax.jms.QueueConnectionFactory) namingCtx.lookup("java:comp/env/aFieldResRef1"));       
         aFieldResRefWithDefaultName = ((javax.sql.DataSource) namingCtx.lookup("java:comp/env/aFieldResRefWithDefaultName"));       
      } 
      catch(javax.naming.NamingException e) 
      {
	     throw new javax.ejb.EJBException("lookup failed", e);
      }
      finally {
         if (namingCtx != null) 
         {
            try 
            {
               namingCtx.close(); 
            }
            catch(javax.naming.NamingException e) 
            {
               e.printStackTrace();
            }			
         }
      }
   }

   public void unsetSessionContext() 
   {
   }

   public void ejbRemove() 
   {
   }

   public void ejbCreate() throws javax.ejb.CreateException
   {
   }

   private  java.lang.Double aMethodEnvEntry;
   protected java.lang.Double aMethodEnvEntry()
   {
      return aMethodEnvEntry;
   }
   private  java.lang.Character aMethodEnvEntryWithDefaultName;
   protected java.lang.Character aMethodEnvEntryWithDefaultName()
   {
      return aMethodEnvEntryWithDefaultName;
   }
   private  float aPrimitiveMethodEnvEntry;
   protected float aPrimitiveMethodEnvEntry()
   {
      return aPrimitiveMethodEnvEntry;
   }
   private  javax.jms.QueueConnectionFactory aMethodResRef;
   protected javax.jms.QueueConnectionFactory aMethodResRef()
   {
      return aMethodResRef;
   }
   private  javax.jms.TopicConnectionFactory aMethodResRefWithDefaultName;
   protected javax.jms.TopicConnectionFactory aMethodResRefWithDefaultName()
   {
      return aMethodResRefWithDefaultName;
   }

}

Reply via email to