Home / converter-generator-1.2.0
Name Modified Size InfoDownloads / Week
Parent folder
README.txt 2015-06-06 10.5 kB
converter-generator-1.2.0.zip 2015-06-06 148.5 kB
LICENSE.txt 2015-06-06 69 Bytes
Totals: 3 Items   159.1 kB 0
ÿþ### Description



The Converter-Generator creates Java Source Code for classes convertering a bean into another bean in a half-automated way.



The generated code, however, is not guaranteed to run instantly correct. It is crucial that a programmer supervises the code

and correct it where needed.



This fact seems to be a great disadvantage. But when looking closer the Converter-Generator can save a lot of programming time

and boring manual class generation routines.



The Converter-Generator generates the "structure" of a converter framework and concrete converter classes. The programmer needs only

to supervise the generated code and change where necessary. The programmer saves the time to create manually a lot of classes.





### API



The Converter-Generator has the following API class:



- ch.lyrer.walter.generator.converter.api.IConverterGenerator



This API class has three methods:



1. setGlobalProperties

2. generateConverterFramework

3. generateConcreteConverter



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

When calling the method 'generateConcreteConverter' automatically  the method 'generateConverterFramework' is invoked, too,

because the generated converter depend on the converter framework. However, you can call 'generateConverterFramework' only

when you need this.





### Features



There are some features to mention with the Converter-Generator:



1. 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. Each generation method returns a result object. The result object contains information which classes are created and which

   not due to already existing files.





### Design of Generated code



The Converter-Generator provides a design structure. The structure is simple using two Interfaces and two abstract classes.

Following is the inheritance tree (Please not that class AbstractConverter extends AbstractConverterThrowable and implement

IConverter, therefore this class is two times in the inheritance tree below):



- IConverterThrowable

  - AbstractConverterThrowable

    - AbstractConverter

  - IConverter

    - AbstractConverter



IConverterThrowable:

  - Defines several conversion methods.

  - Provides three generic parameters on class level:

    FROM: Type of the from class for conversion

    TO: Type of to class for conversion

    EXCEPTION: Type of used exception



AbstractConverterThrowable:

  - Implements almost all methods defined in IConverterThrowable.

  - Provides one hook method for the sub classes of concrete converter classes:

    - TO convertHook(FROM from) throws EXCEPTION



IConverter:

  - Extends IConverterThrowable

  - Sets generic parameter <EXCEPTION> to java.lang.RuntimeException



AbstractConverter:

  - Implements almost all methods defined in IConverter.

  - Extends AbstractConverterThrowable by setting the generic parameter <EXCEPTION> to java.lang.RuntimeException





### Generation Rules



1. Packages and directories are not created. They must already exist. Otherwise generation fails.

2. No existing Java Source Code is overwritten. When you need this then you must delete the  appropriate files before.

   You can lookup which files are generated or not in the result object of the generation methods.

3. The generator looks in the from class for public getter methods and in the to class for public setter methods.

   From this information code is generated for the following conditions:

   3.1. Exact match of getter and setter method:

        3.1.1. Types of setter and getter method is equal

               to.setBean(from.getBean())

        3.1.2. Types of setter and getter method is not equal

               to.setBean(beanConverter.convert(from.getBean())

               This means that a field beanConverter is created to. The type of the beanConverter field is IConverter/IConverterThrowable.

               The concrete converter for the new type is automatically created as additional converter class.

   3.2. Setter method only available in to bean:

	// TODO adjust following line - missing in from instance

	// to.setBean(from.get...());

   3.3. Getter method only available in from bean:

	// TODO adjust following line - missing in to instance

	// to.set...(from.getBean());



These rules do not cover all possibilities and in some cases superfluous converter classes are created.

You need to supervise the code an correct it.





### License



Apache Lisense 2.0





### Disclaimer



The author cannot be made responsible for any damage caused by the Converter-Generator.

The usage of the Converter-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 Converter-Generator is not guaranteed to run instantly correct.

Manual supervision is necessary and crucial.





### Author



Walter Lyrer

Source: README.txt, updated 2015-06-06