Index: src/main/java/org/exolab/javasource/JField.java =================================================================== --- src/main/java/org/exolab/javasource/JField.java (revision 8039) +++ src/main/java/org/exolab/javasource/JField.java (working copy) @@ -50,32 +50,7 @@ * @author Keith Visco * @version $Revision$ $Date: 2005-02-26 17:30:28 -0700 (Sat, 26 Feb 2005) $ */ -public final class JField extends JAnnotatedElementHelper implements JMember { - //-------------------------------------------------------------------------- - - /** The set of modifiers for this JField. */ - private JModifiers _modifiers = null; - - /** Type of this field. */ - private final JType _type; - - /** Name of the field. */ - private String _name = null; - - /** JavaDoc for this field. */ - private JDocComment _comment = null; - - /** Initialization string for this field. */ - private String _initString = null; - - /** Indicates whether this field is of type date/time. */ - private boolean _isDateTime = false; - - /** The Class in this JField has been declared. */ - private JClass _declaringClass = null; - - - //-------------------------------------------------------------------------- +public final class JField extends AbstractJField { /** * Creates a new JField. * @@ -83,173 +58,13 @@ * @param name Name of this new field. */ public JField(final JType type, final String name) { - setName(name); + super(type, name); + + JModifiers modifiers = getModifiers(); + modifiers.makePrivate(); - _type = type; - _modifiers = new JModifiers(); - _modifiers.makePrivate(); - _comment = new JDocComment(); - _comment.appendComment("Field " + name + "."); + JDocComment comment = new JDocComment(); + comment.appendComment("Field " + name + "."); + setComment(comment); } - - //-------------------------------------------------------------------------- - - /** - * Returns the JavaDoc comment describing this member. - * - * @return The JavaDoc comment describing this member, or null if no comment - * has been set. - */ - public JDocComment getComment() { - return _comment; - } - - /** - * Returns the class in which this JField has been declared. - * - * @return The class in which this JField has been declared. - */ - public JClass getDeclaringClass() { - return _declaringClass; - } - - /** - * Returns the initialization String for this JField. - * - * @return The initialization String for this JField, or null if no - * initialization String was specified. - */ - public String getInitString() { - return _initString; - } - - /** - * Returns the modifiers for this JField. - * - * @return The modifiers for this JField. - */ - public JModifiers getModifiers() { - return _modifiers; - } - - /** - * Returns the name of this JField. - * - * @return The name of this JField. - */ - public String getName() { - return _name; - } - - /** - * Returns the JType representing the type of this JField. - * - * @return The JType representing the type of this JField. - */ - public JType getType() { - return _type; - } - - /** - * Sets the JavaDoc comment describing this JField. - * - * @param comment The JavaDoc comment for this JField. - */ - public void setComment(final JDocComment comment) { - _comment = comment; - } - - /** - * Sets the JavaDoc comment describing this JField. - * - * @param comment The JavaDoc comment for this JField. - */ - public void setComment(final String comment) { - if (_comment == null) { - _comment = new JDocComment(); - } - _comment.setComment(comment); - } - - /** - * Sets the initialization string for this JField. This allows some - * flexibility in declaring default values. - * - * @param init The initialization string for this member. - */ - public void setInitString(final String init) { - _initString = init; - } - - /** - * Sets the name of this JField. - * - * @param name The name of this JField. - */ - public void setName(final String name) { - if (!JNaming.isValidJavaIdentifier(name)) { - String err = "'" + name + "' is "; - if (JNaming.isKeyword(name)) { - err += "a reserved word and may not be used as " - + " a field name."; - } else { - err += "not a valid Java identifier."; - } - throw new IllegalArgumentException(err); - } - _name = name; - } - - /** - * Sets the access modifiers on this JField. - * - * @param modifiers The access modifiers to be used for this JField. - */ - public void setModifiers(final JModifiers modifiers) { - _modifiers = modifiers; - } - - /** - * Sets the class that declares this JField. - * - * @param declaringClass The class in which this Jfield is declared. - */ - protected void setDeclaringClass(final JClass declaringClass) { - _declaringClass = declaringClass; - } - - /** - * Indicates whether this JField instance represents a field of type date/time. - * - * @return True if this field is of type date/time. - */ - public boolean isDateTime() { - return _isDateTime; - } - - /** - * To indicate whether this JField instance represents a field of type date/time. - * - * @param isDateTime True if this field is of type date/time. - */ - public void setDateTime(final boolean isDateTime) { - _isDateTime = isDateTime; - } - - //-------------------------------------------------------------------------- - - /** - * {@inheritDoc} - */ - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(_modifiers.toString()); - sb.append(' '); - sb.append(_type); - sb.append(' '); - sb.append(_name); - return sb.toString(); - } - - //-------------------------------------------------------------------------- } Index: src/main/java/org/exolab/castor/builder/BuilderConfiguration.java =================================================================== --- src/main/java/org/exolab/castor/builder/BuilderConfiguration.java (revision 8039) +++ src/main/java/org/exolab/castor/builder/BuilderConfiguration.java (working copy) @@ -285,7 +285,24 @@ public static final String EXTRA_DOCUMENTATION_METHODS = "org.exolab.castor.builder.extraDocumentationMethods"; - } //--Property + /** + * Specifies whether the XML code generator - when operating in + * 'element mode' should generate code according to how it worked + * with pre-1.3 releases. + * + * Possible values: + * - false (default) + * - true + * + *
+         * org.exolab.castor.builder.javaclassmapping.pre.13
+         * 
+ * + */ + public static final String JAVA_CLASS_MAPPING_PRE_13 = + "org.exolab.castor.builder.javaclassmapping.pre.13"; + + } /** * String value of false. @@ -545,16 +562,19 @@ } //-- setUseEnumeratedTypeInterface /** - * Tests the org.exolab.castor.builder.javaclassmapping property for the - * 'element' value. + * Indicates whether the XML code generator should map XML schema + * elements to Java classes. In other words, tests the + * org.exolab.castor.builder.javaclassmapping property + * for the 'element' value. * - * @return True if the Source Generator is mapping schema elements to Java + * @return True if the XML code generator should map XML schema elements to Java * classes. */ public boolean mappingSchemaElement2Java() { String value = _localProps.getProperty(Property.JAVA_CLASS_MAPPING, ""); + //TODO[WG, 20081223]: add another property to allow restoring wrong behavior return ELEMENT_VALUE.equalsIgnoreCase(value); - } //-- mappingSchemaElement2Java + } /** * Tests the org.exolab.castor.builder.javaclassmapping property for the 'type' value. @@ -564,7 +584,19 @@ public boolean mappingSchemaType2Java() { String value = _localProps.getProperty(Property.JAVA_CLASS_MAPPING, ""); return TYPE_VALUE.equalsIgnoreCase(value); - } //-- mappingSchemaType2Java + } + + /** + * Indicates whether the XML code generator - when operating in + * 'element mode' should generate code according to how it worked + * with pre-1.3 releases + * + * @return True if pre-1.3 functionality should be restored. + */ + public boolean mappingSchemaElement2JavaPre13() { + String value = _localProps.getProperty(Property.JAVA_CLASS_MAPPING_PRE_13, "false"); + return TRUE.equalsIgnoreCase(value); + } /** * Overrides the current set of properties with the given properties. Once Index: src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java =================================================================== --- src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java (revision 8039) +++ src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java (working copy) @@ -69,8 +69,10 @@ import org.exolab.castor.xml.XMLConstants; import org.exolab.castor.xml.XMLFieldDescriptor; import org.exolab.javasource.JClass; +import org.exolab.javasource.JConstant; import org.exolab.javasource.JConstructor; import org.exolab.javasource.JField; +import org.exolab.javasource.JMember; import org.exolab.javasource.JModifiers; import org.exolab.javasource.JNaming; import org.exolab.javasource.JPrimitiveType; @@ -373,14 +375,9 @@ //-- The node name parameter is a reference to a public static final nodeNameParam = nodeName.toUpperCase(); //-- Expose node name as public static final (reused by XMLFieldDescriptorImpl) - JModifiers publicStaticFinal = new JModifiers(); - publicStaticFinal.makePublic(); - publicStaticFinal.setStatic(true); - publicStaticFinal.setFinal(true); - JField jField = new JField(SGTypes.STRING, nodeNameParam); - jField.setModifiers(publicStaticFinal); - jField.setInitString("\"" + nodeName + "\""); - classDesc.addMember(jField); + JConstant constant = new JConstant(SGTypes.STRING, nodeNameParam); + constant.setInitString("\"" + nodeName + "\""); + classDesc.addMember(constant); } } Index: src/main/resources/org/exolab/castor/builder/castorbuilder.properties =================================================================== --- src/main/resources/org/exolab/castor/builder/castorbuilder.properties (revision 8039) +++ src/main/resources/org/exolab/castor/builder/castorbuilder.properties (working copy) @@ -29,8 +29,22 @@ #
 # org.exolab.castor.builder.javaclassmapping
 # 
-#org.exolab.castor.builder.javaclassmapping=element +org.exolab.castor.builder.javaclassmapping=element +# Specifies whether the XML code generator - when operating in +# 'element mode' should generate code according to how it worked +# with pre-1.3 releases +# +# Possible values: +# - false (default) +# - true +# +#
+# org.exolab.castor.builder.javaclassmapping.pre.13
+# 
+# +org.exolab.castor.builder.javaclassmapping.pre.13=false + # Specifies a super class for *all* generated classes. # By default the generated classes do not extend another class. #