Catwalk Model Processor
I have just released the code for Catwalk a Java Annotation Processor for automatically generating derived domain model classes.
Supposing you have a JPA Entity which you want to pass to a servlet stripped of certain private / internal properties, adding a few annotations to the getters you want to expose allows Catwalk to generate a new class with only those properties and convenience methods for converting between the two types of objects.
The project is still missing a few essentials before being useful, such as documentation, proper examples and being uploaded to a Maven repo.
In the following example, a TestModel class is converted to a WebTestModel class:
TestModel.java
package net.dataforte.test.model;
@Model(pattern = "Web#", classPackage = "net.dataforte.test.webmodel")
public class TestModel {
String s;
int i;
@ModelAttribute
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
}
WebTestModel.java
package net.dataforte.test.webmodel;
public class WebTestModel {
private java.lang.String s;
public WebTestModel() {}
public WebTestModel(net.dataforte.test.model.TestModel src) {
this.fromTestModel(src);
}
java.lang.String getS() {
return s;
}
void setS(java.lang.String s) {
this.s = s;
}
public WebTestModel fromTestModel(net.dataforte.test.model.TestModel src) {
this.s = src.getS();
return this;
}
public net.dataforte.test.model.TestModel toTestModel() {
net.dataforte.test.model.TestModel that = new net.dataforte.test.model.TestModel();
that.setS(this.s);
return that;
}
}