forked from AmirHooshangi/DTO-code-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Code Generation for DTO design pattern
License
pooyaho/DTO-code-generation
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
DTO (Data Transfer Object) code generator API helps developers to use DTO design pattern fast and effectively. DTO design pattern is being used in wide area of J2ee projects especially in those which uses EJB,SOAP etc.this API is for developers who hate writing DTO classes and convert those values to their Beans and vise versa. there is some easy steps to use this API, and some important notes that will be mentioned. all you need is methods in BeanConverter interface. DtoGenerator is one of implementations of BeanConverter. so you need instances of this class. example : BeanConverter beanExtractor=new DtoGenerator(); one of the advantages of this API is that it generates DTO class from your main Java Beans. you can generate your DTO class using generateDTOClass method in ClassGenerator interface. there is some notes that you must notice. first add jar of this project to your own project. suppose you have Hibernate Java Bean (it can be any POJO) and want to generate it's DTO class for using it in EJB or SOAP services. you must use @DTO annotation on top the fields on your Hibernate Bean that you want see in DTO class. e.g public class Student { @DTO private int id; private String name; public void setId(int id) { this.id = id; } public int getId() { return id; } } as you see "id" has @DTO annotation but "name" doesn't, so you wont see "name" field in your DTO class. Note: you must generate setters and getters for annotated field and you must do it with standard java naming setXxx(..) getXxx(). now you are ready to generate your DTO class with this method. beanExtractor.generateDtoFromBean(Student.class, "yourPackageName", "pathToSave"); Student is your Hibernate bean class, "yourPackageName" is package of your java class. and "pathToSave" is where you want to save your java file on the hard disk. Now add this class to your project class path. the name of generated class should be StudentDTO. Also you can calls generateDtoFromBean method with package name, for example: beanExtractor.generateDtoFromBean("beans.model", "yourPackageName", "pathToSave"); It will extracts all classes in beans.model package and generates Dtos from classes that have annotation of @DTO
About
Code Generation for DTO design pattern
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- Java 100.0%