Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.3
-
Fix Version/s: 1.3.1
-
Component/s: XML code generator
-
Labels:None
-
Patch Submitted:Yes
-
Number of attachments :
Description
Generation of java5 enums for simpleType enumeration has been added in Castor v1.2 (see CASTOR-2117 issue). castor-maven-plugin v1.5 depends on castor-codegen v1.2 and generates java5 enums well, but I'd like to suggest following few improvements:
1. all java 5 enums implement Serializable (and Comparable too; see java.lang.Enum javadoc), so there is no need to generate "implements java.io.Serializable"
2. similarly, there is no need to generate '@SuppressWarnings("serial")' since there is no need to specify serialVersionUID anyway, all enums have a fixed serialVersionUID = 0L, and even if one specifies different value it is being ignored
3. since all simpleType enumerations have a value, and Castor generates a value property for them and uses/sets that value in Enum constructor for every Enum constant, generated fromValue method could be optimized so that currently used for-loop over the Enum values is replaced with a Map of (value, Enum constant) pairs filled using a static initializer, all for increased efficiency.
Attached patch implements all 3 suggested improvements. To support removal of "implements Serializable", a removeInterface method has been added to org.exolab.javasource.JStructure Castor source code model class. All the rest of the changes have been made solely to the org.exolab.castor.builder.factory.EnumerationFactory class and it's createJava5Enum method.