Menu

Home

Walter Lyrer

Project is inactive

The code of this project lives now in project StrategyStateGenerator.

Description

The Strategy Generator creates Java Source Code for classes representing strategies of strategy type in a half-automated way.

The generated code provides only structures and classes. Concrete methods must be defined manually in the strategy interface and implemented in the strategy classes.

The programmer saves the time to create manually a lot of classes.

However, the methods needed can not be forseen and therefore the strategy interface and its implementations have no methods after creation. It is up to the programmer to define the necessary methods. But the time to create all classes and structures is almost null.

Use Cases

  1. Ease of implementation of strategy pattern classes in Java.

Language and Version

The Strategy Generator version 1.0.0 and later are compiled in the programming language Java in version 1.6.

The Strategy Generator version 0.1.1 and earlier are compiled in the programming language Java in version 1.8.

API

The Strategy Generator has the following API class:

  • ch.lyrer.walter.generator.strategy.api.IStrategyGenerator

This API class has two methods:

  1. setGlobalProperties
  2. generateConcreteStrategies

Some Global Properties must be set with method 'setGlobalProperties' before calling the other method.

The method 'generateConcreteStrategies' accepts an instance having type 'GenerateConcreteStrategyIn' as input parameter.

The interesting part of type GenerateConcreteStrategyIn is the property 'List<? extends Enum<?>> strategyConditionValueList'.
This list must be filled with enumeration values of an enumeration. It is assumed that each enumeration value represents
a strategy. Thus it is expected that such an enumeration exists or is created before the generator is invoked.

Features

There are some features to mention with the Converter Generator:

  1. Way of strategy integration

    • The generated code can have one of two ways of integration you can choose from:
      • SINGLETON_BY_PATTERN: Converter classes are generated following the Singleton Pattern.
      • SINGLETON_BY_SPRING_DI_ON_ANNOTATION: Converter classes are generated using Spring Dependency Injection with annotations @Component and @Autowired
  2. Generation of test classes

    • For each strategy a test class can be generated depending on the TestingFramework you choose.
      • TESTNG_6_8: TestNG version 6.8
      • JUNIT_4: JUnit version 4
      • NONE: No test classes are created
  3. Queryable result object

    • Each generation method returns a result object. The result object contains information which classes are created and which not due to already existing files.
  4. Executable class with main method:

    • Class ExecuteStrategyGenerator provides a main method to call the Strategy Converter. It can be called in two ways:
      1. Pass properties file paths as arguments:
        • args[0] (mandatory): File path of the properties file containing the data for the Global Properties.
        • args[1..n] (optional): File path of a properties file containing data for a Concrete Strategy Type
      2. Pass directory path containing properties files:
        • args[0]: File path of the directory containing the properties files
        • At least one properties file with name StrategyGlobal.properties containing the Global Properties is mandatory.
        • Please note, that no subdirectories are traversed to find properties files.
        • All other properties files are interpreted as properties for a Strategy Converter.

Dependencies of the Strategy Generator

Velocity 1.7 (use velocity-1.7-dep.jar)
Apache Commons Logging 1.2

Design of Generated Converter code

The Strategy Generator provides a design structure. There is a strategy factory interface and implementation:

  • I{strategyName}StrategyFactory
  • {strategyName}StrategyFactoryImpl

The strategies themselves have an interface, an abstract class and all required strategy classes.

  • I{strategyName}Strategy
  • Abstract{strategyName}StrategyFactory
    • {strategyName}{strategyCondition[1]}Strategy
    • ...
    • {strategyName}{strategyCondition[n]}Strategy

Dependencies of the generated Strategy classes

There exist dependencies depending on the set properties provided by the client code:

  1. testingFramework:

  2. integrationType:

It is possible to create strategy classes without any dependencies. To achieve this you must set the property testingFramework=NONE and integrationType=SINGLETON_BY_PATTERN.

Generation Rules

  1. Packages and directories are not created. They must already exist. Otherwise generation fails.
  2. No existing Java Source files are overwritten. When you need to generate a class anew then you must delete the appropriate file before Strategy Generator execution. You can query the generation result from the returned GenerationResult instance.

License

Apache Lisense 2.0

Disclaimer

The author cannot be made responsible for any damage caused by the Strategy Generator.
The usage of the Strategy Generator is on own risk.
The code is designed and implemented on best know-how and with good intensions by the author.
Escpecially is to mention that the generated code of the Strategy-Generator is not guaranteed to run instantly correct.
Manual supervision is necessary and crucial.

Author

Walter Lyrer

Other projects from same author

Converter Generator
Named Parameter Converter
Strategy/State Generator

Notes

The wiki uses Markdown syntax.

Project Members: