Relates :
|
|
Relates :
|
|
Relates :
|
A DESCRIPTION OF THE REQUEST : Give the ability to create abstract classes between the final enum declaration containing the static enumerated values, and the abstract superclass for all enum java.lang.Enum. So an AbstractColumn.java file can contain: public abstract enum AbstractColumn { String columnName; int precision; AbstractColumn() { columnName = name(); precision = 0; } AbstractColumn(String c, int p) { .... } public String getColumnName() {return columnName();} } And inside an O/R Mapping framework an annotation can be: public interface @Column {AbstractColumn definition();} And then the application users have the level of indirection they need to provide logic to the framework using the static annotations. For example: public enum CustomerColumn extends AbstractColumn { firstName, lastName, age; public String getColumnName() { return StringUtils.capitalizeWithUnderscore(name()); } } @Entity public class Customer { @Column(definition = CustomerColumn.firstName) private String firstName; } Then all the problems of hardcoded schema names, copy/paste, string based errors (no type safety), and so on disappear. From my experience, the limitations of Annotations are really pushing developers away, and this feature can unlock the issue. JUSTIFICATION : The request was already reported in Bug ID: 6222244 and Bug ID: 6507006. For example: http://beust.com/weblog/archives/2004_04.html There is a big demand to have more flexible annotations, and one big solution is this one: Have the user define its own enum classes that extends a specific abstract enum provided by the framework, and use this specific enum in the framework annotations. With this, if you want to redirect to XML configuration, nothing stops you... ---------- BEGIN SOURCE ---------- /* * @test @(#)AE1.java 1.7 08/06/07 * @summary support for abstract enum * @author freds * * @compile AE1.java */ package abstractEnum.ae1; public abstract enum AE1 { int i; AE1() {i=2;} AE1(int pi) {i=pi;} public int getI() {return i;} } /* * @test @(#)E1.java 1.7 08/06/07 * @summary support for abstract enum * @author freds * * @compile AE1.java E1.java */ public enum E1 extends AE1 { one(1),two; E1() { } E1(int pi) { super(pi); } } /* * @test @(#)AnnoAETest.java 1.7 08/06/07 * @summary support for abstract enum * @author freds * * @compile AnnoAETest.java */ public @interface AnnoAETest { AE1 ae1(); } /* * @test @(#)AnnoAEUsage.java 1.7 08/06/07 * @summary support for abstract enum * @author freds * * @compile AnnoAEUsage.java */ public class AnnoAEUsage { @AnnoAETest(ae1 = E1.one) private String fisrt; } ---------- END SOURCE ----------
|