Index: codegen/src/test/java/org/exolab/castor/builder/nature/JDOFieldNatureTest.java =================================================================== --- codegen/src/test/java/org/exolab/castor/builder/nature/JDOFieldNatureTest.java (revision 0) +++ codegen/src/test/java/org/exolab/castor/builder/nature/JDOFieldNatureTest.java (revision 0) @@ -0,0 +1,87 @@ +/** + * + */ +package org.exolab.castor.builder.nature; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.castor.xml.JavaNamingImpl; +import org.exolab.castor.builder.factory.FieldMemberAndAccessorFactory; +import org.exolab.castor.builder.info.BaseFieldInfo; +import org.exolab.castor.builder.info.FieldInfo; +import org.exolab.castor.builder.info.JDOFieldNature; +import org.exolab.castor.builder.types.XSBoolean; + +/** + * @author Sebastian Gabmeyer + * + */ +public class JDOFieldNatureTest extends TestCase { + + private FieldInfo _info; + private JDOFieldNature _nature; + + /** + * + */ + public JDOFieldNatureTest() { + // TODO Auto-generated constructor stub + } + + /** + * @param name + */ + public JDOFieldNatureTest(String name) { + super(name); + // TODO Auto-generated constructor stub + } + + + + /** + * @throws Exception + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + _info = new BaseFieldInfo(new XSBoolean(true), "test", + new FieldMemberAndAccessorFactory(new JavaNamingImpl())); + _nature = new JDOFieldNature(_info); + } + + /** + * @throws Exception + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("JDOFieldNature TestSuite"); + + suite.addTest(new JDOFieldNatureTest("testGetAddColumn")); + //suite.addTest(new JDOFieldNatureTest("")); + + return suite; + + } + + public void testGetAddColumn() throws Exception { + String colName = _nature.getColumnName(); + String colType = _nature.getColumnType(); + boolean colAccNulls = _nature.isColumnNullable(); + boolean colReadOnly = _nature.isColumnReadOnly(); + assertNull(colType); + assertNull(colName); + String columnName = "testColumn"; + String columnType = "jdo:string"; + boolean acceptNulls = false; + boolean isReadOnly = false; + _nature.addColumn(columnName , columnType , acceptNulls, isReadOnly); + colName = _nature.getColumnName(); + assertNotNull(colName); + } + +} Index: codegen/src/test/java/org/exolab/castor/builder/nature/JDOClassNatureTest.java =================================================================== --- codegen/src/test/java/org/exolab/castor/builder/nature/JDOClassNatureTest.java (revision 0) +++ codegen/src/test/java/org/exolab/castor/builder/nature/JDOClassNatureTest.java (revision 0) @@ -0,0 +1,120 @@ +/** + * + */ +package org.exolab.castor.builder.nature; + +import java.util.HashMap; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.exolab.castor.builder.info.BaseClassInfo; +import org.exolab.castor.builder.info.ClassInfo; +import org.exolab.castor.builder.info.JDOClassNature; +import org.exolab.castor.builder.info.nature.NatureExtendable; +import org.exolab.castor.builder.info.nature.NatureNotSupportedException; +import org.exolab.castor.mapping.xml.KeyGeneratorDef; +import org.exolab.castor.mapping.xml.Param; +import org.exolab.javasource.JClass; + +/** + * @author Sebastian Gabmeyer + * + */ +public class JDOClassNatureTest extends TestCase { + + private NatureExtendable _holder; + private JDOClassNature _jdoNature; + + /** + * + */ + public JDOClassNatureTest() { + // TODO Auto-generated constructor stub + } + + /** + * @param name + */ + public JDOClassNatureTest(final String name) { + super(name); + // TODO Auto-generated constructor stub + } + + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("JDOClassNature TestSuite"); + + suite.addTest(new JDOClassNatureTest("testGetAddTableName")); + suite.addTest(new JDOClassNatureTest("testGetAddPrimaryKeys")); + suite.addTest(new JDOClassNatureTest("testGetAddPrimaryKeysWithGenerator")); + suite.addTest(new JDOClassNatureTest("testGetAddKeyGenerator")); + suite.addTest(new JDOClassNatureTest("testRiseOfNatureNotSupportedException")); + + return suite; + + } + + public void setUp() throws Exception { + super.setUp(); + _holder = new BaseClassInfo(new JClass("test")); + _jdoNature = new JDOClassNature(_holder); + } + + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testGetAddTableName() throws Exception { + assertNull(_jdoNature.getTableName()); + _jdoNature.setTableName("testTable"); + assertEquals("testTable", _jdoNature.getTableName()); + } + + public void testGetAddPrimaryKeys() throws Exception { + assertNull(_jdoNature.getPrimaryKeys()); + _jdoNature.addPrimaryKey("testPK"); + assertEquals("testPK", _jdoNature.getPrimaryKeys()[0]); + } + + public void testGetAddPrimaryKeysWithGenerator() throws Exception { + assertNull(_jdoNature.getPrimaryKeys()); + _jdoNature.addPrimaryKey("testPK", "testGen"); + String pk = _jdoNature.getPrimaryKeys()[0]; + assertEquals("testPK", pk); + assertEquals("testGen", _jdoNature.getGeneratorNameFor(pk)); + } + + public void testGetAddKeyGenerator() throws Exception { + assertNull(_jdoNature.getKeyGenerator("keyGen")); + HashMap params = new HashMap(); + params.put("key1", "value1"); + _jdoNature.addKeyGenerator("keyGen", "high-low", params); + KeyGeneratorDef expectedGenDef = new KeyGeneratorDef(); + expectedGenDef.setName("high-low"); + expectedGenDef.setAlias("keyGen"); + Param param = new Param(); + param.setName("key1"); + param.setValue("value1"); + expectedGenDef.addParam(param); + KeyGeneratorDef genDef = _jdoNature.getKeyGenerator("keyGen"); + assertNotNull(genDef); + assertEquals(expectedGenDef.getAlias(), genDef.getAlias()); + assertEquals(expectedGenDef.getName(), genDef.getName()); + assertEquals("key1", expectedGenDef.getParam(0).getName()); + assertEquals(expectedGenDef.getParam(0).getName(), genDef.getParam(0).getName()); + assertEquals("value1", expectedGenDef.getParam(0).getValue()); + assertEquals(expectedGenDef.getParam(0).getValue(), genDef.getParam(0).getValue()); + } + + public void testRiseOfNatureNotSupportedException() { + ClassInfo ci2 = new BaseClassInfo(new JClass("test2")); + _jdoNature.setPropertyHolder(ci2); + + try { + _jdoNature.setTableName("test2"); + fail("Expected Exception \"NatureNotSupportedException\" not thrown!"); + } catch (NatureNotSupportedException e) { + } + } + +} Index: codegen/src/test/java/org/exolab/castor/builder/nature/JDONatureTest.java =================================================================== --- codegen/src/test/java/org/exolab/castor/builder/nature/JDONatureTest.java (revision 0) +++ codegen/src/test/java/org/exolab/castor/builder/nature/JDONatureTest.java (revision 0) @@ -0,0 +1,105 @@ +/** + * + */ +package org.exolab.castor.builder.nature; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.exolab.castor.builder.info.BaseClassInfo; +import org.exolab.castor.builder.info.JDONature; +import org.exolab.javasource.JClass; + +/** + * @author Sebastian Gabmeyer + * + */ +public class JDONatureTest extends TestCase { + + private BaseClassInfo ci; + private JDONature nature; + + public JDONatureTest() { + super(); + } + + public JDONatureTest(String name) { + super(name); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + ci = new BaseClassInfo(new JClass("test")); + nature = new JDONature(); + ci.addNature(nature.getId()); + nature.setPropertyHolder(ci); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static Test suite() throws Exception { + TestSuite suite = new TestSuite("JDONature Test"); + + suite.addTest(new JDONatureTest("testSetTableName")); + suite.addTest(new JDONatureTest("testAddPrimaryKey")); + suite.addTest(new JDONatureTest("testAddPrimaryKeyWithKeygenerator")); + + return suite; + + } + + public void testSetTableName() throws Exception { + assertEquals(null, nature.getTableName()); + + nature.setTableName("TestTable"); + assertEquals("TestTable", nature.getTableName()); + } + + public void testAddPrimaryKey() throws Exception { + assertNull(nature.getPrimaryKeys()); + + nature.addPrimaryKey("testPK"); + assertEquals("testPK", nature.getPrimaryKeys()[0]); + } + + public void testAddPrimaryKeyWithKeygenerator() throws Exception { + assertNull(nature.getPrimaryKeys()); + + nature.addPrimaryKey("testPK", "testKeyGen"); + String primaryKey = nature.getPrimaryKeys()[0]; + assertEquals("testPK", primaryKey); + assertEquals("testKeyGen", nature.getGeneratorNameFor(primaryKey)); + } + + // TODO: incomplete tests!! + public void testAddColumn() throws Exception { + // nature.addColumn("test", "testType"); + } + + public void testAddColumnAsForeignKey() throws Exception { + boolean isForeignKey = true; + nature.addColumn("test", "testType", isForeignKey); + } + + public void testAddRelation() throws Exception { + nature.addRelation("name", "type", "collection"); + } + + public void testValidate() throws Exception { + + } + +} Index: codegen/src/main/java/org/exolab/castor/builder/FactoryState.java =================================================================== --- codegen/src/main/java/org/exolab/castor/builder/FactoryState.java (revision 7626) +++ codegen/src/main/java/org/exolab/castor/builder/FactoryState.java (working copy) @@ -52,6 +52,7 @@ import java.util.Vector; import org.exolab.castor.builder.binding.XMLBindingComponent; +import org.exolab.castor.builder.info.BaseClassInfo; import org.exolab.castor.builder.info.ClassInfo; import org.exolab.castor.builder.info.FieldInfo; import org.exolab.castor.xml.schema.Annotated; @@ -162,7 +163,7 @@ _xmlInfoRegistry.bind(_jClass, component, "class"); } - _classInfo = new ClassInfo(_jClass); + _classInfo = new BaseClassInfo(_jClass); _resolver = sgState; Index: codegen/src/main/java/org/exolab/castor/builder/info/FieldInfo.java =================================================================== --- codegen/src/main/java/org/exolab/castor/builder/info/FieldInfo.java (revision 7626) +++ codegen/src/main/java/org/exolab/castor/builder/info/FieldInfo.java (working copy) @@ -1,523 +1,133 @@ -/* - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. - * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). - * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 1999-2004 (C) Intalio, Inc. All Rights Reserved. - * - * This file was originally developed by Keith Visco during the course - * of employment at Intalio Inc. - * Portions of this file developed by Keith Visco after Jan 19 2005 are - * Copyright (C) 2005 Keith Visco. All Rights Reserverd. - * - * $Id$ - */ package org.exolab.castor.builder.info; -import java.util.LinkedList; import java.util.List; import org.exolab.castor.builder.factory.FieldMemberAndAccessorFactory; -import org.exolab.castor.builder.types.XSType; -import org.exolab.javasource.JType; +import org.exolab.castor.builder.info.nature.NatureExtendable; /** - * A class for representing field members of a Class. FieldInfo objects hold all - * the information required about a member in order to be able to produce - * marshal/unmarshal and validation code. + * @author Sebastian Gabmeyer * - * @author Keith Visco - * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ */ -public class FieldInfo extends XMLInfo { +public interface FieldInfo extends NatureExtendable { - /** The Read / Getter method flag. */ - public static final int READ_METHOD = 1; - /** The Write / Setter method flag. */ - public static final int WRITE_METHOD = 2; - /** The Read and Write methods flags. */ - public static final int READ_WRITE_METHODS = 3; - - /** Method prefixes for "Add" methods. */ - public static final String METHOD_PREFIX_ADD = "add"; - /** Method prefixes for "Delete" methods. */ - public static final String METHOD_PREFIX_DELETE = "delete"; - /** Method prefixes for "Get" methods. */ - public static final String METHOD_PREFIX_GET = "get"; - /** Method prefixes for "Has" methods. */ - public static final String METHOD_PREFIX_HAS = "has"; - /** Method prefixes for "Set" methods. */ - public static final String METHOD_PREFIX_SET = "set"; - /** Method prefixes for "Is" methods. */ - public static final String METHOD_PREFIX_IS = "is"; - - /** The Java name for Members described by this FieldInfo. */ - private String _name = null; - - private ClassInfo _declaringClassInfo = null; - /** JavaDoc comment. */ - private String _comment = null; - - /** The default value for this FieldInfo. */ - private String _default = null; - /** The fixed production for this FieldInfo. */ - private String _fixed = null; - /** A flag to indicate a final member. */ - private boolean _final = false; - /** The methods flags, indicates which methods to create. */ - private int _methods = READ_WRITE_METHODS; - /** A reference to the FieldInfo instance within the same class. */ - private FieldInfo _fieldInfoReference = null; - /** A flag to indicate a static member. */ - private boolean _static = false; - /** Flags whether or not the a MarshalDescriptor should be created for this FieldInfo. */ - private boolean _transient = false; - /** A flag to indicate a bound property. */ - private boolean _bound = false; - /** A flag to indicate a container field. */ - private boolean _isContainer = false; /** - * The fully qualified name of the XMLFieldHandler (if any) - * to use in the generated descriptor. - */ - private String _fieldHandler; - /** A boolean to indicate that this field represents a "nillable" field. */ - private boolean _nillable = false; - /** The fully qualified name of the Validator (if any) to use in the generated descriptor. */ - private String _validator; - /** Visibility of this FieldInfo. */ - private String _visibility = "private"; - - /** This factory creates a JField out of a FieldInfo */ - private FieldMemberAndAccessorFactory _memberAndAccessorFactory; - - /** - * Holds the possible substitution groups for this class. - */ - private List _substitutionGroupMembers = new LinkedList(); - - /** - * Creates a new FieldInfo with the given XML Schema type and the given - * member name. - * - * @param type - * the XML Schema type of this member - * @param name - * the name of the member - * @param memberAndAccessorFactory - * the FieldMemberAndAccessorFactory to be used - */ - public FieldInfo(final XSType type, final String name, - final FieldMemberAndAccessorFactory memberAndAccessorFactory) { - this._name = name; - this._memberAndAccessorFactory = memberAndAccessorFactory; - setSchemaType(type); - } //-- FieldInfo - - - /** - * Returns the FieldMemberAndAccessorFactory instance to use to create - * a JField out of this FieldInfo. + * Returns the FieldMemberAndAccessorFactory instance to use to create a + * JField out of this FieldInfo. + * * @return the suitable FieldMemberAndAccessorFactory */ - public FieldMemberAndAccessorFactory getMemberAndAccessorFactory() { - return _memberAndAccessorFactory; - } + FieldMemberAndAccessorFactory getMemberAndAccessorFactory(); - /* Returns the default value for this FieldInfo. - * - * @return the default value for this FieldInfo, or null if no default value - * was set; - */ - public final String getDefaultValue() { - return _default; - } //-- getDefaultValue - /** - * Returns the fixed production for this FieldInfo, or null if no fixed - * value has been specified. - *
- * NOTE: Fixed values are NOT the same as default values
- *
- * @return the fixed value for this FieldInfo
- */
- public final String getFixedValue() {
- return _fixed;
- } //-- getFixedValue
-
- /**
* Returns the name of the delete method for this FieldInfo.
+ *
* @return the name of the delete method for this FieldInfo.
*/
- public final String getDeleteMethodName() {
- return METHOD_PREFIX_DELETE + getMethodSuffix();
- } //-- getDeleteMethodName
+ String getDeleteMethodName(); // -- getDeleteMethodName
/**
* Returns the name of the has method for this FieldInfo.
+ *
* @return the name of the has method for this FieldInfo.
*/
- public final String getHasMethodName() {
- return METHOD_PREFIX_HAS + getMethodSuffix();
- } //-- getHasMethodName
+ String getHasMethodName(); // -- getHasMethodName
/**
* Returns the name of the read method for this FieldInfo.
+ *
* @return the name of the read method for this FieldInfo.
*/
- public final String getReadMethodName() {
- return METHOD_PREFIX_GET + getMethodSuffix();
- } //-- getReadMethodName
+ String getReadMethodName(); // -- getReadMethodName
- /**
- * Returns the fully qualified name of the Validator to use.
- *
- * @return the fully qualified name of the Validator to use.
- */
- public final String getValidator() {
- return _validator;
- }
+ /**
+ * Returns the fully qualified name of the Validator to use.
+ *
+ * @return the fully qualified name of the Validator to use.
+ */
+ String getValidator();
/**
* Returns the name of the write method for this FieldInfo.
+ *
* @return the name of the write method for this FieldInfo.
*/
- public final String getWriteMethodName() {
- if (isMultivalued()) {
- return METHOD_PREFIX_ADD + getMethodSuffix();
- }
- return METHOD_PREFIX_SET + getMethodSuffix();
- } //-- getWriteMethodName
+ String getWriteMethodName(); // -- getWriteMethodName
- /**
- * Returns the fully qualified name of the XMLFieldHandler to use.
- *
- * @return the fully qualified name of the XMLFieldHandler to use.
- */
- public final String getXMLFieldHandler() {
- return _fieldHandler;
- }
-
/**
- * Returns the comment associated with this Member.
- *
- * @return the comment associated with this Member, or null.
- * if one has not been set.
- */
- public final String getComment() {
- return _comment;
- } //-- getComment
-
- /**
* Returns the methods flag that indicates which.
- *
+ *
* methods will be created.
- *
+ *
* @return the methods flag
*/
- public final int getMethods() {
- return _methods;
- } //-- getMethods
+ int getMethods(); // -- getMethods
/**
* Returns the name of this FieldInfo.
- *
+ *
* @return the name of this FieldInfo.
*/
- public final String getName() {
- return this._name;
- } //-- getName
+ String getName(); // -- getName
/**
- * Returns true if this FieldInfo represents a bound property.
- *
- * @return true if this FieldInfo represents a bound property.
- */
- public final boolean isBound() {
- return _bound;
- } //-- isBound
-
- /**
- * Returns true if this FieldInfo describes a container class. A container
- * class is a class which should not be marshalled as XML, but whose members
- * should be.
- *
- * @return true if this ClassInfo describes a container class.
- */
- public final boolean isContainer() {
- return _isContainer;
- } //-- isContainer
-
- /**
* Returns true if the "has" and "delete" methods are needed for the field
* associated with this FieldInfo.
- *
+ *
* @return true if the has and delete methods are needed.
*/
- public final boolean isHasAndDeleteMethods() {
- XSType xsType = getSchemaType();
- JType jType = xsType.getJType();
- return ((!xsType.isEnumerated()) && jType.isPrimitive());
- } //-- isHasMethod
+ boolean isHasAndDeleteMethods(); // -- isHasMethod
/**
- * Returns true if this field represents a nillable field. A nillable field
- * is a field that can have null content (see XML Schema 1.0 definition of
- * nillable).
- *
- * @return true if nillable, otherwise false.
- * @see #setNillable(boolean)
- */
- public final boolean isNillable() {
- return _nillable;
- } //-- isNillable
-
- /**
- * Returns true if this FieldInfo is a transient member. Transient members
- * are members which should be ignored by the Marshalling framework.
- *
- * @return true if this FieldInfo is transient.
- */
- public final boolean isTransient() {
- return (_transient || _final || _static);
- } //-- isTransient
-
- /**
- * Sets the comment for this Member.
- * @param comment the comment or description for this Member
- */
- public final void setComment(final String comment) {
- _comment = comment;
- } //-- setComment
-
- /**
- * Returns the ClassInfo to which this Member was declared, for inheritance reasons.
+ * Returns the ClassInfo to which this Member was declared, for inheritance
+ * reasons.
+ *
* @return the ClassInfo to which this Member was declared.
*/
- public final ClassInfo getDeclaringClassInfo() {
- return this._declaringClassInfo;
- } //-- getDeclaringClassInfo
+ ClassInfo getDeclaringClassInfo(); // -- getDeclaringClassInfo
- /**
- * Sets whether or not this FieldInfo represents a bound property.
- *
- * @param bound the flag when true indicates that this FieldInfo represents a
- * bound property.
- */
- public final void setBound(final boolean bound) {
- _bound = bound;
- } //-- setBound
+ void setDeclaringClassInfo(final ClassInfo declaringClassInfo); // -- setDeclaringClassInfo
/**
- * Sets whether or not this FieldInfo describes a container field. A
- * container field is a field which should not be marshalled directly as
- * XML, but whose members should be. By default this is false.
- *
- * @param isContainer
- * the boolean value when true indicates this class should be a
- * container class.
- */
- public final void setContainer(final boolean isContainer) {
- _isContainer = isContainer;
- } //-- setContainer
-
- public final void setDeclaringClassInfo(final ClassInfo declaringClassInfo) {
- this._declaringClassInfo = declaringClassInfo;
- } //-- setDeclaringClassInfo
-
- /**
- * Sets the default value for this FieldInfo.
- * @param defaultValue the default value
- */
- public final void setDefaultValue(final String defaultValue) {
- this._default = defaultValue;
- } //-- setDefaultValue;
-
- /**
- * Sets the "final" status of this FieldInfo. Final members are also
- * transient.
- *
- * @param isFinal
- * the boolean indicating the final status, if true this
- * FieldInfo will be treated as final.
- */
- public final void setFinal(final boolean isFinal) {
- this._final = isFinal;
- } //-- isFinal
-
- /**
- * Sets the fixed value in which instances of this field type must lexically
- * match. NOTE: This is not the same as default value!
- *
- * @param fixedValue
- * the fixed production for this FieldInfo
- */
- public final void setFixedValue(final String fixedValue) {
- this._fixed = fixedValue;
- } //-- setFixedValue
-
- /**
* Sets which methods to create: READ_METHOD, WRITE_METHOD,
* READ_WRITE_METHODS.
- *
- * @param methods a flag describing which methods to create.
+ *
+ * @param methods
+ * a flag describing which methods to create.
*/
- public final void setMethods(final int methods) {
- _methods = methods;
- } //-- setMethods
+ void setMethods(final int methods); // -- setMethods
/**
- * Sets whether or not this field can be nillable.
- *
- * @param nillable
- * a boolean that when true means the field may be nil.
- * @see #isNillable()
- */
- public final void setNillable(final boolean nillable) {
- _nillable = nillable;
- } //-- setNillable
-
- /**
* Sets the name of the field within the same class that is a reference to
* this field.
- *
+ *
* @param fieldInfo
*/
- public final void setFieldInfoReference(final FieldInfo fieldInfo) {
- _fieldInfoReference = fieldInfo;
- } //-- setReference
+ void setFieldInfoReference(final FieldInfo fieldInfo); // -- setReference
/**
- * Sets the "static" status of this FieldInfo. Static members are also
- * transient.
- *
- * @param isStatic the boolean indicating the static status, if true this
- * FieldInfo will be treated as static
- */
- public final void setStatic(final boolean isStatic) {
- this._static = isStatic;
- } //-- setStatic
-
- /**
- * Sets the transient status of this FieldInfo.
- *
- * @param isTransient the boolean indicating the transient status, if true this
- * FieldInfo will be treated as transient
- */
- public final void setTransient(final boolean isTransient) {
- this._transient = isTransient;
- } //-- setTransient
-
- /**
* Sets the name of the Validator to use.
- *
- * @param validator the fully qualified name of the validator to use.
+ *
+ * @param validator
+ * the fully qualified name of the validator to use.
*/
- public final void setValidator(final String validator) {
- _validator = validator;
- }
+ void setValidator(final String validator);
/**
- * Sets the name of the XMLfieldHandler to use.
- *
- * @param handler the fully qualified name of the handler to use.
- */
- public final void setXMLFieldHandler(final String handler) {
- _fieldHandler = handler;
- }
-
- /**
* Returns the method suffix for creating method names.
- *
+ *
* @return the method suffix used when creating method names.
*/
- public String getMethodSuffix() {
- if (_name.startsWith("_")) {
- return _memberAndAccessorFactory.getJavaNaming().toJavaClassName(_name.substring(1));
- }
- return _memberAndAccessorFactory.getJavaNaming().toJavaClassName(_name);
- }
+ String getMethodSuffix();
/**
- * Sets the visibility of this FieldInfo.
- *
- * @param visibility the visibility of this FieldInfo.
- */
- public final void setVisibility(final String visibility) {
- _visibility = visibility;
- }
-
- /**
* Sets the possible substitution groups for this class.
- * @param substitutionGroupMembers Possible substitution groups for this class.
+ *
+ * @param substitutionGroupMembers
+ * Possible substitution groups for this class.
*/
- public void setSubstitutionGroupMembers(final List substitutionGroupMembers) {
- this._substitutionGroupMembers = substitutionGroupMembers;
- }
+ void setSubstitutionGroupMembers(final List substitutionGroupMembers);
- /**
- * Returns the possible substitution groups for this class.
- * @return the possible substitution groups for this class.
- */
- public List getSubstitutionGroupMembers() {
- return this._substitutionGroupMembers;
- }
-
- public boolean isStatic() {
- return _static;
- }
+ FieldInfo getFieldInfoReference();
- public boolean isFinal() {
- return _final;
- }
-
- public Object getVisibility() {
- return _visibility;
- }
-
- public FieldInfo getFieldInfoReference() {
- return _fieldInfoReference;
- }
-
-
-
-
-
-
-
-}
+}
\ No newline at end of file
Index: codegen/src/main/java/org/exolab/castor/builder/info/JDOFieldNature.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/JDOFieldNature.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/JDOFieldNature.java (revision 0)
@@ -0,0 +1,89 @@
+/**
+ *
+ */
+package org.exolab.castor.builder.info;
+
+import org.exolab.castor.builder.info.nature.Nature;
+import org.exolab.castor.builder.info.nature.NatureExtendable;
+import org.exolab.castor.builder.info.nature.ValidationException;
+
+/**
+ * @author Sebastian Gabmeyer
+ *
+ */
+public class JDOFieldNature implements Nature {
+
+ private NatureExtendable _fieldInfo;
+ private static final String _id = "JDO";
+
+ public JDOFieldNature(NatureExtendable info) {
+ _fieldInfo = info;
+ }
+
+ /**
+ * @return
+ * @see org.exolab.castor.builder.info.nature.Nature#getId()
+ */
+ public String getId() {
+ return _id ;
+ }
+
+ /**
+ * @return
+ * @see org.exolab.castor.builder.info.nature.Nature#getPropertyHolder()
+ */
+ public NatureExtendable getPropertyHolder() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * @param holder
+ * @see org.exolab.castor.builder.info.nature.Nature#setPropertyHolder(org.exolab.castor.builder.info.nature.PropertyHolder)
+ */
+ public void setPropertyHolder(NatureExtendable holder) {
+ _fieldInfo = holder;
+
+ }
+
+ /**
+ * @throws ValidationException
+ * @see org.exolab.castor.builder.info.nature.Nature#validate()
+ */
+ public void validate() throws ValidationException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public String getColumnName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ public void addColumn(String columnName, String columnType,
+ boolean acceptNulls, boolean isReadOnly) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private class Column {
+
+ }
+
+ public String getColumnType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isColumnNullable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isColumnReadOnly() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
Index: codegen/src/main/java/org/exolab/castor/builder/info/IdentityInfo.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/IdentityInfo.java (revision 7626)
+++ codegen/src/main/java/org/exolab/castor/builder/info/IdentityInfo.java (working copy)
@@ -51,7 +51,7 @@
* @author Keith Visco
* @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $
*/
-public final class IdentityInfo extends FieldInfo {
+public final class IdentityInfo extends BaseFieldInfo {
/**
* Creates a new IdentityInfo.
Index: codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfo.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfo.java (revision 7626)
+++ codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfo.java (working copy)
@@ -61,7 +61,7 @@
* @author Keith Visco
* @version $Revision$ $Date: 2006-02-23 01:08:24 -0700 (Thu, 23 Feb 2006) $
*/
-public class CollectionInfo extends FieldInfo {
+public class CollectionInfo extends BaseFieldInfo {
/** Default suffix for the setter/getter by reference method names. */
public static final String DEFAULT_REFERENCE_SUFFIX = "AsReference";
@@ -124,7 +124,7 @@
this.getElementName());
this._parameterPrefix = memberAndAccessorFactory.getJavaNaming().toJavaMemberName(
this.getElementName());
- this._content = new FieldInfo(contentType, "v" + this.getMethodSuffix(),
+ this._content = new BaseFieldInfo(contentType, "v" + this.getMethodSuffix(),
contentMemberAndAccessorFactory);
} // -- CollectionInfo
@@ -215,7 +215,7 @@
/**
* {@inheritDoc}
*
- * @see org.exolab.castor.builder.info.FieldInfo#getMethodSuffix()
+ * @see org.exolab.castor.builder.info.BaseFieldInfo#getMethodSuffix()
*/
public final String getMethodSuffix() {
return this._methodSuffix;
Index: codegen/src/main/java/org/exolab/castor/builder/info/BaseClassInfo.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/BaseClassInfo.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/BaseClassInfo.java (revision 0)
@@ -0,0 +1,472 @@
+/*
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "Exolab" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Intalio, Inc. For written permission,
+ * please contact info@exolab.org.
+ *
+ * 4. Products derived from this Software may not be called "Exolab"
+ * nor may "Exolab" appear in their names without prior written
+ * permission of Intalio, Inc. Exolab is a registered
+ * trademark of Intalio, Inc.
+ *
+ * 5. Due credit should be given to the Exolab Project
+ * (http://www.exolab.org/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
+ *
+ * This file was originally developed by Keith Visco during the course
+ * of employment at Intalio Inc.
+ * All portions of this file developed by Keith Visco after Jan 19 2005
+ * are Copyright (C) 2005 Keith Visco. All Rights Reserverd.
+ *
+ * $Id: ClassInfo.java 6889 2007-03-07 10:54:08Z wguttmn $
+ */
+package org.exolab.castor.builder.info;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import org.exolab.javasource.JClass;
+
+/**
+ * This class holds the necessary information so that the source generator can
+ * properly create the necessary classes for the object model.
+ *
+ * @author Keith Visco
+ * @version $Revision: 6889 $ $Date: 2006-04-13 07:37:49 -0600 (Thu, 13 Apr 2006) $
+ */
+public final class BaseClassInfo extends XMLInfo implements ClassInfo {
+ /** Vector of FieldInfo's for all attributes that are members of this Class. */
+ private Vector _atts = new Vector();
+ /** Vector of FieldInfo's for all elements that are members of this Class. */
+ private Vector _elements = new Vector();
+ /** if this ClassInfo represents a TextField, this is this TextField's FieldInfo. */
+ private FieldInfo _textField = null;
+ /** The base class. */
+ private ClassInfo _baseClass = null;
+ /** A reference to the JClass that this ClassInfo describes. */
+ private JClass _class = null;
+ /** The group information for this ClassInfo. */
+ private GroupInfo _groupInfo = null;
+ /**
+ * true if this ClassInfo describes a container class. That is, a class
+ * which should not be marshalled as XML, but whose members should be.
+ */
+ private boolean _isContainer = false;
+ /** true if this ClassInfo represents an abstract class. */
+ private boolean _abstract = false;
+
+ /**
+ * Holds the possible substitution groups for this class.
+ */
+ private List _substitutionGroups = new LinkedList();
+
+ /**
+ * Creates a new ClassInfo.
+ * @param jClass the JClass which this ClassInfo describes
+ */
+ public BaseClassInfo(final JClass jClass) {
+ super(XMLInfo.ELEMENT_TYPE);
+ if (jClass == null) {
+ String err = "JClass passed to constructor of ClassInfo must not be null.";
+ throw new IllegalArgumentException(err);
+ }
+ this._class = jClass;
+
+ _groupInfo = new GroupInfo();
+ } //-- ClassInfo
+
+ //------------------/
+ //- Public Methods -/
+ //------------------/
+
+ /**
+ * Adds the given FieldInfo to this ClassInfo.
+ *
+ * @param fieldInfo the FieldInfo to add
+ */
+ public void addFieldInfo(final FieldInfo fieldInfo) {
+ if (fieldInfo == null) {
+ return;
+ }
+
+ fieldInfo.setDeclaringClassInfo(this);
+
+ switch(fieldInfo.getNodeType()) {
+ case XMLInfo.ATTRIBUTE_TYPE:
+ if (!_atts.contains(fieldInfo)) {
+ _atts.addElement(fieldInfo);
+ }
+ break;
+ case XMLInfo.TEXT_TYPE:
+ _textField = fieldInfo;
+ break;
+ default:
+ if (!_elements.contains(fieldInfo)) {
+ _elements.addElement(fieldInfo);
+ }
+ break;
+ }
+ } //-- addFieldInfo
+
+ /**
+ * Adds the given set of FieldInfos to this ClassInfo.
+ *
+ * @param fields an Array of FieldInfo objects
+ */
+ public void addFieldInfo(final FieldInfo[] fields) {
+ for (int i = 0; i < fields.length; i++) {
+ addFieldInfo(fields[i]);
+ }
+ } //-- addFieldInfo
+
+ /**
+ * @return true if Classes created with this ClassInfo allow content
+ */
+ public boolean allowContent() {
+ return _textField != null;
+ } //-- allowsTextContent
+
+ /**
+ * Returns true if the given FieldInfo is contained within this ClassInfo.
+ *
+ * @param fieldInfo
+ * the FieldInfo to check
+ * @return true if the given FieldInfo is contained within this ClassInfo
+ */
+ public boolean contains(final FieldInfo fieldInfo) {
+ if (fieldInfo == null) {
+ return false;
+ }
+
+ switch (fieldInfo.getNodeType()) {
+ case XMLInfo.ATTRIBUTE_TYPE:
+ if (_atts != null) {
+ return _atts.contains(fieldInfo);
+ }
+ break;
+ case XMLInfo.TEXT_TYPE:
+ return (fieldInfo == _textField);
+ default:
+ if (_elements != null) {
+ return _elements.contains(fieldInfo);
+ }
+ break;
+ }
+
+ //if (sourceInfo != null)
+ // return sourceInfo.contains(fieldInfo);
+
+ return false;
+ } //-- contains
+
+ /**
+ * Returns an array of XML attribute associated fields.
+ * @return an array of XML attribute associated fields.
+ */
+ public FieldInfo[] getAttributeFields() {
+ FieldInfo[] fields = null;
+ if (_atts != null) {
+ fields = new FieldInfo[_atts.size()];
+ _atts.copyInto(fields);
+ } else {
+ fields = new FieldInfo[0];
+ }
+ return fields;
+ } //-- getAttributeFields
+
+ /**
+ * Returns a fieldInfo that corresponds to an attribute with the given node name.
+ * A ClassInfo cannot have 2 attributes with the same xml name.
+ *
+ * @param nodeName the NodeName of the field to get.
+ * @return a fieldInfo that corresponds to an attribute with the given node name.
+ */
+ public FieldInfo getAttributeField(final String nodeName) {
+ if (_atts == null) {
+ return null;
+ }
+
+ for (int i = 0; i < _atts.size(); i++) {
+ FieldInfo temp = (FieldInfo) _atts.get(i);
+ if (temp.getNodeName().equals(nodeName)) {
+ return temp;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the base class of this classInfo if any. A classInfo can indeed
+ * extend another classInfo to reflect the extension mechanism used in the
+ * XML Schema.
+ *
+ * @return the base class of this classInfo if any.
+ */
+ public ClassInfo getBaseClass() {
+ return _baseClass;
+ }
+
+ /**
+ * Returns an array of XML element associated fields.
+ *
+ * @return an array of XML element associated fields.
+ */
+ public FieldInfo[] getElementFields() {
+ FieldInfo[] members = null;
+ if (_elements != null) {
+ members = new FieldInfo[_elements.size()];
+ _elements.copyInto(members);
+ } else {
+ members = new FieldInfo[0];
+ }
+ return members;
+ } //-- getElementFields
+
+ /**
+ * Returns a fieldInfo that corresponds to an element with the given node name.
+ * A ClassInfo cannot have 2 elements with the same xml name.
+ *
+ * @param nodeName the NodeName of the field to get.
+ * @return a fieldInfo that corresponds to an element with the given node name.
+ */
+ public FieldInfo getElementField(final String nodeName) {
+ if (_elements != null) {
+ for (int i = 0; i < _elements.size(); i++) {
+ FieldInfo temp = (FieldInfo) _elements.get(i);
+ String elementNodeName = temp.getNodeName();
+ if (elementNodeName != null && elementNodeName.equals(nodeName)) {
+ return temp;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the number of FieldInfo definitions for this ClassInfo.
+ *
+ * @return the number of FieldInfo definitions for this ClassInfo.
+ */
+ public int getFieldCount() {
+ int count = 0;
+ if (_atts != null) {
+ count += _atts.size();
+ }
+ if (_elements != null) {
+ count += _elements.size();
+ }
+ if (_textField != null) {
+ ++count;
+ }
+ return count;
+ } //-- getFieldCount
+
+ /**
+ * Returns the GroupInfo for this ClassInfo.
+ *
+ * @return the GroupInfo for this ClassInfo
+ */
+ public GroupInfo getGroupInfo() {
+ return _groupInfo;
+ } //-- getGroupInfo
+
+ /**
+ * Returns the JClass described by this ClassInfo.
+ *
+ * @return the JClass which is described by this ClassInfo
+ */
+ public JClass getJClass() {
+ return _class;
+ } //-- getJClass
+
+ /**
+ * Returns the FieldInfo for the XML text associated field.
+ *
+ * @return the FieldInfo for the text content associated field, this may be
+ * null.
+ */
+ public FieldInfo getTextField() {
+ return _textField;
+ } //-- getTextField
+
+ /**
+ * Returns true if the JClass represented by this ClassInfo is abstract.
+ *
+ * @return true if the JClass represented by this ClassInfo is abstract
+ */
+ public boolean isAbstract() {
+ return _abstract;
+ }
+
+ /**
+ * Returns true if the compositor of this GroupInfo is a choice.
+ *
+ * @return true if the compositor of this GroupInfo is a choice
+ */
+ public boolean isChoice() {
+ return _groupInfo.isChoice();
+ } //-- isChoice
+
+ /**
+ * Returns true if this ClassInfo describes a container class. A container
+ * class is a class which should not be marshalled as XML, but whose members
+ * should be.
+ *
+ * @return true if this ClassInfo describes a container class.
+ */
+ public boolean isContainer() {
+ return _isContainer;
+ } //-- isContainer
+
+ /**
+ * Returns true if the compositor of this GroupInfo is a sequence.
+ *
+ * @return true if the compositor of this GroupInfo is a sequence
+ */
+ public boolean isSequence() {
+ return _groupInfo.isSequence();
+ } //-- isSequence
+
+ /**
+ * Sets the class of this ClassInfo to be abstract of
+ *
+ * abstractClass is true, false otherwise.
+ *
+ * @param abstractClass true if the class represented by this ClassInfo is
+ * abstract
+ */
+ public void setAbstract(final boolean abstractClass) {
+ _abstract = abstractClass;
+ }
+
+ /**
+ * Sets the base class of this classInfo. A classInfo can indeed extend
+ * another classInfo to reflect the extension mechanism used in the XML
+ * Schema
+ *
+ * @param base the base class of this classInfo.
+ */
+ public void setBaseClass(final ClassInfo base) {
+ _baseClass = base;
+ }
+
+ /**
+ * Sets whether or not this ClassInfo describes a container class. A
+ * container class is a class which should not be marshalled as XML, but
+ * whose members should be. By default this is false.
+ *
+ * @param isContainer the boolean value when true indicates this class
+ * should be a container class.
+ */
+ public void setContainer(final boolean isContainer) {
+ _isContainer = isContainer;
+ } //-- setContainer
+
+ /**
+ * Returns the possible substitution groups for this class.
+ * @return the possible substitution groups for this class.
+ */
+ public List getSubstitutionGroups() {
+ return _substitutionGroups;
+ }
+
+ /**
+ * Sets the possible substitution groups for this class.
+ * @param substitutionGroups Possible substitution groups for this class.
+ */
+ public void setSubstitutionGroups(final List substitutionGroups) {
+ _substitutionGroups = substitutionGroups;
+ }
+
+ /**
+ *
+ *
+ * New ClassInfo/nature part.
+ *
+ *
+ */
+
+ /**
+ * a HashMap containing the properties for all Natures.
+ */
+ private Map _properties = new HashMap();
+
+ /**
+ * a list of natures available for this class.
+ */
+ private List _natures = new ArrayList();
+
+ /**
+ * Add support for the specified nature to this ClassInfo.
+ *
+ * @param nature the name of the nature
+ */
+ public void addNature(final String nature) {
+ if (!_natures.contains(nature)) {
+ _natures.add(nature);
+ }
+ }
+ /**
+ * @param nature the name of the nature
+ * @return true if the specified nature is contained
+ */
+ public boolean hasNature(final String nature) {
+ return _natures.contains(nature);
+ }
+
+ /**
+ * @param name the name of the property.
+ * @return the value of the specified property.
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#getNatureProperty(java.lang.String)
+ */
+ public Object getNatureProperty(final String name) {
+ return _properties.get(name);
+ }
+
+ /**
+ * Set a property identified by its name to the passed value.
+ *
+ * @param name
+ * the name of the property to set.
+ * @param value
+ * the value of the property to set.
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#setNatureProperty(java.lang.String,
+ * java.lang.Object)
+ */
+ public void setNatureProperty(final String name, final Object value) {
+ _properties.put(name, value);
+ }
+
+} //-- ClassInfo
Index: codegen/src/main/java/org/exolab/castor/builder/info/nature/Nature2.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/nature/Nature2.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/nature/Nature2.java (revision 0)
@@ -0,0 +1,72 @@
+/**
+ *
+ */
+package org.exolab.castor.builder.info.nature;
+
+import org.exolab.castor.builder.info.ClassInfo;
+
+/**
+ * A Nature defines a way to extend ClassInfo and FieldInfo classes by custom
+ * properties. These properties are stored in a class implementing the
+ * {@link ClassInfo} interface. Note the only difference between {@link Nature}
+ * and Nature2 is the use of the {@link ClassInfo} interface as
+ * PropertyHolder instead of the {@link PropertyHolder} interface
+ * itself.
+ *
+ * @author Sebastian Gabmeyer
+ *
+ */
+public interface Nature2 {
+ /**
+ * Get the unique identifier of the Nature.
+ *
+ * @return the unique identifier of the Nature
+ */
+ String getId();
+
+ /**
+ * Get the {@link ClassInfo} which stores all Nature-specific
+ * properties.
+ *
+ * As an example for a reference implementation of a Nature see
+ * {@link org.exolab.castor.builder.info.JDOClassNature.JDOClassNature}.
+ *
+ * As an example for a reference implementation of a
+ * NatureExtendable and PropertyHolder class
+ * see {@link org.exolab.castor.builder.info.BaseClassInfo2}.
+ *
+ * @return the PropertyHolder of the Nature
+ * @see ClassInfo
+ * @see NatureExtendable
+ * @see org.exolab.castor.builder.info.JDOClassNature
+ */
+ ClassInfo getPropertyHolder();
+
+ /**
+ * Set the {@link ClassInfo} which stores all Nature-specific
+ * properties.
+ *
+ * As an example for a reference implementation of a Nature see
+ * {@link org.exolab.castor.builder.info.JDOClassNature}.
+ *
+ * As an example for a reference implementation of a
+ * NatureExtendable and PropertyHolder class
+ * see {@link org.exolab.castor.builder.info.BaseClassInfo2}.
+ *
+ * @param classInfo
+ * the ClassInfo to set.
+ * @see ClassInfo
+ * @see NatureExtendable
+ * @see org.exolab.castor.builder.info.JDOClassNature
+ * @see org.exolab.castor.builder.info.BaseClassInfo2
+ */
+ void setPropertyHolder(ClassInfo classInfo);
+
+ /**
+ * Checks if the Nature's properties are consistent and conform to the
+ * specified integrity.
+ *
+ * @throws ValidationException if the Nature's integrity/consistency is violated.
+ */
+ void validate() throws ValidationException;
+}
Index: codegen/src/main/java/org/exolab/castor/builder/info/nature/PropertyHolder.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/nature/PropertyHolder.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/nature/PropertyHolder.java (revision 0)
@@ -0,0 +1,29 @@
+/**
+ *
+ */
+package org.exolab.castor.builder.info.nature;
+
+/**
+ *
+ * @see ClassInfo
+ * @see Nature
+ *
+ * @author Sebastian Gabmeyer
+ *
+ */
+public interface PropertyHolder {
+ /**
+ * Get a nature property by its name.
+ *
+ * @param name the name of the property to get.
+ * @return the property as specified by the name.
+ */
+ Object getNatureProperty(final String name);
+ /**
+ * Set a nature property specified by the name to the passed value.
+ *
+ * @param name the name of the property to set.
+ * @param value the value to set the specified property to.
+ */
+ void setNatureProperty(final String name, final Object value);
+}
Index: codegen/src/main/java/org/exolab/castor/builder/info/nature/NatureNotSupportedException.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/nature/NatureNotSupportedException.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/nature/NatureNotSupportedException.java (revision 0)
@@ -0,0 +1,44 @@
+/**
+ *
+ */
+package org.exolab.castor.builder.info.nature;
+
+/**
+ * @author Sebastian Gabmeyer
+ *
+ */
+public class NatureNotSupportedException extends Exception {
+
+ /**
+ *
+ */
+ public NatureNotSupportedException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ */
+ public NatureNotSupportedException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param cause
+ */
+ public NatureNotSupportedException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public NatureNotSupportedException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Index: codegen/src/main/java/org/exolab/castor/builder/info/nature/ValidationException.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/nature/ValidationException.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/nature/ValidationException.java (revision 0)
@@ -0,0 +1,46 @@
+/**
+ *
+ */
+package org.exolab.castor.builder.info.nature;
+
+/**
+ *
+ *
+ * @author Sebastian Gabmeyer
+ *
+ */
+public class ValidationException extends Exception {
+
+ /**
+ *
+ */
+ public ValidationException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ */
+ public ValidationException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param cause
+ */
+ public ValidationException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public ValidationException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Index: codegen/src/main/java/org/exolab/castor/builder/info/nature/NatureExtendable.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/nature/NatureExtendable.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/nature/NatureExtendable.java (revision 0)
@@ -0,0 +1,28 @@
+/**
+ *
+ */
+package org.exolab.castor.builder.info.nature;
+
+/**
+ * @see ClassInfo
+ * @see Nature
+ *
+ * @author Tobias Hochwallner, Sebastian Gabmeyer
+ *
+ */
+public interface NatureExtendable extends PropertyHolder {
+ /**
+ * Checks if a specified nature has been added.
+ *
+ * @param nature the name of the nature.
+ * @return true if the specified nature was added.
+ */
+ boolean hasNature(String nature);
+ /**
+ * Adds a specified nature.
+ *
+ * @param nature the name of the nature
+ */
+ void addNature(String nature);
+
+}
Index: codegen/src/main/java/org/exolab/castor/builder/info/nature/Nature.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/nature/Nature.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/nature/Nature.java (revision 0)
@@ -0,0 +1,68 @@
+package org.exolab.castor.builder.info.nature;
+
+/**
+ * A Nature defines a way to extend ClassInfo and FieldInfo classes by custom
+ * properties. These properties are stored in a class implementing the
+ * {@link PropertyHolder} interface. This class should also implement the
+ * {@link NatureExtendable} interface.
+ *
+ * @author Tobias Hochwallner, Sebastian Gabmeyer
+ *
+ */
+public interface Nature {
+
+ /**
+ * Get the unique identifier of the Nature.
+ *
+ * @return the unique identifier of the Nature
+ */
+ String getId();
+
+ /**
+ * Get the {@link PropertyHolder} which stores all Nature-specific
+ * properties of a (recommended, but not necessarily)
+ * {@link NatureExtendable} class.
+ *
+ * As an example for a reference implementation of a Nature see
+ * {@link org.exolab.castor.builder.info.JDOClassNature.JDOClassNature}.
+ *
+ * As an example for a reference implementation of a
+ * NatureExtendable and PropertyHolder class
+ * see {@link org.exolab.castor.builder.info.BaseClassInfo2}.
+ *
+ * @return the PropertyHolder of the Nature
+ * @see PropertyHolder
+ * @see NatureExtendable
+ * @see org.exolab.castor.builder.info.JDOClassNature
+ */
+ NatureExtendable getPropertyHolder();
+
+ /**
+ * Set the {@link PropertyHolder} which stores all Nature-specific
+ * properties of a (recommended, but not necessarily)
+ * {@link NatureExtendable} class.
+ *
+ * As an example for a reference implementation of a Nature see
+ * {@link org.exolab.castor.builder.info.JDOClassNature}.
+ *
+ * As an example for a reference implementation of a
+ * NatureExtendable and PropertyHolder class
+ * see {@link org.exolab.castor.builder.info.BaseClassInfo2}.
+ *
+ * @param holder
+ * the PropertyHolder to set.
+ * @see PropertyHolder
+ * @see NatureExtendable
+ * @see org.exolab.castor.builder.info.JDOClassNature
+ * @see org.exolab.castor.builder.info.BaseClassInfo2
+ */
+ void setPropertyHolder(NatureExtendable holder);
+
+ /**
+ * Checks if the Nature's properties are consistent and conform to the
+ * specified integrity.
+ *
+ * @throws ValidationException if the Nature's integrity/consistency is violated.
+ */
+ void validate() throws ValidationException;
+}
Index: codegen/src/main/java/org/exolab/castor/builder/info/ClassInfo.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/ClassInfo.java (revision 7626)
+++ codegen/src/main/java/org/exolab/castor/builder/info/ClassInfo.java (working copy)
@@ -1,158 +1,37 @@
-/*
- * Redistribution and use of this software and associated documentation
- * ("Software"), with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * 1. Redistributions of source code must retain copyright
- * statements and notices. Redistributions must also contain a
- * copy of this document.
- *
- * 2. Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and the
- * following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * 3. The name "Exolab" must not be used to endorse or promote
- * products derived from this Software without prior written
- * permission of Intalio, Inc. For written permission,
- * please contact info@exolab.org.
- *
- * 4. Products derived from this Software may not be called "Exolab"
- * nor may "Exolab" appear in their names without prior written
- * permission of Intalio, Inc. Exolab is a registered
- * trademark of Intalio, Inc.
- *
- * 5. Due credit should be given to the Exolab Project
- * (http://www.exolab.org/).
- *
- * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
- *
- * This file was originally developed by Keith Visco during the course
- * of employment at Intalio Inc.
- * All portions of this file developed by Keith Visco after Jan 19 2005
- * are Copyright (C) 2005 Keith Visco. All Rights Reserverd.
- *
- * $Id$
- */
package org.exolab.castor.builder.info;
-import java.util.LinkedList;
import java.util.List;
-import java.util.Vector;
+import org.exolab.castor.builder.info.nature.NatureExtendable;
import org.exolab.javasource.JClass;
+
/**
- * This class holds the necessary information so that the source generator can
- * properly create the necessary classes for the object model.
+ *
+ *
+ * @author Sebastian Gabmeyer
*
- * @author Keith Visco
- * @version $Revision$ $Date: 2006-04-13 07:37:49 -0600 (Thu, 13 Apr 2006) $
*/
-public final class ClassInfo extends XMLInfo {
- /** Vector of FieldInfo's for all attributes that are members of this Class. */
- private Vector _atts = new Vector();
- /** Vector of FieldInfo's for all elements that are members of this Class. */
- private Vector _elements = new Vector();
- /** if this ClassInfo represents a TextField, this is this TextField's FieldInfo. */
- private FieldInfo _textField = null;
- /** The base class. */
- private ClassInfo _baseClass = null;
- /** A reference to the JClass that this ClassInfo describes. */
- private JClass _class = null;
- /** The group information for this ClassInfo. */
- private GroupInfo _groupInfo = null;
- /**
- * true if this ClassInfo describes a container class. That is, a class
- * which should not be marshalled as XML, but whose members should be.
- */
- private boolean _isContainer = false;
- /** true if this ClassInfo represents an abstract class. */
- private boolean _abstract = false;
+public interface ClassInfo extends NatureExtendable {
/**
- * Holds the possible substitution groups for this class.
- */
- private List _substitutionGroups = new LinkedList();
-
- /**
- * Creates a new ClassInfo.
- * @param jClass the JClass which this ClassInfo describes
- */
- public ClassInfo(final JClass jClass) {
- super(XMLInfo.ELEMENT_TYPE);
- if (jClass == null) {
- String err = "JClass passed to constructor of ClassInfo must not be null.";
- throw new IllegalArgumentException(err);
- }
- this._class = jClass;
-
- _groupInfo = new GroupInfo();
- } //-- ClassInfo
-
- //------------------/
- //- Public Methods -/
- //------------------/
-
- /**
* Adds the given FieldInfo to this ClassInfo.
*
* @param fieldInfo the FieldInfo to add
*/
- public void addFieldInfo(final FieldInfo fieldInfo) {
- if (fieldInfo == null) {
- return;
- }
+ void addFieldInfo(final FieldInfo fieldInfo); //-- addFieldInfo
- fieldInfo.setDeclaringClassInfo(this);
-
- switch(fieldInfo.getNodeType()) {
- case XMLInfo.ATTRIBUTE_TYPE:
- if (!_atts.contains(fieldInfo)) {
- _atts.addElement(fieldInfo);
- }
- break;
- case XMLInfo.TEXT_TYPE:
- _textField = fieldInfo;
- break;
- default:
- if (!_elements.contains(fieldInfo)) {
- _elements.addElement(fieldInfo);
- }
- break;
- }
- } //-- addFieldInfo
-
/**
* Adds the given set of FieldInfos to this ClassInfo.
*
* @param fields an Array of FieldInfo objects
*/
- public void addFieldInfo(final FieldInfo[] fields) {
- for (int i = 0; i < fields.length; i++) {
- addFieldInfo(fields[i]);
- }
- } //-- addFieldInfo
+ void addFieldInfo(final FieldInfo[] fields); //-- addFieldInfo
/**
* @return true if Classes created with this ClassInfo allow content
*/
- public boolean allowContent() {
- return _textField != null;
- } //-- allowsTextContent
+ boolean allowContent(); //-- allowsTextContent
/**
* Returns true if the given FieldInfo is contained within this ClassInfo.
@@ -161,46 +40,13 @@
* the FieldInfo to check
* @return true if the given FieldInfo is contained within this ClassInfo
*/
- public boolean contains(final FieldInfo fieldInfo) {
- if (fieldInfo == null) {
- return false;
- }
+ boolean contains(final FieldInfo fieldInfo); //-- contains
- switch (fieldInfo.getNodeType()) {
- case XMLInfo.ATTRIBUTE_TYPE:
- if (_atts != null) {
- return _atts.contains(fieldInfo);
- }
- break;
- case XMLInfo.TEXT_TYPE:
- return (fieldInfo == _textField);
- default:
- if (_elements != null) {
- return _elements.contains(fieldInfo);
- }
- break;
- }
-
- //if (sourceInfo != null)
- // return sourceInfo.contains(fieldInfo);
-
- return false;
- } //-- contains
-
/**
* Returns an array of XML attribute associated fields.
* @return an array of XML attribute associated fields.
*/
- public FieldInfo[] getAttributeFields() {
- FieldInfo[] fields = null;
- if (_atts != null) {
- fields = new FieldInfo[_atts.size()];
- _atts.copyInto(fields);
- } else {
- fields = new FieldInfo[0];
- }
- return fields;
- } //-- getAttributeFields
+ FieldInfo[] getAttributeFields(); //-- getAttributeFields
/**
* Returns a fieldInfo that corresponds to an attribute with the given node name.
@@ -209,21 +55,8 @@
* @param nodeName the NodeName of the field to get.
* @return a fieldInfo that corresponds to an attribute with the given node name.
*/
- public FieldInfo getAttributeField(final String nodeName) {
- if (_atts == null) {
- return null;
- }
+ FieldInfo getAttributeField(final String nodeName);
- for (int i = 0; i < _atts.size(); i++) {
- FieldInfo temp = (FieldInfo) _atts.get(i);
- if (temp.getNodeName().equals(nodeName)) {
- return temp;
- }
- }
-
- return null;
- }
-
/**
* Returns the base class of this classInfo if any. A classInfo can indeed
* extend another classInfo to reflect the extension mechanism used in the
@@ -231,25 +64,14 @@
*
* @return the base class of this classInfo if any.
*/
- public ClassInfo getBaseClass() {
- return _baseClass;
- }
+ ClassInfo getBaseClass();
/**
* Returns an array of XML element associated fields.
*
* @return an array of XML element associated fields.
*/
- public FieldInfo[] getElementFields() {
- FieldInfo[] members = null;
- if (_elements != null) {
- members = new FieldInfo[_elements.size()];
- _elements.copyInto(members);
- } else {
- members = new FieldInfo[0];
- }
- return members;
- } //-- getElementFields
+ FieldInfo[] getElementFields(); //-- getElementFields
/**
* Returns a fieldInfo that corresponds to an element with the given node name.
@@ -258,55 +80,28 @@
* @param nodeName the NodeName of the field to get.
* @return a fieldInfo that corresponds to an element with the given node name.
*/
- public FieldInfo getElementField(final String nodeName) {
- if (_elements != null) {
- for (int i = 0; i < _elements.size(); i++) {
- FieldInfo temp = (FieldInfo) _elements.get(i);
- String elementNodeName = temp.getNodeName();
- if (elementNodeName != null && elementNodeName.equals(nodeName)) {
- return temp;
- }
- }
- }
- return null;
- }
+ FieldInfo getElementField(final String nodeName);
/**
* Returns the number of FieldInfo definitions for this ClassInfo.
*
* @return the number of FieldInfo definitions for this ClassInfo.
*/
- public int getFieldCount() {
- int count = 0;
- if (_atts != null) {
- count += _atts.size();
- }
- if (_elements != null) {
- count += _elements.size();
- }
- if (_textField != null) {
- ++count;
- }
- return count;
- } //-- getFieldCount
+ int getFieldCount(); //-- getFieldCount
/**
* Returns the GroupInfo for this ClassInfo.
*
* @return the GroupInfo for this ClassInfo
*/
- public GroupInfo getGroupInfo() {
- return _groupInfo;
- } //-- getGroupInfo
+ GroupInfo getGroupInfo(); //-- getGroupInfo
/**
* Returns the JClass described by this ClassInfo.
*
* @return the JClass which is described by this ClassInfo
*/
- public JClass getJClass() {
- return _class;
- } //-- getJClass
+ JClass getJClass(); //-- getJClass
/**
* Returns the FieldInfo for the XML text associated field.
@@ -314,27 +109,21 @@
* @return the FieldInfo for the text content associated field, this may be
* null.
*/
- public FieldInfo getTextField() {
- return _textField;
- } //-- getTextField
+ FieldInfo getTextField(); //-- getTextField
/**
* Returns true if the JClass represented by this ClassInfo is abstract.
*
* @return true if the JClass represented by this ClassInfo is abstract
*/
- public boolean isAbstract() {
- return _abstract;
- }
+ boolean isAbstract();
/**
* Returns true if the compositor of this GroupInfo is a choice.
*
* @return true if the compositor of this GroupInfo is a choice
*/
- public boolean isChoice() {
- return _groupInfo.isChoice();
- } //-- isChoice
+ boolean isChoice(); //-- isChoice
/**
* Returns true if this ClassInfo describes a container class. A container
@@ -343,18 +132,14 @@
*
* @return true if this ClassInfo describes a container class.
*/
- public boolean isContainer() {
- return _isContainer;
- } //-- isContainer
+ boolean isContainer(); //-- isContainer
/**
* Returns true if the compositor of this GroupInfo is a sequence.
*
* @return true if the compositor of this GroupInfo is a sequence
*/
- public boolean isSequence() {
- return _groupInfo.isSequence();
- } //-- isSequence
+ boolean isSequence(); //-- isSequence
/**
* Sets the class of this ClassInfo to be abstract of
@@ -364,9 +149,7 @@
* @param abstractClass true if the class represented by this ClassInfo is
* abstract
*/
- public void setAbstract(final boolean abstractClass) {
- _abstract = abstractClass;
- }
+ void setAbstract(final boolean abstractClass);
/**
* Sets the base class of this classInfo. A classInfo can indeed extend
@@ -375,9 +158,7 @@
*
* @param base the base class of this classInfo.
*/
- public void setBaseClass(final ClassInfo base) {
- _baseClass = base;
- }
+ void setBaseClass(final ClassInfo base);
/**
* Sets whether or not this ClassInfo describes a container class. A
@@ -387,24 +168,18 @@
* @param isContainer the boolean value when true indicates this class
* should be a container class.
*/
- public void setContainer(final boolean isContainer) {
- _isContainer = isContainer;
- } //-- setContainer
+ void setContainer(final boolean isContainer); //-- setContainer
/**
* Returns the possible substitution groups for this class.
* @return the possible substitution groups for this class.
*/
- public List getSubstitutionGroups() {
- return _substitutionGroups;
- }
+ List getSubstitutionGroups();
/**
* Sets the possible substitution groups for this class.
* @param substitutionGroups Possible substitution groups for this class.
*/
- public void setSubstitutionGroups(final List substitutionGroups) {
- _substitutionGroups = substitutionGroups;
- }
-
-} //-- ClassInfo
+ void setSubstitutionGroups(final List substitutionGroups);
+
+}
\ No newline at end of file
Index: codegen/src/main/java/org/exolab/castor/builder/info/JDOClassNature.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/JDOClassNature.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/JDOClassNature.java (revision 0)
@@ -0,0 +1,373 @@
+/**
+ *
+ */
+package org.exolab.castor.builder.info;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.exolab.castor.builder.info.nature.Nature;
+import org.exolab.castor.builder.info.nature.NatureExtendable;
+import org.exolab.castor.builder.info.nature.NatureNotSupportedException;
+import org.exolab.castor.builder.info.nature.ValidationException;
+
+/**
+ *
+ *
+ * @author Sebastian Gabmeyer
+ *
+ */
+public class JDOClassNature implements Nature {
+
+ /**
+ * The reference to the ClassInfo for which this Nature's instance defines a
+ * view on.
+ */
+ private NatureExtendable _classInfo;
+
+ /**
+ * The unique ID value to identify this Nature.
+ */
+ private static String _id = "JDO";
+
+ /**
+ * The prefixed property name for the name of the table.
+ */
+ private static final String TABLENAME = "jdo:tablename";
+ /**
+ * The prefixed property name for the primary keys.
+ */
+ private static final String PRIMARY_KEYS = "jdo:primaryKeys";
+ /**
+ * The prefixed property name for the key generators.
+ */
+ private static final String KEY_GENERATORS = "jdo:keyGenerators";
+
+ /**
+ * Initialize a JDONature with the specified {@link NatureExtendable}. If
+ * the classInfo doesn't have the necessary Nature support
+ * (see {@link NatureExtendable#hasNature(String)}), the support is added
+ * (see {@link NatureExtendable#addNature(String)}.
+ *
+ * @param classInfo
+ * set corresponding {@link NatureExtendable}
+ */
+ public JDOClassNature(final NatureExtendable classInfo) {
+ super();
+ _classInfo = classInfo;
+ if (!_classInfo.hasNature(_id)) {
+ _classInfo.addNature(_id);
+ }
+ }
+
+ /**
+ * Initialize an empty JDONature.
+ *
+ * @deprecated This is simply error-prone due to NullPointerExceptions!
+ */
+ public JDOClassNature() {
+ this(null);
+ }
+
+ /**
+ * Get the unique identifier of the Nature.
+ *
+ * @return the unique identifier of the Nature.
+ * @see org.exolab.castor.builder.info.nature.Nature#getId()
+ */
+ public String getId() {
+ return _id;
+ }
+
+ /**
+ * Get the name of the table.
+ *
+ * @return the table name of the table.
+ * @throws NatureNotSupportedException
+ * if the classInfo doesn't support the Nature;
+ * use {@link NatureExtendable#addNature(String)} to add support
+ * for a specific nature.
+ */
+ public String getTableName() throws NatureNotSupportedException {
+ if (!_classInfo.hasNature(_id)) {
+ throw new NatureNotSupportedException();
+ }
+ return (String) _classInfo.getNatureProperty(TABLENAME);
+ }
+
+ /**
+ * Sets the name of the table to the specified value.
+ *
+ * @param tableName
+ * specifies the name of this table.
+ * @throws NatureNotSupportedException
+ * if the classInfo doesn't support the Nature;
+ * use {@link NatureExtendable#addNature(String)} to add support
+ * for a specific nature.
+ */
+ public void setTableName(final String tableName)
+ throws NatureNotSupportedException {
+ if (!_classInfo.hasNature(_id)) {
+ throw new NatureNotSupportedException();
+ }
+ _classInfo.setNatureProperty(TABLENAME, tableName);
+ }
+
+ /**
+ * Add a new primary key constraint to the table by specifying the
+ * corresponding column name.
+ *
+ * Note that if a primary key is added twice only one entry is stored. If a
+ * KeyGenerator was specified for the first entry it will be
+ * removed by calling this method with the same columnName.
+ *
+ * @param columnName
+ * the name of the column holding a primary key.
+ * @throws NatureNotSupportedException
+ * if the classInfo doesn't support the Nature;
+ * use {@link NatureExtendable#addNature(String)} to add support
+ * for a specific nature.
+ */
+ public void addPrimaryKey(final String columnName)
+ throws NatureNotSupportedException {
+ if (!_classInfo.hasNature(_id)) {
+ throw new NatureNotSupportedException();
+ }
+ addPrimaryKey(columnName, null);
+ }
+
+ /**
+ * Add a new primary key constraint to the table by specifying the
+ * corresponding column name. By passing a generatorName a
+ * {@link org.exolab.castor.persist.spi.KeyGenerator} will be used to
+ * generate values for the primary key.
+ *
+ * Note that if a primary key is added twice only one entry is stored. This
+ * is also true for primary keys for which no KeyGenerator
+ * was specified initially; hence, the KeyGenerator is simply
+ * added to the existing primary key entry.
+ *
+ * @param columnName
+ * the name of the column holding a primary key.
+ * @param generatorName
+ * the name of the KeyGenerator.
+ * @throws NatureNotSupportedException
+ * if the classInfo doesn't support the Nature;
+ * use {@link NatureExtendable#addNature(String)} to add support
+ * for a specific nature.
+ */
+ public void addPrimaryKey(final String columnName,
+ final String generatorName) throws NatureNotSupportedException {
+ if (!_classInfo.hasNature(_id)) {
+ throw new NatureNotSupportedException();
+ }
+ Map pks = (Map) _classInfo.getNatureProperty(PRIMARY_KEYS);
+ if (pks == null) {
+ pks = new HashMap();
+ _classInfo.setNatureProperty(PRIMARY_KEYS, pks);
+ }
+ pks.put(columnName, generatorName);
+ }
+
+ /**
+ * Get the names of the primary keys associated with this table.
+ *
+ * @return the list of primary key names or null if no
+ * primary keys are associated with this table.
+ * @throws NatureNotSupportedException
+ * if the classInfo doesn't support the Nature;
+ * use {@link NatureExtendable#addNature(String)} to add support
+ * for a specific nature.
+ */
+ public String[] getPrimaryKeys() throws NatureNotSupportedException {
+ if (!_classInfo.hasNature(_id)) {
+ throw new NatureNotSupportedException();
+ }
+ Map pks = (Map) _classInfo.getNatureProperty(PRIMARY_KEYS);
+ if (pks == null) {
+ return null;
+ }
+ String[] primaryKeyNames = new String[pks.size()];
+ pks.keySet().toArray(primaryKeyNames);
+
+ return primaryKeyNames;
+ }
+
+ /**
+ * Get the name of the KeyGenerator used to produce key
+ * values for the specified primary key.
+ *
+ * @param primaryKey
+ * the key for which to get the name the of key generator.
+ * @return the name of the key generator or null if the key
+ * values are not generated.
+ * @throws NatureNotSupportedException
+ * if the classInfo doesn't support the Nature;
+ * use {@link NatureExtendable#addNature(String)} to add support
+ * for a specific nature.
+ */
+ public String getGeneratorNameFor(final String primaryKey)
+ throws NatureNotSupportedException {
+ if (!_classInfo.hasNature(_id)) {
+ throw new NatureNotSupportedException();
+ }
+ Map pks = (Map) _classInfo.getNatureProperty(PRIMARY_KEYS);
+ if (pks == null) {
+ return null;
+ }
+ return (String) pks.get(primaryKey);
+ }
+
+ /**
+ * Adds a new KeyGenerator.
+ *
+ * @param name
+ * the unique name (aka alias) of the key generator.
+ * @param generatorType
+ * the type of the key generator.
+ * @param params
+ * the list of parameters the key generator require for
+ * initialization.
+ * @throws NatureNotSupportedException
+ * if the classInfo doesn't support the Nature;
+ * use {@link NatureExtendable#addNature(String)} to add support
+ * for a specific nature.
+ */
+ public void addKeyGenerator(final String name, final String generatorType,
+ final Map params) throws NatureNotSupportedException {
+ if (!_classInfo.hasNature(_id)) {
+ throw new NatureNotSupportedException();
+ }
+ org.exolab.castor.mapping.xml.KeyGeneratorDef genDef = new org.exolab.castor.mapping.xml.KeyGeneratorDef();
+ genDef.setAlias(name);
+ genDef.setName(generatorType);
+ Iterator it = params.keySet().iterator();
+ while (it.hasNext()) {
+ org.exolab.castor.mapping.xml.Param param = new org.exolab.castor.mapping.xml.Param();
+ String paramName = (String) it.next();
+ param.setName(paramName);
+ param.setValue((String) params.get(paramName));
+ genDef.addParam(param);
+ }
+ Map keyGenerators = (Map) _classInfo.getNatureProperty(KEY_GENERATORS);
+ if (keyGenerators == null) {
+ keyGenerators = new HashMap();
+ _classInfo.setNatureProperty(KEY_GENERATORS, keyGenerators);
+ }
+ keyGenerators.put(name, genDef);
+ }
+
+ /**
+ * Get the definition of a KeyGenerator by its name.
+ *
+ * @param name
+ * the name of the KeyGenerator to get.
+ * @return the KeyGeneratorDef for the
+ * KeyGenerator specified by its name
+ * or null if no KeyGenerator with the
+ * specified name exists.
+ * @throws NatureNotSupportedException
+ * if the classInfo doesn't support the Nature;
+ * use {@link NatureExtendable#addNature(String)} to add support
+ * for a specific nature.
+ */
+ public org.exolab.castor.mapping.xml.KeyGeneratorDef getKeyGenerator(
+ final String name) throws NatureNotSupportedException {
+ if (!_classInfo.hasNature(_id)) {
+ throw new NatureNotSupportedException();
+ }
+ Map keyGenerators = (Map) _classInfo.getNatureProperty(KEY_GENERATORS);
+ if (keyGenerators == null) {
+ return null;
+ }
+ return (org.exolab.castor.mapping.xml.KeyGeneratorDef) keyGenerators
+ .get(name);
+ }
+
+ /**
+ * Get the {@link org.exolab.castor.builder.info.nature.PropertyHolder}
+ * which stores all Nature-specific properties.
+ *
+ * @return the PropertyHolder of the Nature
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable;
+ */
+ public NatureExtendable getPropertyHolder() {
+ return _classInfo;
+ }
+
+ /**
+ * Set the {@link org.exolab.castor.builder.info.nature.PropertyHolder}
+ * which stores all Nature-specific properties.
+ *
+ * @param holder
+ * the PropertyHolder to set.
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable
+ */
+ public void setPropertyHolder(final NatureExtendable holder) {
+ _classInfo = holder;
+ }
+
+ /**
+ * Checks if the Nature's properties are consistent and conform to the
+ * specified integrity.
+ *
+ * @throws ValidationException
+ * if the Nature's integrity/consistency is violated.
+ */
+ public void validate() throws ValidationException {
+ throw new ValidationException("Validation is not implemented!");
+ }
+
+ /**
+ * A class to represent a primary key.
+ *
+ * @author Sebastian Gabmeyer
+ * @deprecated
+ */
+ private final class PrimaryKey {
+ /**
+ * The name of the primary key.
+ */
+ String _name;
+
+ /**
+ * The key generator for this primary key, may be null.
+ */
+ String _keyGenerator;
+
+ /**
+ * Initializes a primary key.
+ *
+ * @param name
+ * the name of the primary key
+ * @param keyGenerator
+ * the key generator for this primary key.
+ */
+ private PrimaryKey(final String name, final String keyGenerator) {
+ _name = name;
+ _keyGenerator = keyGenerator;
+ }
+
+ /**
+ * Get the name of the primary key.
+ *
+ * @return the name of the primary key.
+ */
+ private String getName() {
+ return _name;
+ }
+
+ /**
+ * Get the key generator for this primary key.
+ *
+ * @return the name of the key generator or null if none is available.
+ */
+ private String getKeyGenerator() {
+ return _keyGenerator;
+ }
+ }
+
+}
Index: codegen/src/main/java/org/exolab/castor/builder/info/BaseFieldInfo.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/BaseFieldInfo.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/BaseFieldInfo.java (revision 0)
@@ -0,0 +1,595 @@
+/*
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ * statements and notices. Redistributions must also contain a
+ * copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. The name "Exolab" must not be used to endorse or promote
+ * products derived from this Software without prior written
+ * permission of Intalio, Inc. For written permission,
+ * please contact info@exolab.org.
+ *
+ * 4. Products derived from this Software may not be called "Exolab"
+ * nor may "Exolab" appear in their names without prior written
+ * permission of Intalio, Inc. Exolab is a registered
+ * trademark of Intalio, Inc.
+ *
+ * 5. Due credit should be given to the Exolab Project
+ * (http://www.exolab.org/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 1999-2004 (C) Intalio, Inc. All Rights Reserved.
+ *
+ * This file was originally developed by Keith Visco during the course
+ * of employment at Intalio Inc.
+ * Portions of this file developed by Keith Visco after Jan 19 2005 are
+ * Copyright (C) 2005 Keith Visco. All Rights Reserverd.
+ *
+ * $Id: FieldInfo.java 7148 2007-08-14 08:26:05Z wguttmn $
+ */
+package org.exolab.castor.builder.info;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.exolab.castor.builder.factory.FieldMemberAndAccessorFactory;
+import org.exolab.castor.builder.types.XSType;
+import org.exolab.javasource.JType;
+
+/**
+ * A class for representing field members of a Class. FieldInfo objects hold all
+ * the information required about a member in order to be able to produce
+ * marshal/unmarshal and validation code.
+ *
+ * @author Keith Visco
+ * @version $Revision: 7148 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr
+ * 2006) $
+ */
+public class BaseFieldInfo extends XMLInfo implements FieldInfo {
+
+ /** The Read / Getter method flag. */
+ public static final int READ_METHOD = 1;
+ /** The Write / Setter method flag. */
+ public static final int WRITE_METHOD = 2;
+ /** The Read and Write methods flags. */
+ public static final int READ_WRITE_METHODS = 3;
+
+ /** Method prefixes for "Add" methods. */
+ public static final String METHOD_PREFIX_ADD = "add";
+ /** Method prefixes for "Delete" methods. */
+ public static final String METHOD_PREFIX_DELETE = "delete";
+ /** Method prefixes for "Get" methods. */
+ public static final String METHOD_PREFIX_GET = "get";
+ /** Method prefixes for "Has" methods. */
+ public static final String METHOD_PREFIX_HAS = "has";
+ /** Method prefixes for "Set" methods. */
+ public static final String METHOD_PREFIX_SET = "set";
+ /** Method prefixes for "Is" methods. */
+ public static final String METHOD_PREFIX_IS = "is";
+
+ /** The Java name for Members described by this FieldInfo. */
+ private String _name = null;
+
+ private ClassInfo _declaringClassInfo = null;
+ /** JavaDoc comment. */
+ private String _comment = null;
+
+ /** The default value for this FieldInfo. */
+ private String _default = null;
+ /** The fixed production for this FieldInfo. */
+ private String _fixed = null;
+ /** A flag to indicate a final member. */
+ private boolean _final = false;
+ /** The methods flags, indicates which methods to create. */
+ private int _methods = READ_WRITE_METHODS;
+ /** A reference to the FieldInfo instance within the same class. */
+ private FieldInfo _fieldInfoReference = null;
+ /** A flag to indicate a static member. */
+ private boolean _static = false;
+ /**
+ * Flags whether or not the a MarshalDescriptor should be created for this
+ * FieldInfo.
+ */
+ private boolean _transient = false;
+ /** A flag to indicate a bound property. */
+ private boolean _bound = false;
+ /** A flag to indicate a container field. */
+ private boolean _isContainer = false;
+ /**
+ * The fully qualified name of the XMLFieldHandler (if any) to use in the
+ * generated descriptor.
+ */
+ private String _fieldHandler;
+ /** A boolean to indicate that this field represents a "nillable" field. */
+ private boolean _nillable = false;
+ /**
+ * The fully qualified name of the Validator (if any) to use in the
+ * generated descriptor.
+ */
+ private String _validator;
+ /** Visibility of this FieldInfo. */
+ private String _visibility = "private";
+
+ /** This factory creates a JField out of a FieldInfo */
+ private FieldMemberAndAccessorFactory _memberAndAccessorFactory;
+
+ /**
+ * Holds the possible substitution groups for this class.
+ */
+ private List _substitutionGroupMembers = new LinkedList();
+
+ /**
+ * Creates a new FieldInfo with the given XML Schema type and the given
+ * member name.
+ *
+ * @param type
+ * the XML Schema type of this member
+ * @param name
+ * the name of the member
+ * @param memberAndAccessorFactory
+ * the FieldMemberAndAccessorFactory to be used
+ */
+ public BaseFieldInfo(final XSType type, final String name,
+ final FieldMemberAndAccessorFactory memberAndAccessorFactory) {
+ this._name = name;
+ this._memberAndAccessorFactory = memberAndAccessorFactory;
+ setSchemaType(type);
+ } // -- FieldInfo
+
+ /**
+ * Returns the FieldMemberAndAccessorFactory instance to use to create a
+ * JField out of this FieldInfo.
+ *
+ * @return the suitable FieldMemberAndAccessorFactory
+ */
+ public FieldMemberAndAccessorFactory getMemberAndAccessorFactory() {
+ return _memberAndAccessorFactory;
+ }
+
+ /*
+ * Returns the default value for this FieldInfo.
+ *
+ * @return the default value for this FieldInfo, or null if no default value
+ * was set;
+ */
+ public final String getDefaultValue() {
+ return _default;
+ } // -- getDefaultValue
+
+ /**
+ * Returns the fixed production for this FieldInfo, or null if no fixed
+ * value has been specified.
+ *
+ * NOTE: Fixed values are NOT the same as default values
+ *
+ * @return the fixed value for this FieldInfo
+ */
+ public final String getFixedValue() {
+ return _fixed;
+ } // -- getFixedValue
+
+ /**
+ * Returns the name of the delete method for this FieldInfo.
+ *
+ * @return the name of the delete method for this FieldInfo.
+ */
+ public final String getDeleteMethodName() {
+ return METHOD_PREFIX_DELETE + getMethodSuffix();
+ } // -- getDeleteMethodName
+
+ /**
+ * Returns the name of the has method for this FieldInfo.
+ *
+ * @return the name of the has method for this FieldInfo.
+ */
+ public final String getHasMethodName() {
+ return METHOD_PREFIX_HAS + getMethodSuffix();
+ } // -- getHasMethodName
+
+ /**
+ * Returns the name of the read method for this FieldInfo.
+ *
+ * @return the name of the read method for this FieldInfo.
+ */
+ public final String getReadMethodName() {
+ return METHOD_PREFIX_GET + getMethodSuffix();
+ } // -- getReadMethodName
+
+ /**
+ * Returns the fully qualified name of the Validator to use.
+ *
+ * @return the fully qualified name of the Validator to use.
+ */
+ public final String getValidator() {
+ return _validator;
+ }
+
+ /**
+ * Returns the name of the write method for this FieldInfo.
+ *
+ * @return the name of the write method for this FieldInfo.
+ */
+ public final String getWriteMethodName() {
+ if (isMultivalued()) {
+ return METHOD_PREFIX_ADD + getMethodSuffix();
+ }
+ return METHOD_PREFIX_SET + getMethodSuffix();
+ } // -- getWriteMethodName
+
+ /**
+ * Returns the fully qualified name of the XMLFieldHandler to use.
+ *
+ * @return the fully qualified name of the XMLFieldHandler to use.
+ */
+ public final String getXMLFieldHandler() {
+ return _fieldHandler;
+ }
+
+ /**
+ * Returns the comment associated with this Member.
+ *
+ * @return the comment associated with this Member, or null. if one has not
+ * been set.
+ */
+ public final String getComment() {
+ return _comment;
+ } // -- getComment
+
+ /**
+ * Returns the methods flag that indicates which.
+ *
+ * methods will be created.
+ *
+ * @return the methods flag
+ */
+ public final int getMethods() {
+ return _methods;
+ } // -- getMethods
+
+ /**
+ * Returns the name of this FieldInfo.
+ *
+ * @return the name of this FieldInfo.
+ */
+ public final String getName() {
+ return this._name;
+ } // -- getName
+
+ /**
+ * Returns true if this FieldInfo represents a bound property.
+ *
+ * @return true if this FieldInfo represents a bound property.
+ */
+ public final boolean isBound() {
+ return _bound;
+ } // -- isBound
+
+ /**
+ * Returns true if this FieldInfo describes a container class. A container
+ * class is a class which should not be marshalled as XML, but whose members
+ * should be.
+ *
+ * @return true if this ClassInfo describes a container class.
+ */
+ public final boolean isContainer() {
+ return _isContainer;
+ } // -- isContainer
+
+ /**
+ * Returns true if the "has" and "delete" methods are needed for the field
+ * associated with this FieldInfo.
+ *
+ * @return true if the has and delete methods are needed.
+ */
+ public final boolean isHasAndDeleteMethods() {
+ XSType xsType = getSchemaType();
+ JType jType = xsType.getJType();
+ return ((!xsType.isEnumerated()) && jType.isPrimitive());
+ } // -- isHasMethod
+
+ /**
+ * Returns true if this field represents a nillable field. A nillable field
+ * is a field that can have null content (see XML Schema 1.0 definition of
+ * nillable).
+ *
+ * @return true if nillable, otherwise false.
+ * @see #setNillable(boolean)
+ */
+ public final boolean isNillable() {
+ return _nillable;
+ } // -- isNillable
+
+ /**
+ * Returns true if this FieldInfo is a transient member. Transient members
+ * are members which should be ignored by the Marshalling framework.
+ *
+ * @return true if this FieldInfo is transient.
+ */
+ public final boolean isTransient() {
+ return (_transient || _final || _static);
+ } // -- isTransient
+
+ /**
+ * Sets the comment for this Member.
+ *
+ * @param comment
+ * the comment or description for this Member
+ */
+ public final void setComment(final String comment) {
+ _comment = comment;
+ } // -- setComment
+
+ /**
+ * Returns the ClassInfo to which this Member was declared, for inheritance
+ * reasons.
+ *
+ * @return the ClassInfo to which this Member was declared.
+ */
+ public final ClassInfo getDeclaringClassInfo() {
+ return this._declaringClassInfo;
+ } // -- getDeclaringClassInfo
+
+ /**
+ * Sets whether or not this FieldInfo represents a bound property.
+ *
+ * @param bound
+ * the flag when true indicates that this FieldInfo represents a
+ * bound property.
+ */
+ public final void setBound(final boolean bound) {
+ _bound = bound;
+ } // -- setBound
+
+ /**
+ * Sets whether or not this FieldInfo describes a container field. A
+ * container field is a field which should not be marshalled directly as
+ * XML, but whose members should be. By default this is false.
+ *
+ * @param isContainer
+ * the boolean value when true indicates this class should be a
+ * container class.
+ */
+ public final void setContainer(final boolean isContainer) {
+ _isContainer = isContainer;
+ } // -- setContainer
+
+ /**
+ * @param declaringClassInfo
+ * @see org.exolab.castor.builder.info.FieldInfo#setDeclaringClassInfo(org.exolab.castor.builder.info.ClassInfo)
+ */
+ public final void setDeclaringClassInfo(final ClassInfo declaringClassInfo) {
+ this._declaringClassInfo = declaringClassInfo;
+ } // -- setDeclaringClassInfo
+
+ /**
+ * Sets the default value for this FieldInfo.
+ *
+ * @param defaultValue
+ * the default value
+ */
+ public final void setDefaultValue(final String defaultValue) {
+ this._default = defaultValue;
+ } // -- setDefaultValue;
+
+ /**
+ * Sets the "final" status of this FieldInfo. Final members are also
+ * transient.
+ *
+ * @param isFinal
+ * the boolean indicating the final status, if true this
+ * FieldInfo will be treated as final.
+ */
+ public final void setFinal(final boolean isFinal) {
+ this._final = isFinal;
+ } // -- isFinal
+
+ /**
+ * Sets the fixed value in which instances of this field type must lexically
+ * match. NOTE: This is not the same as default value!
+ *
+ * @param fixedValue
+ * the fixed production for this FieldInfo
+ */
+ public final void setFixedValue(final String fixedValue) {
+ this._fixed = fixedValue;
+ } // -- setFixedValue
+
+ /**
+ * Sets which methods to create: READ_METHOD, WRITE_METHOD,
+ * READ_WRITE_METHODS.
+ *
+ * @param methods
+ * a flag describing which methods to create.
+ */
+ public final void setMethods(final int methods) {
+ _methods = methods;
+ } // -- setMethods
+
+ /**
+ * Sets whether or not this field can be nillable.
+ *
+ * @param nillable
+ * a boolean that when true means the field may be nil.
+ * @see #isNillable()
+ */
+ public final void setNillable(final boolean nillable) {
+ _nillable = nillable;
+ } // -- setNillable
+
+ /**
+ * Sets the name of the field within the same class that is a reference to
+ * this field.
+ *
+ * @param fieldInfo
+ */
+ public final void setFieldInfoReference(final FieldInfo fieldInfo) {
+ _fieldInfoReference = fieldInfo;
+ } // -- setReference
+
+ /**
+ * Sets the "static" status of this FieldInfo. Static members are also
+ * transient.
+ *
+ * @param isStatic
+ * the boolean indicating the static status, if true this
+ * FieldInfo will be treated as static
+ */
+ public final void setStatic(final boolean isStatic) {
+ this._static = isStatic;
+ } // -- setStatic
+
+ /**
+ * Sets the transient status of this FieldInfo.
+ *
+ * @param isTransient
+ * the boolean indicating the transient status, if true this
+ * FieldInfo will be treated as transient
+ */
+ public final void setTransient(final boolean isTransient) {
+ this._transient = isTransient;
+ } // -- setTransient
+
+ /**
+ * Sets the name of the Validator to use.
+ *
+ * @param validator
+ * the fully qualified name of the validator to use.
+ */
+ public final void setValidator(final String validator) {
+ _validator = validator;
+ }
+
+ /**
+ * Sets the name of the XMLfieldHandler to use.
+ *
+ * @param handler
+ * the fully qualified name of the handler to use.
+ */
+ public final void setXMLFieldHandler(final String handler) {
+ _fieldHandler = handler;
+ }
+
+ /**
+ * Returns the method suffix for creating method names.
+ *
+ * @return the method suffix used when creating method names.
+ */
+ public String getMethodSuffix() {
+ if (_name.startsWith("_")) {
+ return _memberAndAccessorFactory.getJavaNaming().toJavaClassName(
+ _name.substring(1));
+ }
+ return _memberAndAccessorFactory.getJavaNaming().toJavaClassName(_name);
+ }
+
+ /**
+ * Sets the visibility of this FieldInfo.
+ *
+ * @param visibility
+ * the visibility of this FieldInfo.
+ */
+ public final void setVisibility(final String visibility) {
+ _visibility = visibility;
+ }
+
+ /**
+ * Sets the possible substitution groups for this class.
+ *
+ * @param substitutionGroupMembers
+ * Possible substitution groups for this class.
+ */
+ public void setSubstitutionGroupMembers(final List substitutionGroupMembers) {
+ this._substitutionGroupMembers = substitutionGroupMembers;
+ }
+
+ /**
+ * Returns the possible substitution groups for this class.
+ *
+ * @return the possible substitution groups for this class.
+ */
+ public List getSubstitutionGroupMembers() {
+ return this._substitutionGroupMembers;
+ }
+
+ public boolean isStatic() {
+ return _static;
+ }
+
+ public boolean isFinal() {
+ return _final;
+ }
+
+ public Object getVisibility() {
+ return _visibility;
+ }
+
+ public FieldInfo getFieldInfoReference() {
+ return _fieldInfoReference;
+ }
+
+ /**
+ *
+ *
+ * NATURE SUPPORT!
+ *
+ *
+ *
+ */
+
+ /**
+ *
+ * @param nature
+ */
+ public void addNature(String nature) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ *
+ * @param nature
+ * @return
+ */
+ public boolean hasNature(String nature) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /**
+ * @param name
+ * @return
+ */
+ public Object getNatureProperty(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * @param name
+ * @param value
+ */
+ public void setNatureProperty(String name, Object value) {
+ // TODO Auto-generated method stub
+
+ }
+}
Index: codegen/src/main/java/org/exolab/castor/builder/info/JDONature.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/info/JDONature.java (revision 0)
+++ codegen/src/main/java/org/exolab/castor/builder/info/JDONature.java (revision 0)
@@ -0,0 +1,477 @@
+/**
+ *
+ */
+package org.exolab.castor.builder.info;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.exolab.castor.builder.info.nature.Nature2;
+import org.exolab.castor.builder.info.nature.ValidationException;
+
+
+
+
+/**
+ * @author Tobias Hochwallner, Sebastian Gabmeyer
+ *
+ */
+public class JDONature implements Nature2 {
+
+ /**
+ * The reference to the ClassInfo for which this Nature's instance defines a
+ * view on.
+ */
+ private ClassInfo _classInfo;
+
+ /**
+ * The uniqe ID value to identify this Nature.
+ */
+ private static String _id = "JDO";
+
+ /**
+ * The prefixed property name for the name of the table.
+ */
+ private static final String TABLENAME = "jdo:tablename";
+ /**
+ * The prefixed property name for the primary keys.
+ */
+ private static final String PRIMARY_KEYS = "jdo:primaryKeys";
+ /**
+ * The prefixed property name for a column.
+ */
+ private static final String COLUMN = "jdo:column";
+ /**
+ * The prefixed property name for the columns.
+ * @deprecated
+ */
+ private static final String COLUMNS = "jdo:columns";
+ /**
+ * The prefixed property name for the key generators.
+ */
+ private static final String KEY_GENERATORS = "jdo:keyGenerators";
+
+ /**
+ * Initialize a JDONature with the specified {@link ClassInfo}.
+ *
+ * @param classInfo
+ * set corresponding {@link ClassInfo}
+ */
+ public JDONature(final ClassInfo classInfo) {
+ super();
+ _classInfo = classInfo;
+ if (!_classInfo.hasNature(_id)) {
+ _classInfo.addNature(_id);
+ }
+ }
+
+ /**
+ * Initialize an empty JDONature.
+ */
+ public JDONature() {
+ this(null);
+ }
+
+ /**
+ * Get the unique identifier of the Nature.
+ *
+ * @return the unique identifier of the Nature.
+ * @see org.exolab.castor.builder.info.nature.Nature#getId()
+ */
+ public String getId() {
+ return _id;
+ }
+
+ /**
+ * Get the name of the table.
+ *
+ * @return the table name of the table.
+ */
+ public String getTableName() {
+ return (String) _classInfo.getNatureProperty(TABLENAME);
+ }
+
+ /**
+ * Sets the name of the table to the specified value.
+ *
+ * @param tableName
+ * specifies the name of this table.
+ */
+ public void setTableName(final String tableName) {
+ _classInfo.setNatureProperty(TABLENAME, tableName);
+ }
+
+ /**
+ * Add a new primary key constraint to the table by specifying the
+ * corresponding column name.
+ *
+ * Note that if a primary key is added twice only one entry is stored. If a
+ * KeyGenerator was specified for the first entry it will be
+ * removed by calling this method with the same columnName.
+ *
+ * @param columnName
+ * the name of the column holding a primary key.
+ */
+ public void addPrimaryKey(final String columnName) {
+ addPrimaryKey(columnName, null);
+ }
+
+ /**
+ * Add a new primary key constraint to the table by specifying the
+ * corresponding column name. By passing a generatorName a
+ * {@link org.exolab.castor.persist.spi.KeyGenerator} will be used to
+ * generate values for the primary key.
+ *
+ * Note that if a primary key is added twice only one entry is stored. This
+ * is also true for primary keys for which no KeyGenerator
+ * was specified initially; hence, the KeyGenerator is simply
+ * added to the existing primary key entry.
+ *
+ * @param columnName
+ * the name of the column holding a primary key.
+ * @param generatorName
+ * the name of the KeyGenerator.
+ */
+ public void addPrimaryKey(final String columnName, final String generatorName) {
+ Map pks = (Map) _classInfo.getNatureProperty(PRIMARY_KEYS);
+ if (pks == null) {
+ pks = new HashMap();
+ _classInfo.setNatureProperty(PRIMARY_KEYS, pks);
+ }
+ pks.put(columnName, generatorName);
+ }
+
+
+ /**
+ * Get the names of the primary keys associated with this table.
+ *
+ * @return the list of primary key names or null if no
+ * primary key are associated with this table.
+ */
+ public String[] getPrimaryKeys() {
+ Map pks = (Map) _classInfo.getNatureProperty(PRIMARY_KEYS);
+ if (pks == null) {
+ return null;
+ }
+ String[] primaryKeyNames = new String[pks.size()];
+ pks.keySet().toArray(primaryKeyNames);
+
+ return primaryKeyNames;
+ }
+
+ /**
+ * Get the name of the KeyGenerator used to produce key
+ * values for the specified primary key.
+ *
+ * @param primaryKey
+ * the key for which to get the name the of key generator.
+ * @return the name of the key generator or null if the key
+ * values are not generated.
+ */
+ public String getGeneratorNameFor(final String primaryKey) {
+ Map pks = (Map) _classInfo.getNatureProperty(PRIMARY_KEYS);
+
+ return (String) pks.get(primaryKey);
+ }
+
+ /**
+ * Adds a new KeyGenerator.
+ *
+ * @param name the unique name (aka alias) of the key generator.
+ * @param generatorType the type of the key generator.
+ * @param params the list of parameters the key generator require for initialization.
+ */
+ public void addKeyGenerator(final String name, final String generatorType,
+ final Map params) {
+ org.exolab.castor.mapping.xml.KeyGeneratorDef genDef =
+ new org.exolab.castor.mapping.xml.KeyGeneratorDef();
+ genDef.setAlias(name);
+ genDef.setName(generatorType);
+ Iterator it = params.keySet().iterator();
+ while (it.hasNext()) {
+ org.exolab.castor.mapping.xml.Param param = new org.exolab.castor.mapping.xml.Param();
+ String paramName = (String) it.next();
+ param.setName(paramName);
+ param.setValue((String) params.get(paramName));
+ genDef.addParam(param);
+ }
+ Map keyGenerators = (Map) _classInfo.getNatureProperty(KEY_GENERATORS);
+ if (keyGenerators == null) {
+ keyGenerators = new HashMap();
+ _classInfo.setNatureProperty(KEY_GENERATORS, keyGenerators);
+ }
+ keyGenerators.put(name, genDef);
+ }
+
+ /**
+ * Get the definition of a KeyGenerator by its name.
+ *
+ * @param name
+ * the name of the KeyGenerator to get.
+ * @return the KeyGeneratorDef for the
+ * KeyGenerator specified by its name
+ * or null if no KeyGenerator with the
+ * specified name exists.
+ */
+ public org.exolab.castor.mapping.xml.KeyGeneratorDef getKeyGenerator(final String name) {
+ Map keyGenerators = (Map) _classInfo.getNatureProperty(KEY_GENERATORS);
+ if (keyGenerators == null) {
+ return null;
+ }
+ return (org.exolab.castor.mapping.xml.KeyGeneratorDef) keyGenerators.get(name);
+ }
+
+ /**
+ * Get the set of columns the table consists of.
+ *
+ * @return the set of columns.
+ *
+ * @deprecated
+ */
+ public Collection getColumns() {
+ return (Collection) _classInfo.getNatureProperty(COLUMNS);
+ }
+
+ /**
+ * Assigns a set of columns of which the table consists.
+ *
+ * @param columns
+ * the set of columns to be assigned to the table.
+ * @deprecated
+ */
+ public void setColumns(final Collection columns) {
+ _classInfo.setNatureProperty(COLUMNS, columns);
+ }
+
+ /**
+ * Assigns a single column to the table. This is a convience method and
+ * might be removed in the future (if not needed)!
+ *
+ * @param column
+ * a single column.
+ * @deprecated
+ */
+ public void addColumn(final Column column) {
+ Collection columns = (Collection) _classInfo.getNatureProperty(COLUMNS);
+ if (columns == null) {
+ columns = new ArrayList();
+ _classInfo.setNatureProperty(COLUMNS, columns);
+ }
+ columns.add(column);
+ }
+
+ /**
+ * Add a column.
+ *
+ * @param name
+ * the name of the column.
+ * @param type
+ * the type of the column.
+ * @param fieldInfo
+ * the {@link FieldInfo} for which a column property is added.
+ * @throws Exception
+ * if fieldInfo is not contained in
+ * classInfo an Exception is thrown.
+ * @see FieldInfo
+ */
+ public void addColumn(final FieldInfo fieldInfo, final String name,
+ final String type) throws Exception {
+ // TODO change the nature
+ // JDOFieldInfoFactory.createColumn(name, type);
+ if (_classInfo.contains(fieldInfo)) {
+ fieldInfo.setNatureProperty(COLUMN, name);
+ fieldInfo.setNatureProperty("jdo:columnType", type);
+ } else {
+ // TODO: re-factor to some meaningful Exception
+ throw new Exception();
+ }
+ }
+
+ /**
+ * @param name
+ * the name of the column.
+ * @param type
+ * the type of the column.
+ * @param isForeignKey
+ * Set to true if this column holds a foreigen key.
+ */
+ public void addColumn(final String name, final String type,
+ final boolean isForeignKey) {
+ // TODO Auto-generated method stub
+ // JDOFieldInfoFactory.createColumn(name, type, isForeignKey);
+ }
+
+ // TODO check usefulness and JavaDoc!
+ /**
+ * @param name
+ * the name of the relation.
+ * @param type
+ * the type of the relation.
+ * @param collection
+ * the name of the collection.
+ */
+ public void addRelation(final String name, final String type,
+ final String collection) {
+ // TODO Auto-generated method stub
+ // JDOFieldInfoFactory.createRelation(name, type, collection);
+ }
+
+ /**
+ * Get the {@link ClassInfo} of the Nature.
+ *
+ * @return the {@link ClassInfo} of the Nature.
+ * @see org.exolab.castor.builder.info.nature.Nature#getPropertyHolder()
+ * @see ClassInfo
+ */
+ public ClassInfo getPropertyHolder() {
+ return _classInfo;
+ }
+
+ /**
+ * Assign a {@link ClassInfo} to the Nature.
+ *
+ * @param classInfo
+ * the {@link ClassInfo} to assign to the Nature.
+ * @see ClassInfo
+ */
+ public void setPropertyHolder(final ClassInfo classInfo) {
+ _classInfo = classInfo;
+ }
+
+ /**
+ * Checks if the Nature's properties are consistent and conform to the
+ * specified integrity.
+ *
+ * @throws ValidationException if the Nature's integrity/consistency is violated.
+ */
+ public void validate() throws ValidationException {
+ throw new ValidationException("Validation is not implemented!");
+ }
+
+ /**
+ * This class defines a column in the context of JDO/SQL.
+ *
+ * @author Sebastian Gabmeyer
+ *
+ */
+ public class Column {
+ /**
+ * The name of the column.
+ */
+ private String _name;
+
+ /**
+ * The type the column stores, e.g. jdo:string, jdo:integer, and so on.
+ */
+ private String _type;
+
+ /**
+ * Specifies if this column contains a foreign key reference.
+ */
+ private boolean _isReference = false;
+
+ /**
+ *
+ */
+ private String _referencedTable = null;
+
+ /**
+ * Initialize an empty Column.
+ */
+ public Column() {
+ }
+
+ /**
+ * Initialize a Column.
+ *
+ * @param name
+ * the name of the column.
+ * @param type
+ * the type of the values the column stores.
+ * @param isReference
+ * set true if this column represents a foreign key, false
+ * otherwise.
+ */
+ public Column(final String name, final String type,
+ final boolean isReference) {
+ _name = name;
+ _type = type;
+ _isReference = isReference;
+ }
+
+ /**
+ * Get the name of the column.
+ *
+ * @return the name of the column.
+ */
+ public String getName() {
+ return _name;
+ }
+
+ /**
+ * Set the name of the column.
+ *
+ * @param name
+ * the name of the column to set.
+ */
+ public void setName(final String name) {
+ _name = name;
+ }
+
+ /**
+ * Get the type the column stores.
+ *
+ * @return the type the column stores.
+ */
+ public String getType() {
+ return _type;
+ }
+
+ /**
+ * Set the type of the entries this column stores.
+ *
+ * @param type
+ * the type of the column to set.
+ */
+ public void setType(final String type) {
+ _type = type;
+ }
+
+ /**
+ *
+ *
+ * @return the isReference
+ */
+ public boolean isReference() {
+ return _isReference;
+ }
+
+ /**
+ * @param isReference
+ * specifies whether this column contains a reference to
+ * another table or not.
+ */
+ public void setReference(final boolean isReference) {
+ _isReference = isReference;
+ }
+
+ /**
+ * @return the referenced table
+ */
+ public String getReferencedTable() {
+ return _referencedTable;
+ }
+
+ /**
+ * @param referencedTable
+ * the referencedTable to set
+ */
+ public void setReferencedTable(final String referencedTable) {
+ this._referencedTable = referencedTable;
+ }
+ }
+
+}
Index: codegen/src/main/java/org/exolab/castor/builder/factory/MemberFactory.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/factory/MemberFactory.java (revision 7626)
+++ codegen/src/main/java/org/exolab/castor/builder/factory/MemberFactory.java (working copy)
@@ -59,13 +59,14 @@
import org.exolab.castor.builder.SGTypes;
import org.exolab.castor.builder.SourceGenerator;
import org.exolab.castor.builder.binding.XMLBindingComponent;
+import org.exolab.castor.builder.info.BaseFieldInfo;
import org.exolab.castor.builder.info.ClassInfo;
import org.exolab.castor.builder.info.CollectionInfo;
import org.exolab.castor.builder.info.FieldInfo;
import org.exolab.castor.builder.info.XMLInfo;
+import org.exolab.castor.builder.types.XSClass;
import org.exolab.castor.builder.types.XSList;
import org.exolab.castor.builder.types.XSListType;
-import org.exolab.castor.builder.types.XSClass;
import org.exolab.castor.builder.types.XSString;
import org.exolab.castor.builder.types.XSType;
import org.exolab.castor.xml.schema.AttributeDecl;
@@ -193,7 +194,7 @@
fInfo.setRequired(false);
fInfo.setTransient(true);
fInfo.setNodeName("##any");
- fInfo.setMethods(FieldInfo.READ_METHOD);
+ fInfo.setMethods(BaseFieldInfo.READ_METHOD);
return fInfo;
} //-- createFieldInfoForChoiceValue
Index: codegen/src/main/java/org/exolab/castor/builder/factory/FieldInfoFactory.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/factory/FieldInfoFactory.java (revision 7626)
+++ codegen/src/main/java/org/exolab/castor/builder/factory/FieldInfoFactory.java (working copy)
@@ -49,6 +49,7 @@
import org.castor.xml.JavaNaming;
import org.castor.xml.JavaNamingImpl;
import org.exolab.castor.builder.SourceGeneratorConstants;
+import org.exolab.castor.builder.info.BaseFieldInfo;
import org.exolab.castor.builder.info.CollectionInfo;
import org.exolab.castor.builder.info.CollectionInfoJ2;
import org.exolab.castor.builder.info.CollectionInfoJ2Collection;
@@ -210,14 +211,14 @@
}
/**
- * Creates a {@link FieldInfo} instance for the given {@link XSType} and
+ * Creates a {@link BaseFieldInfo} instance for the given {@link XSType} and
* its name.
* @param type {@link XSType} of the field.
* @param name Field name.
* @return The {@link FieldInfo} instance just created.
*/
public FieldInfo createFieldInfo(final XSType type, final String name) {
- FieldInfo fieldInfo = new FieldInfo(type, name, this.fieldMemberAndAccessorFactory);
+ FieldInfo fieldInfo = new BaseFieldInfo(type, name, this.fieldMemberAndAccessorFactory);
if (_bound) { fieldInfo.setBound(true); }
return fieldInfo;
}
Index: codegen/src/main/java/org/exolab/castor/builder/factory/FieldMemberAndAccessorFactory.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/factory/FieldMemberAndAccessorFactory.java (revision 7626)
+++ codegen/src/main/java/org/exolab/castor/builder/factory/FieldMemberAndAccessorFactory.java (working copy)
@@ -2,6 +2,7 @@
import org.castor.xml.JavaNaming;
import org.exolab.castor.builder.AnnotationBuilder;
+import org.exolab.castor.builder.info.BaseFieldInfo;
import org.exolab.castor.builder.info.FieldInfo;
import org.exolab.castor.builder.types.XSType;
import org.exolab.javasource.JClass;
@@ -60,7 +61,7 @@
jsc.add("try {");
jsc.indent();
}
- buffer.append(FieldInfo.METHOD_PREFIX_SET);
+ buffer.append(BaseFieldInfo.METHOD_PREFIX_SET);
buffer.append(fieldInfo.getMethodSuffix());
buffer.append('(');
buffer.append(value);
@@ -159,10 +160,10 @@
*/
public void createAccessMethods(final FieldInfo fieldInfo,
final JClass jClass, final boolean useJava50, final AnnotationBuilder[] annotationBuilders) {
- if ((fieldInfo.getMethods() & FieldInfo.READ_METHOD) > 0) {
+ if ((fieldInfo.getMethods() & BaseFieldInfo.READ_METHOD) > 0) {
createGetterMethod(fieldInfo, jClass, useJava50, annotationBuilders);
}
- if ((fieldInfo.getMethods() & FieldInfo.WRITE_METHOD) > 0) {
+ if ((fieldInfo.getMethods() & BaseFieldInfo.WRITE_METHOD) > 0) {
createSetterMethod(fieldInfo, jClass, useJava50);
}
if (fieldInfo.isHasAndDeleteMethods()) {
@@ -218,7 +219,7 @@
JType jType = xsType.getJType();
//-- create get method
- method = new JMethod(FieldInfo.METHOD_PREFIX_GET + mname, jType,
+ method = new JMethod(BaseFieldInfo.METHOD_PREFIX_GET + mname, jType,
"the value of field '" + mname + "'.");
if (useJava50) {
Java5HacksHelper.addOverrideAnnotations(method.getSignature());
@@ -239,7 +240,7 @@
if (xsType.getType() == XSType.BOOLEAN_TYPE) {
// -- create is