de.enough.polish
Class Extension

java.lang.Object
  extended by de.enough.polish.Extension
Direct Known Subclasses:
CustomPreprocessor, Debugger, DescriptorCreator, Emulator, Finalizer, LibraryProcessor, LogHandler, ManifestCreator, Obfuscator, Packager, PostCompiler, PostObfuscator, PreCompiler, Preverifier, PropertyFunction, ResourceCopier

public abstract class Extension
extends Object

Provides the common base for any extensions of J2ME Polish.

Copyright Enough Software 2005

 history
        04-Apr-2005 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
protected  org.apache.tools.ant.Project antProject
           
protected  String autoStartCondition
           
protected  Environment environment
           
protected  ExtensionDefinition extensionDefinition
           
protected  ExtensionManager extensionManager
           
protected  ExtensionSetting extensionSetting
           
protected  ExtensionTypeDefinition extensionTypeDefinition
           
protected  boolean isBuildStarted
           
 
Constructor Summary
Extension()
          Creates a new extension.
 
Method Summary
 void configure(Variable[] parameters)
          Configures this extension with conditional parameters.
abstract  void execute(Device device, Locale locale, Environment env)
          Executes this extension.
 void executeAntTarget(String targetName, List antPropertiesList)
          Executes an Ant target.
 void executeAntTarget(String targetName, Variable[] antProperties)
          Executes an Ant target.
 void finalize(Device device, Locale locale, Environment env)
          Finalizes this extension for a the device and locale.
 org.apache.tools.ant.Project getAntProject()
           
 String getAutoStartCondition()
           
 Environment getEnvironment()
           
 ExtensionDefinition getExtensionDefinition()
           
 ExtensionSetting getExtensionSetting()
           
static Extension getInstance(ExtensionTypeDefinition typeDefinition, ExtensionDefinition definition, ExtensionSetting setting, org.apache.tools.ant.Project antProject, ExtensionManager manager, Environment environment)
          Instantiates the specified exception.
 String getParameterValue(String parameterName, Environment env)
          Retrieves a parameter value from either the setting, the definition or the type definition of this extension.
 String getType()
           
protected  void init(ExtensionTypeDefinition typeDefinition, ExtensionDefinition definition, ExtensionSetting setting, org.apache.tools.ant.Project project, ExtensionManager manager, Environment env)
          Initialises this extension.
 void initialize(Device device, Locale locale, Environment env)
          Initializes this extension for a new device or a new locale.
 boolean isConditionFulfilled(Environment env)
          Checks whether the autostart condition for this extension is fulfilled.
 void notifyBuildEnd(Environment env)
          Notifies the extension about the end of the build process.
 void notifyBuildStart(Environment env)
          Notifies the extension about the start of the build process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

extensionSetting

protected ExtensionSetting extensionSetting

antProject

protected org.apache.tools.ant.Project antProject

extensionManager

protected ExtensionManager extensionManager

extensionDefinition

protected ExtensionDefinition extensionDefinition

extensionTypeDefinition

protected ExtensionTypeDefinition extensionTypeDefinition

environment

protected Environment environment

autoStartCondition

protected String autoStartCondition

isBuildStarted

protected boolean isBuildStarted
Constructor Detail

Extension

public Extension()
Creates a new extension.

Method Detail

init

protected void init(ExtensionTypeDefinition typeDefinition,
                    ExtensionDefinition definition,
                    ExtensionSetting setting,
                    org.apache.tools.ant.Project project,
                    ExtensionManager manager,
                    Environment env)
Initialises this extension.

Parameters:
typeDefinition - the definition of the base type, can be null
definition - the extension definition taken from extensions.xml or custom-extensions.xml
setting - the extension settings
project - the ant project
env -

getExtensionSetting

public ExtensionSetting getExtensionSetting()

getExtensionDefinition

public ExtensionDefinition getExtensionDefinition()

getAntProject

public org.apache.tools.ant.Project getAntProject()

getEnvironment

public Environment getEnvironment()

configure

public void configure(Variable[] parameters)
Configures this extension with conditional parameters. Subclasses can implement the setParameters( Variable[] parameters, File baseDir ) method and subsequently use this method for only setting parameters that either have no conditions or which conditions are fulfilled. For each valid parameter the subclass needs to provide the method set[param-name] with either the argument String, File or boolean. If the parameter name is "message" you need to implement either setMessage( String ), setMessage( File ) or setMessage( boolean ), for example.

Parameters:
parameters - the parameters.
Throws:
IllegalArgumentException - when a parameter has a syntax error or when a needed method has not be found.

notifyBuildStart

public void notifyBuildStart(Environment env)
Notifies the extension about the start of the build process. Always call super.notifyBuildStart(env) in subclasses.

Parameters:
env - the environment without device specific settings

notifyBuildEnd

public void notifyBuildEnd(Environment env)
Notifies the extension about the end of the build process. Always call super.notifyBuildEnd(env) in subclasses.

Parameters:
env - the environment without device specific settings

initialize

public void initialize(Device device,
                       Locale locale,
                       Environment env)
Initializes this extension for a new device or a new locale. The default implementation doesn't do anything.

Parameters:
device - the current device
locale - the current locale, can be null
env - the environment/configuration

finalize

public void finalize(Device device,
                     Locale locale,
                     Environment env)
Finalizes this extension for a the device and locale. The default implementation doesn't do anything.

Parameters:
device - the current device
locale - the current locale, can be null
env - the environment/configuration

execute

public abstract void execute(Device device,
                             Locale locale,
                             Environment env)
                      throws BuildException
Executes this extension. Not all extension types are executed.

Parameters:
device - the current device
locale - the current locale, can be null
env - the environment/configuration
Throws:
BuildException - when the execution failed

getParameterValue

public String getParameterValue(String parameterName,
                                Environment env)
Retrieves a parameter value from either the setting, the definition or the type definition of this extension.

Parameters:
parameterName - the name of the parameter
env - the environment, can be null
Returns:
either the value or null of the parameter is not defined anywhere

getInstance

public static Extension getInstance(ExtensionTypeDefinition typeDefinition,
                                    ExtensionDefinition definition,
                                    ExtensionSetting setting,
                                    org.apache.tools.ant.Project antProject,
                                    ExtensionManager manager,
                                    Environment environment)
                             throws ClassNotFoundException,
                                    InstantiationException,
                                    IllegalAccessException
Instantiates the specified exception. At least one of the given definition of setting parameters must not be null.

Parameters:
typeDefinition - the definition of the type, can be null
definition - the definition taken from extensions.xml or custom-extensions.xml
setting - the configuration taken from build.xml
antProject - the Ant project
manager - the extension manager
environment - the environment settings
Returns:
the configured extension.
Throws:
ClassNotFoundException - when the class was not found
InstantiationException - when the class could not get instantiated
IllegalAccessException - when the class could not be accessed
IllegalArgumentException - when both definition and setting are null or when no class has been defined anywhere.

executeAntTarget

public void executeAntTarget(String targetName,
                             List antPropertiesList)
Executes an Ant target.

Parameters:
targetName -
antPropertiesList -

executeAntTarget

public void executeAntTarget(String targetName,
                             Variable[] antProperties)
Executes an Ant target.

Parameters:
targetName -
antProperties -

getAutoStartCondition

public String getAutoStartCondition()

isConditionFulfilled

public boolean isConditionFulfilled(Environment env)
Checks whether the autostart condition for this extension is fulfilled.

Parameters:
env - the environment
Returns:
true when this condition is fulfilled

getType

public String getType()
Returns:
the type of this extension