org.javagen.agile.core.ioc.spring
Class SpringMain

java.lang.Object
  extended by org.javagen.agile.core.ioc.spring.SpringMain

public abstract class SpringMain
extends Object

Loads XML configuration and executes code generation pipeline using Spring framework IoC BeanFactory.

This is an extremely flexible way to configure the code generator, avoiding a one-size-fits-all approach.

Your Main class should extended this class:

 public class Main extends SpringMain {
   public static void main(String[] args) {
     SpringMain main = new SpringMain();
     main.setArgs(args);
     main.runPipeline();
   }
 }
 
This is the only Spring dependency in JavaGen Agile. If you don't like having to use Spring XML files to configure the generator then by all means write a non-Spring Main and contribute your code for inclusion in the framework!

Author:
Richard Easterling

Field Summary
protected  org.springframework.beans.factory.BeanFactory beanFactory
           
protected  String configFile
           
static String DEFAULT_CONFIG_FILE
           
static String DEFAULT_CONFIGURER_BEAN_ID
           
static String DEFAULT_PIPELINE_BEAN_ID
           
static String DEFAULT_ROOT_BEAN_NAME_ID
           
static String DEFAULT_TEMPLATE_GENERATOR_BEAN_ID
           
protected  Properties properties
           
protected  String propertyFile
           
protected  String startModelBeanId
           
 
Constructor Summary
SpringMain()
           
 
Method Summary
 Object getBean(String beanId)
          Uses underlying IoC container to access bean instance by ID.
protected  org.springframework.beans.factory.BeanFactory getBeanFactory()
          Load config and properties.
 String getConfigFile()
          Any type of configuration can be achieved using XXXSpringConfig.xml including: Pipeline components and order of execution Template names, locations and types and their artifact naming patterns and relative output locations Per-template overwrite predicates Binding templates to model instances Root structure of model tree including global properties and parent containers for generated model instances Default and artifact-specific naming patterns using model and emitter contexts Reading, writing and merging of metadata Code naming and conversion implementations Anything that gen.properties can specify
 String getConfigurerBeanId()
           
 String getPipelineBeanId()
           
 String getStartModelBeanId()
          The bean id of the model instance to use as input to the pipeline.
 Model runPipeline()
          Pulls pipeline bean out of factory and calls the gen method.
 void setArgs(String[] args)
          Scans arguments for config and/or property file.
 void setConfigFile(String configFile)
           
 void setProperties(Properties properties)
          Overrides default properties set in configFile.
 void setPropertyFile(String propertyFile)
          The properties file is meant to be the first (ie easiest) level of generator configuration specifying: Generated project name and directory location Source folder layout Output types
 void setStartModelBeanId(String parentNodeBeanId)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONFIGURER_BEAN_ID

public static final String DEFAULT_CONFIGURER_BEAN_ID
See Also:
Constant Field Values

DEFAULT_PIPELINE_BEAN_ID

public static final String DEFAULT_PIPELINE_BEAN_ID
See Also:
Constant Field Values

DEFAULT_TEMPLATE_GENERATOR_BEAN_ID

public static final String DEFAULT_TEMPLATE_GENERATOR_BEAN_ID
See Also:
Constant Field Values

DEFAULT_ROOT_BEAN_NAME_ID

public static final String DEFAULT_ROOT_BEAN_NAME_ID
See Also:
Constant Field Values

DEFAULT_CONFIG_FILE

public static final String DEFAULT_CONFIG_FILE
See Also:
Constant Field Values

configFile

protected String configFile

propertyFile

protected String propertyFile

properties

protected Properties properties

beanFactory

protected org.springframework.beans.factory.BeanFactory beanFactory

startModelBeanId

protected String startModelBeanId
Constructor Detail

SpringMain

public SpringMain()
Method Detail

setArgs

public void setArgs(String[] args)
Scans arguments for config and/or property file.

Parameters:
args - takes an optional Spring XML configuration file location and/or a properties file. Files can be any valid URL or classpath location. File types are recognized by their extension, names and order are not important. Here are some valid examples:
  • file:src/gen/GenSpringConfig.xml
  • classpath:GenSpringConfig.xml
  • file:src/gen/gen.properties
  • classpath:gen.properties

getBean

public Object getBean(String beanId)
Uses underlying IoC container to access bean instance by ID. Configuration should be completed before calling this method.


runPipeline

public Model runPipeline()
Pulls pipeline bean out of factory and calls the gen method.

Parameters:
factory - - configured BeanFactory instance

getBeanFactory

protected org.springframework.beans.factory.BeanFactory getBeanFactory()
Load config and properties.

Properties inputs have the following precedence from lowest to highest:

  1. Properties specified in the GlobalPropertyHolder bean within the SpringConfig.xml file.
  2. Properties specified in the external propertyFile. Note: this can be specified as a GlobalPropertyHolder property and overridden here.
  3. Properties specified in the properties instance. Note: these are usually set by the invoking tool (i.e. Maven).

See Also:
http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-extension-factory-postprocessors

getConfigFile

public String getConfigFile()
Any type of configuration can be achieved using XXXSpringConfig.xml including:

Parameters:
configFile - Spring xml context file.

setConfigFile

public void setConfigFile(String configFile)

setProperties

public void setProperties(Properties properties)
Overrides default properties set in configFile.

Parameters:
properties -

setPropertyFile

public void setPropertyFile(String propertyFile)
The properties file is meant to be the first (ie easiest) level of generator configuration specifying:


getConfigurerBeanId

public String getConfigurerBeanId()

getPipelineBeanId

public String getPipelineBeanId()

getStartModelBeanId

public String getStartModelBeanId()
The bean id of the model instance to use as input to the pipeline.

Note: normally the startModel is set directly on the pipeline in the SpringConfig.xml file.


setStartModelBeanId

public void setStartModelBeanId(String parentNodeBeanId)


Copyright 2006-2006-2007 Outsource Cafe Inc.. All Rights Reserved.