User: rinkrank
Date: 02/03/16 10:22:11
Modified: core/src/xdoclet Tag: XJAVADOC_REFACTORING
ConfigParamIntrospector.java DocletContext.java
DocletSupport.java DocletTask.java
NoInnerClassSubTask.java SubTask.java
TemplateSubTask.java XDocletTagSupport.java
Log:
xjavadoc refactoring. doesn't work yet, but it compiles
Revision Changes Path
No revision
No revision
1.4.2.1 +9 -9 xdoclet/core/src/xdoclet/ConfigParamIntrospector.java
Index: ConfigParamIntrospector.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/ConfigParamIntrospector.java,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -w -r1.4 -r1.4.2.1
--- ConfigParamIntrospector.java 9 Mar 2002 23:23:08 -0000 1.4
+++ ConfigParamIntrospector.java 16 Mar 2002 18:22:11 -0000 1.4.2.1
@@ -2,7 +2,7 @@
import org.apache.log4j.Category;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Map;
@@ -16,12 +16,12 @@
import xdoclet.tags.ConfigTagsHandler;
/**
- * Used by DocletTask. Creates and returns a Hashtable of config params for a
+ * Used by DocletTask. Creates and returns a HashMap of config params for a
* DocletTask or SubTask.
*
* @author Ara Abrahamian ([EMAIL PROTECTED])
* @created Jan 19, 2002
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.4.2.1 $
*/
public final class ConfigParamIntrospector
{
@@ -81,14 +81,14 @@
return getter_method;
}
- static void fillConfigParamsFor( DocletTask task, Hashtable configs )
+ static void fillConfigParamsFor( DocletTask task, HashMap configs )
{
- fillConfigParamsHashtableUsingReflectionFor( task, configs, "" );
+ fillConfigParamsHashMapUsingReflectionFor( task, configs, "" );
}
- static void fillConfigParamsFor( SubTask subtask, Hashtable configs )
+ static void fillConfigParamsFor( SubTask subtask, HashMap configs )
{
- fillConfigParamsHashtableUsingReflectionFor( subtask, configs,
subtask.getSubTaskName() + "." );
+ fillConfigParamsHashMapUsingReflectionFor( subtask, configs,
subtask.getSubTaskName() + "." );
}
/**
@@ -115,9 +115,9 @@
* @param configs
* @param prop_prefix
*/
- private static void fillConfigParamsHashtableUsingReflectionFor( Object
javabean, Hashtable configs, String prop_prefix )
+ private static void fillConfigParamsHashMapUsingReflectionFor( Object
javabean, HashMap configs, String prop_prefix )
{
- Category cat = Log.getCategory( ConfigParamIntrospector.class,
"fillConfigParamsHashtableUsingReflectionFor" );
+ Category cat = Log.getCategory( ConfigParamIntrospector.class,
"fillConfigParamsHashMapUsingReflectionFor" );
if( cat.isDebugEnabled() )
{
1.11.2.1 +15 -21 xdoclet/core/src/xdoclet/DocletContext.java
Index: DocletContext.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/DocletContext.java,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -u -w -r1.11 -r1.11.2.1
--- DocletContext.java 4 Mar 2002 21:57:31 -0000 1.11
+++ DocletContext.java 16 Mar 2002 18:22:11 -0000 1.11.2.1
@@ -1,35 +1,39 @@
package xdoclet;
-import xdoclet.template.TemplateContext;
-
import java.util.Hashtable;
+import java.util.HashMap;
import java.util.Collections;
import java.util.Map;
/**
* @author Ara Abrahamian ([EMAIL PROTECTED])
* @created June 19, 2001
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.11.2.1 $
*/
-public class DocletContext extends TemplateContext implements java.io.Serializable
+public class DocletContext implements java.io.Serializable
{
private static DocletContext singleInstance = null;
- private String sourcePath;
- private String classPath;
private String destDir;
private String mergeDir;
private String excludedTags;
private SubTask[] subTasks;
private Hashtable properties;
+ private HashMap configs;
+ private boolean force;
+
private Map unmodifiableProperties;
- private Hashtable configs;
private SubTask activeSubTask;
- private boolean force;
- public DocletContext( String sourcePath, String classPath, String destDir,
String mergeDir, String excludedTags, SubTask[] subTasks, Hashtable properties,
Hashtable configs, boolean force )
+ public DocletContext(
+ String destDir,
+ String mergeDir,
+ String excludedTags,
+ SubTask[] subTasks,
+ Hashtable properties,
+ HashMap configs,
+ boolean force
+ )
{
- this.sourcePath = sourcePath;
- this.classPath = classPath;
this.destDir = destDir;
this.mergeDir = mergeDir;
this.excludedTags = excludedTags;
@@ -52,16 +56,6 @@
public SubTask getActiveSubTask()
{
return activeSubTask;
- }
-
- public String getSourcePath()
- {
- return sourcePath;
- }
-
- public String getClassPath()
- {
- return classPath;
}
public String getDestDir()
1.6.2.1 +46 -48 xdoclet/core/src/xdoclet/DocletSupport.java
Index: DocletSupport.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/DocletSupport.java,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -w -r1.6 -r1.6.2.1
--- DocletSupport.java 5 Feb 2002 00:47:09 -0000 1.6
+++ DocletSupport.java 16 Mar 2002 18:22:11 -0000 1.6.2.1
@@ -1,22 +1,20 @@
package xdoclet;
-import com.sun.javadoc.ClassDoc;
-import com.sun.javadoc.FieldDoc;
-import com.sun.javadoc.MethodDoc;
-import com.sun.javadoc.PackageDoc;
-import com.sun.javadoc.ConstructorDoc;
-import com.sun.javadoc.Tag;
+import xjavadoc.XClass;
+import xjavadoc.XField;
+import xjavadoc.XMethod;
+import xjavadoc.XPackage;
+import xjavadoc.XConstructor;
+import xjavadoc.XTag;
import org.apache.log4j.Category;
-import xdoclet.util.DocletUtil;
-
import java.util.Stack;
/**
* @author Ara Abrahamian ([EMAIL PROTECTED])
* @created Oct 13, 2001
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.6.2.1 $
*/
public abstract class DocletSupport
{
@@ -26,7 +24,7 @@
* between class/method/field/constructor/whatever tags, and currentTag can
* point to any one them.
*/
- protected static Tag currentTag;
+ protected static XTag currentTag;
/**
* The current class stack is used for pushing/poping classes to/from it, so
@@ -35,9 +33,9 @@
* and each may set a new class as the current class (by pushing the class to
* top of stack).
*
- * @see #setCurrentClass(com.sun.javadoc.ClassDoc)
+ * @see #setCurrentClass(xjavadoc.XClass)
* @see #getCurrentClass()
- * @see #pushCurrentClass(com.sun.javadoc.ClassDoc)
+ * @see #pushCurrentClass(xjavadoc.XClass)
* @see #popCurrentClass()
*/
private transient Stack currentClassStack = null;
@@ -48,9 +46,9 @@
* nestedly.
*
* @see #getCurrentMethod()
- * @see #setCurrentMethod(com.sun.javadoc.MethodDoc)
+ * @see #setCurrentMethod(xjavadoc.XMethod)
*/
- private transient MethodDoc currentMethod = null;
+ private transient XMethod currentMethod = null;
/**
* Reference to the current constructor. Unlike current class stack, there's no
@@ -58,9 +56,9 @@
* reference nestedly.
*
* @see #getCurrentConstructor()
- * @see #setCurrentConstructor(com.sun.javadoc.ConstructorDoc)
+ * @see #setCurrentConstructor(xjavadoc.XConstructor)
*/
- private transient ConstructorDoc currentConstructor = null;
+ private transient XConstructor currentConstructor = null;
/**
* Reference to the current field. Unlike current class stack, there's no stack
@@ -68,9 +66,9 @@
* nestedly.
*
* @see #getCurrentField()
- * @see #setCurrentField(com.sun.javadoc.FieldDoc)
+ * @see #setCurrentField(xjavadoc.XField)
*/
- private transient FieldDoc currentField = null;
+ private transient XField currentField = null;
/**
* Reference to the current package. Unlike current class stack, there's no
@@ -78,16 +76,16 @@
* reference nestedly.
*
* @see #getCurrentPackage()
- * @see #setCurrentPackage(com.sun.javadoc.PackageDoc)
+ * @see #setCurrentPackage(xjavadoc.XPackage)
*/
- private transient PackageDoc currentPackage = null;
+ private transient XPackage currentPackage = null;
public DocletSupport()
{
currentClassStack = new Stack();
}
- public static Tag getCurrentTag()
+ public static XTag getCurrentTag()
{
return currentTag;
}
@@ -101,12 +99,12 @@
* @ejb:doclet-generated class tag defined. EJBDoclet does not try to analyze
* classes that are generated by EJBDoclet itself.
*/
- public static boolean isDocletGenerated( ClassDoc clazz )
+ public static boolean isDocletGenerated( XClass clazz )
{
- return DocletUtil.hasTag( clazz, "xdoclet-generated", false );
+ return clazz.doc().hasTag( "xdoclet-generated", false );
}
- public static void setCurrentTag( Tag currentTag )
+ public static void setCurrentTag( XTag currentTag )
{
DocletSupport.currentTag = currentTag;
}
@@ -115,20 +113,20 @@
* Peeks and return the current class from top of currentClassStack stack.
*
* @return The CurrentClass value
- * @see #setCurrentClass(com.sun.javadoc.ClassDoc)
+ * @see #setCurrentClass(xjavadoc.XClass)
*/
- public ClassDoc getCurrentClass()
+ public XClass getCurrentClass()
{
- return currentClassStack.empty() ? null : ( ClassDoc )
currentClassStack.peek();
+ return currentClassStack.empty() ? null : ( XClass )
currentClassStack.peek();
}
/**
* Returns current package.
*
* @return The CurrentPackage value
- * @see #setCurrentPackage(com.sun.javadoc.PackageDoc)
+ * @see #setCurrentPackage(xjavadoc.XPackage)
*/
- public PackageDoc getCurrentPackage()
+ public XPackage getCurrentPackage()
{
return currentPackage;
}
@@ -137,9 +135,9 @@
* Returns current method.
*
* @return The CurrentMethod value
- * @see #setCurrentMethod(com.sun.javadoc.MethodDoc)
+ * @see #setCurrentMethod(xjavadoc.XMethod)
*/
- public MethodDoc getCurrentMethod()
+ public XMethod getCurrentMethod()
{
return currentMethod;
}
@@ -148,9 +146,9 @@
* Returns current constructor.
*
* @return The CurrentConstructor value
- * @see #setCurrentConstructor(com.sun.javadoc.ConstructorDoc)
+ * @see #setCurrentConstructor(xjavadoc.XConstructor)
*/
- public ConstructorDoc getCurrentConstructor()
+ public XConstructor getCurrentConstructor()
{
return currentConstructor;
}
@@ -159,9 +157,9 @@
* Returns current field.
*
* @return The CurrentField value
- * @see #setCurrentField(com.sun.javadoc.FieldDoc)
+ * @see #setCurrentField(xjavadoc.XField)
*/
- public FieldDoc getCurrentField()
+ public XField getCurrentField()
{
return currentField;
}
@@ -170,9 +168,9 @@
* Returns current package.
*
* @param pakkage The new CurrentPackage value
- * @see #setCurrentPackage(com.sun.javadoc.PackageDoc)
+ * @see #setCurrentPackage(xjavadoc.XPackage)
*/
- public void setCurrentPackage( PackageDoc pakkage )
+ public void setCurrentPackage( XPackage pakkage )
{
currentPackage = pakkage;
@@ -181,17 +179,17 @@
currentClassStack.clear();
}
- public void setCurrentMethod( MethodDoc method )
+ public void setCurrentMethod( XMethod method )
{
currentMethod = method;
}
- public void setCurrentConstructor( ConstructorDoc constructor )
+ public void setCurrentConstructor( XConstructor constructor )
{
currentConstructor = constructor;
}
- public void setCurrentField( FieldDoc field )
+ public void setCurrentField( XField field )
{
currentField = field;
}
@@ -203,7 +201,7 @@
* @param clazz The new CurrentClass value
* @see #getCurrentClass()
*/
- public void setCurrentClass( ClassDoc clazz )
+ public void setCurrentClass( XClass clazz )
{
currentClassStack.clear();
currentClassStack.push( clazz );
@@ -216,12 +214,12 @@
* @param clazz Description of Parameter
* @return Description of the Returned Value
* @see #getCurrentClass()
- * @see #setCurrentClass(com.sun.javadoc.ClassDoc)
+ * @see #setCurrentClass(xjavadoc.XClass)
* @see #popCurrentClass()
*/
- public ClassDoc pushCurrentClass( ClassDoc clazz )
+ public XClass pushCurrentClass( XClass clazz )
{
- return ( ClassDoc ) currentClassStack.push( clazz );
+ return ( XClass ) currentClassStack.push( clazz );
}
/**
@@ -230,12 +228,12 @@
*
* @return Description of the Returned Value
* @see #getCurrentClass()
- * @see #setCurrentClass(com.sun.javadoc.ClassDoc)
- * @see #pushCurrentClass(com.sun.javadoc.ClassDoc)
+ * @see #setCurrentClass(xjavadoc.XClass)
+ * @see #pushCurrentClass(xjavadoc.XClass)
*/
- public ClassDoc popCurrentClass()
+ public XClass popCurrentClass()
{
- return ( ClassDoc ) currentClassStack.pop();
+ return ( XClass ) currentClassStack.pop();
}
}
1.22.2.1 +70 -364 xdoclet/core/src/xdoclet/DocletTask.java
Index: DocletTask.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/DocletTask.java,v
retrieving revision 1.22
retrieving revision 1.22.2.1
diff -u -w -r1.22 -r1.22.2.1
--- DocletTask.java 7 Mar 2002 22:37:18 -0000 1.22
+++ DocletTask.java 16 Mar 2002 18:22:11 -0000 1.22.2.1
@@ -1,7 +1,5 @@
package xdoclet;
-import com.sun.javadoc.RootDoc;
-
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
@@ -17,9 +15,11 @@
import xdoclet.util.Translator;
import xdoclet.tags.ConfigTagsHandler;
+import xjavadoc.ant.XJavadocTask;
+
import java.io.*;
-import java.util.Hashtable;
-import java.util.Vector;
+import java.util.HashMap;
+import java.util.ArrayList;
import java.beans.Introspector;
/**
@@ -28,71 +28,45 @@
* writing a new task.
*
* @author Ara Abrahamian ([EMAIL PROTECTED])
+ * @author <a href="mailto:[EMAIL PROTECTED]">Aslak Helles�y</a>
* @created June 19, 2001
- * @version $Revision: 1.22 $
+ * @version $Revision: 1.22.2.1 $
*/
-public class DocletTask extends Task
+public class DocletTask extends XJavadocTask
{
- public final static String XDOCLET_VERSION = "1.1.2";
-
+ public final static String XDOCLET_VERSION = "1.2.0";
protected transient DocletContext context = null;
+
private File destDir;
private File mergeDir;
- private Path sourcePath;
- private Path classpath;
- private Reference classpathRef;
-
- private Vector filesets = new Vector();
-
- private String packageNames = null;
- private String excludePackageNames = null;
private String excludedTags = null;
- private String maxmemory = null;
private boolean force = false;
- private Vector templates = new Vector();
- private Vector configParams = new Vector();
+ private ArrayList templates = new ArrayList();
+ private ArrayList configParams = new ArrayList();
- public Vector getConfigParams()
- {
- return configParams;
+ public DocletTask() {
+ setClassname("xdoclet.XDocletMain");
}
- public File getMergeDir()
- {
- return mergeDir;
- }
-
- public Path getSourcePath()
- {
- return sourcePath;
- }
-
- public Path getClasspath()
- {
- return classpath;
- }
-
- public Reference getClasspathRef()
- {
- return classpathRef;
- }
-
- public Vector getFilesets()
- {
- return filesets;
+ public void setSourcepath( Path path ) {
+ System.out.println( "sourcepath is deprecated. the preferred way to
design sources is via nested <fileset>" );
+ String dir = path.toString();
+ FileSet fileSet = new FileSet();
+ fileSet.setDir(new File(dir));
+ fileSet.setIncludes("**/*.java");
}
- public String getPackageNames()
+ public ArrayList getConfigParams()
{
- return packageNames;
+ return configParams;
}
- public String getExcludePackageNames()
+ public File getMergeDir()
{
- return excludePackageNames;
+ return mergeDir;
}
public String getExcludedTags()
@@ -100,7 +74,7 @@
return excludedTags;
}
- public Vector getTemplates()
+ public ArrayList getTemplates()
{
return templates;
}
@@ -110,11 +84,6 @@
return destDir;
}
- public String getMaxmemory()
- {
- return maxmemory;
- }
-
public boolean isForce()
{
return force;
@@ -122,12 +91,12 @@
public void setPackageNames( String src )
{
- packageNames = src;
+ throw new BuildException("packageNames is obsolete since xjavadoc was
introduced. Use a fileset instead");
}
public void setExcludePackageNames( String src )
{
- excludePackageNames = src;
+ throw new BuildException("excludePackageNames is obsolete since
xjavadoc was introduced. Use a fileset instead");
}
public void setExcludedTags( String tags )
@@ -145,125 +114,33 @@
mergeDir = dir;
}
- public void setSourcepath( Path src )
- {
- if( sourcePath == null )
- sourcePath = src;
- else
- sourcePath.append( src );
- }
-
- public void setClasspath( Path src )
- {
- if( classpath == null )
- classpath = src;
- else
- classpath.append( src );
- }
-
- public void setClasspathRef( org.apache.tools.ant.types.Reference ref )
- {
- this.classpathRef = ref;
- createClasspath().setRefid( ref );
- }
-
- public void setMaxmemory( String maxmemory )
- {
- this.maxmemory = maxmemory;
- }
-
public void setForce( boolean force )
{
this.force = force;
}
- /**
- * Create a nested <sourcepath ...> element for multiple source path support.
- *
- * @return a nested src element.
- */
- public Path createSourcepath()
- {
- if( sourcePath == null )
- sourcePath = new Path( project );
-
- return sourcePath.createPath();
- }
-
- public Path createClasspath()
- {
- if( classpath == null )
- classpath = new Path( project );
-
- return classpath.createPath();
- }
-
- /**
- * Adds a set of files (nested fileset attribute).
- *
- * @param set The feature to be added to the Fileset attribute
- */
- public void addFileset( FileSet set )
- {
- filesets.addElement( set );
- }
-
public void addTemplate( TemplateSubTask subtask )
{
- templates.addElement( subtask );
+ templates.add( subtask );
}
public void addXmlTemplate( XmlSubTask subtask )
{
- templates.addElement( subtask );
+ templates.add( subtask );
}
public void addConfigParam( ConfigParameter config_param )
{
- configParams.addElement( config_param );
+ configParams.add( config_param );
}
- public void execute() throws BuildException
- {
- Category cat = Log.getCategory( DocletTask.class, "execute" );
-
- validateOptions();
-
- cat.debug( "Options validated." );
-
- try
- {
- saveContext( getContext(), "DocletContext.edc" );
-
- cat.debug( "Context saved." );
-
- createTask().execute();
-
- cat.debug( "Task executed." );
- }
- catch( IOException ex )
+ protected ArrayList getSubTasks()
{
- cat.error( "IO error!", ex );
-
- try
- {
- throw new BuildException( Translator.getString(
"context_write_error",
- new String[]{getTaskName()} ) );
- }
- catch( XDocletException xe )
- {
- throw new BuildException( xe );
- }
- }
- }
-
- protected Vector getSubTasks()
- {
- Vector true_subtasks = new Vector();
+ ArrayList true_subtasks = new ArrayList();
for( int i = 0; i < templates.size(); i++ )
{
- TemplateSubTask holder = ( TemplateSubTask )
templates.elementAt( i );
+ TemplateSubTask holder = ( TemplateSubTask ) templates.get( i
);
SubTask subtask = getSubTaskFromPlaceHolder( holder );
@@ -280,7 +157,7 @@
continue;
}
- true_subtasks.addElement( subtask );
+ true_subtasks.add( subtask );
}
return true_subtasks;
@@ -327,12 +204,18 @@
if( context != null )
return context;
- Vector subtasks = getSubTasks();
- Hashtable configs = getConfigParams( subtasks );
+ ArrayList subtasks = getSubTasks();
+ HashMap configs = getConfigParams( subtasks );
- context = new DocletContext( this.sourcePath.toString(),
this.classpath.toString(), this.destDir.toString(),
- this.mergeDir != null ? this.mergeDir.toString() : null,
this.excludedTags,
- ( SubTask[] ) subtasks.toArray( new SubTask[0] ),
project.getProperties(), configs, force );
+ context = new DocletContext(
+ this.destDir.toString(),
+ this.mergeDir != null ? this.mergeDir.toString() : null,
+ this.excludedTags,
+ ( SubTask[] ) subtasks.toArray( new SubTask[0] ),
+ project.getProperties(),
+ configs,
+ force
+ );
//now register this single instance
DocletContext.setSingleInstance( context );
@@ -340,9 +223,9 @@
return context;
}
- protected Hashtable getConfigParams( Vector subtasks )
+ protected HashMap getConfigParams( ArrayList subtasks )
{
- Hashtable configs = new Hashtable();
+ HashMap configs = new HashMap();
//config params of task
ConfigParamIntrospector.fillConfigParamsFor( this, configs );
@@ -350,7 +233,7 @@
//config params of substask
for( int i = 0; i < subtasks.size(); i++ )
{
- SubTask sub_task = ( SubTask ) subtasks.elementAt( i );
+ SubTask sub_task = ( SubTask ) subtasks.get( i );
if( sub_task != null )
{
@@ -369,22 +252,11 @@
protected void validateOptions() throws BuildException
{
+ super.validateOptions();
try
{
if( destDir == null )
throw new BuildException( Translator.getString(
"attribute_not_present_error", new String[]{"destDir"} ), location );
-
- if( sourcePath == null )
- throw new BuildException( Translator.getString(
"attribute_not_present_error", new String[]{"sourcePath"} ), location );
-
- if( sourcePath.list().length == 0 )
- throw new BuildException( Translator.getString(
"attribute_not_set_error", new String[]{"sourcePath"} ), location );
-
- if( classpath == null )
- classpath =
org.apache.tools.ant.types.Path.systemClasspath;
-
- if( ( packageNames == null && filesets.size() == 0 ) || (
packageNames != null && filesets.size() > 0 ) )
- throw new BuildException( Translator.getString(
"no_packagenames_or_filesets" ), location );
}
catch( XDocletException xe )
{
@@ -394,6 +266,26 @@
validateSubTasks();
}
+ private final static File DEFAULT_TMP_FILE = new
File(System.getProperty("java.io.tmpdir"), "xdoclet.ser");
+ private File _tmpFile = DEFAULT_TMP_FILE;
+
+ public void setXdoclettempfile(File tmpFile) {
+ _tmpFile = tmpFile;
+ }
+
+ public void execute() throws BuildException
+ {
+ try {
+ // save the context and pass its filename as an arg to the main
+ save(getContext(), _tmpFile);
+ createArg().setValue(_tmpFile.getAbsolutePath());
+ super.execute();
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new BuildException(e);
+ }
+ }
+
protected void validateSubTasks() throws BuildException
{
DocletContext context = getContext();
@@ -417,200 +309,14 @@
}
}
- protected Javadoc createTask() throws BuildException
- {
- Javadoc javadoc = ( Javadoc ) project.createTask( "javadoc" );
-
- javadoc.setVerbose( false );
- javadoc.setFailonerror( true );
- javadoc.setPrivate( true );
- javadoc.setUseExternalFile( true );
-
- if( getMaxmemory() != null )
- javadoc.setMaxmemory( getMaxmemory() );
-
- javadoc.setOwningTarget( this.getOwningTarget() );
- javadoc.setTaskName( this.getTaskName() );
- javadoc.setDescription( this.getDescription() );
-
- if( this.packageNames != null )
- {
- javadoc.setPackagenames( this.packageNames );
- }
- else if( filesets.size() > 0 )
- {
- String comma_sep_list = "";
-
- for( int i = 0; i < filesets.size(); i++ )
- {
- FileSet fs = ( FileSet ) filesets.elementAt( i );
- DirectoryScanner ds = fs.getDirectoryScanner( project
);
- File from_dir = fs.getDir( project );
- String[] src_files = ds.getIncludedFiles();
-
- for( int j = 0; j < src_files.length; j++ )
- {
- File source_file = new File( from_dir +
File.separator + src_files[j] );
-
- if( source_file.getName().endsWith( ".java" ) )
- {
- // only pass java files to javadoc.
- comma_sep_list +=
source_file.toString();
- comma_sep_list += ",";
- }
- }
- }
-
- javadoc.setSourcefiles( comma_sep_list );
- }
-
- String log4j_config_file = System.getProperty( "log4j.configuration" );
-
- if( log4j_config_file != null )
- javadoc.setAdditionalparam( "-J-Dlog4j.configuration=" +
log4j_config_file );
-
- //\\javadoc.setExcludePackageNames( this.excludePackageNames );
-
- javadoc.setSourcepath( this.sourcePath );
- javadoc.setClasspath( this.classpath );
- javadoc.setClasspathRef( this.classpathRef );
-
- Javadoc.DocletInfo doclet = javadoc.createDoclet();
-
- doclet.setName( "xdoclet.DocletTask$DocletMain" );
- doclet.setPath( this.classpath );
- doclet.setPathRef( this.classpathRef );
-
- /*
- * String path_str =
this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile().toString();
- * if( path_str != null && path_str.startsWith( "/" ) )
- * {
- * it always begins with a / in front of it!!!
- * path_str = path_str.substring( 1 );
- * }
- * doclet.createPath().setPath( path_str );
- */
- return javadoc;
- }
-
- protected void saveContext( DocletContext context, String file_name ) throws
java.io.IOException
- {
- FileOutputStream fos = new FileOutputStream( System.getProperty(
"java.io.tmpdir" ) + File.separator + file_name );
- ObjectOutputStream oos = new ObjectOutputStream( new
BufferedOutputStream( fos ) );
-
- oos.writeObject( context );
- oos.flush();
- fos.close();
- }
-
- private void fillWithUserDefinedConfigParams( Hashtable configs, Vector
config_params, String prefix )
+ private void fillWithUserDefinedConfigParams( HashMap configs, ArrayList
config_params, String prefix )
{
//config params declared with <configParam name="nnn" value="val"/>
for( int i = 0; i < config_params.size(); i++ )
{
- ConfigParameter config_param = ( ConfigParameter )
config_params.elementAt( i );
+ ConfigParameter config_param = ( ConfigParameter )
config_params.get( i );
configs.put( ( prefix + config_param.getName()
).toLowerCase(), config_param.getValue() );
- }
- }
-
- /**
- * @author Ara Abrahamian ([EMAIL PROTECTED])
- * @created April 30, 2001
- */
- public final static class DocletMain
- {
- public static boolean start( RootDoc root ) throws XDocletException
- {
- Category cat = Log.getCategory( DocletMain.class, "start" );
-
- try
- {
- DocletContext.setSingleInstance( loadContext() );
-
- if( cat.isDebugEnabled() )
- cat.debug( "Context successfully loaded." );
-
- DocletContext.getInstance().setRoot( root );
-
- SubTask[] subtasks =
DocletContext.getInstance().getSubTasks();
-
- for( int i = 0; i < subtasks.length; i++ )
- {
- if( subtasks[i] != null )
- {
- if( cat.isDebugEnabled() )
- cat.debug( "SubTask " +
subtasks[i].getSubTaskName() + "Initialized." );
-
- subtasks[i].init();
-
DocletContext.getInstance().setActiveSubTask( subtasks[i] );
-
- System.out.println(
Translator.getString( "running_taskname", new String[]{"<" +
subtasks[i].getSubTaskName() + "/>"} ) );
- subtasks[i].execute();
- }
- }
-
- return true;
- }
- catch( IOException e )
- {
- System.out.println( Translator.getString(
"context_read_error" ) );
-
- if( cat.isDebugEnabled() )
- {
- cat.error( "IOException", e );
- }
-
- return false;
- }
- catch( XDocletException e )
- {
- System.out.println( Translator.getString(
"running_failed" ) );
- System.out.println( "<<" + e.getMessage() + ">>" );
-
- if( e.getNestedException() instanceof
TemplateException )
- {
- TemplateException template_ex = (
TemplateException ) e.getNestedException();
-
- if( cat.isDebugEnabled() )
- {
- cat.error( "Template Exception = " +
template_ex );
- cat.error( "Nested Exception = " +
template_ex.getNestedException() );
- }
- }
-
- //for now throw XDocletException to stop Ant till
Ant's <javadoc/> task is fixed.
-
- if( cat.isDebugEnabled() )
- {
- cat.error( "Exception trace:\n" +
e.getPrintStackTrace() );
- }
-
- throw e;
- //return false;
- }
- }
-
- private static DocletContext loadContext() throws IOException,
XDocletException
- {
- File file = new File( System.getProperty( "java.io.tmpdir" ) +
File.separator + "DocletContext.edc" );
- FileInputStream fis = new FileInputStream( file );
- ObjectInputStream ois = new ObjectInputStream( new
BufferedInputStream( fis ) );
- DocletContext context = null;
-
- try
- {
- context = ( DocletContext ) ois.readObject();
- }
- catch( ClassNotFoundException e )
- {
- throw new XDocletException( Translator.getString(
"incorrect_classpath" ) );
- }
-
- fis.close();
- file.delete();
-
- return context;
}
}
1.2.2.1 +2 -2 xdoclet/core/src/xdoclet/NoInnerClassSubTask.java
Index: NoInnerClassSubTask.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/NoInnerClassSubTask.java,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -w -r1.2 -r1.2.2.1
--- NoInnerClassSubTask.java 9 Mar 2002 23:23:08 -0000 1.2
+++ NoInnerClassSubTask.java 16 Mar 2002 18:22:11 -0000 1.2.2.1
@@ -1,7 +1,7 @@
package xdoclet;
-import com.sun.javadoc.ClassDoc;
+import xjavadoc.XClass;
import xdoclet.TemplateSubTask;
import xdoclet.XDocletException;
@@ -22,7 +22,7 @@
* @return true if not an inner class
* @exception XDocletException
*/
- protected boolean matchesGenerationRules( ClassDoc clazz ) throws
XDocletException
+ protected boolean matchesGenerationRules( XClass clazz ) throws
XDocletException
{
// don't want to generate for inner classes
return clazz.containingClass() == null;
1.62.2.1 +5 -5 xdoclet/core/src/xdoclet/SubTask.java
Index: SubTask.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/SubTask.java,v
retrieving revision 1.62
retrieving revision 1.62.2.1
diff -u -w -r1.62 -r1.62.2.1
--- SubTask.java 4 Mar 2002 21:32:41 -0000 1.62
+++ SubTask.java 16 Mar 2002 18:22:11 -0000 1.62.2.1
@@ -4,7 +4,7 @@
import java.io.File;
import java.io.Serializable;
-import java.util.Vector;
+import java.util.ArrayList;
import xdoclet.util.Log;
@@ -22,7 +22,7 @@
*
* @author Ara Abrahamian ([EMAIL PROTECTED])
* @created June 16, 2001
- * @version $Revision: 1.62 $
+ * @version $Revision: 1.62.2.1 $
*/
public abstract class SubTask extends DocletSupport implements Serializable
{
@@ -40,11 +40,11 @@
*/
private File mergeDir = null;
- private Vector configParams = new Vector();
+ private ArrayList configParams = new ArrayList();
private String subtaskName;
- public Vector getConfigParams()
+ public ArrayList getConfigParams()
{
return configParams;
}
@@ -86,7 +86,7 @@
public void addConfigParam( ConfigParameter config_param )
{
- configParams.addElement( config_param );
+ configParams.add( config_param );
}
/**
1.29.2.1 +36 -127 xdoclet/core/src/xdoclet/TemplateSubTask.java
Index: TemplateSubTask.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/TemplateSubTask.java,v
retrieving revision 1.29
retrieving revision 1.29.2.1
diff -u -w -r1.29 -r1.29.2.1
--- TemplateSubTask.java 9 Mar 2002 23:23:08 -0000 1.29
+++ TemplateSubTask.java 16 Mar 2002 18:22:11 -0000 1.29.2.1
@@ -1,7 +1,9 @@
package xdoclet;
-import com.sun.javadoc.ClassDoc;
-import com.sun.javadoc.PackageDoc;
+import xjavadoc.XJavaDoc;
+import xjavadoc.XClass;
+import xjavadoc.XPackage;
+import xjavadoc.XJavaDocException;
import org.apache.log4j.Category;
import xdoclet.tags.ClassTagsHandler;
import xdoclet.tags.PackageTagsHandler;
@@ -10,7 +12,7 @@
import xdoclet.template.TemplateEngine;
import xdoclet.template.TemplateException;
import xdoclet.template.TemplateParser;
-import xdoclet.util.DocletUtil;
+
import xdoclet.util.Log;
import xdoclet.util.Translator;
import xdoclet.ejb.UtilObjectSubTask;
@@ -27,7 +29,7 @@
*
* @author Ara Abrahamian ([EMAIL PROTECTED])
* @created Sep 25, 2001
- * @version $Revision: 1.29 $
+ * @version $Revision: 1.29.2.1 $
*/
public class TemplateSubTask extends SubTask
{
@@ -90,7 +92,7 @@
*/
private String subTaskClassName = null;
- private Vector packageSubstitutions = new Vector();
+ private ArrayList packageSubstitutions = new ArrayList();
private boolean packageSubstitutionInheritanceSupported = true;
private boolean guessGenerationNeeded = true;
@@ -107,7 +109,7 @@
return className.replace( '.', '/' ) + ".java";
}
- public Vector getPackageSubstitutions()
+ public ArrayList getPackageSubstitutions()
{
return packageSubstitutions;
}
@@ -184,7 +186,7 @@
this.guessGenerationNeeded = guessGenerationNeeded;
}
- public void setPackageSubstitutions( Vector packageSubstitutions )
+ public void setPackageSubstitutions( ArrayList packageSubstitutions )
{
this.packageSubstitutions = packageSubstitutions;
}
@@ -277,7 +279,7 @@
*/
public void addPackageSubstitution( PackageTagsHandler.PackageSubstitution ps )
{
- packageSubstitutions.addElement( ps );
+ packageSubstitutions.add( ps );
}
public void copyAttributesFrom( TemplateSubTask src )
@@ -296,8 +298,8 @@
try
{
- setEngine( new TemplateEngine( getContext() ) );
- setParser( new TemplateParser( getContext() ) );
+ setEngine( new TemplateEngine( ) );
+ setParser( new TemplateParser( ) );
}
catch( TemplateException te )
{
@@ -333,11 +335,11 @@
* @return The GeneratedClassName value
* @exception XDocletException Description of Exception
*/
- protected String getGeneratedFileName( ClassDoc clazz ) throws XDocletException
+ protected String getGeneratedFileName( XClass clazz ) throws XDocletException
{
Category cat = Log.getCategory( TemplateSubTask.class,
"getGeneratedFileName" );
- PackageDoc pak = clazz.containingPackage();
+ XPackage pak = clazz.containingPackage();
String pak_name = isPackageSubstitutionInheritanceSupported() == true
? PackageTagsHandler.packageNameAsPathFor( pak ) : null;
String dest_file = MessageFormat.format( getDestinationFile(), new
Object[]{clazz.name()} );
@@ -378,12 +380,17 @@
if( cat.isDebugEnabled() )
cat.debug( "Per class." );
- ClassDoc[] classes = getContext().getRoot().classes();
+ XClass[] classes;
+ try {
+ classes = XJavaDoc.getInstance().sourceClasses();
+ } catch(XJavaDocException e ) {
+ throw new XDocletException(e, e.getMessage());
+ }
for( int i = 0; i < classes.length; i++ )
{
setCurrentClass( classes[i] );
-
+System.out.println("ASLAK:"+classes[i].qualifiedName());
if( matchesGenerationRules( classes[i] ) == true )
generateForClass( classes[i] );
}
@@ -426,7 +433,7 @@
* @return Description of the Returned Value
* @exception XDocletException Description of Exception
*/
- protected boolean matchesGenerationRules( ClassDoc clazz ) throws
XDocletException
+ protected boolean matchesGenerationRules( XClass clazz ) throws
XDocletException
{
Category cat = Log.getCategory( TemplateSubTask.class,
"matchesGenerationRules" );
@@ -450,7 +457,7 @@
if( getHavingClassTag() != null )
{
- if( DocletUtil.hasTag( clazz, getHavingClassTag(), false ) ==
false )
+ if( !clazz.doc().hasTag( getHavingClassTag(), false ) )
{
if( cat.isDebugEnabled() )
cat.debug( "Reject class '" +
clazz.qualifiedName() + "' because it doesn't have class tag '" + getHavingClassTag()
+ "'." );
@@ -467,19 +474,17 @@
* @param clazz Description of Parameter
* @exception XDocletException Description of Exception
*/
- protected void generateForClass( ClassDoc clazz ) throws XDocletException
+ protected void generateForClass( XClass clazz ) throws XDocletException
{
Category cat = Log.getCategory( TemplateSubTask.class,
"generateForClass" );
File file = new File( getDestDir().toString(), getGeneratedFileName(
clazz ) );
- File beanFile = beanFile( clazz );
if( cat.isDebugEnabled() )
{
cat.debug( "destDir.toString()=" + getDestDir().toString() );
cat.debug( "getGeneratedFileName()=" + getGeneratedFileName(
clazz ) );
cat.debug( "file=" + file );
- cat.debug( "beanFile=" + beanFile );
}
if( file.exists() )
@@ -531,57 +536,6 @@
{
}
- /**
- * Returns the File pointing to where current class is stored.
- *
- * @param clazz Description of Parameter
- * @return Description of the Returned Value
- * @exception XDocletException
- */
- protected File beanFile( ClassDoc clazz ) throws XDocletException
- {
- Category cat = Log.getCategory( TemplateSubTask.class, "beanFile" );
-
- String source_path = getContext().getSourcePath();
- String full_class_name = ClassTagsHandler.getFullClassNameFor( clazz );
- String java_file = javaFile( full_class_name );
-
- if( cat.isDebugEnabled() )
- {
- cat.debug( "source_path=" + source_path );
- cat.debug( "full_class_name=" + full_class_name );
- cat.debug( "java_file=" + java_file );
- }
-
- File file = beanFileInSourcePath( source_path, java_file );
-
- if( file != null )
- return file;
-
- //maybe it's an inner class? Strip out .Inner from
com.foo.MyClass.Inner and try loading it, do that recursively
-
- String containing_class = full_class_name;
-
- while( true )
- {
- int dot_index = containing_class.lastIndexOf( '.' );
-
- if( dot_index != -1 )
- {
- containing_class = containing_class.substring( 0,
dot_index );
- java_file = javaFile( containing_class );
-
- file = beanFileInSourcePath( source_path, java_file );
- if( file != null )
- return file;
- }
- else
- break;
- }
-
- throw new IllegalStateException( Translator.getString(
"couldnt_find_bean", new String[]{full_class_name, source_path} ) );
- }
-
protected void startEngine( URL templateURL, File output_file ) throws
TemplateException
{
//Category cat = Log.getCategory( TemplateSubTask.class, "startEngine"
);
@@ -614,7 +568,7 @@
* @return true if generation is needed
* @exception XDocletException
*/
- private boolean isGenerationNeeded( ClassDoc clazz, File file, boolean
withTemplate )
+ private boolean isGenerationNeeded( XClass clazz, File file, boolean
withTemplate )
throws XDocletException
{
Category cat = Log.getCategory( TemplateSubTask.class, "generation" );
@@ -633,8 +587,6 @@
return true;
}
- File beanFile = null;
-
// 1. Check the classpath for timestamp on XDOCLET JAR
File xdocletJar = getXdocletJar();
@@ -648,52 +600,31 @@
cat.debug( "Reject file because of timestamp of " +
xdocletJar.getName() );
// 2. Check the bean timestamp
- try
- {
- beanFile = beanFile( clazz );
- }
- catch( IllegalStateException e )
- {
- cat.warn( "One parameter must be wrong in your build file,
could not find file for " + clazz, e );
- return true;
- }
-
- if( file.lastModified() < beanFile.lastModified() )
+ if( file.lastModified() < clazz.lastModified() )
{
if( cat.isDebugEnabled() )
- cat.debug( "Generation needed because of timestamp of
" + beanFile.getName() );
+ cat.debug( "Generation needed because of timestamp of
" + clazz.qualifiedName() );
return true;
}
if( cat.isDebugEnabled() )
- cat.debug( "Reject file because of timestamp of " +
beanFile.getName() );
+ cat.debug( "Reject file because of timestamp of " +
clazz.qualifiedName() );
// 3. Check the superclasses timestamp
- ClassDoc supers = clazz.superclass();
-
- while( true )
- {
- File superFile = null;
+ XClass supers = clazz.superclass();
- try
- {
- superFile = beanFile( supers );
- }
- catch( Exception e )
+ while( supers != null )
{
- // Here we come to a file in a JAR, here it will be
java.lang.Object or sth similar then we can think the generation is not needed
- if( cat.isDebugEnabled() )
- cat.debug( "Stop looking class hierarchy at "
+ supers );
- break;
+ if( supers.qualifiedName().equals("java.lang.Object") ) {
+ return false;
}
-
- if( file.lastModified() < superFile.lastModified() )
+ if( file.lastModified() < supers.lastModified() )
{
if( cat.isDebugEnabled() )
- cat.debug( "Generation needed because of
timestamp of " + superFile.getName() );
+ cat.debug( "Generation needed because of
timestamp of " + supers.qualifiedName() );
return true;
}
if( cat.isDebugEnabled() )
- cat.debug( "Reject file because of timestamp of " +
superFile.getName() );
+ cat.debug( "Reject file because of timestamp of " +
supers.qualifiedName() );
supers = supers.superclass();
}
@@ -748,7 +679,7 @@
cat.debug( "Generation need check for " + file.getName() );
// 3. Check Timestamp of all java sources in sourcepath
- ClassDoc[] classes = AbstractProgramElementTagsHandler.getAllClasses();
+ XClass[] classes = AbstractProgramElementTagsHandler.getAllClasses();
for( int i = 0; i < classes.length; i++ )
{
@@ -834,28 +765,6 @@
path_str = path_str.substring( 1 );
}
return new File( path_str );
- }
-
- /**
- * See if we can find it somewhere in one of the sourcepaths.
- *
- * @param source_path
- * @param java_file
- * @return The File.
- */
- private File beanFileInSourcePath( String source_path, String java_file )
- {
- StringTokenizer tok = new StringTokenizer( source_path,
File.pathSeparator );
-
- while( tok.hasMoreTokens() )
- {
- File f = new File( tok.nextToken(), java_file );
-
- if( f.exists() )
- return f;
- }
-
- return null;
}
/**
1.24.2.1 +260 -692 xdoclet/core/src/xdoclet/XDocletTagSupport.java
Index: XDocletTagSupport.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/XDocletTagSupport.java,v
retrieving revision 1.24
retrieving revision 1.24.2.1
diff -u -w -r1.24 -r1.24.2.1
--- XDocletTagSupport.java 4 Mar 2002 21:57:32 -0000 1.24
+++ XDocletTagSupport.java 16 Mar 2002 18:22:11 -0000 1.24.2.1
@@ -2,24 +2,26 @@
import java.util.Properties;
import java.util.StringTokenizer;
-import java.util.Hashtable;
-import java.util.Vector;
-import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
import java.util.Map;
-import com.sun.javadoc.ClassDoc;
-import com.sun.javadoc.FieldDoc;
-import com.sun.javadoc.MethodDoc;
-import com.sun.javadoc.PackageDoc;
-import com.sun.javadoc.ConstructorDoc;
-import com.sun.javadoc.ProgramElementDoc;
-import com.sun.javadoc.Tag;
+import xjavadoc.XClass;
+import xjavadoc.XDoc;
+import xjavadoc.XField;
+import xjavadoc.XMethod;
+import xjavadoc.XPackage;
+import xjavadoc.XConstructor;
+import xjavadoc.XProgramElement;
+import xjavadoc.XTag;
import org.apache.log4j.Category;
import xdoclet.template.TemplateEngine;
import xdoclet.template.TemplateTagHandler;
-import xdoclet.util.DocletUtil;
+
import xdoclet.util.Log;
import xdoclet.util.Translator;
import xdoclet.util.TypeConversionUtil;
@@ -30,7 +32,7 @@
*
* @author Dmitri Colebatch ([EMAIL PROTECTED])
* @created October 12, 2001
- * @version $Revision: 1.24 $
+ * @version $Revision: 1.24.2.1 $
*/
public abstract class XDocletTagSupport extends TemplateTagHandler
{
@@ -45,225 +47,21 @@
protected final static String PARAMETER_DELIMITER = ",";
/**
- * Given the raw javadoc tag content as the <i>value</i> parameter parses it
- * and searches for the specified parameter and if found returns its value,
- * null otherwise.
- *
- * @param clazz
- * @param value
- * @param param_name
- * @param param_num
- * @return The parameter value; null if not found
- * @exception XDocletException
- * @todo Erik: refactor this method! its a mess. :) Ara:
- * I agree :o)
- */
- public static String getParameterValue( ClassDoc clazz, String value, String
param_name, int param_num ) throws XDocletException
- {
- Category cat = Log.getCategory( XDocletTagSupport.class,
"getParameterValue" );
-
- cat.debug( "[value " + value + "] [param_name " + param_name + "]
[param_num " + param_num + "]" );
-
- if( value == null )
- {
- cat.debug( "null value passed, returning null" );
- return null;
- }
-
- if( param_name == null && param_num == -1 )
- return dereferenceProperties( value );
-
- String attr_name = "";
- String attr_value = "";
- int i = 0;
- int params_parsed = 0;
-
- while( i < value.length() )
- {
- i = TemplateEngine.skipWhitespace( value, i );
-
- //explicitly to handle the trailing white spaces
-
- if( i >= value.length() )
- break;
-
- //read attribute name
-
- while( i < value.length() && value.charAt( i ) != '=' && (
!Character.isWhitespace( value.charAt( i ) ) ) )
- {
- attr_name += value.charAt( i );
- i++;
- }
-
- i = TemplateEngine.skipWhitespace( value, i );
-
- //skip = sign
-
- if( i < value.length() && value.charAt( i ) == '=' )
- i++;
- else
- {
- i = TemplateEngine.skipWhitespace( value, i );
-
- if( i < value.length() && value.charAt( i ) == '"' )
- {
- //if single value item like @blabla "value"
-
- if( params_parsed == 0 &&
value.trim().endsWith( "\"" ) )
- {
- String trimmed_value = value.trim();
-
- return dereferenceProperties(
trimmed_value.substring( 1, trimmed_value.length() - 1 ) );
- //return the whole line minus
start/end " signs as the parameter
- }
- else
- {
- cat.debug( "missing '=' sign: " +
value );
- throw new XDocletException(
Translator.getString( "tag_missing_equals",
- new
String[]{clazz.qualifiedName(), value} ) );
- }
- }
- else
- {
- //if single value item with no = and " signs
-
- if( params_parsed == 0 && param_num == 0 )
- {
- // we might have " - XXX: this code
needs to be checked... dim.
-
- value = value.trim();
-
- if( value.startsWith( "\"" ) &&
value.startsWith( "\"" ) )
- return dereferenceProperties(
value.substring( 1, value.length() - 1 ) );
-
- return dereferenceProperties( value );
- //return the whole line as the
parameter
- }
- else
- {
- cat.debug( "malformed value: " + value
);
- throw new XDocletException(
Translator.getString( "tag_malformed_value",
- new
String[]{clazz.qualifiedName(), value} ) );
- }
- }
- }
-
- i = TemplateEngine.skipWhitespace( value, i );
-
- //skip " sign
-
- if( i < value.length() && value.charAt( i ) == '"' )
- i++;
- else
- throw new XDocletException( Translator.getString(
"tag_quote_expected",
- new String[]{clazz.qualifiedName(), value} ) );
-
- //read attribute value
-
- while( i < value.length() )
- {
- if( value.charAt( i ) == '"' )
- {
- //if not escaped \" char
-
- if( value.charAt( i - 1 ) != '\\' )
- {
- //if last " (last parameter) in whole
value string
-
- if( i + 1 >= value.length() )
- break;
- else
- {
- //if tailing " with whitespace
after it
-
- if( Character.isWhitespace(
value.charAt( i + 1 ) ) )
- break;
- else
- {
- //probably user does
not know escaping is needed!
-
- throw new
XDocletException( Translator.getString( "tag_must_escape_quotes",
- new
String[]{clazz.qualifiedName(), value} ) );
- }
- }
- }
- else
- {
- //remove \"
-
- attr_value = attr_value.substring( 0,
attr_value.length() - 1 );
-
- //append a single "
-
- attr_value += "\"";
- i++;
-
- continue;
- }
- }
-
- attr_value += value.charAt( i );
- i++;
- }
-
- //skip " sign
-
- if( i < value.length() && value.charAt( i ) == '"' )
- i++;
- else
- throw new XDocletException( Translator.getString(
"tag_no_closing_quote",
- new String[]{clazz.qualifiedName(), value} ) );
-
- if( param_name != null && attr_name.equalsIgnoreCase(
param_name ) )
- return dereferenceProperties( attr_value );
- else
- {
- params_parsed++;
- attr_name = "";
- attr_value = "";
- }
- }
-
- //param not found
-
- return null;
- }
-
- /**
* @return The current tag.
*/
- public static Tag getCurrentTag()
+ public static XTag getCurrentTag()
{
return getDocletContext().getActiveSubTask().getCurrentTag();
}
/**
- * For classes.
- *
- * @param tag_name Description of Parameter
- * @param param_name Description of Parameter
- * @param param_num Description of Parameter
- * @param valid_values Description of Parameter
- * @param default_value Description of Parameter
- * @param superclasses Description of Parameter
- * @param is_mandatory Description of Parameter
- * @param clazz Description of Parameter
- * @return The ClassTagValue value
- * @exception XDocletException Description of Exception
- */
- public static String getClassTagValue( ClassDoc clazz, String tag_name, String
param_name, int param_num, String valid_values, String default_value, boolean
superclasses, boolean is_mandatory ) throws XDocletException
- {
- return getTagValue( clazz, tag_name, param_name, param_num,
valid_values, default_value, null, null, null, superclasses, FOR_CLASS, is_mandatory );
- }
-
- /**
* Provides the current method in the XDoclet build, or null if there is no
* current method.
*
* @return The CurrentMethod value
* @see #setCurrentMethod
*/
- public static MethodDoc getCurrentMethod()
+ public static XMethod getCurrentMethod()
{
return getDocletContext().getActiveSubTask().getCurrentMethod();
}
@@ -275,7 +73,7 @@
* @return The CurrentField value
* @see #setCurrentField
*/
- public static FieldDoc getCurrentField()
+ public static XField getCurrentField()
{
return getDocletContext().getActiveSubTask().getCurrentField();
}
@@ -287,7 +85,7 @@
* @return The CurrentConstructor value
* @see #setCurrentConstructor
*/
- public static ConstructorDoc getCurrentConstructor()
+ public static XConstructor getCurrentConstructor()
{
return getDocletContext().getActiveSubTask().getCurrentConstructor();
}
@@ -300,7 +98,7 @@
* @see #pushCurrentClass
* @see #popCurrentClass
*/
- public static ClassDoc getCurrentClass()
+ public static XClass getCurrentClass()
{
return getDocletContext().getActiveSubTask().getCurrentClass();
}
@@ -311,7 +109,7 @@
*
* @return The CurrentPackage value
*/
- public static PackageDoc getCurrentPackage()
+ public static XPackage getCurrentPackage()
{
return getDocletContext().getActiveSubTask().getCurrentPackage();
}
@@ -322,7 +120,7 @@
* @param method The method to make the current method
* @see #getCurrentMethod
*/
- public static void setCurrentMethod( MethodDoc method )
+ public static void setCurrentMethod( XMethod method )
{
getDocletContext().getActiveSubTask().setCurrentMethod( method );
}
@@ -333,7 +131,7 @@
* @param constructor The constructor to make the current constructor
* @see #getCurrentConstructor
*/
- public static void setCurrentConstructor( ConstructorDoc constructor )
+ public static void setCurrentConstructor( XConstructor constructor )
{
getDocletContext().getActiveSubTask().setCurrentConstructor(
constructor );
}
@@ -345,7 +143,7 @@
* @param clazz The new CurrentClass value
* @see #getCurrentClass()
*/
- public static void setCurrentClass( ClassDoc clazz )
+ public static void setCurrentClass( XClass clazz )
{
getDocletContext().getActiveSubTask().setCurrentClass( clazz );
}
@@ -356,12 +154,12 @@
* @param pakkage The new CurrentPackage value
* @see #getCurrentPackage
*/
- public static void setCurrentPackage( PackageDoc pakkage )
+ public static void setCurrentPackage( XPackage pakkage )
{
getDocletContext().getActiveSubTask().setCurrentPackage( pakkage );
}
- public static void setCurrentTag( Tag currentTag )
+ public static void setCurrentTag( XTag currentTag )
{
getDocletContext().getActiveSubTask().setCurrentTag( currentTag );
}
@@ -372,7 +170,7 @@
* @param field The field to make the current field
* @see #getCurrentMethod
*/
- public static void setCurrentField( FieldDoc field )
+ public static void setCurrentField( XField field )
{
getDocletContext().getActiveSubTask().setCurrentField( field );
}
@@ -381,7 +179,7 @@
* Replaces <code>${xxx}</code> style constructions in the given value with the
* string value of the corresponding data types. NOTE: This method was taken
* directly from Ant's source code (org.apache.tools.ant.ProjectHelper) and
- * modified slightly to use a Map instead of a Hashtable.
+ * modified slightly to use a Map instead of a HashMap.
*
* @param value The string to be scanned for property references. May be
* <code>null</code>, in which case this method returns immediately with
@@ -398,22 +196,22 @@
return null;
}
- Vector fragments = new Vector();
- Vector propertyRefs = new Vector();
+ ArrayList fragments = new ArrayList();
+ ArrayList propertyRefs = new ArrayList();
parsePropertyString( value, fragments, propertyRefs );
StringBuffer sb = new StringBuffer();
- Enumeration i = fragments.elements();
- Enumeration j = propertyRefs.elements();
+ Iterator i = fragments.iterator();
+ Iterator j = propertyRefs.iterator();
- while( i.hasMoreElements() )
+ while( i.hasNext() )
{
- String fragment = ( String ) i.nextElement();
+ String fragment = ( String ) i.next();
if( fragment == null )
{
- String propertyName = ( String ) j.nextElement();
+ String propertyName = ( String ) j.next();
fragment = ( keys.containsKey( propertyName ) ) ? (
String ) keys.get( propertyName )
: "${" + propertyName + "}";
@@ -437,9 +235,10 @@
* @param fragments List to add text fragments to. Must not be
<code>null</code>
* .
* @param propertyRefs List to add property names to. Must not be
<code>null</code>
+ * @todo move to some Util class. -Not DocletUtil, some more generic util
class.
* .
*/
- public static void parsePropertyString( String value, Vector fragments, Vector
propertyRefs )
+ public static void parsePropertyString( String value, List fragments, List
propertyRefs )
{
int prev = 0;
int pos;
@@ -448,17 +247,17 @@
{
if( pos > 0 )
{
- fragments.addElement( value.substring( prev, pos ) );
+ fragments.add( value.substring( prev, pos ) );
}
if( pos == ( value.length() - 1 ) )
{
- fragments.addElement( "$" );
+ fragments.add( "$" );
prev = pos + 1;
}
else if( value.charAt( pos + 1 ) != '{' )
{
- fragments.addElement( value.substring( pos + 1, pos +
2 ) );
+ fragments.add( value.substring( pos + 1, pos + 2 ) );
prev = pos + 2;
}
else
@@ -470,21 +269,21 @@
// In Ant this is a BuildException condition
as its an
// incomplete property reference. Here we'll
leave it
// in the output string
- fragments.addElement( value.substring( pos ) );
+ fragments.add( value.substring( pos ) );
return;
}
String propertyName = value.substring( pos + 2,
endName );
- fragments.addElement( null );
- propertyRefs.addElement( propertyName );
+ fragments.add( null );
+ propertyRefs.add( propertyName );
prev = endName + 1;
}
}
if( prev < value.length() )
{
- fragments.addElement( value.substring( prev ) );
+ fragments.add( value.substring( prev ) );
}
}
@@ -497,7 +296,7 @@
* @see #getCurrentClass
* @see #popCurrentClass
*/
- public static ClassDoc pushCurrentClass( ClassDoc clazz )
+ public static XClass pushCurrentClass( XClass clazz )
{
return getDocletContext().getActiveSubTask().pushCurrentClass( clazz );
}
@@ -509,7 +308,7 @@
* @see #getCurrentClass
* @see #pushCurrentClass
*/
- public static ClassDoc popCurrentClass()
+ public static XClass popCurrentClass()
{
return getDocletContext().getActiveSubTask().popCurrentClass();
}
@@ -522,149 +321,180 @@
return DocletContext.getInstance();
}
- protected static String getTagValue( ProgramElementDoc prg_elem_doc, String
tag_name, String param_name, int param_num, String valid_values, String default_value,
String tn,
- String delimiter, String return_delimiters, boolean superclasses, int
for_type, boolean is_mandatory ) throws XDocletException
+ /**
+ * Throws an XDocletException exception to stop the build process. The
+ * exception has an informative message to help user find out the cause of the
+ * error (not specifying a mandatory parameter for a tag).
+ *
+ * @param param_name Description of Parameter
+ * @param tag_name Description of Parameter
+ * @param programElement Description of Parameter
+ * @exception XDocletException Description of Exception
+ */
+ protected static void mandatoryParamNotFound( XDoc doc, String param_name,
String tag_name ) throws XDocletException
{
- Category cat = Log.getCategory( XDocletTagSupport.class, "getTagValue"
);
-
- if( tag_name == null )
- throw new XDocletException( Translator.getString(
"template_tagname_is_null" ) );
+ XProgramElement programElement = doc.getOwner();
+ if( programElement instanceof XMethod )
+ {
+ XMethod method = ( XMethod ) programElement;
- String value = null;
- Tag the_tag = null;
+ throw new XDocletException( Translator.getString(
"mandatory_tag_param_missing_method",
+ new String[]{param_name, tag_name, method.name(),
method.containingClass().qualifiedName()} ) );
+ }
+ else if( programElement instanceof XClass )
+ {
+ XClass clazz = ( XClass ) programElement;
- if( prg_elem_doc == null )
+ throw new XDocletException( Translator.getString(
"mandatory_tag_param_missing_class",
+ new String[]{param_name, tag_name,
clazz.qualifiedName()} ) );
+ }
+ else if( programElement instanceof XConstructor )
{
- switch ( for_type )
+ XConstructor constructor = ( XConstructor ) programElement;
+
+ throw new XDocletException( Translator.getString(
"mandatory_tag_param_missing_constructor",
+ new String[]{param_name, tag_name,
constructor.containingClass().qualifiedName()} ) );
+ }
+ else if( programElement instanceof XField )
{
- case FOR_CLASS:
- throw new XDocletException( Translator.getString(
"tagvalue_null_class" ) );
- case FOR_METHOD:
- throw new XDocletException( Translator.getString(
"tagvalue_null_method" ) );
- case FOR_CONSTRUCTOR:
- throw new XDocletException( Translator.getString(
"tagvalue_null_constructor" ) );
- case FOR_FIELD:
- throw new XDocletException( Translator.getString(
"tagvalue_null_field" ) );
- default:
- throw new XDocletException( Translator.getString(
"bad_tagvalue_type" ) );
+ XField field = ( XField ) programElement;
+
+ throw new XDocletException( Translator.getString(
"mandatory_tag_param_missing_field",
+ new String[]{param_name, tag_name, field.name(),
field.containingClass().qualifiedName()} ) );
}
+ else
+ throw new XDocletException( Translator.getString(
"bad_prgelemdoc_type",
+ new String[]{programElement.toString()} ) );
}
- // First use currentTag, then if null or not the tag we're searching
for
- // continue searching
- String complete_tag_name = "@" + tag_name;
- String complete_dotted_format_tag_name = complete_tag_name.replace(
':', '.' );
+ /**
+ * Replace properties in a string. Properties are in the form ${prop.name} and
+ * the replace properties are obtained from the DocletContext.
+ *
+ * @param value The string to check for properties.
+ * @return The value replaced with any property substitutions
+ */
+ private static String dereferenceProperties( String value )
+ {
+ // check to see if the property has a value.
+ Map properties = DocletContext.getInstance().getProperties();
+
+ return replaceProperties( value, properties );
+ }
- if( getCurrentTag() != null && ( getCurrentTag().name().equals(
complete_tag_name ) || getCurrentTag().name().equals( complete_dotted_format_tag_name
) ) )
- the_tag = getCurrentTag();
- else
+ /**
+ * Return the Value of a tag specified in a Properties object. This method work
+ * on the currentTag object variable, matchs it against the XTag specified in
+ * the attributes Properties and returns the value of the specified tag.
+ *
+ * @param attributes The attributes of the template tag
+ * @param for_type if FOR_CLASS, then a fifth property
+ * superclasses is searched, if this is set to true, then the tag is also
+ * searched in all superclasses of current class. If for_type is set to
+ * FOR_METHOD or FOR_CONSTRUCTOR or FOR_FIELD, current method or field is
+ * searched for the tag.
+ * @return The TagValue value
+ * @exception XDocletException Description of Exception
+ */
+ protected static String getTagValue( Properties attributes, int for_type )
throws XDocletException
+ {
+ String tag_name = attributes.getProperty( "tagName" );
+ String param_name = attributes.getProperty( "paramName" );
+ String valid_values = attributes.getProperty( "values" );
+ String default_value = attributes.getProperty( "default" );
+ boolean superclasses = TypeConversionUtil.stringToBoolean(
attributes.getProperty( "superclasses" ), true );
+ boolean is_mandatory = TypeConversionUtil.stringToBoolean(
attributes.getProperty( "mandatory" ), true );
+
+ return getTagValue(
+ for_type,
+ tag_name,
+ param_name,
+ valid_values,
+ default_value,
+ superclasses,
+ is_mandatory
+ );
+ }
+
+ protected static String getTagValue(
+ int for_type,
+ String tag_name,
+ String param_name,
+ String valid_values,
+ String default_value,
+ boolean superclasses,
+ boolean is_mandatory
+ ) throws XDocletException
{
- Tag[] tags = null;
+ XProgramElement prg_elem = null;
switch ( for_type )
{
case FOR_CLASS:
- tags = DocletUtil.getTagsByName( ( ClassDoc )
prg_elem_doc, tag_name, superclasses );
+ prg_elem = getCurrentClass();
break;
case FOR_METHOD:
- tags = DocletUtil.getTagsByName( ( MethodDoc )
prg_elem_doc, tag_name );
+ prg_elem = getCurrentMethod();
break;
case FOR_CONSTRUCTOR:
- tags = DocletUtil.getTagsByName( ( ConstructorDoc )
prg_elem_doc, tag_name );
+ prg_elem = getCurrentConstructor();
break;
case FOR_FIELD:
- tags = DocletUtil.getTagsByName( ( FieldDoc )
prg_elem_doc, tag_name );
+ prg_elem = getCurrentField();
break;
default:
throw new XDocletException( Translator.getString(
"bad_tagvalue_type" ) );
}
- if( tags != null && tags.length > 0 )
- {
- // In case multiple tags are found, only the first is
used.
- // Don't use this method if you want to get the value
of a tag other
- // than the first, in other words don't use it if it's
legal to have
- // multiple tags of that name for the entity.
- the_tag = tags[0];
- }
- }
-
- if( the_tag != null )
- {
- // param_num is legacy! We previously supported
space-separated tag values.
- // It's now only used with the value of 0 for single-value
tags.
-
- ClassDoc clazz = null;
-
- if( prg_elem_doc instanceof ClassDoc )
- clazz = ( ClassDoc ) prg_elem_doc;
- else if( prg_elem_doc instanceof MethodDoc )
- clazz = ( ( MethodDoc ) prg_elem_doc
).containingClass();
- else if( prg_elem_doc instanceof ConstructorDoc )
- clazz = ( ( ConstructorDoc ) prg_elem_doc
).containingClass();
- else
- clazz = ( ( FieldDoc ) prg_elem_doc
).containingClass();
-
- value = DocletUtil.getText( the_tag );
- value = getParameterValue( clazz, value, param_name, param_num
);
-
- if( value == null )
- {
- boolean param_found = false;
-
- //the tag is there but not the parameter we're
searching for, so search in superclass
- // potentially some redundancy here as we may have
already looked in superclasses to get the_tag
- // but the_tag didn't contain the param - so we'll
start again.
- if( for_type == FOR_CLASS && superclasses == true )
- {
- ClassDoc superclass = ( ( ClassDoc )
prg_elem_doc ).superclass();
-
- while( superclass != null )
- {
- Tag[] tags = DocletUtil.getTagsByName(
superclass, tag_name, false );
-
- if( tags != null && tags.length > 0 )
- {
- the_tag = tags[0];
- value = DocletUtil.getText(
the_tag );
- value = getParameterValue(
superclass, value, param_name, param_num );
-
- if( value != null )
- {
- param_found = true;
- break;
- }
+ XDoc doc = prg_elem.doc();
+ return getTagValue(
+ doc,
+ tag_name,
+ param_name,
+ valid_values,
+ default_value,
+ superclasses,
+ is_mandatory
+ );
}
- superclass = superclass.superclass();
- }
+ /**
+ * @todo (Aslak) maybe this method ought to be moved to xjavadoc.XDoc? Not a
big deal though.
+ */
+ protected static String getTagValue(
+ XDoc doc,
+ String tag_name,
+ String param_name,
+ String valid_values,
+ String default_value,
+ boolean superclasses,
+ boolean is_mandatory
+ ) throws XDocletException
+ {
+ String value;
+ if( param_name == null ) {
+ // the value of the tag is requested
+ value = doc.tag( tag_name, superclasses ).value();
+ } else {
+ // the value of a tag attribute is requested
+ value = doc.tagAttributeValue( tag_name, param_name,
superclasses );
+ }
+
+ if( value == null ) {
+ // nothing found in javadocs
+ if( is_mandatory ) {
+ // throws XDocletException
+ mandatoryParamNotFound( doc, param_name, tag_name );
}
-
- //after all those searches in superclasses param
wasn't found
- if( param_found == false )
- {
- if( default_value != null )
+ if( default_value != null ) {
return default_value;
- else
- {
- if( is_mandatory == true )
- mandatoryParamNotFound(
prg_elem_doc, param_name, tag_name );
- else
+ } else {
return null;
}
- }
- }
-
- if( cat.isDebugEnabled() )
- cat.debug( "tag_name=" + tag_name + ", param_name=" +
param_name + ",value=" + value );
-
- // tokenize value if necesary
- value = tokenizeValue( value, tn, delimiter, return_delimiters
);
-
- if( valid_values == null )
- return value;
- else
- {
+ } else {
+ // a value was found. perform sanity checks
+ if( valid_values != null ) {
+ // check if the value is among the valid values
StringTokenizer st = new StringTokenizer(
valid_values, "," );
while( st.hasMoreTokens() )
@@ -672,192 +502,88 @@
if( st.nextToken().equals( value ) )
return value;
}
- invalidParamValueFound( prg_elem_doc, param_name,
tag_name, value, valid_values );
- }
- }
- else
- {
- // If the tag/param not found use default if any
- if( default_value == null )
- return null;
- else
- return default_value;
- }
-
- //will never reach here though!
- return null;
- }
-
- /**
- * For methods.
- *
- * @param tag_name Description of Parameter
- * @param param_name Description of Parameter
- * @param param_num Description of Parameter
- * @param valid_values Description of Parameter
- * @param default_value Description of Parameter
- * @param is_mandatory Description of Parameter
- * @param method Description of Parameter
- * @return The MethodTagValue value
- * @exception XDocletException Description of Exception
- */
- protected static String getMethodTagValue( MethodDoc method, String tag_name,
String param_name, int param_num, String valid_values, String default_value, boolean
is_mandatory ) throws XDocletException
- {
- return getTagValue( method, tag_name, param_name, param_num,
valid_values, default_value, null, null, null, false, FOR_METHOD, is_mandatory );
+ invalidParamValueFound( doc, param_name, tag_name,
value, valid_values );
}
-
- /**
- * For fields.
- *
- * @param tag_name Description of Parameter
- * @param param_name Description of Parameter
- * @param param_num Description of Parameter
- * @param valid_values Description of Parameter
- * @param default_value Description of Parameter
- * @param is_mandatory Description of Parameter
- * @param field Description of Parameter
- * @return The MethodTagValue value
- * @exception XDocletException Description of Exception
- */
- protected static String getFieldTagValue( FieldDoc field, String tag_name,
String param_name, int param_num, String valid_values, String default_value, boolean
is_mandatory ) throws XDocletException
- {
- return getTagValue( field, tag_name, param_name, param_num,
valid_values, default_value, null, null, null, false, FOR_FIELD, is_mandatory );
}
-
- /**
- * For constructors.
- *
- * @param tag_name Description of Parameter
- * @param param_name Description of Parameter
- * @param param_num Description of Parameter
- * @param valid_values Description of Parameter
- * @param default_value Description of Parameter
- * @param is_mandatory Description of Parameter
- * @param constructor Description of Parameter
- * @return The ConstructorTagValue value
- * @exception XDocletException Description of Exception
- */
- protected static String getConstructorTagValue( ConstructorDoc constructor,
String tag_name, String param_name, int param_num, String valid_values, String
default_value, boolean is_mandatory ) throws XDocletException
- {
- return getTagValue( constructor, tag_name, param_name, param_num,
valid_values, default_value, null, null, null, false, FOR_CONSTRUCTOR, is_mandatory );
+ return value;
}
/**
- * Uses tokenNumber and delimiter to tokenize value and returns desired token
+ * A utility method used by ifMethodTagValueEquals/ifMethodTagValueNotEquals
+ * and ifClassTagValueEquals/ifClassTagValueNotEquals, return true if the value
+ * of the tag/XParameter equals with value.
*
- * @param value Description of Parameter
- * @param tn Description of Parameter
- * @param delimiter Description of Parameter
- * @param return_delimiters Description of Parameter
+ * @param template The body of the block tag
+ * @param attributes The attributes of the template tag
+ * @param FOR_TYPE
* @return Description of the Returned Value
+ * @exception XDocletException Description of Exception
*/
- protected static String tokenizeValue( String value, String tn, String
delimiter, String return_delimiters )
- {
- //String tn = attributes.getProperty( "tokenNumber" );
- //String delimiter = attributes.getProperty( "delimiter" );
- //String return_delimiters = attributes.getProperty(
"returnDelimiters" )
-
- Category cat = Log.getCategory( XDocletTagSupport.class,
"tokenizeValue" );
-
- if( cat.isDebugEnabled() )
- cat.debug( "tn=" + tn );
-
- if( value == null )
- return null;
-
- // bail out if there is no token number
- if( tn == null )
- return value;
-
- int tokenNumber = Integer.valueOf( tn ).intValue();
-
- if( cat.isDebugEnabled() )
- cat.debug( "got token number: " + tokenNumber );
-
- if( cat.isDebugEnabled() )
- cat.debug( "currentTag: " + getCurrentTag().toString() );
-
- if( cat.isDebugEnabled() )
- cat.debug( "get property: " + delimiter );
-
- if( delimiter == null )
+ protected static boolean isTagValueEqual( Properties attributes, int for_type
) throws XDocletException
{
- if( cat.isDebugEnabled() )
- cat.debug( "got null delimiter..." );
+ checkLegacy(attributes);
- delimiter = PARAMETER_DELIMITER;
+ // the value to check for
+ String value = attributes.getProperty( "value" );
+ if( value == null ) {
+ throw new XDocletException( "The value property is not
specified" );
}
- boolean returnDelimiters = TypeConversionUtil.stringToBoolean(
return_delimiters, false );
+ String attribute_value = null;
- if( cat.isDebugEnabled() )
+ // if currentTag is set first check against it, this is needed for
forAll... tags
+ // where currentTag is set by these tags and we don't need/want to
delegate the
+ // lookup to the surrounding current class or method.
+ String tag_name = attributes.getProperty( "tagName" );
+ String param_name = attributes.getProperty( "paramName" );
+ if( getCurrentTag() != null && getCurrentTag().name().equals( "@" +
tag_name ) )
{
- cat.debug( "delimiters: " + delimiter );
- cat.debug( "tokenizing value: " + value );
+ attribute_value = getCurrentTag().attributeValue( param_name );
}
-
- StringTokenizer st = new StringTokenizer( value, delimiter,
returnDelimiters );
-
- if( st.countTokens() < tokenNumber + 1 )
+ else
{
- if( cat.isDebugEnabled() )
- cat.debug( "Need token " + tokenNumber + " but only "
+ st.countTokens() + " available -- value=" + value + " delimiter=" + delimiter + "
returnDelimiters=" + returnDelimiters );
-
- return "";
+ attribute_value = getTagValue( attributes, for_type );
}
- if( cat.isDebugEnabled() )
- cat.debug( "amount tokens found: " + st.countTokens() );
-
- for( int i = 0; i < tokenNumber; i++ )
- st.nextToken();
-
- return st.nextToken();
+ return value.equals(attribute_value);
}
/**
- * Throws an XDocletException exception to stop the build process. The
- * exception has an informative message to help user find out the cause of the
- * error (not specifying a mandatory parameter for a tag).
+ * A utility method used by ifHasClassTag/ifDoesntHaveClassTag and
+ * ifHasMethodTag/ifDoesntHaveMethodTag, return true if at least one tag exists
+ * with the specified name.
*
- * @param param_name Description of Parameter
- * @param tag_name Description of Parameter
- * @param prg_elem_doc Description of Parameter
+ * @param template The body of the block tag
+ * @param attributes The attributes of the template tag
+ * @param for_type
+ * @return Description of the Returned Value
* @exception XDocletException Description of Exception
*/
- protected static void mandatoryParamNotFound( ProgramElementDoc prg_elem_doc,
String param_name, String tag_name ) throws XDocletException
- {
- if( prg_elem_doc instanceof MethodDoc )
+ protected static boolean hasTag( Properties attributes, int for_type ) throws
XDocletException
{
- MethodDoc method = ( MethodDoc ) prg_elem_doc;
+ checkLegacy(attributes);
- throw new XDocletException( Translator.getString(
"mandatory_tag_param_missing_method",
- new String[]{param_name, tag_name, method.name(),
method.containingClass().qualifiedName()} ) );
+ return getTagValue(attributes, for_type) != null;
}
- else if( prg_elem_doc instanceof ClassDoc )
- {
- ClassDoc clazz = ( ClassDoc ) prg_elem_doc;
- throw new XDocletException( Translator.getString(
"mandatory_tag_param_missing_class",
- new String[]{param_name, tag_name,
clazz.qualifiedName()} ) );
+ /**
+ * @todo remove this method after xjavadoc refactoring
+ */
+ private static void checkLegacy(Properties attributes) throws XDocletException
{
+ // this is just a check to get rid of legacy functionality in the
templates
+ String param_num = attributes.getProperty( "paramNum" );
+ if( param_num != null ) throw new XDocletException("paramNum is
deprecated. Fix the template to use attributes");
}
- else if( prg_elem_doc instanceof ConstructorDoc )
- {
- ConstructorDoc constructor = ( ConstructorDoc ) prg_elem_doc;
- throw new XDocletException( Translator.getString(
"mandatory_tag_param_missing_constructor",
- new String[]{param_name, tag_name,
constructor.containingClass().qualifiedName()} ) );
- }
- else if( prg_elem_doc instanceof FieldDoc )
+ /**
+ * @param template_tag_name
+ * @param param_name
+ * @exception XDocletException
+ */
+ protected void mandatoryTemplateTagParamNotFound( String template_tag_name,
String param_name ) throws XDocletException
{
- FieldDoc field = ( FieldDoc ) prg_elem_doc;
-
- throw new XDocletException( Translator.getString(
"mandatory_tag_param_missing_field",
- new String[]{param_name, tag_name, field.name(),
field.containingClass().qualifiedName()} ) );
- }
- else
- throw new XDocletException( Translator.getString(
"bad_prgelemdoc_type",
- new String[]{prg_elem_doc.toString()} ) );
+ throw new XDocletException( Translator.getString(
"mandatory_tag_param_missing_template",
+ new String[]{param_name, template_tag_name} ) );
}
/**
@@ -869,201 +595,43 @@
* @param tag_name Description of Parameter
* @param value Description of Parameter
* @param valid_values Description of Parameter
- * @param prg_elem_doc Description of Parameter
+ * @param programElement Description of Parameter
* @exception XDocletException Description of Exception
*/
- protected static void invalidParamValueFound( ProgramElementDoc prg_elem_doc,
String param_name, String tag_name, String value, String valid_values ) throws
XDocletException
+ private static void invalidParamValueFound( XDoc doc, String param_name,
String tag_name, String value, String valid_values ) throws XDocletException
{
- if( prg_elem_doc instanceof MethodDoc )
+ XProgramElement programElement = doc.getOwner();
+ if( programElement instanceof XMethod )
{
- MethodDoc method = ( MethodDoc ) prg_elem_doc;
+ XMethod method = ( XMethod ) programElement;
throw new XDocletException( Translator.getString(
"invalid_tag_param_value_method",
new String[]{value, param_name, tag_name,
method.name(), method.containingClass().qualifiedName(), valid_values} ) );
}
- else if( prg_elem_doc instanceof ClassDoc )
+ else if( programElement instanceof XClass )
{
- ClassDoc clazz = ( ClassDoc ) prg_elem_doc;
+ XClass clazz = ( XClass ) programElement;
throw new XDocletException( Translator.getString(
"invalid_tag_param_value_class",
new String[]{value, param_name, tag_name,
clazz.qualifiedName(), valid_values} ) );
}
- else if( prg_elem_doc instanceof ConstructorDoc )
+ else if( programElement instanceof XConstructor )
{
- ConstructorDoc constructor = ( ConstructorDoc ) prg_elem_doc;
+ XConstructor constructor = ( XConstructor ) programElement;
throw new XDocletException( Translator.getString(
"invalid_tag_param_value_constructor",
new String[]{value, param_name, tag_name,
constructor.containingClass().qualifiedName(), valid_values} ) );
}
- else if( prg_elem_doc instanceof FieldDoc )
+ else if( programElement instanceof XField )
{
- FieldDoc field = ( FieldDoc ) prg_elem_doc;
+ XField field = ( XField ) programElement;
throw new XDocletException( Translator.getString(
"invalid_tag_param_value_field",
new String[]{value, param_name, tag_name,
field.name(), field.containingClass().qualifiedName(), valid_values} ) );
}
else
throw new XDocletException( Translator.getString(
"bad_prgelemdoc_type",
- new String[]{prg_elem_doc.toString()} ) );
- }
-
- /**
- * Replace properties in a string. Properties are in the form ${prop.name} and
- * the replace properties are obtained from the DocletContext.
- *
- * @param value The string to check for properties.
- * @return The value replaced with any property substitutions
- */
- private static String dereferenceProperties( String value )
- {
- // check to see if the property has a value.
- Map properties = DocletContext.getInstance().getProperties();
-
- return replaceProperties( value, properties );
- }
-
- /**
- * For classes.
- *
- * @param tag_name Description of Parameter
- * @param param_name Description of Parameter
- * @param param_num Description of Parameter
- * @param valid_values Description of Parameter
- * @param default_value Description of Parameter
- * @param superclasses Description of Parameter
- * @param is_mandatory Description of Parameter
- * @return The ClassTagValue value
- * @exception XDocletException Description of Exception
- */
- public String getClassTagValue( String tag_name, String param_name, int
param_num, String valid_values, String default_value, boolean superclasses, boolean
is_mandatory ) throws XDocletException
- {
- return getClassTagValue( getCurrentClass(), tag_name, param_name,
param_num, valid_values, default_value, superclasses, is_mandatory );
- }
-
- /**
- * Parses and searches the value string for the parameter named param_name and
- * returns its value. Parameters are in name="value" format or if param_num
- * specified then can also be in space=separated format, which are used in
- * cases where the tag has only a single parameter.
- *
- * @param value Description of Parameter
- * @param param_name Description of Parameter
- * @param param_num Description of Parameter
- * @return The ParameterValue value
- * @exception XDocletException Description of Exception
- */
- protected String getParameterValue( String value, String param_name, int
param_num ) throws XDocletException
- {
- DocletContext context = getDocletContext();
- ClassDoc clazz = getCurrentClass();
-
- return getParameterValue( clazz, value, param_name, param_num );
- }
-
- /**
- * Return the Value of a tag specified in a Properties object. This method work
- * on the currentTag object variable, matchs it against the Tag specified in
- * the attributes Properties and returns the value of the specified tag. This
- * method is used by various tag implementations, specially classTagValue and
- * methodTagValue.
- *
- * @param attributes The attributes of the template tag
- * @param for_type if FOR_CLASS, then a fifth property
- * superclasses is searched, if this is set to true, then the tag is also
- * searched in all superclasses of current class. If for_type is set to
- * FOR_METHOD or FOR_CONSTRUCTOR or FOR_FIELD, current method or field is
- * searched for the tag.
- * @return The TagValue value
- * @exception XDocletException Description of Exception
- */
- protected String getTagValue( Properties attributes, int for_type ) throws
XDocletException
- {
- String tag_name = attributes.getProperty( "tagName" );
- String param_name = attributes.getProperty( "paramName" );
- String param_num = attributes.getProperty( "paramNum" );
- int param_int = -1;
- String valid_values = attributes.getProperty( "values" );
- String default_value = attributes.getProperty( "default" );
- String tn = attributes.getProperty( "tokenNumber" );
- String delimiter = attributes.getProperty( "delimiter" );
- String return_delimiters = attributes.getProperty( "returnDelimiters"
);
- boolean superclasses = TypeConversionUtil.stringToBoolean(
attributes.getProperty( "superclasses" ), true );
-
- if( param_num != null )
- param_int = Integer.valueOf( param_num ).intValue();
-
- return getTagValue( tag_name, param_name, param_int, valid_values,
default_value, tn, delimiter, return_delimiters, superclasses, for_type, true );
- }
-
- /**
- * For methods.
- *
- * @param tag_name Description of Parameter
- * @param param_name Description of Parameter
- * @param param_num Description of Parameter
- * @param valid_values Description of Parameter
- * @param default_value Description of Parameter
- * @param is_mandatory Description of Parameter
- * @return The MethodTagValue value
- * @exception XDocletException Description of Exception
- */
- protected String getMethodTagValue( String tag_name, String param_name, int
param_num, String valid_values, String default_value, boolean is_mandatory ) throws
XDocletException
- {
- return getMethodTagValue( getCurrentMethod(), tag_name, param_name,
param_num, valid_values, default_value, is_mandatory );
- }
-
- /**
- * For fields.
- *
- * @param tag_name Description of Parameter
- * @param param_name Description of Parameter
- * @param param_num Description of Parameter
- * @param valid_values Description of Parameter
- * @param default_value Description of Parameter
- * @param is_mandatory Description of Parameter
- * @return The MethodTagValue value
- * @exception XDocletException Description of Exception
- */
- protected String getFieldTagValue( String tag_name, String param_name, int
param_num, String valid_values, String default_value, boolean is_mandatory ) throws
XDocletException
- {
- return getFieldTagValue( getCurrentField(), tag_name, param_name,
param_num, valid_values, default_value, is_mandatory );
- }
-
- protected String getTagValue( String tag_name, String param_name, int
param_num, String valid_values, String default_value, String tn,
- String delimiter, String return_delimiters, boolean superclasses, int
for_type, boolean is_mandatory ) throws XDocletException
- {
- ProgramElementDoc prg_elem_doc = null;
-
- switch ( for_type )
- {
- case FOR_CLASS:
- prg_elem_doc = getCurrentClass();
- break;
- case FOR_METHOD:
- prg_elem_doc = getCurrentMethod();
- break;
- case FOR_CONSTRUCTOR:
- prg_elem_doc = getCurrentConstructor();
- break;
- case FOR_FIELD:
- prg_elem_doc = getCurrentField();
- break;
- default:
- throw new XDocletException( Translator.getString(
"bad_tagvalue_type" ) );
- }
-
- return getTagValue( prg_elem_doc, tag_name, param_name, param_num,
valid_values, default_value, tn, delimiter, return_delimiters, superclasses, for_type,
is_mandatory );
- }
-
- /**
- * @param template_tag_name
- * @param param_name
- * @exception XDocletException
- */
- protected void mandatoryTemplateTagParamNotFound( String template_tag_name,
String param_name ) throws XDocletException
- {
- throw new XDocletException( Translator.getString(
"mandatory_tag_param_missing_template",
- new String[]{param_name, template_tag_name} ) );
+ new String[]{programElement.toString()} ) );
}
}
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel