User: ara_e_w
Date: 02/04/07 04:24:10
Modified: core/src/xdoclet/ejb/tags EjbTagsHandler.java
Log:
- GenerationManager is a nested element now
- fixed a mini problem in isLocal for ejb1.1
- refactored and updated websphere's bnd template, made useIds="true" for it
- some other mini changes, or maybe just <pretty/>!
Revision Changes Path
1.37 +808 -701 xdoclet/core/src/xdoclet/ejb/tags/EjbTagsHandler.java
Index: EjbTagsHandler.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/ejb/tags/EjbTagsHandler.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -w -r1.36 -r1.37
--- EjbTagsHandler.java 4 Apr 2002 01:03:06 -0000 1.36
+++ EjbTagsHandler.java 7 Apr 2002 11:24:10 -0000 1.37
@@ -33,993 +33,1100 @@
/**
* @author Ara Abrahamian ([EMAIL PROTECTED])
* @created Oct 15, 2001
- * @version $Revision: 1.36 $
+ * @version $Revision: 1.37 $
*/
-public class EjbTagsHandler extends XDocletTagSupport {
+public class EjbTagsHandler extends XDocletTagSupport
+{
/**
* @todo-javadoc Describe the field
*/
protected final static String LOCAL_SUFFIX = "Local";
-
/**
- * Returns the name of current EJB bean.
+ * Gets the AConcreteEJBean attribute of the EjbTagsHandler class
*
- * @param attributes The attributes of the template tag
- * @return The name of current EJB bean.
- * @exception XDocletException Description of Exception
- * @see #getEjbNameFor(xjavadoc.XClass)
- * @doc:tag type="content"
- * @doc:param name="prefixWithEjbSlash" optional="true" values="true,false"
- * description="Specifies whether to prefix it with ejb/ or not. False by
- * default."
+ * @param clazz Describe what the parameter does
+ * @return The AConcreteEJBean value
+ * @exception XDocletException Describe the exception
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for exception
*/
- public String ejbName(Properties attributes) throws XDocletException {
- String prefix_with_ejbslash_str =
attributes.getProperty("prefixWithEjbSlash");
- boolean prefix_with_ejbslash =
TypeConversionUtil.stringToBoolean(prefix_with_ejbslash_str, false);
- String ejb_name = getEjbNameFor(getCurrentClass());
+ public static boolean isAConcreteEJBean( XClass clazz ) throws XDocletException
+ {
+ Category cat = Log.getCategory( EjbTagsHandler.class,
"ifIsAConcreteEJBean" );
- if (prefix_with_ejbslash == true) {
- return prefixWithEjbSlash(ejb_name);
+ XTag bean_tag = clazz.doc().tag( "ejb:bean" );
+
+ if( bean_tag != null )
+ {
+ String generate_str = bean_tag.attributeValue( "generate" );
+
+ if( generate_str != null )
+ {
+ boolean generate = TypeConversionUtil.stringToBoolean(
generate_str, true );
+
+ //generate="true" specifically
+ if( generate == true )
+ {
+ return true;
}
- else {
- return ejb_name;
+ else
+ {
+ //generate="false" specifically
+ return false;
}
}
+ //ejb:beam name specified, so it's a concrete ejb
+ if( bean_tag.attributeValue( "name" ) != null )
+ {
+ return true;
+ }
+ }
- /**
- * Returns the name of EJB ref.
- *
- * @return The name of current EJB bean.
- * @exception XDocletException Description of Exception
- * @doc:tag type="content"
- */
- public String ejbRefName() throws XDocletException {
- String ejb_ref_name = null;
- String ref_name = getTagValue(
- FOR_CLASS,
- "ejb:ejb-ref",
- "ref-name",
- null,
- null,
- true,
- false
- );
+ //now try to guess because it wasn't specifically specified whether it
should be generated or not
- if (ref_name != null) {
- ejb_ref_name = ref_name;
+ SubTask subtask = getSubTaskClassForClass( clazz );
+
+ if( clazz.isAbstract() == true )
+ {
+ if( hasANonDocletGeneratedSubClass( clazz ) == true )
+ {
+ return false;
}
- else {
- ejb_ref_name = getEjbNameFor(getCurrentClass());
- String type = getTagValue(
- FOR_CLASS,
- "ejb:ejb-ref",
- "view-type",
- null,
- null,
- true,
- false
- );
+ //an abstract mdb/etc?
+ if( subtask == null )
+ {
+ return false;
+ }
- if (type != null && type.equals("local") &&
isLocalEjb(getCurrentClass()) && isRemoteEjb(getCurrentClass())) {
- ejb_ref_name = ejb_ref_name + LOCAL_SUFFIX;
+ //if <entitycmp/bmp/session/> is on, then do the best to guess
correctly
+ if( DocletContext.getInstance().isSubTaskDefined(
subtask.getSubTaskName() ) == true )
+ {
+ /*
+ * This piece of code is commented out because I found
it overkill to check all those cases
+ *
+ * XMethod[] methods = getCurrentClass().methods();
+ * boolean has_abstract_method = false;
+ * for( int i = 0; i < methods.length; i++ )
+ * {
+ * XMethod method = methods[i];
+ * if( method.isAbstract() == true )
+ * {
+ * if a method other than
create/remove/getData/like-that is abstract so it's not a concrete bean
+ * if( InterfaceTagsHandler.isInterfaceMethod( method
) == false &&
+ * DataObjectTagsHandler.isDataObjectMethod( method )
== false &&
+ * PersistentTagsHandler.isPersistentFieldMethod() ==
false
+ * )
+ * {
+ * has_abstract_method = true;
+ * }
+ * }
+ * }
+ * if( has_abstract_method == true )
+ * {
+ * return;
+ * }
+ */
+ //none of the above guesses worked, assume it's
concrete!
+ return true;
}
+ else
+ {
+ //if <entitycmp/bmp/session/> is off, so if class is
abstract then the bean is abstract except for entity cmp beans in ejb2 cmp2
+ if( CmpTagsHandler.isEntityCmp( clazz ) &&
CmpTagsHandler.isUsingCmp2Impl( clazz ) )
+ {
+ return true;
}
- return prefixWithEjbSlash(ejb_ref_name);
+ return false;
+ }
+ }
+ else
+ {
+ //if <entitycmp/bmp/> is on, then it's an error or not specify
the class abstract, except for <session/> that non-abstract is also legal
+ if( subtask != null &&
DocletContext.getInstance().isSubTaskDefined( subtask.getSubTaskName() ) )
+ {
+ if( subtask.getSubTaskName().equals(
SessionSubTask.SUBTASK_NAME ) )
+ {
+ return true;
}
+ String cur_class_name =
ClassTagsHandler.getFullClassNameFor( clazz );
+
+ throw new XDocletException( Translator.getString(
"xdoclet.ejb.Messages", "class_not_abstract",
+ new String[]{cur_class_name,
SessionSubTask.SUBTASK_NAME} ) );
+ }
+ else
+ {
+ return true;
+ }
+ }
+ }
/**
- * Returns the name of EJB ref.
+ * Returns the EJB name of the clazz by seaching for ejb:bean's name parameter.
+ * If that is not found, it uses the class' name minus any suffix from the list
+ * in the 'ejbClassNameSuffix' config parameter ("Bean,EJB,Ejb" by default).
*
- * @return The name of current EJB bean.
+ * @param clazz The EJB bean class for which we want the EJB
+ * name
+ * @return The EjbName value
* @exception XDocletException Description of Exception
- * @doc:tag type="content"
+ * @see #ejbName(java.util.Properties)
*/
- public String ejbExternalRefName() throws XDocletException {
- String ejb_ref_name = null;
- String ref_name = getTagValue(
- FOR_CLASS,
- "ejb:ejb-external-ref",
- "ref-name",
- null,
- null,
- true,
- false
- );
+ public static String getEjbNameFor( XClass clazz ) throws XDocletException
+ {
+ XTag bean_tag = clazz.doc().tag( "ejb:bean" );
+ String param_val = null;
- if (ref_name != null) {
- ejb_ref_name = ref_name;
+ if( bean_tag != null )
+ {
+ param_val = bean_tag.attributeValue( "name" );
+ }
+
+ if( param_val == null )
+ {
+ String clazz_name = clazz.qualifiedName();
+
+ clazz_name.replace( '.', '/' );
+
+ // remove any suffix from ejbClassNameSuffix list
+ String suffixlist = ( String )
getDocletContext().getConfigParam( "ejbClassNameSuffix" );
+ StringTokenizer st = new StringTokenizer( suffixlist, "," );
+
+ while( st.hasMoreTokens() )
+ {
+ String suffix = st.nextToken();
+
+ if( clazz_name.endsWith( suffix ) )
+ {
+ int index = clazz_name.lastIndexOf( suffix );
+
+ clazz_name = clazz_name.substring( 0, index );
+ break;
}
- else {
- ejb_ref_name = getTagValue(
- FOR_CLASS,
- "ejb:ejb-external-ref",
- "ejb-name",
- null,
- null,
- true,
- true
- );
}
- return prefixWithEjbSlash(ejb_ref_name);
+ return clazz_name;
}
+ return param_val;
+ }
/**
- * Returns the symbolic name of the current class. For an EJBean it's the value
- * of ejb:bean's name parameter.
+ * Returns short version of the EJB name of the clazz.
*
- * @return The symbolic name of the current class
+ * @param clazz the class we want its short EJB name
+ * @return The shortEjbName value
* @exception XDocletException Description of Exception
* @see #shortEjbName()
- * @doc:tag type="content"
*/
- public String symbolicClassName() throws XDocletException {
- return shortEjbName();
- }
+ public static String getShortEjbNameFor( XClass clazz ) throws XDocletException
+ {
+ Category cat = Log.getCategory( EjbTagsHandler.class, "shortEjbName" );
+ // Find the last part of the name
+ StringTokenizer ejbNameTokens = new StringTokenizer( getEjbNameFor(
clazz ), ":./\\-" );
+ String name;
- /**
- * Returns short version of ejbName(). Example: "foo.bar.MyBean" ->"MyBean",
- * "foo/bar/MyBean" ->"MyBean"
- *
- * @return Description of the Returned Value
- * @exception XDocletException Description of Exception
- * @see #getShortEjbNameFor(xjavadoc.XClass)
- * @doc:tag type="content"
- */
- public String shortEjbName() throws XDocletException {
- return getShortEjbNameFor(getCurrentClass());
+ do
+ {
+ name = ejbNameTokens.nextToken();
+ }while ( ejbNameTokens.hasMoreTokens() );
+
+ if( cat.isDebugEnabled() )
+ {
+ cat.debug( "Name=" + name );
}
+ return name;
+ }
/**
- * Evaluates the body block for each EJBean derived from one of the three EJB
- * types: EntityBean, SessionBean or MessageDrivenBean.
- *
- * @param template The body of the block tag
+ * @param clazz Description of Parameter
+ * @return a unique id for clazz
* @exception XDocletException Description of Exception
- * @see EntityTagsHandler#isEntity(xjavadoc.XClass)
- * @see SessionTagsHandler#isSession(xjavadoc.XClass)
- * @see MdbTagsHandler#isMessageDriven(xjavadoc.XClass)
- * @doc:tag type="block"
*/
- public void forAllBeans(String template) throws XDocletException {
- try {
- XClass[] classes = XJavaDoc.getInstance().sourceClasses();
-
- for (int i = 0; i < classes.length; i++) {
- setCurrentClass(classes[i]);
-
- if
(DocletSupport.isDocletGenerated(getCurrentClass())) {
- continue;
- }
-
- if (EntityTagsHandler.isEntity(getCurrentClass()) ||
SessionTagsHandler.isSession(getCurrentClass()) ||
-
MdbTagsHandler.isMessageDriven(getCurrentClass())) {
- generate(template);
- }
- }
- } catch (XJavaDocException e) {
- throw new XDocletException(e, e.getMessage());
- }
+ public static String getEjbIdFor( XClass clazz ) throws XDocletException
+ {
+ return getEjbNameFor( clazz ).replace( '/', '_' );
}
-
/**
- * Evaluates the body block if current bean is a concrete bean meaning the
- * generate parameter of ejb:bean is either not specified or equals to "true",
- * otherwise the bean is just an abstract base class bean not meant to be used
- * as a EJBean but serve as the base for other EJBeans.
+ * Returns the EJB specification version used. The generated files will be
+ * compatible with the version specified.
*
- * @param template The body of the block tag
- * @param attributes The attributes of the template tag
- * @exception XDocletException Description of Exception
- * @doc:tag type="block"
+ * @return The Ejbspec value
*/
- public void ifIsAConcreteEJBean(String template, Properties attributes) throws
XDocletException {
- if (isAConcreteEJBean(getCurrentClass()) == true) {
- generate(template);
- }
+ public static String getEjbSpec()
+ {
+ return ( String ) getDocletContext().getConfigParam( "EjbSpec" );
}
-
/**
- * Returns Bean type : "Entity", "Session" or "Message Driven".
+ * Gets the LocalEjb attribute of the EjbTagsHandler class
*
- * @return "Entity", "Session" or "Message Driven".
- * @exception XDocletException Description of Exception
- * @see EntityTagsHandler#isEntity(xjavadoc.XClass)
- * @see SessionTagsHandler#isSession(xjavadoc.XClass)
- * @see MdbTagsHandler#isMessageDriven(xjavadoc.XClass)
- * @doc:tag type="content"
+ * @param clazz Describe what the parameter does
+ * @return The LocalEjb value
+ * @exception XDocletException Describe the exception
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for exception
*/
- public String beanType() throws XDocletException {
- if (EntityTagsHandler.isEntity(getCurrentClass())) {
- return "Entity";
- }
- else if (SessionTagsHandler.isSession(getCurrentClass())) {
- return "Session";
- }
- else if (MdbTagsHandler.isMessageDriven(getCurrentClass())) {
- return "Message Driven";
- }
- else {
- return "Unknown";
+ public static boolean isLocalEjb( XClass clazz ) throws XDocletException
+ {
+ String value = getTagValue(
+ clazz.doc(),
+ "ejb:bean",
+ "view-type",
+ "remote,local,both",
+ null,
+ true,
+ false
+ );
+
+ if( value == null )
+ {
+ //default is both if ejb2, remote if ejb1.1
+ if( getEjbSpec().equals( "2.0" ) )
+ return true;
+ else
+ return false;
}
+ else
+ return value.indexOf( "local" ) != -1 || value.indexOf( "both"
) != -1;
}
-
/**
- * Returns the full-qualified name of the current class's concrete class. This
- * is the class that is generated and is derived from current class.
+ * Gets the RemoteEjb attribute of the EjbTagsHandler class
*
- * @return The full-qualified name of the current class's concrete class
- * @exception XDocletException Description of Exception
- * @see SessionTagsHandler#sessionClass()
- * @see BmpTagsHandler#entityBmpClass()
- * @see CmpTagsHandler#entityCmpClass()
- * @see MdbTagsHandler#messageDrivenClass()
- * @doc:tag type="content"
+ * @param clazz Describe what the parameter does
+ * @return The RemoteEjb value
+ * @exception XDocletException Describe the exception
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for exception
*/
- public String concreteFullClassName() throws XDocletException {
- if (SessionTagsHandler.isSession(getCurrentClass())) {
- if
(DocletContext.getInstance().isSubTaskDefined(SessionSubTask.SUBTASK_NAME)) {
- return
SessionTagsHandler.getSessionClassFor(getCurrentClass());
- }
- else {
- return getCurrentClass().qualifiedName();
- }
- }
- else if (BmpTagsHandler.isEntityBmp(getCurrentClass())) {
- if
(DocletContext.getInstance().isSubTaskDefined(EntityBmpSubTask.SUBTASK_NAME)) {
- return
BmpTagsHandler.getEntityBmpClassFor(getCurrentClass());
- }
- else {
- return getCurrentClass().qualifiedName();
- }
- }
- else if (CmpTagsHandler.isEntityCmp(getCurrentClass())) {
- if
(DocletContext.getInstance().isSubTaskDefined(EntityCmpSubTask.SUBTASK_NAME)) {
- return
CmpTagsHandler.getEntityCmpClassFor(getCurrentClass());
- }
- else {
- return getCurrentClass().qualifiedName();
- }
- }
- else if (MdbTagsHandler.isMessageDriven(getCurrentClass())) {
- return
MdbTagsHandler.getMessageDrivenClassFor(getCurrentClass());
- }
- else {
- return null;
+ public static boolean isRemoteEjb( XClass clazz ) throws XDocletException
+ {
+ String value = getTagValue(
+ clazz.doc(),
+ "ejb:bean",
+ "view-type",
+ "remote,local,both",
+ null,
+ true,
+ false
+ );
+
+ if( value == null )
+ {
+ //default is both if ejb2, remote if ejb1.1
+ return true;
}
+ else
+ return value.indexOf( "remote" ) != -1 || value.indexOf(
"both" ) != -1;
}
-
/**
- * Returns unique id for current ejb.
+ * Returns true if clazz is only a local EJB by looking at ejb:bean's view-type
+ * parameter.
*
- * @return Description of the Returned Value
+ * @param clazz Description of Parameter
+ * @return The OnlyLocalEjb value
* @exception XDocletException Description of Exception
- * @doc:tag type="content"
*/
- public String id() throws XDocletException {
- return getEjbIdFor(getCurrentClass());
+ public static boolean isOnlyLocalEjb( XClass clazz ) throws XDocletException
+ {
+ return isLocalEjb( clazz ) && !isRemoteEjb( clazz );
}
-
/**
- * @param template Description of Parameter
+ * Returns true if clazz is only a remote EJB by looking at ejb:bean's
+ * view-type parameter.
+ *
+ * @param clazz Description of Parameter
+ * @return The OnlyRemoteEjb value
* @exception XDocletException Description of Exception
*/
- public void ifLocalEjb(String template) throws XDocletException {
- if (isLocalEjb(getCurrentClass())) {
- generate(template);
- }
+ public static boolean isOnlyRemoteEjb( XClass clazz ) throws XDocletException
+ {
+ return isRemoteEjb( clazz ) && !isLocalEjb( clazz );
}
-
/**
- * @param template Description of Parameter
+ * Returns modified package name for a package name. If package name ends with
+ * one of the toReplace Strings, then it's substituted by the replaceWith
+ * String. If package_pattern not null then it's roughly used.
+ *
+ * @param packageName The name of the package name the new package
+ * name will be derived from
+ * @param package_pattern The package pattern to use. Can be null
+ * @param for_subtask
+ * @return Description of the Returned Value
* @exception XDocletException Description of Exception
*/
- public void ifRemoteEjb(String template) throws XDocletException {
- if (isRemoteEjb(getCurrentClass())) {
- generate(template);
- }
- }
+ protected static String choosePackage( String packageName, String
package_pattern, String for_subtask ) throws XDocletException
+ {
+ Category cat = Log.getCategory( EjbTagsHandler.class, "choosePackage"
);
+ ArrayList package_substitutions =
PackageTagsHandler.getPackageSubstitutions( for_subtask );
- /**
- * @param template
- * @exception XDocletException
- * @doc: tag type="body"
- */
- public void ifNotLocalEjb(String template) throws XDocletException {
- if (!isLocalEjb(getCurrentClass())) {
- generate(template);
+ if( cat.isDebugEnabled() )
+ {
+ cat.debug( "Package name=" + packageName + " - Pattern=" +
package_pattern );
}
+
+ if( package_pattern != null )
+ {
+ // later we may do some parametric {0} fancy stuff here
+ return package_pattern;
}
+ else
+ {
+ for( int i = 0; i < package_substitutions.size(); i++ )
+ {
+ PackageTagsHandler.PackageSubstitution ps = (
PackageTagsHandler.PackageSubstitution ) package_substitutions.get( i );
+ StringTokenizer st = new StringTokenizer(
ps.getPackages(), ",", false );
+ while( st.hasMoreTokens() )
+ {
+ String packages = st.nextToken();
+ String suffix = "." + packages;
- /**
- * @param template
- * @exception XDocletException
- * @doc:tag type="body"
- */
- public void ifNotRemoteEjb(String template) throws XDocletException {
- if (!isRemoteEjb(getCurrentClass())) {
- generate(template);
+ if( packageName.endsWith( suffix ) )
+ {
+ packageName = packageName.substring(
0, packageName.length() - suffix.length() ) + "." + ps.getSubstituteWith();
+ break;
+ }
}
}
-
-
- /**
- * Returns true of clazz is an EJB (derived from an EJB type), false otherwise.
- *
- * @param clazz Description of Parameter
- * @return The Ejb value
- * @exception XDocletException Description of Exception
- */
- protected boolean isEjb(XClass clazz) throws XDocletException {
- return TypeTagsHandler.isOfType(clazz,
"javax.ejb.SessionBean,javax.ejb.EntityBean,javax.ejb.MessageDrivenBean",
TypeTagsHandler.TYPE_HIERARCHY);
}
-
- /**
- * sub-classes which deal with patternized class names return a reasonable
- * value
- *
- * @param clazz the class
- * @param type type value used for view-type of remote/local
- * @return dependent class name for the class and type
- * @exception XDocletException
- */
- protected String getDependentClassFor(XClass clazz, String type) throws
XDocletException {
- return null;
+ if( cat.isDebugEnabled() )
+ {
+ cat.debug( "Package name=" + packageName );
}
+ return packageName;
+ }
/**
- * Gets the DependentClassTagName attribute of the EjbTagsHandler object
+ * Gets the SubTaskClassForClass attribute of the EjbTagsHandler class
*
- * @return The DependentClassTagName value
+ * @param clazz Describe what the parameter does
+ * @return The SubTaskClassForClass value
+ * @exception XDocletException Describe the exception
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for exception
*/
- protected String getDependentClassTagName() {
- //it's too much dependency, we should find a better way
- if
(getDocletContext().getActiveSubTask().getSubTaskName().equals(DataObjectSubTask.SUBTASK_NAME))
{
- return "ejb:data-object";
- }
- else if
(getDocletContext().getActiveSubTask().getSubTaskName().equals(EntityBmpSubTask.SUBTASK_NAME)
||
-
getDocletContext().getActiveSubTask().getSubTaskName().equals(EntityBmpSubTask.SUBTASK_NAME))
{
- return "ejb:bean";
- }
- else if
(getDocletContext().getActiveSubTask().getSubTaskName().equals(RemoteInterfaceSubTask.SUBTASK_NAME)
||
-
getDocletContext().getActiveSubTask().getSubTaskName().equals(LocalInterfaceSubTask.SUBTASK_NAME))
{
- return "ejb:interface";
+ private static SubTask getSubTaskClassForClass( XClass clazz ) throws
XDocletException
+ {
+ if( CmpTagsHandler.isEntityCmp( clazz ) )
+ {
+ return DocletContext.getInstance().getSubTaskBy(
EntityCmpSubTask.SUBTASK_NAME );
}
- else if
(getDocletContext().getActiveSubTask().getSubTaskName().equals(HomeInterfaceSubTask.SUBTASK_NAME)
||
-
getDocletContext().getActiveSubTask().getSubTaskName().equals(LocalHomeInterfaceSubTask.SUBTASK_NAME))
{
- return "ejb:interface";
+ else if( BmpTagsHandler.isEntityBmp( clazz ) )
+ {
+ return DocletContext.getInstance().getSubTaskBy(
EntityBmpSubTask.SUBTASK_NAME );
}
- else if
(getDocletContext().getActiveSubTask().getSubTaskName().equals(EntityPkSubTask.SUBTASK_NAME))
{
- return "ejb:pk";
+ else if( SessionTagsHandler.isSession( clazz ) )
+ {
+ return DocletContext.getInstance().getSubTaskBy(
SessionSubTask.SUBTASK_NAME );
}
- else {
+ else
+ {
return null;
}
}
-
/**
* Describe what the method does
*
- * @param ejb_name Describe what the parameter does
+ * @param cur_clazz Describe what the parameter does
* @return Describe the return value
+ * @exception XDocletException Describe the exception
* @todo-javadoc Write javadocs for method
* @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for return value
+ * @todo-javadoc Write javadocs for exception
*/
- protected String prefixWithEjbSlash(String ejb_name) {
- if (ejb_name.startsWith("ejb/")) {
- return ejb_name;
- }
- else {
- return "ejb/" + ejb_name;
+ private static boolean hasANonDocletGeneratedSubClass( XClass cur_clazz )
throws XDocletException
+ {
+ try
+ {
+ //check if it's abstract and has a non-xdoclet-generated
derived class
+ String full_class_name = ClassTagsHandler.getFullClassNameFor(
cur_clazz );
+ XClass[] classes = XJavaDoc.getInstance().sourceClasses();
+
+ for( int i = 0; i < classes.length; i++ )
+ {
+ XClass clazz = classes[i];
+
+ if( full_class_name.equals(
ClassTagsHandler.getFullClassNameFor( clazz ) ) == false &&
+ !clazz.doc().hasTag( "xdoclet-generated" ) &&
+ TypeTagsHandler.isOfType( clazz,
full_class_name, TypeTagsHandler.TYPE_HIERARCHY ) )
+ {
+ return true;
}
}
+ return false;
+ }
+ catch( XJavaDocException e )
+ {
+ throw new XDocletException( e, e.getMessage() );
+ }
+ }
/**
- * Returns true if class/method denoted by doc has ejb:transaction tag, false
- * otherwise.
+ * Returns the name of current EJB bean.
*
- * @param doc Description of Parameter
- * @return Description of the Returned Value
+ * @param attributes The attributes of the template tag
+ * @return The name of current EJB bean.
* @exception XDocletException Description of Exception
+ * @see #getEjbNameFor(xjavadoc.XClass)
+ * @doc:tag type="content"
+ * @doc:param name="prefixWithEjbSlash" optional="true"
+ * values="true,false" description="Specifies whether to prefix it with
+ * ejb/ or not. False by default."
*/
- protected boolean hasTransaction(XDoc doc) throws XDocletException {
- return doc.hasTag("ejb:transaction");
- }
+ public String ejbName( Properties attributes ) throws XDocletException
+ {
+ String prefix_with_ejbslash_str = attributes.getProperty(
"prefixWithEjbSlash" );
+ boolean prefix_with_ejbslash = TypeConversionUtil.stringToBoolean(
prefix_with_ejbslash_str, false );
+ String ejb_name = getEjbNameFor( getCurrentClass() );
+ if( prefix_with_ejbslash == true )
+ {
+ return prefixWithEjbSlash( ejb_name );
+ }
+ else
+ {
+ return ejb_name;
+ }
+ }
/**
- * Returns the name of the class pk/etc class extends.
+ * Returns the name of EJB ref.
*
- * @param clazz the class
- * @param tag_name name of the tag (ejb:bean for example, used for getting
- * generate parameter)
- * @param type type value used for view type of remote/local
- * @param extends_param_name extends parameter name (is "extends" for ejb:bean
- * but is "local-extends" for local)
- * @param default_base_class_name default base class name, returned when not
- * deriving from another base class
- * @return correct value for the extends statement of a generated class
- * @exception XDocletException
+ * @return The name of current EJB bean.
+ * @exception XDocletException Description of Exception
+ * @doc:tag type="content"
*/
- protected String extendsFromFor(XClass clazz, String tag_name, String type,
String extends_param_name, String default_base_class_name) throws XDocletException {
- Category cat = Log.getCategory(EjbTagsHandler.class, "extendsFromFor");
-
- //see ejb:pk/etc generate="?" in superclass
- XClass superclass = clazz.superclass();
-
- boolean super_generate;
-
- if (superclass.doc().hasTag(tag_name)) {
- String super_generate_str = getTagValue(
- superclass.doc(),
- tag_name,
- "generate",
+ public String ejbRefName() throws XDocletException
+ {
+ String ejb_ref_name = null;
+ String ref_name = getTagValue(
+ FOR_CLASS,
+ "ejb:ejb-ref",
+ "ref-name",
null,
null,
- false,
+ true,
false
);
- super_generate =
TypeConversionUtil.stringToBoolean(super_generate_str, true);
- }
- else {
- // Two Cases : PersonBean and BaseEntityBean
- super_generate = false;
-
- XClass[] interfaces = clazz.superclass().interfaces();
-
- for (int i = 0; i < interfaces.length; i++) {
- XClass intf = interfaces[i];
-
- //if superclass is not javax.ejb.EntityBean then we
have a superclass which is itself deriving from javax.ejb.EntityBean
- if
(intf.qualifiedName().equals("javax.ejb.EntityBean") ||
-
intf.qualifiedName().equals("javax.ejb.SessionBean") ||
-
intf.qualifiedName().equals("javax.ejb.MessageDrivenBean")) {
- //it derives from javax.ejb.*Bean and no
superclass for pk/etc class is explicitly defined
- super_generate = true;
- }
- }
-
+ if( ref_name != null )
+ {
+ ejb_ref_name = ref_name;
}
+ else
+ {
+ ejb_ref_name = getEjbNameFor( getCurrentClass() );
- //note: look for ejb:pk/etc extends in superclasses also only if
generate="false" in superclass
- //so extends attribute is inherited only if superclass's pk/etc is not
to be generated
-
- String extends_value = getTagValue(
- clazz.doc(),
- tag_name,
- extends_param_name,
+ String type = getTagValue(
+ FOR_CLASS,
+ "ejb:ejb-ref",
+ "view-type",
null,
null,
- !super_generate,
+ true,
false
);
- //if explicitly specified
- if (extends_value != null) {
- return extends_value;
+ if( type != null && type.equals( "local" ) && isLocalEjb(
getCurrentClass() ) && isRemoteEjb( getCurrentClass() ) )
+ {
+ ejb_ref_name = ejb_ref_name + LOCAL_SUFFIX;
}
- else {
- //now try to guess
- //if we are deriving from another ejb bean then derive from
that bean's pk class too
- //(if generate="true" for superclass's pk/etc class)
-
- // java.lang.Object (the only that have no superclass)
- if (superclass.superclass() == null) {
- return default_base_class_name;
}
- //if a superclass with generate="true"
- else if (super_generate == true) {
- String class_name = getDependentClassFor(superclass,
type);
- if (cat.isDebugEnabled()) {
- cat.debug("DCF = " + class_name + " " +
superclass.superclass());
- }
- if (class_name != null) {
- return class_name;
- }
- else {
- return default_base_class_name;
- }
- }
- else {
- //so we have a superclass with pk-generate="false",
look at superclass of that superclass!
- return extendsFromFor(superclass, tag_name, type,
extends_param_name, default_base_class_name);
- }
- }
+ return prefixWithEjbSlash( ejb_ref_name );
}
-
/**
- * Describe what the method does
+ * Returns the name of EJB ref.
*
- * @param clazz Describe what the parameter does
- * @param tag_name Describe what the parameter does
- * @return Describe the return value
- * @exception XDocletException Describe the exception
- * @todo-javadoc Write javadocs for method
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for return value
- * @todo-javadoc Write javadocs for exception
+ * @return The name of current EJB bean.
+ * @exception XDocletException Description of Exception
+ * @doc:tag type="content"
*/
- protected boolean shouldTraverseSuperclassForDependentClass(XClass clazz,
String tag_name) throws XDocletException {
- Category cat = Log.getCategory(EjbTagsHandler.class,
"shouldTraverseSuperclassForDependentClass");
-
- if (clazz.qualifiedName().equals("java.lang.Object")) {
- cat.debug("clazz = java.lang.Object");
-
- return true;
- }
-
- if (!TypeTagsHandler.isOfType(clazz,
"javax.ejb.EntityBean,javax.ejb.SessionBean", TypeTagsHandler.TYPE_HIERARCHY)) {
- cat.debug(clazz.qualifiedName() + " is _not_ of type
javax.ejb.EntityBean,javax.ejb.SessionBean");
-
- return true;
- }
- else {
- cat.debug(clazz.qualifiedName() + " _is_ of type
javax.ejb.EntityBean,javax.ejb.SessionBean");
- }
-
- //see ejb:bean generate="?" in superclass
- String bean_generate_str = getTagValue(
- clazz.doc(),
- "ejb:bean",
- "generate",
+ public String ejbExternalRefName() throws XDocletException
+ {
+ String ejb_ref_name = null;
+ String ref_name = getTagValue(
+ FOR_CLASS,
+ "ejb:ejb-external-ref",
+ "ref-name",
null,
- "true",
- false,
+ null,
+ true,
false
);
- boolean bean_generate =
TypeConversionUtil.stringToBoolean(bean_generate_str, true);
-
- if (bean_generate == false) {
- cat.debug("bean_generate == false");
- return true;
+ if( ref_name != null )
+ {
+ ejb_ref_name = ref_name;
}
-
- boolean generate = false;
-
- if (tag_name != null) {
- //see ejb:pk/etc generate="?" in superclass
- String generate_str = getTagValue(
- clazz.doc(),
- tag_name,
- "generate",
+ else
+ {
+ ejb_ref_name = getTagValue(
+ FOR_CLASS,
+ "ejb:ejb-external-ref",
+ "ejb-name",
null,
- "true",
- false,
- false
+ null,
+ true,
+ true
);
-
- generate = TypeConversionUtil.stringToBoolean(generate_str,
true);
}
- if (generate == false) {
- cat.debug("generate == false");
-
- return true;
+ return prefixWithEjbSlash( ejb_ref_name );
}
- else {
- cat.debug("generate == true");
- return false;
- }
+ /**
+ * Returns the symbolic name of the current class. For an EJBean it's the value
+ * of ejb:bean's name parameter.
+ *
+ * @return The symbolic name of the current class
+ * @exception XDocletException Description of Exception
+ * @see #shortEjbName()
+ * @doc:tag type="content"
+ */
+ public String symbolicClassName() throws XDocletException
+ {
+ return shortEjbName();
}
-
/**
- * Gets the AConcreteEJBean attribute of the EjbTagsHandler class
+ * Returns short version of ejbName(). Example: "foo.bar.MyBean" ->"MyBean",
+ * "foo/bar/MyBean" ->"MyBean"
*
- * @param clazz Describe what the parameter does
- * @return The AConcreteEJBean value
- * @exception XDocletException Describe the exception
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for exception
+ * @return Description of the Returned Value
+ * @exception XDocletException Description of Exception
+ * @see #getShortEjbNameFor(xjavadoc.XClass)
+ * @doc:tag type="content"
*/
- public static boolean isAConcreteEJBean(XClass clazz) throws XDocletException {
- Category cat = Log.getCategory(EjbTagsHandler.class,
"ifIsAConcreteEJBean");
+ public String shortEjbName() throws XDocletException
+ {
+ return getShortEjbNameFor( getCurrentClass() );
+ }
- XTag bean_tag = clazz.doc().tag("ejb:bean");
+ /**
+ * Evaluates the body block for each EJBean derived from one of the three EJB
+ * types: EntityBean, SessionBean or MessageDrivenBean.
+ *
+ * @param template The body of the block tag
+ * @exception XDocletException Description of Exception
+ * @see EntityTagsHandler#isEntity(xjavadoc.XClass)
+ * @see SessionTagsHandler#isSession(xjavadoc.XClass)
+ * @see MdbTagsHandler#isMessageDriven(xjavadoc.XClass)
+ * @doc:tag type="block"
+ */
+ public void forAllBeans( String template ) throws XDocletException
+ {
+ try
+ {
+ XClass[] classes = XJavaDoc.getInstance().sourceClasses();
- if (bean_tag != null) {
- String generate_str = bean_tag.attributeValue("generate");
+ for( int i = 0; i < classes.length; i++ )
+ {
+ setCurrentClass( classes[i] );
- if (generate_str != null) {
- boolean generate =
TypeConversionUtil.stringToBoolean(generate_str, true);
+ if( DocletSupport.isDocletGenerated( getCurrentClass()
) )
+ {
+ continue;
+ }
- //generate="true" specifically
- if (generate == true) {
- return true;
+ if( EntityTagsHandler.isEntity( getCurrentClass() ) ||
SessionTagsHandler.isSession( getCurrentClass() ) ||
+ MdbTagsHandler.isMessageDriven(
getCurrentClass() ) )
+ {
+ generate( template );
}
- else {
- //generate="false" specifically
- return false;
}
}
-
- //ejb:beam name specified, so it's a concrete ejb
- if (bean_tag.attributeValue("name") != null) {
- return true;
+ catch( XJavaDocException e )
+ {
+ throw new XDocletException( e, e.getMessage() );
}
}
- //now try to guess because it wasn't specifically specified whether it
should be generated or not
-
- SubTask subtask = getSubTaskClassForClass(clazz);
-
- if (clazz.isAbstract() == true) {
- if (hasANonDocletGeneratedSubClass(clazz) == true) {
- return false;
+ /**
+ * Evaluates the body block if current bean is a concrete bean meaning the
+ * generate parameter of ejb:bean is either not specified or equals to "true",
+ * otherwise the bean is just an abstract base class bean not meant to be used
+ * as a EJBean but serve as the base for other EJBeans.
+ *
+ * @param template The body of the block tag
+ * @param attributes The attributes of the template tag
+ * @exception XDocletException Description of Exception
+ * @doc:tag type="block"
+ */
+ public void ifIsAConcreteEJBean( String template, Properties attributes )
throws XDocletException
+ {
+ if( isAConcreteEJBean( getCurrentClass() ) == true )
+ {
+ generate( template );
}
-
- //an abstract mdb/etc?
- if (subtask == null) {
- return false;
}
- //if <entitycmp/bmp/session/> is on, then do the best to guess
correctly
- if
(DocletContext.getInstance().isSubTaskDefined(subtask.getSubTaskName()) == true) {
- /*
- * This piece of code is commented out because I
found it overkill to check all those cases
+ /**
+ * Returns Bean type : "Entity", "Session" or "Message Driven".
*
- * XMethod[] methods = getCurrentClass().methods();
- * boolean has_abstract_method = false;
- * for( int i = 0; i < methods.length; i++ )
- * {
- * XMethod method = methods[i];
- * if( method.isAbstract() == true )
- * {
- * if a method other than
create/remove/getData/like-that is abstract so it's not a concrete bean
- * if( InterfaceTagsHandler.isInterfaceMethod( method
) == false &&
- * DataObjectTagsHandler.isDataObjectMethod( method )
== false &&
- * PersistentTagsHandler.isPersistentFieldMethod() ==
false
- * )
- * {
- * has_abstract_method = true;
- * }
- * }
- * }
- * if( has_abstract_method == true )
- * {
- * return;
- * }
+ * @return "Entity", "Session" or "Message Driven".
+ * @exception XDocletException Description of Exception
+ * @see EntityTagsHandler#isEntity(xjavadoc.XClass)
+ * @see SessionTagsHandler#isSession(xjavadoc.XClass)
+ * @see MdbTagsHandler#isMessageDriven(xjavadoc.XClass)
+ * @doc:tag type="content"
*/
- //none of the above guesses worked, assume it's
concrete!
- return true;
+ public String beanType() throws XDocletException
+ {
+ if( EntityTagsHandler.isEntity( getCurrentClass() ) )
+ {
+ return "Entity";
}
- else {
- //if <entitycmp/bmp/session/> is off, so if class is
abstract then the bean is abstract except for entity cmp beans in ejb2 cmp2
- if (CmpTagsHandler.isEntityCmp(clazz) &&
CmpTagsHandler.isUsingCmp2Impl(clazz)) {
- return true;
+ else if( SessionTagsHandler.isSession( getCurrentClass() ) )
+ {
+ return "Session";
}
-
- return false;
+ else if( MdbTagsHandler.isMessageDriven( getCurrentClass() ) )
+ {
+ return "Message Driven";
}
+ else
+ {
+ return "Unknown";
}
- else {
- //if <entitycmp/bmp/> is on, then it's an error or not specify
the class abstract, except for <session/> that non-abstract is also legal
- if (subtask != null &&
DocletContext.getInstance().isSubTaskDefined(subtask.getSubTaskName())) {
- if
(subtask.getSubTaskName().equals(SessionSubTask.SUBTASK_NAME)) {
- return true;
}
- String cur_class_name =
ClassTagsHandler.getFullClassNameFor(clazz);
-
- throw new
XDocletException(Translator.getString("xdoclet.ejb.Messages", "class_not_abstract",
- new String[]{cur_class_name,
SessionSubTask.SUBTASK_NAME}));
+ /**
+ * Returns the full-qualified name of the current class's concrete class. This
+ * is the class that is generated and is derived from current class.
+ *
+ * @return The full-qualified name of the current class's
+ * concrete class
+ * @exception XDocletException Description of Exception
+ * @see SessionTagsHandler#sessionClass()
+ * @see BmpTagsHandler#entityBmpClass()
+ * @see CmpTagsHandler#entityCmpClass()
+ * @see MdbTagsHandler#messageDrivenClass()
+ * @doc:tag type="content"
+ */
+ public String concreteFullClassName() throws XDocletException
+ {
+ if( SessionTagsHandler.isSession( getCurrentClass() ) )
+ {
+ if( DocletContext.getInstance().isSubTaskDefined(
SessionSubTask.SUBTASK_NAME ) )
+ {
+ return SessionTagsHandler.getSessionClassFor(
getCurrentClass() );
}
- else {
- return true;
+ else
+ {
+ return getCurrentClass().qualifiedName();
}
}
+ else if( BmpTagsHandler.isEntityBmp( getCurrentClass() ) )
+ {
+ if( DocletContext.getInstance().isSubTaskDefined(
EntityBmpSubTask.SUBTASK_NAME ) )
+ {
+ return BmpTagsHandler.getEntityBmpClassFor(
getCurrentClass() );
+ }
+ else
+ {
+ return getCurrentClass().qualifiedName();
+ }
+ }
+ else if( CmpTagsHandler.isEntityCmp( getCurrentClass() ) )
+ {
+ if( DocletContext.getInstance().isSubTaskDefined(
EntityCmpSubTask.SUBTASK_NAME ) )
+ {
+ return CmpTagsHandler.getEntityCmpClassFor(
getCurrentClass() );
+ }
+ else
+ {
+ return getCurrentClass().qualifiedName();
+ }
+ }
+ else if( MdbTagsHandler.isMessageDriven( getCurrentClass() ) )
+ {
+ return MdbTagsHandler.getMessageDrivenClassFor(
getCurrentClass() );
+ }
+ else
+ {
+ return null;
+ }
}
-
/**
- * Returns the EJB name of the clazz by seaching for ejb:bean's name parameter.
- * If that is not found, it uses the class' name minus any suffix from the list
- * in the 'ejbClassNameSuffix' config parameter ("Bean,EJB,Ejb" by default).
+ * Returns unique id for current ejb.
*
- * @param clazz The EJB bean class for which we want the EJB name
- * @return The EjbName value
+ * @return Description of the Returned Value
* @exception XDocletException Description of Exception
- * @see #ejbName(java.util.Properties)
+ * @doc:tag type="content"
*/
- public static String getEjbNameFor(XClass clazz) throws XDocletException {
- XTag bean_tag = clazz.doc().tag("ejb:bean");
- String param_val = null;
-
- if (bean_tag != null) {
- param_val = bean_tag.attributeValue("name");
+ public String id() throws XDocletException
+ {
+ return getEjbIdFor( getCurrentClass() );
}
- if (param_val == null) {
- String clazz_name = clazz.qualifiedName();
-
- clazz_name.replace('.', '/');
-
- // remove any suffix from ejbClassNameSuffix list
- String suffixlist =
(String)getDocletContext().getConfigParam("ejbClassNameSuffix");
- StringTokenizer st = new StringTokenizer(suffixlist, ",");
-
- while (st.hasMoreTokens()) {
- String suffix = st.nextToken();
-
- if (clazz_name.endsWith(suffix)) {
- int index = clazz_name.lastIndexOf(suffix);
-
- clazz_name = clazz_name.substring(0, index);
- break;
+ /**
+ * @param template Description of Parameter
+ * @exception XDocletException Description of Exception
+ */
+ public void ifLocalEjb( String template ) throws XDocletException
+ {
+ if( isLocalEjb( getCurrentClass() ) )
+ {
+ generate( template );
}
}
- return clazz_name;
+ /**
+ * @param template Description of Parameter
+ * @exception XDocletException Description of Exception
+ */
+ public void ifRemoteEjb( String template ) throws XDocletException
+ {
+ if( isRemoteEjb( getCurrentClass() ) )
+ {
+ generate( template );
}
-
- return param_val;
}
-
/**
- * Returns short version of the EJB name of the clazz.
- *
- * @param clazz the class we want its short EJB name
- * @return The shortEjbName value
- * @exception XDocletException Description of Exception
- * @see #shortEjbName()
+ * @param template
+ * @exception XDocletException
+ * @doc: tag type="body"
*/
- public static String getShortEjbNameFor(XClass clazz) throws XDocletException {
- Category cat = Log.getCategory(EjbTagsHandler.class, "shortEjbName");
-
- // Find the last part of the name
- StringTokenizer ejbNameTokens = new
StringTokenizer(getEjbNameFor(clazz), ":./\\-");
- String name;
-
- do {
- name = ejbNameTokens.nextToken();
- } while (ejbNameTokens.hasMoreTokens());
+ public void ifNotLocalEjb( String template ) throws XDocletException
+ {
+ if( !isLocalEjb( getCurrentClass() ) )
+ {
+ generate( template );
+ }
+ }
- if (cat.isDebugEnabled()) {
- cat.debug("Name=" + name);
+ /**
+ * @param template
+ * @exception XDocletException
+ * @doc:tag type="body"
+ */
+ public void ifNotRemoteEjb( String template ) throws XDocletException
+ {
+ if( !isRemoteEjb( getCurrentClass() ) )
+ {
+ generate( template );
}
-
- return name;
}
-
/**
+ * Returns true of clazz is an EJB (derived from an EJB type), false otherwise.
+ *
* @param clazz Description of Parameter
- * @return a unique id for clazz
+ * @return The Ejb value
* @exception XDocletException Description of Exception
*/
- public static String getEjbIdFor(XClass clazz) throws XDocletException {
- return getEjbNameFor(clazz).replace('/', '_');
+ protected boolean isEjb( XClass clazz ) throws XDocletException
+ {
+ return TypeTagsHandler.isOfType( clazz,
"javax.ejb.SessionBean,javax.ejb.EntityBean,javax.ejb.MessageDrivenBean",
TypeTagsHandler.TYPE_HIERARCHY );
}
-
/**
- * Returns the EJB specification version used. The generated files will be
- * compatible with the version specified.
+ * sub-classes which deal with patternized class names return a reasonable
+ * value
*
- * @return The Ejbspec value
+ * @param clazz the class
+ * @param type type value used for view-type of remote/local
+ * @return dependent class name for the class and type
+ * @exception XDocletException
*/
- public static String getEjbSpec() {
- return (String)getDocletContext().getConfigParam("EjbSpec");
+ protected String getDependentClassFor( XClass clazz, String type ) throws
XDocletException
+ {
+ return null;
}
-
/**
- * Gets the LocalEjb attribute of the EjbTagsHandler class
+ * Gets the DependentClassTagName attribute of the EjbTagsHandler object
*
- * @param clazz Describe what the parameter does
- * @return The LocalEjb value
- * @exception XDocletException Describe the exception
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for exception
+ * @return The DependentClassTagName value
*/
- public static boolean isLocalEjb(XClass clazz) throws XDocletException {
- String value = getTagValue(
- clazz.doc(),
- "ejb:bean",
- "view-type",
- "remote,local,both",
- null,
- true,
- false
- );
-
- if (value == null) {
- return true;
+ protected String getDependentClassTagName()
+ {
+ //it's too much dependency, we should find a better way
+ if( getDocletContext().getActiveSubTask().getSubTaskName().equals(
DataObjectSubTask.SUBTASK_NAME ) )
+ {
+ return "ejb:data-object";
}
- else {
- return value.indexOf("local") != -1 || value.indexOf("both")
!= -1;
+ else if(
getDocletContext().getActiveSubTask().getSubTaskName().equals(
EntityBmpSubTask.SUBTASK_NAME ) ||
+ getDocletContext().getActiveSubTask().getSubTaskName().equals(
EntityBmpSubTask.SUBTASK_NAME ) )
+ {
+ return "ejb:bean";
+ }
+ else if(
getDocletContext().getActiveSubTask().getSubTaskName().equals(
RemoteInterfaceSubTask.SUBTASK_NAME ) ||
+ getDocletContext().getActiveSubTask().getSubTaskName().equals(
LocalInterfaceSubTask.SUBTASK_NAME ) )
+ {
+ return "ejb:interface";
+ }
+ else if(
getDocletContext().getActiveSubTask().getSubTaskName().equals(
HomeInterfaceSubTask.SUBTASK_NAME ) ||
+ getDocletContext().getActiveSubTask().getSubTaskName().equals(
LocalHomeInterfaceSubTask.SUBTASK_NAME ) )
+ {
+ return "ejb:interface";
+ }
+ else if(
getDocletContext().getActiveSubTask().getSubTaskName().equals(
EntityPkSubTask.SUBTASK_NAME ) )
+ {
+ return "ejb:pk";
+ }
+ else
+ {
+ return null;
}
}
-
/**
- * Gets the RemoteEjb attribute of the EjbTagsHandler class
+ * Describe what the method does
*
- * @param clazz Describe what the parameter does
- * @return The RemoteEjb value
- * @exception XDocletException Describe the exception
+ * @param ejb_name Describe what the parameter does
+ * @return Describe the return value
+ * @todo-javadoc Write javadocs for method
* @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for exception
+ * @todo-javadoc Write javadocs for return value
*/
- public static boolean isRemoteEjb(XClass clazz) throws XDocletException {
- String value = getTagValue(
- clazz.doc(),
- "ejb:bean",
- "view-type",
- "remote,local,both",
- null,
- true,
- false
- );
-
- if (value == null) {
- return true;
+ protected String prefixWithEjbSlash( String ejb_name )
+ {
+ if( ejb_name.startsWith( "ejb/" ) )
+ {
+ return ejb_name;
}
- else {
- return value.indexOf("remote") != -1 || value.indexOf("both")
!= -1;
+ else
+ {
+ return "ejb/" + ejb_name;
}
}
-
/**
- * Returns true if clazz is only a local EJB by looking at ejb:bean's view-type
- * parameter.
+ * Returns true if class/method denoted by doc has ejb:transaction tag, false
+ * otherwise.
*
- * @param clazz Description of Parameter
- * @return The OnlyLocalEjb value
+ * @param doc Description of Parameter
+ * @return Description of the Returned Value
* @exception XDocletException Description of Exception
*/
- public static boolean isOnlyLocalEjb(XClass clazz) throws XDocletException {
- return isLocalEjb(clazz) && !isRemoteEjb(clazz);
+ protected boolean hasTransaction( XDoc doc ) throws XDocletException
+ {
+ return doc.hasTag( "ejb:transaction" );
}
-
/**
- * Returns true if clazz is only a remote EJB by looking at ejb:bean's
- * view-type parameter.
+ * Returns the name of the class pk/etc class extends.
*
- * @param clazz Description of Parameter
- * @return The OnlyRemoteEjb value
- * @exception XDocletException Description of Exception
+ * @param clazz the class
+ * @param tag_name name of the tag (ejb:bean for example, used
+ * for getting generate parameter)
+ * @param type type value used for view type of
+ * remote/local
+ * @param extends_param_name extends parameter name (is "extends" for
+ * ejb:bean but is "local-extends" for local)
+ * @param default_base_class_name default base class name, returned when not
+ * deriving from another base class
+ * @return correct value for the extends statement of a
+ * generated class
+ * @exception XDocletException
*/
- public static boolean isOnlyRemoteEjb(XClass clazz) throws XDocletException {
- return isRemoteEjb(clazz) && !isLocalEjb(clazz);
- }
+ protected String extendsFromFor( XClass clazz, String tag_name, String type,
String extends_param_name, String default_base_class_name ) throws XDocletException
+ {
+ Category cat = Log.getCategory( EjbTagsHandler.class, "extendsFromFor"
);
+ //see ejb:pk/etc generate="?" in superclass
+ XClass superclass = clazz.superclass();
- /**
- * Returns modified package name for a package name. If package name ends with
- * one of the toReplace Strings, then it's substituted by the replaceWith
- * String. If package_pattern not null then it's roughly used.
- *
- * @param packageName The name of the package name the new package name will be
- * derived from
- * @param package_pattern The package pattern to use. Can be null
- * @param for_subtask
- * @return Description of the Returned Value
- * @exception XDocletException Description of Exception
- */
- protected static String choosePackage(String packageName, String
package_pattern, String for_subtask) throws XDocletException {
- Category cat = Log.getCategory(EjbTagsHandler.class, "choosePackage");
+ boolean super_generate;
- ArrayList package_substitutions =
PackageTagsHandler.getPackageSubstitutions(for_subtask);
+ if( superclass.doc().hasTag( tag_name ) )
+ {
+ String super_generate_str = getTagValue(
+ superclass.doc(),
+ tag_name,
+ "generate",
+ null,
+ null,
+ false,
+ false
+ );
- if (cat.isDebugEnabled()) {
- cat.debug("Package name=" + packageName + " - Pattern=" +
package_pattern);
+ super_generate = TypeConversionUtil.stringToBoolean(
super_generate_str, true );
}
+ else
+ {
+ // Two Cases : PersonBean and BaseEntityBean
+ super_generate = false;
- if (package_pattern != null) {
- // later we may do some parametric {0} fancy stuff here
- return package_pattern;
- }
- else {
- for (int i = 0; i < package_substitutions.size(); i++) {
- PackageTagsHandler.PackageSubstitution ps =
(PackageTagsHandler.PackageSubstitution)package_substitutions.get(i);
- StringTokenizer st = new
StringTokenizer(ps.getPackages(), ",", false);
+ XClass[] interfaces = clazz.superclass().interfaces();
- while (st.hasMoreTokens()) {
- String packages = st.nextToken();
- String suffix = "." + packages;
+ for( int i = 0; i < interfaces.length; i++ )
+ {
+ XClass intf = interfaces[i];
- if (packageName.endsWith(suffix)) {
- packageName = packageName.substring(0,
packageName.length() - suffix.length()) + "." + ps.getSubstituteWith();
- break;
- }
- }
+ //if superclass is not javax.ejb.EntityBean then we
have a superclass which is itself deriving from javax.ejb.EntityBean
+ if( intf.qualifiedName().equals(
"javax.ejb.EntityBean" ) ||
+ intf.qualifiedName().equals(
"javax.ejb.SessionBean" ) ||
+ intf.qualifiedName().equals(
"javax.ejb.MessageDrivenBean" ) )
+ {
+ //it derives from javax.ejb.*Bean and no
superclass for pk/etc class is explicitly defined
+ super_generate = true;
}
}
- if (cat.isDebugEnabled()) {
- cat.debug("Package name=" + packageName);
}
- return packageName;
+ //note: look for ejb:pk/etc extends in superclasses also only if
generate="false" in superclass
+ //so extends attribute is inherited only if superclass's pk/etc is not
to be generated
+
+ String extends_value = getTagValue(
+ clazz.doc(),
+ tag_name,
+ extends_param_name,
+ null,
+ null,
+ !super_generate,
+ false
+ );
+
+ //if explicitly specified
+ if( extends_value != null )
+ {
+ return extends_value;
}
+ else
+ {
+ //now try to guess
+ //if we are deriving from another ejb bean then derive from
that bean's pk class too
+ //(if generate="true" for superclass's pk/etc class)
+ // java.lang.Object (the only that have no superclass)
+ if( superclass.superclass() == null )
+ {
+ return default_base_class_name;
+ }
+ //if a superclass with generate="true"
+ else if( super_generate == true )
+ {
+ String class_name = getDependentClassFor( superclass,
type );
- /**
- * Gets the SubTaskClassForClass attribute of the EjbTagsHandler class
- *
- * @param clazz Describe what the parameter does
- * @return The SubTaskClassForClass value
- * @exception XDocletException Describe the exception
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for exception
- */
- private static SubTask getSubTaskClassForClass(XClass clazz) throws
XDocletException {
- if (CmpTagsHandler.isEntityCmp(clazz)) {
- return
DocletContext.getInstance().getSubTaskBy(EntityCmpSubTask.SUBTASK_NAME);
+ if( cat.isDebugEnabled() )
+ {
+ cat.debug( "DCF = " + class_name + " " +
superclass.superclass() );
}
- else if (BmpTagsHandler.isEntityBmp(clazz)) {
- return
DocletContext.getInstance().getSubTaskBy(EntityBmpSubTask.SUBTASK_NAME);
+ if( class_name != null )
+ {
+ return class_name;
}
- else if (SessionTagsHandler.isSession(clazz)) {
- return
DocletContext.getInstance().getSubTaskBy(SessionSubTask.SUBTASK_NAME);
+ else
+ {
+ return default_base_class_name;
+ }
+ }
+ else
+ {
+ //so we have a superclass with pk-generate="false",
look at superclass of that superclass!
+ return extendsFromFor( superclass, tag_name, type,
extends_param_name, default_base_class_name );
}
- else {
- return null;
}
}
-
/**
* Describe what the method does
*
- * @param cur_clazz Describe what the parameter does
+ * @param clazz Describe what the parameter does
+ * @param tag_name Describe what the parameter does
* @return Describe the return value
* @exception XDocletException Describe the exception
* @todo-javadoc Write javadocs for method
* @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for return value
* @todo-javadoc Write javadocs for exception
*/
- private static boolean hasANonDocletGeneratedSubClass(XClass cur_clazz) throws
XDocletException {
- try {
- //check if it's abstract and has a non-xdoclet-generated
derived class
- String full_class_name =
ClassTagsHandler.getFullClassNameFor(cur_clazz);
- XClass[] classes = XJavaDoc.getInstance().sourceClasses();
+ protected boolean shouldTraverseSuperclassForDependentClass( XClass clazz,
String tag_name ) throws XDocletException
+ {
+ Category cat = Log.getCategory( EjbTagsHandler.class,
"shouldTraverseSuperclassForDependentClass" );
- for (int i = 0; i < classes.length; i++) {
- XClass clazz = classes[i];
+ if( clazz.qualifiedName().equals( "java.lang.Object" ) )
+ {
+ cat.debug( "clazz = java.lang.Object" );
+
+ return true;
+ }
+
+ if( !TypeTagsHandler.isOfType( clazz,
"javax.ejb.EntityBean,javax.ejb.SessionBean", TypeTagsHandler.TYPE_HIERARCHY ) )
+ {
+ cat.debug( clazz.qualifiedName() + " is _not_ of type
javax.ejb.EntityBean,javax.ejb.SessionBean" );
+
+ return true;
+ }
+ else
+ {
+ cat.debug( clazz.qualifiedName() + " _is_ of type
javax.ejb.EntityBean,javax.ejb.SessionBean" );
+ }
+
+ //see ejb:bean generate="?" in superclass
+ String bean_generate_str = getTagValue(
+ clazz.doc(),
+ "ejb:bean",
+ "generate",
+ null,
+ "true",
+ false,
+ false
+ );
+ boolean bean_generate = TypeConversionUtil.stringToBoolean(
bean_generate_str, true );
+
+ if( bean_generate == false )
+ {
+ cat.debug( "bean_generate == false" );
- if
(full_class_name.equals(ClassTagsHandler.getFullClassNameFor(clazz)) == false &&
-
!clazz.doc().hasTag("xdoclet-generated") &&
- TypeTagsHandler.isOfType(clazz,
full_class_name, TypeTagsHandler.TYPE_HIERARCHY)) {
return true;
}
+
+ boolean generate = false;
+
+ if( tag_name != null )
+ {
+ //see ejb:pk/etc generate="?" in superclass
+ String generate_str = getTagValue(
+ clazz.doc(),
+ tag_name,
+ "generate",
+ null,
+ "true",
+ false,
+ false
+ );
+
+ generate = TypeConversionUtil.stringToBoolean( generate_str,
true );
+ }
+
+ if( generate == false )
+ {
+ cat.debug( "generate == false" );
+
+ return true;
}
+ else
+ {
+ cat.debug( "generate == true" );
return false;
- } catch (XJavaDocException e) {
- throw new XDocletException(e, e.getMessage());
}
}
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel