xdoclet
Class Plugin

java.lang.Object
  |
  +--java.beans.beancontext.BeanContextChildSupport
        |
        +--java.beans.beancontext.BeanContextSupport
              |
              +--xdoclet.beans.BeanContextSupportEx
                    |
                    +--xdoclet.Plugin
All Implemented Interfaces:
BeanContext, BeanContextChild, BeanContextServiceRevokedListener, BeanContextServicesListener, Collection, DesignMode, EventListener, PropertyChangeListener, Serializable, VetoableChangeListener, Visibility
Direct Known Subclasses:
BetwixtPlugin, ScriptPlugin

public abstract class Plugin
extends BeanContextSupportEx

A Plugin is responsible for the generation of a particular kind of file. It is also an abstraction of underlying generation mechanisms such as Velocity, Jelly and Betwixt.

A plugin also implements BeanContextChild, because it might be used in a Java Beans compliant environment such as an IDE. Therefore, this class is implicitly a Collection, and all contained objects (package substitutions etc) are contained directly in the instances of this class. They are filtered out by various internal Predicates.

A plugin can operate in two different modes, depending on the value of the fileName:

Version:
$Revision: 1.29 $
Author:
Aslak Hellesøy
See Also:
PluginFactory, XDoclet, Serialized Form

Field Summary
 
Fields inherited from class java.beans.beancontext.BeanContextSupport
bcmListeners, children, designTime, locale, okToUseGui
 
Fields inherited from class java.beans.beancontext.BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport
 
Fields inherited from interface java.beans.beancontext.BeanContext
globalHierarchyLock
 
Fields inherited from interface java.beans.DesignMode
PROPERTYNAME
 
Constructor Summary
Plugin()
           
 
Method Summary
 void Acleanup()
           
 Collection AcreateMetadataCollection()
           
 String AgetFilenameSubstitutionValue(Object o)
           
 String AgetPackageName(Object o)
           
 void AsetClasspath(String classpath)
           
protected static void checkClass(String className)
          Throws XDocletException if a specific class is not on the CP.
 Accept createAccept()
          Creates a new Accept
 PackageSubstitution createPackageSubstitution()
          Creates a new PackageSubstitution
 void execute()
          Generates the content.
protected abstract  void generate(File destinationFile, Collection metaData)
          Generates a file.
protected abstract  void generate(File destinationFile, Object metaData)
          Generates a file.
 File getDestinationDir()
          Returns the destination directory (without package directory).
 File getDestinationFileForAll()
          Returns the destination file derived from a particular object.
 File getDestinationFileForOne(Object object)
          Returns the destination file derived from a particular object.
 String getEncoding()
          Gets the XML encoding.
 String getFileName()
           
protected  Collection getFilteredMetadataCollection()
          Gets all accepted objects.
protected  MetadataProvider getMetadataProvider()
           
 String getName()
          Gets the name of the plugin.
 String getPackageName()
           
 XDoclet getXDoclet()
           
protected  boolean isGenerateOneFile()
          Indicates whether or not to generate one file per metadata object or one file for all metadata objects.
 Object jxpath(Object contextBean, String xpath)
          Hook to JXPath, which lets templates query the datamodel with xpath.
 void setDestination(String destination)
          Sets the destination directory.
 void setDestinationDir(File destinationDir)
          Sets (and creates) the destination directory.
 void setEncoding(String encoding)
          Sets the encoding to use.
 void setFileName(String fileName)
          Sets the file name of the generated file(s).
 void setMetadataProvider(MetadataProvider metadataProvider)
           
 void setName(String name)
          Sets the name of the plugin.
 void setPackageName(String packageName)
          Sets the package name of the generated files.
protected  void validate()
           
 
Methods inherited from class xdoclet.beans.BeanContextSupportEx
add, createInvocations, getInvocations, getParent, setParent
 
Methods inherited from class java.beans.beancontext.BeanContextSupport
addAll, addBeanContextMembershipListener, avoidingGui, bcsChildren, bcsPreDeserializationHook, bcsPreSerializationHook, childDeserializedHook, childJustAddedHook, childJustRemovedHook, classEquals, clear, contains, containsAll, containsKey, copyChildren, createBCSChild, deserialize, dontUseGui, fireChildrenAdded, fireChildrenRemoved, getBeanContextPeer, getChildBeanContextChild, getChildBeanContextMembershipListener, getChildPropertyChangeListener, getChildSerializable, getChildVetoableChangeListener, getChildVisibility, getLocale, getResource, getResourceAsStream, initialize, instantiateChild, isDesignTime, isEmpty, isSerializing, iterator, needsGui, okToUseGui, propertyChange, readChildren, remove, remove, removeAll, removeBeanContextMembershipListener, retainAll, serialize, setDesignTime, setLocale, size, toArray, toArray, validatePendingAdd, validatePendingRemove, vetoableChange, writeChildren
 
Methods inherited from class java.beans.beancontext.BeanContextChildSupport
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, initializeBeanContextResources, isDelegated, releaseBeanContextResources, removePropertyChangeListener, removeVetoableChangeListener, serviceAvailable, serviceRevoked, setBeanContext, validatePendingSetBeanContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.beans.beancontext.BeanContextChild
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

Plugin

public Plugin()
Method Detail

getXDoclet

public XDoclet getXDoclet()

setMetadataProvider

public void setMetadataProvider(MetadataProvider metadataProvider)

getMetadataProvider

protected MetadataProvider getMetadataProvider()

getName

public final String getName()
Gets the name of the plugin.

Returns:
the name of the plugin.

setName

public final void setName(String name)
Sets the name of the plugin.

Parameters:
name - the name of the plugin.

getEncoding

public String getEncoding()
Gets the XML encoding.

Returns:
the XML encoding.
See Also:
setEncoding(java.lang.String)

setEncoding

public void setEncoding(String encoding)
Sets the encoding to use. Only applies to generation of XML files. Default is "ISO-8859-1"

Parameters:
encoding - the encoding to use.

getDestinationDir

public File getDestinationDir()
Returns the destination directory (without package directory).

Returns:
the destination directory

setDestinationDir

public void setDestinationDir(File destinationDir)
Sets (and creates) the destination directory.

Parameters:
destinationDir - the directory where the plugin will write its files.

setDestination

public void setDestination(String destination)
Sets the destination directory. The reason why the argument is not a java.io.File is that the ant wrapper uses reflection in order to call this method, and it only works with java.lang.String. If this method is called explicitly (typically from an IDE wrapper), make sure the destination is an absolute path.

Parameters:
destination - the directory where the plugin will write its files.

setFileName

public void setFileName(String fileName)
Sets the file name of the generated file(s). The value should be a plain a pattern such as Foo{0}.java or a plain String such as Bar.txt The occurrance of {0} will be substituted by the name of the class the file is generated from.

Parameters:
fileName - the name of the generated file(s).

getFileName

public final String getFileName()

createAccept

public final Accept createAccept()
Creates a new Accept


createPackageSubstitution

public final PackageSubstitution createPackageSubstitution()
Creates a new PackageSubstitution


execute

public void execute()
             throws IOException,
                    XDocletException
Generates the content.

Throws:
XDocletException
IOException

generate

protected abstract void generate(File destinationFile,
                                 Collection metaData)
                          throws IOException,
                                 XDocletException
Generates a file.

Parameters:
destinationFile - file to be generated.
metaData - metadata used during generation.
Throws:
XDocletException - if generation fails.
IOException - if an IO error occurs.

generate

protected abstract void generate(File destinationFile,
                                 Object metaData)
                          throws IOException,
                                 XDocletException
Generates a file.

Parameters:
destinationFile - file to be generated.
metaData - metadata used during generation.
Throws:
XDocletException - if generation fails.
IOException - if an IO error occurs.

validate

protected void validate()
                 throws XDocletException
XDocletException

isGenerateOneFile

protected boolean isGenerateOneFile()
Indicates whether or not to generate one file per metadata object or one file for all metadata objects.

Returns:
true if the fileName does not contain "{0}".
See Also:
setFileName(java.lang.String)

setPackageName

public final void setPackageName(String packageName)
Sets the package name of the generated files. This will be converted to a path and appended to destinationDir. Only specify this if no packageSubstitution is used.

Parameters:
packageName - the package name.

getPackageName

public final String getPackageName()

getFilteredMetadataCollection

protected final Collection getFilteredMetadataCollection()
                                                  throws XDocletException
Gets all accepted objects. Subclasses can control what's accepted by calling createAccept() and call setPredicate on it, using a predicate from the xdoclet.util.predicates package. If no predicate is set, all classes that were parsed will be returned.

Returns:
all accepted classes.
XDocletException

getDestinationFileForAll

public final File getDestinationFileForAll()
                                    throws XDocletException
Returns the destination file derived from a particular object. Will be called if fileName does not have "{0}" in it.

Returns:
the File where content will be written
Throws:
XDocletException

getDestinationFileForOne

public final File getDestinationFileForOne(Object object)
                                    throws XDocletException
Returns the destination file derived from a particular object. Will be called if fileName has "{0}" in it.

Parameters:
object - the object the generated file is derived from
Returns:
the File where content will be written
Throws:
XDocletException

checkClass

protected static void checkClass(String className)
                          throws XDocletException
Throws XDocletException if a specific class is not on the CP. Should be called from subclasses constructors to verify that classpath is OK.

Parameters:
className - the name of the class to check.
XDocletException

jxpath

public Object jxpath(Object contextBean,
                     String xpath)
Hook to JXPath, which lets templates query the datamodel with xpath.

Parameters:
contextBean - the bean to query.
xpath - the xpath expression.
Returns:
the resulting bean.

AcreateMetadataCollection

public final Collection AcreateMetadataCollection()
                                           throws XDocletException
XDocletException

AgetFilenameSubstitutionValue

public final String AgetFilenameSubstitutionValue(Object o)
                                           throws XDocletException
XDocletException

AgetPackageName

public final String AgetPackageName(Object o)

Acleanup

public final void Acleanup()
                    throws XDocletException
XDocletException

AsetClasspath

public final void AsetClasspath(String classpath)
                         throws XDocletException
XDocletException


Copyright © 2000-2003 XDoclet Team. All Rights Reserved.