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,106 @@ +/** + * + */ +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.JDOClassNature; +import org.exolab.castor.builder.info.nature.PropertyHolder; +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 PropertyHolder _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")); + + 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()); + } + +} 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/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,52 @@ +/** + * + */ +package org.exolab.castor.builder.info; + +import org.exolab.castor.builder.info.nature.Nature; +import org.exolab.castor.builder.info.nature.PropertyHolder; +import org.exolab.castor.builder.info.nature.ValidationException; + +/** + * @author Sebastian Gabmeyer + * + */ +public class JDOFieldNature implements Nature { + + /** + * @return + * @see org.exolab.castor.builder.info.nature.Nature#getId() + */ + public String getId() { + // TODO Auto-generated method stub + return null; + } + + /** + * @return + * @see org.exolab.castor.builder.info.nature.Nature#getPropertyHolder() + */ + public PropertyHolder 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(PropertyHolder holder) { + // TODO Auto-generated method stub + + } + + /** + * @throws ValidationException + * @see org.exolab.castor.builder.info.nature.Nature#validate() + */ + public void validate() throws ValidationException { + // TODO Auto-generated method stub + + } + +} 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 +0,0 @@ -/* - * 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; - -/** - * 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$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ - */ -public class FieldInfo extends XMLInfo { - - /** 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. - * @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 - - 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; - } - - - - - - - -} Index: codegen/src/main/java/org/exolab/castor/builder/info/XMLInfo.java =================================================================== --- codegen/src/main/java/org/exolab/castor/builder/info/XMLInfo.java (revision 7626) +++ codegen/src/main/java/org/exolab/castor/builder/info/XMLInfo.java (working copy) @@ -51,6 +51,9 @@ * * @author Keith Visco * @version $Revision$ $Date: 2006-02-23 01:37:50 -0700 (Thu, 23 Feb 2006) $ + * + * @deprecated This class' functionality will be replaced by XMLClassNature and + * XMLFieldNature */ public class XMLInfo { Index: codegen/src/main/java/org/exolab/castor/builder/info/BaseClassInfo.java =================================================================== --- codegen/src/main/java/org/exolab/castor/builder/info/BaseClassInfo.java (revision 7626) +++ codegen/src/main/java/org/exolab/castor/builder/info/BaseClassInfo.java (working copy) @@ -49,6 +49,8 @@ */ 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.Vector; @@ -62,7 +64,7 @@ * @author Keith Visco * @version $Revision$ $Date: 2006-04-13 07:37:49 -0600 (Thu, 13 Apr 2006) $ */ -public final class ClassInfo extends XMLInfo { +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. */ @@ -92,7 +94,7 @@ * Creates a new ClassInfo. * @param jClass the JClass which this ClassInfo describes */ - public ClassInfo(final JClass jClass) { + public BaseClassInfo(final JClass jClass) { super(XMLInfo.ELEMENT_TYPE); if (jClass == null) { String err = "JClass passed to constructor of ClassInfo must not be null."; @@ -109,8 +111,9 @@ /** * Adds the given FieldInfo to this ClassInfo. - * + * * @param fieldInfo the FieldInfo to add + * @see org.exolab.castor.builder.info.ClassInfo#addFieldInfo(org.exolab.castor.builder.info.FieldInfo) */ public void addFieldInfo(final FieldInfo fieldInfo) { if (fieldInfo == null) { @@ -140,6 +143,7 @@ * Adds the given set of FieldInfos to this ClassInfo. * * @param fields an Array of FieldInfo objects + * @see org.exolab.castor.builder.info.ClassInfo#addFieldInfo(org.exolab.castor.builder.info.FieldInfo[]) */ public void addFieldInfo(final FieldInfo[] fields) { for (int i = 0; i < fields.length; i++) { @@ -148,7 +152,11 @@ } //-- addFieldInfo /** + * Returns true if Classes created with this ClassInfo allow + * content. + * * @return true if Classes created with this ClassInfo allow content + * @see org.exolab.castor.builder.info.ClassInfo#allowContent() */ public boolean allowContent() { return _textField != null; @@ -160,6 +168,7 @@ * @param fieldInfo * the FieldInfo to check * @return true if the given FieldInfo is contained within this ClassInfo + * @see org.exolab.castor.builder.info.ClassInfo#contains(org.exolab.castor.builder.info.FieldInfo) */ public boolean contains(final FieldInfo fieldInfo) { if (fieldInfo == null) { @@ -189,7 +198,9 @@ /** * Returns an array of XML attribute associated fields. + * * @return an array of XML attribute associated fields. + * @see org.exolab.castor.builder.info.ClassInfo#getAttributeFields() */ public FieldInfo[] getAttributeFields() { FieldInfo[] fields = null; @@ -208,6 +219,7 @@ * * @param nodeName the NodeName of the field to get. * @return a fieldInfo that corresponds to an attribute with the given node name. + * @see org.exolab.castor.builder.info.ClassInfo#getAttributeField(java.lang.String) */ public FieldInfo getAttributeField(final String nodeName) { if (_atts == null) { @@ -239,6 +251,7 @@ * Returns an array of XML element associated fields. * * @return an array of XML element associated fields. + * @see org.exolab.castor.builder.info.ClassInfo#getElementFields() */ public FieldInfo[] getElementFields() { FieldInfo[] members = null; @@ -257,6 +270,7 @@ * * @param nodeName the NodeName of the field to get. * @return a fieldInfo that corresponds to an element with the given node name. + * @see org.exolab.castor.builder.info.ClassInfo#getElementField(java.lang.String) */ public FieldInfo getElementField(final String nodeName) { if (_elements != null) { @@ -275,6 +289,7 @@ * Returns the number of FieldInfo definitions for this ClassInfo. * * @return the number of FieldInfo definitions for this ClassInfo. + * @see org.exolab.castor.builder.info.ClassInfo#getFieldCount() */ public int getFieldCount() { int count = 0; @@ -294,6 +309,7 @@ * Returns the GroupInfo for this ClassInfo. * * @return the GroupInfo for this ClassInfo + * @see org.exolab.castor.builder.info.ClassInfo#getGroupInfo() */ public GroupInfo getGroupInfo() { return _groupInfo; @@ -303,6 +319,7 @@ * Returns the JClass described by this ClassInfo. * * @return the JClass which is described by this ClassInfo + * @see org.exolab.castor.builder.info.ClassInfo#getJClass() */ public JClass getJClass() { return _class; @@ -313,6 +330,7 @@ * * @return the FieldInfo for the text content associated field, this may be * null. + * @see org.exolab.castor.builder.info.ClassInfo#getTextField() */ public FieldInfo getTextField() { return _textField; @@ -322,6 +340,7 @@ * Returns true if the JClass represented by this ClassInfo is abstract. * * @return true if the JClass represented by this ClassInfo is abstract + * @see org.exolab.castor.builder.info.ClassInfo#isAbstract() */ public boolean isAbstract() { return _abstract; @@ -331,6 +350,7 @@ * Returns true if the compositor of this GroupInfo is a choice. * * @return true if the compositor of this GroupInfo is a choice + * @see org.exolab.castor.builder.info.ClassInfo#isChoice() */ public boolean isChoice() { return _groupInfo.isChoice(); @@ -342,6 +362,7 @@ * should be. * * @return true if this ClassInfo describes a container class. + * @see org.exolab.castor.builder.info.ClassInfo#isContainer() */ public boolean isContainer() { return _isContainer; @@ -351,6 +372,7 @@ * Returns true if the compositor of this GroupInfo is a sequence. * * @return true if the compositor of this GroupInfo is a sequence + * @see org.exolab.castor.builder.info.ClassInfo#isSequence() */ public boolean isSequence() { return _groupInfo.isSequence(); @@ -363,6 +385,7 @@ * * @param abstractClass true if the class represented by this ClassInfo is * abstract + * @see org.exolab.castor.builder.info.ClassInfo#setAbstract(boolean) */ public void setAbstract(final boolean abstractClass) { _abstract = abstractClass; @@ -386,6 +409,7 @@ * * @param isContainer the boolean value when true indicates this class * should be a container class. + * @see org.exolab.castor.builder.info.ClassInfo#setContainer(boolean) */ public void setContainer(final boolean isContainer) { _isContainer = isContainer; @@ -393,7 +417,9 @@ /** * Returns the possible substitution groups for this class. + * * @return the possible substitution groups for this class. + * @see org.exolab.castor.builder.info.ClassInfo#getSubstitutionGroups() */ public List getSubstitutionGroups() { return _substitutionGroups; @@ -401,10 +427,75 @@ /** * Sets the possible substitution groups for this class. + * * @param substitutionGroups Possible substitution groups for this class. + * @see org.exolab.castor.builder.info.ClassInfo#setSubstitutionGroups(java.util.List) */ public void setSubstitutionGroups(final List substitutionGroups) { _substitutionGroups = substitutionGroups; } - + + + + /** + * + * + * New ClassInfo/nature part. + * + * + */ + + /** + * a HashMap containing the properties for all Natures. + */ + private HashMap _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.BaseClassInfo}. + * + * @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.BaseClassInfo}. + * + * @param classInfo + * the ClassInfo to set. + * @see ClassInfo + * @see NatureExtendable + * @see org.exolab.castor.builder.info.JDOClassNature + * @see org.exolab.castor.builder.info.BaseClassInfo + */ + 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/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 { + /** + * 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.BaseClassInfo}. + * + * @return the PropertyHolder of the Nature + * @see PropertyHolder + * @see NatureExtendable + * @see org.exolab.castor.builder.info.JDOClassNature + */ + PropertyHolder 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.BaseClassInfo}. + * + * @param holder + * the PropertyHolder to set. + * @see PropertyHolder + * @see NatureExtendable + * @see org.exolab.castor.builder.info.JDOClassNature + * @see org.exolab.castor.builder.info.BaseClassInfo + */ + void setPropertyHolder(PropertyHolder 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,410 +0,0 @@ -/* - * 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.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$ $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; - - /** - * 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; - } - - 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; - } - -} //-- ClassInfo 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,297 @@ +/** + * + */ +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.PropertyHolder; +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 PropertyHolder _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 the key generators. + */ + private static final String KEY_GENERATORS = "jdo:keyGenerators"; + + /** + * Initialize a JDONature with the specified {@link PropertyHolder}. + * @param classInfo set corresponding {@link PropertyHolder} + */ + public JDOClassNature(final PropertyHolder classInfo) { + super(); + _classInfo = classInfo; + } + + /** + * Initialize an empty JDONature. + */ + 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. + */ + 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 keys 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); + 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. + */ + 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 {@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 PropertyHolder 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 PropertyHolder 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 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 7626) +++ codegen/src/main/java/org/exolab/castor/builder/info/BaseFieldInfo.java (working copy) @@ -60,72 +60,79 @@ * 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$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ + * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr + * 2006) $ */ -public class FieldInfo extends XMLInfo { +public class BaseFieldInfo extends XMLInfo implements FieldInfo { /** The Read / Getter method flag. */ - public static final int READ_METHOD = 1; + public static final int READ_METHOD = 1; /** The Write / Setter method flag. */ - public static final int WRITE_METHOD = 2; + public static final int WRITE_METHOD = 2; /** The Read and Write methods flags. */ - public static final int READ_WRITE_METHODS = 3; + public static final int READ_WRITE_METHODS = 3; /** Method prefixes for "Add" methods. */ - public static final String METHOD_PREFIX_ADD = "add"; + 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"; + public static final String METHOD_PREFIX_GET = "get"; /** Method prefixes for "Has" methods. */ - public static final String METHOD_PREFIX_HAS = "has"; + public static final String METHOD_PREFIX_HAS = "has"; /** Method prefixes for "Set" methods. */ - public static final String METHOD_PREFIX_SET = "set"; + public static final String METHOD_PREFIX_SET = "set"; /** Method prefixes for "Is" methods. */ - public static final String METHOD_PREFIX_IS = "is"; + public static final String METHOD_PREFIX_IS = "is"; /** The Java name for Members described by this FieldInfo. */ - private String _name = null; + private String _name = null; private ClassInfo _declaringClassInfo = null; /** JavaDoc comment. */ - private String _comment = null; + private String _comment = null; /** The default value for this FieldInfo. */ - private String _default = null; + private String _default = null; /** The fixed production for this FieldInfo. */ - private String _fixed = null; + private String _fixed = null; /** A flag to indicate a final member. */ - private boolean _final = false; + 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 _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. + * 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. */ + /** + * 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. */ @@ -134,87 +141,92 @@ /** * 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 + * @param memberAndAccessorFactory * the FieldMemberAndAccessorFactory to be used */ - public FieldInfo(final XSType type, final String name, + public BaseFieldInfo(final XSType type, final String name, final FieldMemberAndAccessorFactory memberAndAccessorFactory) { - this._name = name; + this._name = name; this._memberAndAccessorFactory = memberAndAccessorFactory; setSchemaType(type); - } //-- FieldInfo + } // -- 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; } - /* Returns the default value for this FieldInfo. - * + /* + * Returns the default value for this FieldInfo. + * * @return the default value for this FieldInfo, or null if no default value - * was set; + * was set; */ public final String getDefaultValue() { return _default; - } //-- getDefaultValue + } // -- 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 + } // -- 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 + } // -- 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 + } // -- 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 + } // -- getReadMethodName - /** - * Returns the fully qualified name of the Validator to use. - * - * @return the fully qualified name of the Validator to use. - */ + /** + * 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() { @@ -222,231 +234,246 @@ return METHOD_PREFIX_ADD + getMethodSuffix(); } return METHOD_PREFIX_SET + getMethodSuffix(); - } //-- getWriteMethodName + } // -- getWriteMethodName - /** - * Returns the fully qualified name of the XMLFieldHandler to use. - * - * @return the fully qualified name of the XMLFieldHandler to use. - */ + /** + * 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. + * + * @return the comment associated with this Member, or null. if one has not + * been set. */ public final String getComment() { return _comment; - } //-- getComment + } // -- getComment /** * Returns the methods flag that indicates which. - * + * * methods will be created. - * + * * @return the methods flag */ public final int getMethods() { return _methods; - } //-- getMethods + } // -- getMethods /** * Returns the name of this FieldInfo. - * + * * @return the name of this FieldInfo. */ public final String getName() { return this._name; - } //-- 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 + } // -- 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 + } // -- 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(); + JType jType = xsType.getJType(); return ((!xsType.isEnumerated()) && jType.isPrimitive()); - } //-- isHasMethod + } // -- 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 + 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 + } // -- isTransient /** * Sets the comment for this Member. - * @param comment the comment or description for this Member + * + * @param comment + * the comment or description for this Member */ public final void setComment(final String comment) { _comment = comment; - } //-- setComment + } // -- 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 + } // -- 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. + * + * @param bound + * the flag when true indicates that this FieldInfo represents a + * bound property. */ public final void setBound(final boolean bound) { _bound = bound; - } //-- setBound + } // -- 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 + } // -- 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 + } // -- setDeclaringClassInfo /** * Sets the default value for this FieldInfo. - * @param defaultValue the default value + * + * @param defaultValue + * the default value */ public final void setDefaultValue(final String defaultValue) { this._default = defaultValue; - } //-- setDefaultValue; + } // -- 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 + } // -- 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 + } // -- 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 + } // -- 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 + } // -- 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 + } // -- 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 + * + * @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 + } // -- 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 + * + * @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 + } // -- 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; @@ -454,8 +481,9 @@ /** * Sets the name of the XMLfieldHandler to use. - * - * @param handler the fully qualified name of the handler to use. + * + * @param handler + * the fully qualified name of the handler to use. */ public final void setXMLFieldHandler(final String handler) { _fieldHandler = handler; @@ -463,20 +491,22 @@ /** * 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.substring(1)); } return _memberAndAccessorFactory.getJavaNaming().toJavaClassName(_name); } /** * Sets the visibility of this FieldInfo. - * - * @param visibility the visibility of this FieldInfo. + * + * @param visibility + * the visibility of this FieldInfo. */ public final void setVisibility(final String visibility) { _visibility = visibility; @@ -484,7 +514,9 @@ /** * 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; @@ -492,32 +524,72 @@ /** * 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! + * + * + * + */ - public boolean isStatic() { - return _static; - } + /** + * + * @param nature + */ + public void addNature(String nature) { + // TODO Auto-generated method stub + + } - public boolean isFinal() { - return _final; - } + /** + * + * @param nature + * @return + */ + public boolean hasNature(String nature) { + // TODO Auto-generated method stub + return false; + } - public Object getVisibility() { - return _visibility; - } + /** + * @param name + * @return + */ + public Object getNatureProperty(String name) { + // TODO Auto-generated method stub + return null; + } - public FieldInfo getFieldInfoReference() { - return _fieldInfoReference; - } - - - - - - - + /** + * @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,474 @@ +/** + * + */ +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; + } + + /** + * 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; + } + } + +}