User: vharcq
Date: 02/04/14 23:15:48
Modified: core/src/xdoclet/ejb/tags HomeTagsHandler.java
Log:
Only beautifier changes
Revision Changes Path
1.32 +708 -767 xdoclet/core/src/xdoclet/ejb/tags/HomeTagsHandler.java
Index: HomeTagsHandler.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/ejb/tags/HomeTagsHandler.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -w -r1.31 -r1.32
--- HomeTagsHandler.java 8 Apr 2002 23:01:46 -0000 1.31
+++ HomeTagsHandler.java 15 Apr 2002 06:15:48 -0000 1.32
@@ -1,6 +1,37 @@
/*
- * Copyright (c) 2001,2002 The XDoclet team
+ * Copyright (c) 2001, Aslak Helles�y, BEKK Consulting
* All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of BEKK Consulting nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+/*
+ * Change log
+ *
*/
package xdoclet.ejb.tags;
@@ -27,10 +58,9 @@
/**
* @author Ara Abrahamian ([EMAIL PROTECTED])
* @created Oct 15, 2001
- * @version $Revision: 1.31 $
+ * @version $Revision: 1.32 $
*/
-public class HomeTagsHandler extends EjbTagsHandler
-{
+public class HomeTagsHandler extends EjbTagsHandler {
/**
* @todo-javadoc Describe the field
*/
@@ -40,638 +70,235 @@
*/
private String currentExceptions;
+
/**
- * Similar to {@link InterfaceTagsHandler#getComponentInterface}. Relies on the
- * ejb:home tag, which has the following relevant properties:
- * <ul>
- * <li> remote-class: The fully qualified name of the remote class -
- * overrides all set patterns
- * <li> local-class: The fully qualified name of the local class - overrides
- * all set patterns
- * <li> remote-pattern: The pattern to be used to determine the unqualified
- * name of the remote class
- * <li> local-pattern: The pattern to be used to determine the unqualified
- * name of the local class
- * <li> pattern: The pattern to be used in determining the unqualified remote
- * and/or local home interface name - used where remote- or local- pattern
- * are not specified.
- * <li> remote-package: The package the remote home interface is to be placed
- * in
- * <li> local-package: The package the local home interface is to be placed
- * in
- * <li> package: The package the remote and/or local home interface is to be
- * placed in - used where remote- or local- package are not specified.
- * </ul>
- *
+ * Returns the full qualified local or remote home interface name for the bean,
+ * depending on the value of type parameter.
*
- * @param type The type of home interface - can be remote or
- * local.
- * @param clazz Description of Parameter
- * @return The HomeInterface value
+ * @param attributes The attributes of the template tag
+ * @return Description of the Returned Value
* @exception XDocletException Description of Exception
+ * @doc:tag type="content"
+ * @doc:param name="type" optional="false" values="remote,local"
+ * description="Specifies the type of component home interface."
*/
- public static String getHomeInterface( String type, XClass clazz ) throws
XDocletException
- {
- Category cat = Log.getCategory( HomeTagsHandler.class,
"getHomeInterface" );
+ public String homeInterface(Properties attributes) throws XDocletException {
+ String type = attributes.getProperty("type");
- // validate type
- if( !"remote".equals( type ) && !"local".equals( type ) )
- {
- throw new XDocletException( Translator.getString(
"xdoclet.ejb.Messages",
- "method_only_takes_remote_or_local", new
String[]{"getHomeInterface", type} ) );
+ type = type != null ? type : "remote";
+
+ return getHomeInterface(type, getCurrentClass());
}
- String fileName = clazz.containingPackage().name();
- String name_pattern = null;
- String package_pattern = null;
- String home_interface = null;
- home_interface = clazz.doc().tagAttributeValue( "ejb:home", type +
"-class" );
- if( cat.isDebugEnabled() )
- {
- cat.debug( type + " home Interface for " +
clazz.qualifiedName() + " = " + home_interface );
- }
+ /**
+ * Evaluates the body block if current method is a create method. Create
+ * methods should have ejb:create-method defined.
+ *
+ * @todo I commented somehting strange but surely needed
+ * @param template The body of the block tag
+ * @param attributes The attributes of the template tag
+ * @exception XDocletException Description of Exception
+ * @see #isCreateMethod(xjavadoc.XMethod)
+ * @doc:tag type="block"
+ * @doc:param name="superclasses" optional="true" description="Traverse
+ * superclasses too. With false value used in remote/local home interface
+ * templates. Default is False."
+ */
+ public void ifIsCreateMethod(String template, Properties attributes) throws
XDocletException {
+ String superclasses_str = attributes.getProperty("superclasses");
+ boolean superclasses =
TypeConversionUtil.stringToBoolean(superclasses_str, true);
- if( home_interface != null )
- {
- return home_interface;
+ if (isCreateMethod(getCurrentMethod())) {
+ boolean currentMethodDoesntBelongToCurrentClass =
!getCurrentMethod().containingClass().equals(getCurrentClass());
+ boolean shouldTraverse =
shouldTraverseSuperclassForDependentClass(getCurrentMethod().containingClass(),
"ejb:home");
+
+ if (superclasses == false &&
currentMethodDoesntBelongToCurrentClass == true && shouldTraverse == false) {
+ return;
}
- name_pattern = clazz.doc().tagAttributeValue( "ejb:home", type +
"-pattern" );
- if( name_pattern == null )
- {
- name_pattern = clazz.doc().tagAttributeValue( "ejb:home",
"pattern" );
- if( name_pattern == null )
- {
- name_pattern = "remote".equals( type ) ?
getHomeClassPattern() : getLocalHomeClassPattern();
+ generate(template);
}
}
- package_pattern = clazz.doc().tagAttributeValue( "ejb:home", type +
"-package" );
- if( package_pattern == null )
- {
- package_pattern = clazz.doc().tagAttributeValue( "ejb:home",
"package" );
- }
- String ejb_name = null;
+ /**
+ * Evaluates the body block if current create method's ejbPostCreate method
+ * does not exist.
+ *
+ * @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 ifDoesntHavePostCreateMethod(String template, Properties
attributes)
+ throws XDocletException {
+ XMethod currentMethod = getCurrentMethod();
- if( name_pattern.indexOf( "{0}" ) != -1 )
- {
- ejb_name = MessageFormat.format( name_pattern, new
Object[]{getShortEjbNameFor( clazz )} );
- }
- else
- {
- ejb_name = name_pattern;
+ if (!isCreateMethod(currentMethod)) {
+ throw new XDocletException("Cannot call
ifDoesntHavePostCreateMethod if the current method is not a create method: "
+ + currentMethod);
}
- String subtask_name = null;
+ StringBuffer currentMethodName = new
StringBuffer(currentMethod.nameWithSignature());
- if( type.equals( "remote" ) )
- {
- subtask_name = HomeInterfaceSubTask.SUBTASK_NAME;
- }
- else
- {
- subtask_name = LocalHomeInterfaceSubTask.SUBTASK_NAME;
- }
+ currentMethodName.insert(3, "Post");
- // Fix package name
- fileName = choosePackage( fileName, package_pattern, subtask_name );
- fileName += "." + ejb_name;
+ XMethod ejbPostCreateMethod =
getCurrentClass().getMethod(currentMethodName.toString());
- return fileName;
+ if (ejbPostCreateMethod == null) {
+ generate(template);
}
+ }
+
/**
- * Returns true if method is an ejbRemove method, false otherwise.
+ * Returns the appropriate ejbPostCreate method name for the current ejbCreate
+ * method.
*
- * @param method Description of Parameter
- * @return The RemoveMethod value
- * @exception XDocletException Description of Exception
+ * @param attributes The attributes of the template tag
+ * @return Description of the Returned Value
+ * @doc:tag type="content"
*/
- public static boolean isRemoveMethod( XMethod method ) throws XDocletException
- {
- return method.name().equals( "ejbRemove" );
+ public String ejbPostCreateSignature(Properties attributes) {
+ StringBuffer currentMethodName = new
StringBuffer(getCurrentMethod().name());
+
+ currentMethodName.insert(3, "Post");
+ return currentMethodName.toString();
}
+
/**
- * Returns true if method is a create method marked with a ejb:create-method
- * tag, false otherwise.
+ * Evaluates the body block if current method is a home method. Home methods
+ * should have ejb:home-method defined.
*
- * @param method Description of Parameter
- * @return The CreateMethod value
+ * @param template The body of the block tag
+ * @param attributes The attributes of the template tag
* @exception XDocletException Description of Exception
+ * @see #isHomeMethod(xjavadoc.XMethod)
+ * @doc:tag type="block"
+ * @doc:param name="superclasses" optional="true" description="Traverse
+ * superclasses too. With false value used in remote/local home interface
+ * templates. Default is False."
*/
- public static boolean isCreateMethod( XMethod method ) throws XDocletException
- {
- return method.doc().hasTag( "ejb:create-method" );
+ public void ifIsHomeMethod(String template, Properties attributes) throws
XDocletException {
+ String superclasses_str = attributes.getProperty("superclasses");
+ boolean superclasses =
TypeConversionUtil.stringToBoolean(superclasses_str, true);
+
+ if (isHomeMethod(getCurrentMethod())) {
+ if (superclasses == false &&
getCurrentMethod().containingClass() != getCurrentClass() &&
shouldTraverseSuperclassForDependentClass(getCurrentMethod().containingClass(),
"ejb:home") == false) {
+ return;
+ }
+
+ generate(template);
+ }
}
+
/**
- * Returns true if method is a home method marked with a ejb:home-method tag,
- * false otherwise.
+ * Evaluates the body block if current method is ejbRemove method.
*
- * @param method Description of Parameter
- * @return The HomeMethod value
+ * @param template The body of the block tag
* @exception XDocletException Description of Exception
+ * @see #isRemoveMethod(xjavadoc.XMethod)
+ * @doc:tag type="block"
*/
- public static boolean isHomeMethod( XMethod method ) throws XDocletException
- {
- return method.doc().hasTag( "ejb:home-method" );
+ public void ifNotRemoveMethod(String template) throws XDocletException {
+ if (!isRemoveMethod(getCurrentMethod())) {
+ generate(template);
+ }
}
+
+// /**
+// * Evaluates the body block if current method is a ejbFind method.
+// *
+// * @param template The body of the block tag
+// * @param attributes The attributes of the template tag
+// * @exception XDocletException Description of Exception
+// * @see #isHomeMethod(xjavadoc.XMethod)
+// * @doc:tag type="block"
+// * @doc:param name="superclasses" optional="true"
+// * description="Traverse superclasses too. With false value used in
+// * remote/local home interface templates. Default is False."
+// */
+// public void ifIsFinderMethod( String template, Properties attributes ) throws
XDocletException
+// {
+// String superclasses_str = attributes.getProperty( "superclasses" );
+// boolean superclasses = TypeConversionUtil.stringToBoolean(
superclasses_str, true );
+//
+// if( isFinderMethod( getCurrentMethod() ) )
+// {
+// if( superclasses == false &&
getCurrentMethod().containingClass() != getCurrentClass() &&
shouldTraverseSuperclassForDependentClass( getCurrentMethod().containingClass(),
"ejb:home" ) == false )
+// return;
+//
+// generate( template );
+// }
+// }
+//
/**
- * Gets the CompNameFor attribute of the HomeTagsHandler class
- *
- * @param clazz Describe what the parameter does
- * @param type Describe what the parameter does
- * @return The CompNameFor value
- * @exception XDocletException Describe the exception
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for exception
+ * @param attributes The attributes of the template tag
+ * @return Description of the Returned Value
+ * @exception XDocletException Description of Exception
+ * @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."
+ * @doc:param name="type" optional="false" values="remote,local"
+ * description="Specifies if we want the jndi name value for local or
+ * remote lookup."
*/
- public static String getCompNameFor( XClass clazz, String type ) throws
XDocletException
- {
- String compName = getEjbNameFor( clazz ).replace( '.', '/' );
+ public String compName(Properties attributes) throws XDocletException {
+ String prefix_with_ejbslash_str =
attributes.getProperty("prefixWithEjbSlash");
+ boolean prefix_with_ejbslash =
TypeConversionUtil.stringToBoolean(prefix_with_ejbslash_str, false);
+ String type = attributes.getProperty("type");
- if( type.equals( "local" ) && isLocalEjb( clazz ) && isRemoteEjb(
clazz ) )
- {
- compName = compName + LOCAL_SUFFIX;
+ String ejb_name = getCompNameFor(getCurrentClass(), type);
+
+ String compName;
+
+ if (prefix_with_ejbslash == true) {
+ compName = prefixWithEjbSlash(ejb_name);
+ }
+ else {
+ compName = ejb_name;
}
return compName;
}
- /**
- * Returns true if method is an ejbFind method, false otherwise.
- *
- * @param method Description of Parameter
- * @return The FinderMethod value
- * @exception XDocletException Description of Exception
- */
- public static boolean isFinderMethod( XMethod method ) throws XDocletException
- {
- return method.name().startsWith( "ejbFind" );
- }
/**
- * Gets the HomeDefinition attribute of the HomeTagsHandler class
- *
- * @param clazz Describe what the parameter does
- * @param method Describe what the parameter does
- * @param tagType Describe what the parameter does
- * @param type Describe what the parameter does
- * @return The HomeDefinition value
- * @exception XDocletException Describe the exception
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for method parameter
- * @todo-javadoc Write javadocs for exception
+ * @param attributes
+ * @return Description of the Returned Value
+ * @exception XDocletException Description of Exception
+ * @doc:tag type="content"
+ * @doc:param name="type" optional="false" values="remote,local"
+ * description="Specifies if we want the jndi name value for local or
+ * remote lookup."
*/
- public static String getHomeDefinition( XClass clazz, XMethod method, String
tagType, String type )
- throws XDocletException
- {
- String methodName = method.name().substring( 3 );
- StringBuffer homeMethodName = new StringBuffer();
-
- if( tagType.equals( "ejb:finder" ) )
- {
- String ejbReturn = method.returnType().toString();
+ public String jndiName(Properties attributes) throws XDocletException {
+ String type = attributes.getProperty("type");
+ XTag bean_tag = getCurrentClass().doc().tag("ejb:bean");
+ String compName = getCompNameFor(getCurrentClass(), type);
- if( ejbReturn.equals( "java.util.Collection" ) )
- {
- homeMethodName.append( ejbReturn );
+ if (bean_tag != null) {
+ String jndiName =
dereferenceProperties(bean_tag.attributeValue("jndi-name"));
+ String localJndiName =
dereferenceProperties(bean_tag.attributeValue("local-jndi-name"));
+ //Return "local" jndi name
+ if ("local".equals(type)) {
+ return localJndiName != null ? localJndiName :
compName;
}
- // end of if ()
- else
- {
- homeMethodName.append(
InterfaceTagsHandler.getComponentInterface( type, clazz ) );
+ //Didn't ask for local, assume remote
+ return jndiName != null ? jndiName : compName;
}
- // end of else
- }
- else if( tagType.equals( "ejb:create-method" ) )
- {
- homeMethodName.append(
InterfaceTagsHandler.getComponentInterface( type, clazz ) );
- }
- homeMethodName.append( " " );
- homeMethodName.append( methodName.substring( 0, 1 ).toLowerCase() );
- homeMethodName.append( methodName.substring( 1 ) );
- homeMethodName.append( "(" );
-
- StringTokenizer st = new StringTokenizer(
method.signature().substring( 1, method.signature().length() - 1 ), "," );
- int k = 1;
-
- while( st.hasMoreTokens() )
- {
- homeMethodName.append( st.nextToken() ).append( " " ).append(
"param" ).append( k++ );
- if( st.hasMoreTokens() )
- {
- homeMethodName.append( " , " );
- }
- }
- homeMethodName.append( ")" );
- return fullPackageChange( homeMethodName.toString() );
- }
-
- /**
- * Converts ejbHome<em>blabla</em> to home<em>blabla</em> , the one that should
- * appear in home interface.
- *
- * @param methodName Description of Parameter
- * @return Description of the Returned Value
- * @exception XDocletException Description of Exception
- */
- public static String toHomeMethod( String methodName ) throws XDocletException
- {
- // Remove "ejbHome" prefix and lower case first char in rest:
"ejbHomeFoo"->"foo"
- return Character.toLowerCase( methodName.charAt( 7 ) ) +
methodName.substring( 8 );
- }
-
- /**
- * Converts ejbCreate<em>blabla</em> to create<em>blabla</em> , the one that
- * should appear in home interface.
- *
- * @param methodName Description of Parameter
- * @return Description of the Returned Value
- * @exception XDocletException Description of Exception
- */
- public static String toCreateMethod( String methodName ) throws
XDocletException
- {
- if( methodName.length() > 9 )
- {
- // Remove "ejbCreate" prefix and lower case first char in
rest: "ejbCreateFoo"->"createFoo", EJB 2 only
- return "create" + Character.toUpperCase( methodName.charAt( 9
) ) + methodName.substring( 10 );
- }
- else
- {
- return "create";
- }
- }
-
- /**
- * Describe what the method does
- *
- * @param 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
- */
- public static XMethod findFirstCreateMethodFor( XClass clazz ) throws
XDocletException
- {
- XMethod[] methods = clazz.methods();
-
- do
- {
- for( int i = 0; i < methods.length; i++ )
- {
- XMethod method = methods[i];
-
- if( HomeTagsHandler.isCreateMethod( method ) )
- {
- return method;
- }
- }
-
- clazz = clazz.superclass();
- }while ( clazz != null );
-
- return null;
- }
-
- /**
- * Converts ejbFind<em>blabla</em> to find<em>blabla</em> , the one that should
- * appear in home interface.
- *
- * @param methodName Description of Parameter
- * @return Description of the Returned Value
- * @exception XDocletException Description of Exception
- */
- public static String toFinderMethod( String methodName ) throws
XDocletException
- {
- // Remove "ejb" prefix and lower case first char in rest:
"ejbFindByPrimaryKey"->"findByPrimaryKey"
- return Character.toLowerCase( methodName.charAt( 3 ) ) +
methodName.substring( 4 );
- }
-
- /**
- * Describe what the method does
- *
- * @param s 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 return value
- */
- public static String fullPackageChange( String s )
- {
- StringTokenizer st = new StringTokenizer( s, " " );
- String sign = st.nextToken();
- StringBuffer ret = new StringBuffer();
-
- if( sign.equals( "Collection" ) )
- {
- ret.append( "java.util.Collection" );
- }
- else if( sign.equals( "Enumeration" ) )
- {
- ret.append( "java.util.Enumeration" );
- }
- else
- {
- ret.append( sign );
- }
- while( st.hasMoreTokens() )
- {
- ret.append( " " ).append( st.nextToken() );
- }
- return ret.toString();
- }
-
- /**
- * Gets the LocalHomeClassPattern attribute of the HomeTagsHandler class
- *
- * @return The LocalHomeClassPattern value
- */
- protected static String getLocalHomeClassPattern()
- {
- LocalHomeInterfaceSubTask localhomeintf_subtask = ( (
LocalHomeInterfaceSubTask ) DocletContext.getInstance().getSubTaskBy(
LocalHomeInterfaceSubTask.SUBTASK_NAME ) );
-
- if( localhomeintf_subtask != null )
- {
- return localhomeintf_subtask.getLocalHomeClassPattern();
- }
- else
- {
- return
LocalHomeInterfaceSubTask.DEFAULT_LOCALHOMEINTERFACE_CLASS_PATTERN;
- }
- }
-
- /**
- * Gets the HomeClassPattern attribute of the HomeTagsHandler class
- *
- * @return The HomeClassPattern value
- */
- protected static String getHomeClassPattern()
- {
- HomeInterfaceSubTask homeintf_subtask = ( ( HomeInterfaceSubTask )
DocletContext.getInstance().getSubTaskBy( HomeInterfaceSubTask.SUBTASK_NAME ) );
-
- if( homeintf_subtask != null )
- {
- return homeintf_subtask.getHomeClassPattern();
- }
- else
- {
- return
HomeInterfaceSubTask.DEFAULT_HOMEINTERFACE_CLASS_PATTERN;
- }
- }
-
- /**
- * Returns the full qualified local or remote home interface name for the bean,
- * depending on the value of type parameter.
- *
- * @param attributes The attributes of the template tag
- * @return Description of the Returned Value
- * @exception XDocletException Description of Exception
- * @doc:tag type="content"
- * @doc:param name="type" optional="false"
- * values="remote,local" description="Specifies the type of component home
- * interface."
- */
- public String homeInterface( Properties attributes ) throws XDocletException
- {
- String type = attributes.getProperty( "type" );
-
- type = type != null ? type : "remote";
-
- return getHomeInterface( type, getCurrentClass() );
- }
-
- /**
- * Evaluates the body block if current method is a create method. Create
- * methods should have ejb:create-method defined.
- *
- * @param template The body of the block tag
- * @param attributes The attributes of the template tag
- * @exception XDocletException Description of Exception
- * @todo I commented somehting strange but surely needed
- * @see #isCreateMethod(xjavadoc.XMethod)
- * @doc:tag type="block"
- * @doc:param name="superclasses" optional="true"
- * description="Traverse superclasses too. With false value used in
- * remote/local home interface templates. Default is False."
- */
- public void ifIsCreateMethod( String template, Properties attributes ) throws
XDocletException
- {
- String superclasses_str = attributes.getProperty( "superclasses" );
- boolean superclasses = TypeConversionUtil.stringToBoolean(
superclasses_str, true );
-
- if( isCreateMethod( getCurrentMethod() ) )
- {
- boolean currentMethodDoesntBelongToCurrentClass =
!getCurrentMethod().containingClass().equals( getCurrentClass() );
- boolean shouldTraverse =
shouldTraverseSuperclassForDependentClass( getCurrentMethod().containingClass(),
"ejb:home" );
-
- if( superclasses == false &&
currentMethodDoesntBelongToCurrentClass == true && shouldTraverse == false )
- {
- return;
- }
-
- generate( template );
- }
- }
-
- /**
- * Evaluates the body block if current create method's ejbPostCreate method
- * does not exist.
- *
- * @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 ifDoesntHavePostCreateMethod( String template, Properties
attributes )
- throws XDocletException
- {
- XMethod currentMethod = getCurrentMethod();
-
- if( !isCreateMethod( currentMethod ) )
- {
- throw new XDocletException( "Cannot call
ifDoesntHavePostCreateMethod if the current method is not a create method: "
- + currentMethod );
- }
-
- StringBuffer currentMethodName = new StringBuffer(
currentMethod.nameWithSignature() );
-
- currentMethodName.insert( 3, "Post" );
-
- XMethod ejbPostCreateMethod = getCurrentClass().getMethod(
currentMethodName.toString() );
-
- if( ejbPostCreateMethod == null )
- {
- generate( template );
- }
- }
-
- /**
- * Returns the appropriate ejbPostCreate method name for the current ejbCreate
- * method.
- *
- * @param attributes The attributes of the template tag
- * @return Description of the Returned Value
- * @doc:tag type="content"
- */
- public String ejbPostCreateSignature( Properties attributes )
- {
- StringBuffer currentMethodName = new StringBuffer(
getCurrentMethod().name() );
-
- currentMethodName.insert( 3, "Post" );
- return currentMethodName.toString();
- }
-
- /**
- * Evaluates the body block if current method is a home method. Home methods
- * should have ejb:home-method defined.
- *
- * @param template The body of the block tag
- * @param attributes The attributes of the template tag
- * @exception XDocletException Description of Exception
- * @see #isHomeMethod(xjavadoc.XMethod)
- * @doc:tag type="block"
- * @doc:param name="superclasses" optional="true"
- * description="Traverse superclasses too. With false value used in
- * remote/local home interface templates. Default is False."
- */
- public void ifIsHomeMethod( String template, Properties attributes ) throws
XDocletException
- {
- String superclasses_str = attributes.getProperty( "superclasses" );
- boolean superclasses = TypeConversionUtil.stringToBoolean(
superclasses_str, true );
-
- if( isHomeMethod( getCurrentMethod() ) )
- {
- if( superclasses == false &&
getCurrentMethod().containingClass() != getCurrentClass() &&
shouldTraverseSuperclassForDependentClass( getCurrentMethod().containingClass(),
"ejb:home" ) == false )
- {
- return;
- }
-
- generate( template );
- }
- }
-
- /**
- * Evaluates the body block if current method is ejbRemove method.
- *
- * @param template The body of the block tag
- * @exception XDocletException Description of Exception
- * @see #isRemoveMethod(xjavadoc.XMethod)
- * @doc:tag type="block"
- */
- public void ifNotRemoveMethod( String template ) throws XDocletException
- {
- if( !isRemoveMethod( getCurrentMethod() ) )
- {
- generate( template );
- }
- }
-
-// /**
-// * Evaluates the body block if current method is a ejbFind method.
-// *
-// * @param template The body of the block tag
-// * @param attributes The attributes of the template tag
-// * @exception XDocletException Description of Exception
-// * @see #isHomeMethod(xjavadoc.XMethod)
-// * @doc:tag type="block"
-// * @doc:param name="superclasses" optional="true"
-// * description="Traverse superclasses too. With false value used in
-// * remote/local home interface templates. Default is False."
-// */
-// public void ifIsFinderMethod( String template, Properties attributes ) throws
XDocletException
-// {
-// String superclasses_str = attributes.getProperty( "superclasses" );
-// boolean superclasses = TypeConversionUtil.stringToBoolean(
superclasses_str, true );
-//
-// if( isFinderMethod( getCurrentMethod() ) )
-// {
-// if( superclasses == false &&
getCurrentMethod().containingClass() != getCurrentClass() &&
shouldTraverseSuperclassForDependentClass( getCurrentMethod().containingClass(),
"ejb:home" ) == false )
-// return;
-//
-// generate( template );
-// }
-// }
-//
- /**
- * @param attributes The attributes of the template tag
- * @return Description of the Returned Value
- * @exception XDocletException Description of Exception
- * @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."
- * @doc:param name="type" optional="false"
- * values="remote,local" description="Specifies if we want the jndi name
- * value for local or remote lookup."
- */
- public String compName( Properties attributes ) throws XDocletException
- {
- String prefix_with_ejbslash_str = attributes.getProperty(
"prefixWithEjbSlash" );
- boolean prefix_with_ejbslash = TypeConversionUtil.stringToBoolean(
prefix_with_ejbslash_str, false );
- String type = attributes.getProperty( "type" );
-
- String ejb_name = getCompNameFor( getCurrentClass(), type );
-
- String compName;
-
- if( prefix_with_ejbslash == true )
- {
- compName = prefixWithEjbSlash( ejb_name );
- }
- else
- {
- compName = ejb_name;
- }
-
- return compName;
+ //nothing specified so madeup one
+ return compName;
}
- /**
- * @param attributes
- * @return Description of the Returned Value
- * @exception XDocletException Description of Exception
- * @doc:tag type="content"
- * @doc:param name="type" optional="false"
- * values="remote,local" description="Specifies if we want the jndi name
- * value for local or remote lookup."
- */
- public String jndiName( Properties attributes ) throws XDocletException
- {
- String type = attributes.getProperty( "type" );
- XTag bean_tag = getCurrentClass().doc().tag( "ejb:bean" );
- String compName = getCompNameFor( getCurrentClass(), type );
-
- if( bean_tag != null )
- {
- String jndiName = dereferenceProperties(
bean_tag.attributeValue( "jndi-name" ) );
- String localJndiName = dereferenceProperties(
bean_tag.attributeValue( "local-jndi-name" ) );
-
- //Return "local" jndi name
- if( "local".equals( type ) )
- {
- return localJndiName != null ? localJndiName :
compName;
- }
-
- //Didn't ask for local, assume remote
- return jndiName != null ? jndiName : compName;
- }
-
- //nothing specified so madeup one
- return compName;
- }
/**
* Returns the name of the class home interface extends.
@@ -681,8 +308,7 @@
* @exception XDocletException Description of Exception
* @doc:tag type="content"
*/
- public String extendsFrom( Properties attributes ) throws XDocletException
- {
+ public String extendsFrom(Properties attributes) throws XDocletException {
String type = attributes.getProperty( "type" );
type = type != null ? type : "remote";
@@ -693,33 +319,30 @@
return extendsFromFor( getCurrentClass(), "ejb:home", type,
extends_param_name, def_base_class_name );
}
+
/**
* Iterates over all finder methods defined in a class and super classes
*
+ * @todo skip EJBException as we do in home.j for home-methods
* @param template The body of the block tag
* @param attributes The attributes of the template tag
* @exception XDocletException Description of Exception
- * @todo skip EJBException as we do in home.j for
- * home-methods
* @doc:tag type="block"
- * @doc:param name="tagName" optional="false"
- * description="The tag name."
- * @doc:param name="superclasses" values="true,false"
- * description="If true then traverse superclasses also, otherwise look up
- * the tag in current concrete class only."
- * @doc:param name="tagKey" description="A tag property that
- * will be used as a unique key. This is used to avoid duplicate code due
- * to similar tags in superclasses."
+ * @doc:param name="tagName" optional="false" description="The tag name."
+ * @doc:param name="superclasses" values="true,false" description="If true then
+ * traverse superclasses also, otherwise look up the tag in current
+ * concrete class only."
+ * @doc:param name="tagKey" description="A tag property that will be used as a
+ * unique key. This is used to avoid duplicate code due to similar tags in
+ * superclasses."
*/
- public void forAllHomeMethods( String template, Properties attributes ) throws
XDocletException
- {
+ public void forAllHomeMethods(String template, Properties attributes) throws
XDocletException {
Category cat = Log.getCategory( HomeTagsHandler.class, "forAllFinders"
);
boolean superclasses = TypeConversionUtil.stringToBoolean(
attributes.getProperty( "superclasses" ), false );
String type = attributes.getProperty( "type" );
String tagType = attributes.getProperty( "tagName" );
- if( type == null )
- {
+ if (type == null) {
throw new XDocletException( "Attribute 'type' is mandatory for
'forAllFinders'" );
}
@@ -728,39 +351,31 @@
// Exclude definition coming from super classes
XClass currentClass = getCurrentClass().superclass();
- while( currentClass != null )
- {
- if( cat.isDebugEnabled() )
- {
+ while (currentClass != null) {
+ if (cat.isDebugEnabled()) {
cat.debug( "Looking for super definition in " +
currentClass.name() );
}
// 1. METHOD tags
XMethod[] methods = currentClass.methods();
- for( int i = 0; i < methods.length; i++ )
- {
+ for (int i = 0; i < methods.length; i++) {
XMethod method = methods[i];
- if( tagType.equals( "ejb:finder" ) )
- {
- if( !isFinderMethod( method ) )
- {
+ if (tagType.equals("ejb:finder")) {
+ if (!isFinderMethod(method)) {
continue;
}
}
- else if( tagType.equals( "ejb:create-method" ) )
- {
- if( !isCreateMethod( method ) )
- {
+ else if (tagType.equals("ejb:create-method")) {
+ if (!isCreateMethod(method)) {
continue;
}
}
String signature = getHomeDefinition( currentClass,
method, tagType, type );
- if( cat.isDebugEnabled() )
- {
+ if (cat.isDebugEnabled()) {
cat.debug( "Found " + signature );
}
already.add( signature );
@@ -769,15 +384,12 @@
// 2. CLASS tags
XTag[] superTags = currentClass.doc().tags( tagType, true );
- for( int i = 0; i < superTags.length; i++ )
- {
+ for (int i = 0; i < superTags.length; i++) {
String signature = fullPackageChange(
superTags[i].attributeValue( "signature" ) );
String typeMapping = superTags[i].attributeValue(
"result-type-mapping" );
- if( typeMapping == null ||
typeMapping.equalsIgnoreCase( type ) )
- {
- if( cat.isDebugEnabled() )
- {
+ if (typeMapping == null ||
typeMapping.equalsIgnoreCase(type)) {
+ if (cat.isDebugEnabled()) {
cat.debug( "Found " + signature );
}
already.add( signature );
@@ -790,96 +402,77 @@
XMethod[] methods = getCurrentClass().methods();
boolean fbpkFound = false;
- for( int i = 0; i < methods.length; i++ )
- {
+ for (int i = 0; i < methods.length; i++) {
XMethod method = methods[i];
String signature = null;
- if( tagType.equals( "ejb:finder" ) )
- {
- if( !isFinderMethod( method ) )
- {
+ if (tagType.equals("ejb:finder")) {
+ if (!isFinderMethod(method)) {
continue;
}
signature = getHomeDefinition( getCurrentClass(),
method, tagType, type );
- if( !already.add( signature ) )
- {
+ if (!already.add(signature)) {
continue;
}
- if( cat.isDebugEnabled() )
- {
+ if (cat.isDebugEnabled()) {
cat.debug( "Finder Method = " + signature );
}
}
- else if( tagType.equals( "ejb:create-method" ) )
- {
- if( !isCreateMethod( method ) )
- {
+ else if (tagType.equals("ejb:create-method")) {
+ if (!isCreateMethod(method)) {
continue;
}
String viewType = null;
XTag[] tags = method.doc().tags( tagType, superclasses
);
- for( int k = 0; k < tags.length; k++ )
- {
+ for (int k = 0; k < tags.length; k++) {
String attr = tags[k].attributeValue(
"view-type" );
- if( attr != null )
- {
+ if (attr != null) {
viewType = attr;
}
}
- if( viewType != null && !viewType.equals( "both" ) &&
!viewType.equals( type ) )
- {
+ if (viewType != null && !viewType.equals("both") &&
!viewType.equals(type)) {
continue;
}
signature = getHomeDefinition( getCurrentClass(),
method, tagType, type );
- if( !already.add( signature ) )
- {
+ if (!already.add(signature)) {
continue;
}
- if( cat.isDebugEnabled() )
- {
+ if (cat.isDebugEnabled()) {
cat.debug( "Create Method = " + signature );
}
}
- if( signature != null )
- {
+ if (signature != null) {
setCurrentSignature( signature );
XClass[] exceptions = method.thrownExceptions();
StringBuffer exc = new StringBuffer();
- for( int j = 0; j < exceptions.length; j++ )
- {
+ for (int j = 0; j < exceptions.length; j++) {
XClass exception = exceptions[j];
exc.append( exception.qualifiedName() );
- if( j != exceptions.length - 1 )
- {
+ if (j != exceptions.length - 1) {
exc.append( ',' );
}
}
- if( exc.length() == 0 )
- {
- if( tagType.equals( "ejb:finder" ) )
- {
+ if (exc.length() == 0) {
+ if (tagType.equals("ejb:finder")) {
exc.append(
"javax.ejb.FinderException" );
}
- else if( tagType.equals( "ejb:create-method" )
)
- {
+ else if (tagType.equals("ejb:create-method")) {
exc.append(
"javax.ejb.CreateException" );
}
}
- if( type.equalsIgnoreCase( "remote" ) )
- {
+ if (type.equalsIgnoreCase("remote")) {
exc.append( ",java.rmi.RemoteException" );
}
setCurrentExceptions( exc.toString() );
@@ -888,8 +481,9 @@
// If custom findByPrimaryKey exists then we should
not add the
// mandatory later
- if( method.name().equals( "findByPrimaryKey" ) )
+ if (method.name().equals("findByPrimaryKey")) {
fbpkFound = true;
+ }
generate( template );
}
@@ -898,25 +492,22 @@
// 2. Handle CLASS Tag level ejb:finder
XTag[] tags = getCurrentClass().doc().tags( tagType, superclasses );
- for( int i = 0; i < tags.length; i++ )
- {
+ for (int i = 0; i < tags.length; i++) {
String signature = fullPackageChange( tags[i].attributeValue(
"signature" ) );
String typeMapping = tags[i].attributeValue(
"result-type-mapping" );
- if( typeMapping == null || typeMapping.equalsIgnoreCase( type
) )
- {
- if( !already.add( signature ) )
- {
+ if (typeMapping == null || typeMapping.equalsIgnoreCase(type))
{
+ if (!already.add(signature)) {
continue;
}
- if( cat.isDebugEnabled() )
- {
+ if (cat.isDebugEnabled()) {
cat.debug( "Finder Method = " + signature );
}
- if( signature.indexOf( "findByPrimaryKey" ) != -1 )
+ if (signature.indexOf("findByPrimaryKey") != -1) {
fbpkFound = true;
+ }
setCurrentTag( tags[i] );
setCurrentSignature( signature );
@@ -924,169 +515,519 @@
StringBuffer exc = new StringBuffer();
exc.append( "javax.ejb.FinderException" );
- if( type.equalsIgnoreCase( "remote" ) )
- {
+ if (type.equalsIgnoreCase("remote")) {
+ exc.append(",java.rmi.RemoteException");
+ }
+ setCurrentExceptions(exc.toString());
+
+ generate(template);
+ }
+ }
+
+ // Add mandatory findByPrimaryKey if not already there
+ if (!fbpkFound && CmpTagsHandler.isEntityCmp(getCurrentClass()) &&
tagType.equals("ejb:finder")) {
+ StringBuffer fbpkSign = new
StringBuffer(InterfaceTagsHandler.getComponentInterface(type, getCurrentClass()));
+
+ fbpkSign.append(" findByPrimaryKey(");
+
fbpkSign.append(PkTagsHandler.getPkClassFor(getCurrentClass())).append("
pk").append(")");
+ if (already.add(fbpkSign)) {
+ setCurrentSignature(fbpkSign.toString());
+
+ StringBuffer exc = new StringBuffer();
+
+ exc.append("javax.ejb.FinderException");
+ if (type.equalsIgnoreCase("remote")) {
+ exc.append(",java.rmi.RemoteException");
+ }
+
+ setCurrentExceptions(exc.toString());
+ setCurrentMethod(null);
+ generate(template);
+ }
+ }
+
+ // Add mandatory create() method for stateless beans
+ if (SessionTagsHandler.isSession(getCurrentClass()) &&
tagType.equals("ejb:create-method")) {
+ if (already.size() == 0) {
+ StringBuffer createSign = new
StringBuffer(InterfaceTagsHandler.getComponentInterface(type, getCurrentClass()));
+
+ createSign.append(" create()");
+ setCurrentSignature(createSign.toString());
+
+ StringBuffer exc = new StringBuffer();
+
+ exc.append("javax.ejb.CreateException");
+ if (type.equalsIgnoreCase("remote")) {
exc.append( ",java.rmi.RemoteException" );
}
- setCurrentExceptions( exc.toString() );
+ setCurrentExceptions(exc.toString());
+ setCurrentMethod(null);
+ generate(template);
+ }
+ }
+
+ setCurrentTag(null);
+ setCurrentSignature(null);
+ setCurrentExceptions(null);
+ setCurrentMethod(null);
+
+ }
+
+
+ /**
+ * Describe what the method does
+ *
+ * @return Describe the return value
+ * @exception XDocletException Describe the exception
+ * @todo-javadoc Write javadocs for method
+ * @todo-javadoc Write javadocs for return value
+ * @todo-javadoc Write javadocs for exception
+ */
+ public String currentSignature() throws XDocletException {
+ return currentSignature;
+ }
+
+
+ /**
+ * Describe what the method does
+ *
+ * @return Describe the return value
+ * @exception XDocletException Describe the exception
+ * @todo-javadoc Write javadocs for method
+ * @todo-javadoc Write javadocs for return value
+ * @todo-javadoc Write javadocs for exception
+ */
+ public String currentExceptions() throws XDocletException {
+ return currentExceptions;
+ }
+
+
+ /**
+ * Sets the CurrentSignature attribute of the HomeTagsHandler object
+ *
+ * @param cs The new CurrentSignature value
+ */
+ protected void setCurrentSignature(String cs) {
+ this.currentSignature = cs;
+ }
+
+
+ /**
+ * Sets the CurrentExceptions attribute of the HomeTagsHandler object
+ *
+ * @param es The new CurrentExceptions value
+ */
+ protected void setCurrentExceptions(String es) {
+ this.currentExceptions = es;
+ }
+
+
+ /**
+ * Gets the DependentClassFor attribute of the HomeTagsHandler object
+ *
+ * @param clazz Describe what the parameter does
+ * @param type Describe what the parameter does
+ * @return The DependentClassFor value
+ * @exception XDocletException Describe the exception
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for exception
+ */
+ protected String getDependentClassFor(XClass clazz, String type) throws
XDocletException {
+ if ((type.equals("local") && InterfaceTagsHandler.isLocalEjb(clazz))
|| (type.equals("remote") && InterfaceTagsHandler.isRemoteEjb(clazz))) {
+ return getHomeInterface(type, clazz);
+ }
+ else {
+ return null;
+ }
+ }
+
+
+ /**
+ * Describe what the method 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
+ */
+ protected boolean shouldTraverseSuperclassForDependentClass(XClass clazz,
String tag_name) throws XDocletException {
+ if (super.shouldTraverseSuperclassForDependentClass(clazz, tag_name)
== false) {
+ return false;
+ }
+
+ //shouldn't include create methods of parent if parent is itself a
concrete ejb
+ if (isAConcreteEJBean(clazz)) {
+ return false;
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Similar to {@link InterfaceTagsHandler#getComponentInterface}. Relies on the
+ * ejb:home tag, which has the following relevant properties:
+ * <ul>
+ * <li> remote-class: The fully qualified name of the remote class -
+ * overrides all set patterns
+ * <li> local-class: The fully qualified name of the local class - overrides
+ * all set patterns
+ * <li> remote-pattern: The pattern to be used to determine the unqualified
+ * name of the remote class
+ * <li> local-pattern: The pattern to be used to determine the unqualified
+ * name of the local class
+ * <li> pattern: The pattern to be used in determining the unqualified remote
+ * and/or local home interface name - used where remote- or local- pattern
+ * are not specified.
+ * <li> remote-package: The package the remote home interface is to be placed
+ * in
+ * <li> local-package: The package the local home interface is to be placed
+ * in
+ * <li> package: The package the remote and/or local home interface is to be
+ * placed in - used where remote- or local- package are not specified.
+ * </ul>
+ *
+ *
+ * @param type The type of home interface - can be remote or local.
+ * @param clazz Description of Parameter
+ * @return The HomeInterface value
+ * @exception XDocletException Description of Exception
+ */
+ public static String getHomeInterface(String type, XClass clazz) throws
XDocletException {
+ Category cat = Log.getCategory(HomeTagsHandler.class,
"getHomeInterface");
+
+ // validate type
+ if (!"remote".equals(type) && !"local".equals(type)) {
+ throw new
XDocletException(Translator.getString("xdoclet.ejb.Messages",
+ "method_only_takes_remote_or_local", new
String[]{"getHomeInterface", type}));
+ }
+
+ String fileName = clazz.containingPackage().name();
+ String name_pattern = null;
+ String package_pattern = null;
+ String home_interface = null;
+
+ home_interface = clazz.doc().tagAttributeValue("ejb:home", type +
"-class");
+ if (cat.isDebugEnabled()) {
+ cat.debug(type + " home Interface for " +
clazz.qualifiedName() + " = " + home_interface);
+ }
+
+ if (home_interface != null) {
+ return home_interface;
+ }
- generate( template );
+ name_pattern = clazz.doc().tagAttributeValue("ejb:home", type +
"-pattern");
+ if (name_pattern == null) {
+ name_pattern = clazz.doc().tagAttributeValue("ejb:home",
"pattern");
+ if (name_pattern == null) {
+ name_pattern = "remote".equals(type) ?
getHomeClassPattern() : getLocalHomeClassPattern();
}
}
- // Add mandatory findByPrimaryKey if not already there
- if( !fbpkFound && CmpTagsHandler.isEntityCmp( getCurrentClass() ) &&
tagType.equals( "ejb:finder" ) )
- {
- StringBuffer fbpkSign = new StringBuffer(
InterfaceTagsHandler.getComponentInterface( type, getCurrentClass() ) );
-
- fbpkSign.append( " findByPrimaryKey(" );
- fbpkSign.append( PkTagsHandler.getPkClassFor(
getCurrentClass() ) ).append( " pk" ).append( ")" );
- if( already.add( fbpkSign ) )
- {
- setCurrentSignature( fbpkSign.toString() );
+ package_pattern = clazz.doc().tagAttributeValue("ejb:home", type +
"-package");
+ if (package_pattern == null) {
+ package_pattern = clazz.doc().tagAttributeValue("ejb:home",
"package");
+ }
- StringBuffer exc = new StringBuffer();
+ String ejb_name = null;
- exc.append( "javax.ejb.FinderException" );
- if( type.equalsIgnoreCase( "remote" ) )
- {
- exc.append( ",java.rmi.RemoteException" );
+ if (name_pattern.indexOf("{0}") != -1) {
+ ejb_name = MessageFormat.format(name_pattern, new
Object[]{getShortEjbNameFor(clazz)});
+ }
+ else {
+ ejb_name = name_pattern;
}
- setCurrentExceptions( exc.toString() );
- setCurrentMethod( null );
- generate( template );
+ String subtask_name = null;
+
+ if (type.equals("remote")) {
+ subtask_name = HomeInterfaceSubTask.SUBTASK_NAME;
}
+ else {
+ subtask_name = LocalHomeInterfaceSubTask.SUBTASK_NAME;
}
- // Add mandatory create() method for stateless beans
- if( SessionTagsHandler.isSession( getCurrentClass() ) &&
tagType.equals( "ejb:create-method" ) )
- {
- if( already.size() == 0 )
- {
- StringBuffer createSign = new StringBuffer(
InterfaceTagsHandler.getComponentInterface( type, getCurrentClass() ) );
+ // Fix package name
+ fileName = choosePackage(fileName, package_pattern, subtask_name);
+ fileName += "." + ejb_name;
- createSign.append( " create()" );
- setCurrentSignature( createSign.toString() );
+ return fileName;
+ }
- StringBuffer exc = new StringBuffer();
- exc.append( "javax.ejb.CreateException" );
- if( type.equalsIgnoreCase( "remote" ) )
- {
- exc.append( ",java.rmi.RemoteException" );
- }
- setCurrentExceptions( exc.toString() );
- setCurrentMethod( null );
- generate( template );
+ /**
+ * Returns true if method is an ejbRemove method, false otherwise.
+ *
+ * @param method Description of Parameter
+ * @return The RemoveMethod value
+ * @exception XDocletException Description of Exception
+ */
+ public static boolean isRemoveMethod(XMethod method) throws XDocletException {
+ return method.name().equals("ejbRemove");
}
+
+
+ /**
+ * Returns true if method is a create method marked with a ejb:create-method
+ * tag, false otherwise.
+ *
+ * @param method Description of Parameter
+ * @return The CreateMethod value
+ * @exception XDocletException Description of Exception
+ */
+ public static boolean isCreateMethod(XMethod method) throws XDocletException {
+ return method.doc().hasTag("ejb:create-method");
}
- setCurrentTag( null );
- setCurrentSignature( null );
- setCurrentExceptions( null );
- setCurrentMethod( null );
+ /**
+ * Returns true if method is a home method marked with a ejb:home-method tag,
+ * false otherwise.
+ *
+ * @param method Description of Parameter
+ * @return The HomeMethod value
+ * @exception XDocletException Description of Exception
+ */
+ public static boolean isHomeMethod(XMethod method) throws XDocletException {
+ return method.doc().hasTag("ejb:home-method");
}
+
/**
- * Describe what the method does
+ * Gets the CompNameFor attribute of the HomeTagsHandler class
*
- * @return Describe the return value
+ * @param clazz Describe what the parameter does
+ * @param type Describe what the parameter does
+ * @return The CompNameFor value
* @exception XDocletException Describe the exception
- * @todo-javadoc Write javadocs for method
- * @todo-javadoc Write javadocs for return value
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for exception
*/
- public String currentSignature() throws XDocletException
- {
- return currentSignature;
+ public static String getCompNameFor(XClass clazz, String type) throws
XDocletException {
+ String compName = getEjbNameFor(clazz).replace('.', '/');
+
+ if (type.equals("local") && isLocalEjb(clazz) && isRemoteEjb(clazz)) {
+ compName = compName + LOCAL_SUFFIX;
+ }
+
+ return compName;
}
+
/**
- * Describe what the method does
+ * Returns true if method is an ejbFind method, false otherwise.
*
- * @return Describe the return value
- * @exception XDocletException Describe the exception
- * @todo-javadoc Write javadocs for method
- * @todo-javadoc Write javadocs for return value
- * @todo-javadoc Write javadocs for exception
+ * @param method Description of Parameter
+ * @return The FinderMethod value
+ * @exception XDocletException Description of Exception
*/
- public String currentExceptions() throws XDocletException
- {
- return currentExceptions;
+ public static boolean isFinderMethod(XMethod method) throws XDocletException {
+ return method.name().startsWith("ejbFind");
}
+
/**
- * Gets the DependentClassFor attribute of the HomeTagsHandler object
+ * Gets the HomeDefinition attribute of the HomeTagsHandler class
*
* @param clazz Describe what the parameter does
+ * @param method Describe what the parameter does
+ * @param tagType Describe what the parameter does
* @param type Describe what the parameter does
- * @return The DependentClassFor value
+ * @return The HomeDefinition value
* @exception XDocletException Describe the exception
* @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for exception
*/
- protected String getDependentClassFor( XClass clazz, String type ) throws
XDocletException
- {
- if( ( type.equals( "local" ) && InterfaceTagsHandler.isLocalEjb( clazz
) ) || ( type.equals( "remote" ) && InterfaceTagsHandler.isRemoteEjb( clazz ) ) )
- {
- return getHomeInterface( type, clazz );
+ public static String getHomeDefinition(XClass clazz, XMethod method, String
tagType, String type)
+ throws XDocletException {
+ String methodName = method.name().substring(3);
+ StringBuffer homeMethodName = new StringBuffer();
+
+ if (tagType.equals("ejb:finder")) {
+ String ejbReturn = method.returnType().toString();
+
+ if (ejbReturn.equals("java.util.Collection")) {
+ homeMethodName.append(ejbReturn);
+
+ }
+ // end of if ()
+ else {
+
homeMethodName.append(InterfaceTagsHandler.getComponentInterface(type, clazz));
+
+ }
+ // end of else
+
+ }
+ else if (tagType.equals("ejb:create-method")) {
+
homeMethodName.append(InterfaceTagsHandler.getComponentInterface(type, clazz));
+ }
+ homeMethodName.append(" ");
+ homeMethodName.append(methodName.substring(0, 1).toLowerCase());
+ homeMethodName.append(methodName.substring(1));
+ homeMethodName.append("(");
+
+ StringTokenizer st = new
StringTokenizer(method.signature().substring(1, method.signature().length() - 1), ",");
+ int k = 1;
+
+ while (st.hasMoreTokens()) {
+ homeMethodName.append(st.nextToken()).append("
").append("param").append(k++);
+ if (st.hasMoreTokens()) {
+ homeMethodName.append(" , ");
}
- else
- {
- return null;
}
+ homeMethodName.append(")");
+ return fullPackageChange(homeMethodName.toString());
}
+
/**
- * Sets the CurrentSignature attribute of the HomeTagsHandler object
+ * Converts ejbHome<em>blabla</em> to home<em>blabla</em> , the one that should
+ * appear in home interface.
*
- * @param cs The new CurrentSignature value
+ * @param methodName Description of Parameter
+ * @return Description of the Returned Value
+ * @exception XDocletException Description of Exception
*/
- protected void setCurrentSignature( String cs )
- {
- this.currentSignature = cs;
+ public static String toHomeMethod(String methodName) throws XDocletException {
+ // Remove "ejbHome" prefix and lower case first char in rest:
"ejbHomeFoo"->"foo"
+ return Character.toLowerCase(methodName.charAt(7)) +
methodName.substring(8);
}
+
/**
- * Sets the CurrentExceptions attribute of the HomeTagsHandler object
+ * Converts ejbCreate<em>blabla</em> to create<em>blabla</em> , the one that
+ * should appear in home interface.
*
- * @param es The new CurrentExceptions value
+ * @param methodName Description of Parameter
+ * @return Description of the Returned Value
+ * @exception XDocletException Description of Exception
*/
- protected void setCurrentExceptions( String es )
- {
- this.currentExceptions = es;
+ public static String toCreateMethod(String methodName) throws XDocletException
{
+ if (methodName.length() > 9) {
+ // Remove "ejbCreate" prefix and lower case first char in
rest: "ejbCreateFoo"->"createFoo", EJB 2 only
+ return "create" + Character.toUpperCase(methodName.charAt(9))
+ methodName.substring(10);
}
+ else {
+ return "create";
+ }
+ }
+
/**
* Describe what the method 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
*/
- protected boolean shouldTraverseSuperclassForDependentClass( XClass clazz,
String tag_name ) throws XDocletException
- {
- if( super.shouldTraverseSuperclassForDependentClass( clazz, tag_name )
== false )
- {
- return false;
+ public static XMethod findFirstCreateMethodFor(XClass clazz) throws
XDocletException {
+ XMethod[] methods = clazz.methods();
+
+ do {
+ for (int i = 0; i < methods.length; i++) {
+ XMethod method = methods[i];
+
+ if (HomeTagsHandler.isCreateMethod(method)) {
+ return method;
+ }
}
- //shouldn't include create methods of parent if parent is itself a
concrete ejb
- if( isAConcreteEJBean( clazz ) )
- {
- return false;
+ clazz = clazz.superclass();
+ } while (clazz != null);
+
+ return null;
}
- return true;
+
+ /**
+ * Converts ejbFind<em>blabla</em> to find<em>blabla</em> , the one that should
+ * appear in home interface.
+ *
+ * @param methodName Description of Parameter
+ * @return Description of the Returned Value
+ * @exception XDocletException Description of Exception
+ */
+ public static String toFinderMethod(String methodName) throws XDocletException
{
+ // Remove "ejb" prefix and lower case first char in rest:
"ejbFindByPrimaryKey"->"findByPrimaryKey"
+ return Character.toLowerCase(methodName.charAt(3)) +
methodName.substring(4);
+ }
+
+
+ /**
+ * Describe what the method does
+ *
+ * @param s 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 return value
+ */
+ public static String fullPackageChange(String s) {
+ StringTokenizer st = new StringTokenizer(s, " ");
+ String sign = st.nextToken();
+ StringBuffer ret = new StringBuffer();
+
+ if (sign.equals("Collection")) {
+ ret.append("java.util.Collection");
+ }
+ else if (sign.equals("Enumeration")) {
+ ret.append("java.util.Enumeration");
+ }
+ else {
+ ret.append(sign);
+ }
+ while (st.hasMoreTokens()) {
+ ret.append(" ").append(st.nextToken());
+ }
+ return ret.toString();
+ }
+
+
+ /**
+ * Gets the LocalHomeClassPattern attribute of the HomeTagsHandler class
+ *
+ * @return The LocalHomeClassPattern value
+ */
+ protected static String getLocalHomeClassPattern() {
+ LocalHomeInterfaceSubTask localhomeintf_subtask =
((LocalHomeInterfaceSubTask)DocletContext.getInstance().getSubTaskBy(LocalHomeInterfaceSubTask.SUBTASK_NAME));
+
+ if (localhomeintf_subtask != null) {
+ return localhomeintf_subtask.getLocalHomeClassPattern();
+ }
+ else {
+ return
LocalHomeInterfaceSubTask.DEFAULT_LOCALHOMEINTERFACE_CLASS_PATTERN;
+ }
+ }
+
+
+ /**
+ * Gets the HomeClassPattern attribute of the HomeTagsHandler class
+ *
+ * @return The HomeClassPattern value
+ */
+ protected static String getHomeClassPattern() {
+ HomeInterfaceSubTask homeintf_subtask =
((HomeInterfaceSubTask)DocletContext.getInstance().getSubTaskBy(HomeInterfaceSubTask.SUBTASK_NAME));
+
+ if (homeintf_subtask != null) {
+ return homeintf_subtask.getHomeClassPattern();
+ }
+ else {
+ return
HomeInterfaceSubTask.DEFAULT_HOMEINTERFACE_CLASS_PATTERN;
+ }
}
}
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel