org.enhydra.xml.xmlc.taskdef
Class Xmlc

org.enhydra.xml.xmlc.taskdef.Xmlc

public class Xmlc

ANT task to invoke the XMLC compiler to generate Java code.

Implements an Ant taskdef to perform XMLC compilations. Please refer to the Ant website for more information. XMLCTask extends MatchingTask which means that it has the ability to include or exclude files based on pattern matching. The supported tags are as follows:

tag required default value description
srcdir yes   The source directory root
sourceout no value of srcdir The destination directory into which the generated source *ML.java files are written, if keep="yes". If sourceout is not specified it is set to the value of the srcdir. This will put the *ML.java files in the same location as the .*ml files.
destdir no   The destination directory root. Only really useful if you want XMLC to do the compilation, so we can check dependencies.
packagedir no relative path from srcdir Package prefix for generated classes, expressed as a directory path (relative to srcdir). Eg... my/package. If not specified, the relative path from srcdir becomes the package.
packagename no blank package Package prefix for generated classes, while preserving any source file directory paths. For example, given <xmlc srcdir="foo/resources" sourceout="foo/source" packagename="a.b" />, packagename="a.b", markup file located at "foo/resources/c/d/Foo.ml" will be generated to "foo/source/a/b/c/d/FooML.java" and will start with a "package a.b.c.d;" statement.
markup no HTML The kind of markup language being processed. Choices currently include HTML, WML, XHTML, CHTML and VoiceXML. The generated class is suffixed with this value
verbose no no Displays the XMLC command and all of the arguments
compile no no Have XMLC compile the resulting java files? Note: The default is to not invoke the Java compiler through XMLC, since this is really slow. Any java files created are better handled by the ANT rule.
force no no Force XMLC to always re-process the ML code whether it has changed or not
keep no yes Keep the Java files generated by XMLC? To not keep them, you must allow XMLC to compile them first. However, since this is slower, the default is to keep them and let ANT compile the files using a seperate task.
performExec no no XMLC is invoked by performing a Runtime.exec()
(kept for historical reasons by the author)
options no   File name of XMLC options or a glob style pattern.
<arg> no   Nested element representing additional command line arguments to be passed to XMLC. See the XMLC documentation for all the possible commands. Note: these are applied after the other XMLC arguments derived from the options listed above.

For example, to specify an URL mapping to XMLC:

            <xmlc source="." includes="*.html">
              <arg value="-urlmapping" />
              <arg value="Edit.html" />
              <arg value="To.po" />
            </xmlc>
            
Caution: Do not be tempted to surround the URL's with single-quotes, as is common when calling XMLC from a shell command line, for example
            <xmlc source="." includes="*.html">
              <arg line="-urlmapping 'Edit.html' 'To.po'" />
            </xmlc>
            
The single-quotes will be taken as part of the URL to replace, and this is probably not what you intend
<resourcePath> | resourcePath | resourcePathRef no   Nested element or attributes representing additional classpath entries providing XMLC access to user-defined resources such as XCatalog or DTD files, which are looked up via the classloader when given values such as 'file:/org/mypackage/resources/custom.xcat' or 'file:/org/mypackage/resources/custom.dtd'. Though these look like file system URL's, XMLC's XMLEntityResolver strips the leading 'file:/' and looks these up on the classpath. Without configuring the resource path, XMLC will only be able to look up resources in the classpath provided to the taskdef for <xmlc/>, which should only be used to provide the XMLC and XMLC taskdef jars (and any other dependencies) to load the task itself. The classloader's classpath is manipulated only temporarily while in use by XMLC. It is then restored to its original state before exiting the task so that the classloader is not polluted for uses external to the current <xmlc/> task invocation.

One caveat to note is that this feature will only work if the XMLC task is defined using a taskdef with a custom classpath rather than loaded from Ant's primordial classloader, which would be the case if one put the jar (and dependencies) in ${ant.home}/lib or ${user.home}/.ant/lib. The issue is that when this is the case, the classloader is a plain old URLClassLoader, which doesn't provide any easy way to manipulate, then restore, its internal classpath. This should not be a problem in normal usage, since I can't imagine anyone wanting to put the XMLC taskdef, XMLC itself, and all XMLC's dependencies up at that level. In any case, now you know for sure not to do that.

Note: If the resource can't be found on the classpath, an attempt will be made to look it up on the file system, so you can provide a fully qualified file system URL (or any other supported URL protocol, for that matter). However, it is recommended that the resources be loaded from the classpath for consistent behavior between compile and run-time environments, with no extra effort required for packaging the application for runtime.

For example...

            <xmlc ...>
              <resourcePath>
                <pathelement location="${resources}"/>
              </resourcePath>
            </xmlc>
            
            OR
            
            <xmlc resourcePath="${resources}" .../>
            
            OR
            
            <path id="xmlcResources">
   		    <pathelement location="${resources}"/>
  		  </path>
            <xmlc resourcePathRef="xmlcResources" .../>
            

Since:
2.2
Version:
%I%, %G%
Author:
simon.tuffs@lutris.com, christos@dynamic.net.au, kevin@bluedog.com.au, ericb@interactiveportal.com, Christian Cryder [christianc@granitepeaks.com], Stephen Peterson [stephen_peterson@agilent.com], Jacob Kjome [hoju@visi.com], David Li [taweili@yahoo.com], Stefan Armbruster [sarmbruster@web.de]

Inner Class Summary
static class Xmlc.BooleanAttribute
           
 
Field Summary
protected  String classPath
           
protected  org.apache.tools.ant.types.Commandline cmdl
           
protected  boolean compile
           
protected  File destDir
           
protected  boolean forceBuild
           
protected  boolean keep
           
protected static String logHdr
           
protected  int logLevel
           
protected  String ML
           
protected  String options
           
protected  String packageDir
           
protected  String packageName
           
protected  String performExec
           
protected  org.apache.tools.ant.types.Path resourcePath
           
protected  File srcDir
           
protected  String srcDirName
           
protected  File srcOutDir
           
protected  String srcOutDirName
           
protected  int upToDate
           
protected  boolean verbose
           
protected  String xmlcArgs
           
 
Constructor Summary
Xmlc()
           
 
Method Summary
 org.apache.tools.ant.types.Commandline.Argument createArg()
          Set nested arguments to the XMLC command to be executed.
 org.apache.tools.ant.types.Path createResourcePath()
          Adds a path to the resource path
 void execute()
          Required by ant framework - implements execute() in Task.
 org.apache.tools.ant.types.Path getResourcePath()
          Gets the resource path used to look up resources such as XCatalogs and custom DTDs
 void setArgs(String args)
          Deprecated. Use <arg> tags for now, this will eventually be removed.
 void setClasspath(String classpath)
          Deprecated. Use nested elements or "args" option instead.
 void setCompile(Xmlc.BooleanAttribute compile)
          Set whether or not to have XMLC compile the generated Java file.
 void setDestdir(String destDirName)
          Set the destination directory into which the generated classes are written.
 void setForce(Xmlc.BooleanAttribute force)
          Force XMLC to always re-process the ML code (or not)
 void setKeep(Xmlc.BooleanAttribute keep)
          Set whether or not to keep the generated Java file.
 void setMarkup(String markup)
          The kind of markup language being processed.
 void setOptions(String options)
          Set to a specific options file to add parameters to the XMLC command.
 void setPackagedir(String packagedir)
          Set the Package prefix for generated classes.
 void setPackagename(String packagename)
          Set the package prefix for generated classes, while preserving any source file directory paths.
 void setPerformexec(String performExec)
          Set whether or not to invoke XMLC by using Runtime.exec() to create a seperate JVM.
 void setResourcePath(org.apache.tools.ant.types.Path resourcePath)
          Sets the resource path used to look up resources such as XCatalogs and custom DTDs.
 void setResourcePathRef(org.apache.tools.ant.types.Reference ref)
          Adds a reference to a resource path defined elsewhere
 void setSourceout(String sourceout)
          Set the destination directory into which the generated source .java files are written, if -keep is used.
 void setSrcdir(String srcdirname)
          Set the source directory containing the HTML files.
 void setVerbose(Xmlc.BooleanAttribute verbose)
          Run XMLC in verbose mode (-verbose flag)
 

Field Detail

logHdr

protected static String logHdr

srcDir

protected File srcDir

destDir

protected File destDir

srcOutDir

protected File srcOutDir

classPath

protected String classPath

packageDir

protected String packageDir

packageName

protected String packageName

srcDirName

protected String srcDirName

srcOutDirName

protected String srcOutDirName

options

protected String options

xmlcArgs

protected String xmlcArgs

performExec

protected String performExec

verbose

protected boolean verbose

forceBuild

protected boolean forceBuild

compile

protected boolean compile

keep

protected boolean keep

logLevel

protected int logLevel

upToDate

protected int upToDate

ML

protected String ML

cmdl

protected org.apache.tools.ant.types.Commandline cmdl

resourcePath

protected org.apache.tools.ant.types.Path resourcePath
Constructor Detail

Xmlc

public Xmlc()
Method Detail

setResourcePath

public void setResourcePath(org.apache.tools.ant.types.Path resourcePath)
Sets the resource path used to look up resources such as XCatalogs and custom DTDs.
Parameters:
resourcePath - an Ant Path object containing the resource path

getResourcePath

public org.apache.tools.ant.types.Path getResourcePath()
Gets the resource path used to look up resources such as XCatalogs and custom DTDs
Returns:
an Ant Path object containing the resource path

createResourcePath

public org.apache.tools.ant.types.Path createResourcePath()
Adds a path to the resource path
Returns:
a resource path to be configured

setResourcePathRef

public void setResourcePathRef(org.apache.tools.ant.types.Reference ref)
Adds a reference to a resource path defined elsewhere
Parameters:
ref - a reference to a path

setSrcdir

public void setSrcdir(String srcdirname)
Set the source directory containing the HTML files.
Parameters:
srcdirname - The name of the directory containing the HTML files

setDestdir

public void setDestdir(String destDirName)
Set the destination directory into which the generated classes are written.
Parameters:
destDirName - The destination directory into which the generated classes are written.

setArgs

public void setArgs(String args)
Deprecated. Use <arg> tags for now, this will eventually be removed.

Allow general XMLC options to be passed through unchanged. Appended to the options lists.
Parameters:
args - The XMLC options to be passed through.

setClasspath

public void setClasspath(String classpath)
Deprecated. Use nested elements or "args" option instead.

Set the classpath for the XMLC compiler.
Parameters:
classpath - The classpath for XMLC to use.

setSourceout

public void setSourceout(String sourceout)
Set the destination directory into which the generated source .java files are written, if -keep is used.
Parameters:
sourceout - The destination directory into which the generated sources are written. Note: Currently -keep is used by default since the .java files are best compiled by the built-in Ant javac command as a separate rule.

setForce

public void setForce(Xmlc.BooleanAttribute force)
Force XMLC to always re-process the ML code (or not)
Parameters:
force - whether to force re-processing of markup or not

setVerbose

public void setVerbose(Xmlc.BooleanAttribute verbose)
Run XMLC in verbose mode (-verbose flag)
Parameters:
verbose - Set "true" for -verbose, anything else (e.g. "false") for quiet mode.

setKeep

public void setKeep(Xmlc.BooleanAttribute keep)
Set whether or not to keep the generated Java file.
Parameters:
keep - Set to "true" or "false"

setCompile

public void setCompile(Xmlc.BooleanAttribute compile)
Set whether or not to have XMLC compile the generated Java file.
Parameters:
compile - Set to "true" or "false"

setOptions

public void setOptions(String options)
Set to a specific options file to add parameters to the XMLC command. Or, use a glob style pattern to base the options file name off the name of each source file to be processed (e.g. *.xmlc).
Parameters:
options - Set to file name or glob pattern

setPackagedir

public void setPackagedir(String packagedir)
Set the Package prefix for generated classes. Expressed as a directory path.

Note: packagedir is used to set the package name of the generated class, and to specify the directory where the file will be generated (relative to sourceout). As such, any directory prefix on a source file is stripped before the packagedir is applied. This means that all files from the source tree will end up in the same directory, which may not be what you intend, if you are using Xmlc to process files in a directory hierarchy.

Parameters:
packagedir - Expressed as a directory path, either '/' or '\' are accepted.
See Also:
setPackagename(String)

setPackagename

public void setPackagename(String packagename)
Set the package prefix for generated classes, while preserving any source file directory paths. This is useful if you want to take source (markup language) files from one tree, but generate the Java code into another tree, preserving relative paths.

For example, suppose that you have .html files under a directory called "foo/resources", and you want to generate Java code under "foo/source", but have the package name be "a.b". The following Xmlc taskdef will achieve this:

<xmlc srcdir="foo/resources" sourceout="foo/source" packagename="a.b" />

A markup file located at "foo/resources/c/d/Foo.ml" will be generated to "foo/source/a/b/c/d/FooML.java" and will start with a "package a.b.c.d" statement.

Parameters:
packagename - Expressed as a package path, [package].[package]
See Also:
setPackagedir(String)

setMarkup

public void setMarkup(String markup)
The kind of markup language being processed. Choices currently include HTML, WML, XHTML, CHTML and VoiceXML. The generated class is suffixed with this value.
Parameters:
markup - The type of markup language (controls only the file-name suffix, the actual markup is controlled through the XMLC -dom option which is accessible through the "args" option or <arg> tag.

setPerformexec

public void setPerformexec(String performExec)
Set whether or not to invoke XMLC by using Runtime.exec() to create a seperate JVM. This capability was originally written to get around a problem with name-space clashes between packages. Set this to the command to execute.
Parameters:
performExec - Set to "true" or "false"

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Required by ant framework - implements execute() in Task. Called by the project to let the task do its work.
Throws:
BuildException - All exceptions are thrown as BuildException. Note: most of the logic here was cloned from the Javac command. Unfortunately this was the only way to 'reuse' it.

createArg

public org.apache.tools.ant.types.Commandline.Argument createArg()
Set nested arguments to the XMLC command to be executed.


Copyright © 1999-2002 David Li, enhydra.org. All Rights reserved.