Index: main/java/org/exolab/castor/builder/MemberFactory.java =================================================================== --- main/java/org/exolab/castor/builder/MemberFactory.java (Revision 6732) +++ main/java/org/exolab/castor/builder/MemberFactory.java (Arbeitskopie) @@ -197,7 +197,7 @@ public FieldInfo createFieldInfoForContent(final XSType xsType, final boolean useJava50) { String fieldName = "_content"; //new xsType()??? FieldInfo fInfo = null; - if (xsType.getType() == XSType.COLLECTION) { + if (xsType.isCollection()) { fInfo = this.getInfoFactory().createCollection( ((XSListType) xsType).getContentType(), fieldName, null, useJava50); } else { @@ -371,6 +371,8 @@ fieldInfo = this.getInfoFactory().createIdentity(memberName); break; case XSType.COLLECTION: + case XSType.IDREFS_TYPE: + case XSType.NMTOKENS_TYPE: String collectionName = component.getCollectionType(); XSType contentType = ((XSListType) xsType).getContentType(); fieldInfo = this.getInfoFactory().createCollection(contentType, Index: main/java/org/exolab/castor/builder/MappingFileSourceFactory.java =================================================================== --- main/java/org/exolab/castor/builder/MappingFileSourceFactory.java (Revision 6732) +++ main/java/org/exolab/castor/builder/MappingFileSourceFactory.java (Arbeitskopie) @@ -207,7 +207,7 @@ } //Attributes can handle COLLECTION type for NMTOKENS or IDREFS for instance - if (xsType.getType() == XSType.COLLECTION) { + if (xsType.isCollection()) { xsType = ((CollectionInfo) member).getContent().getSchemaType(); } Index: main/java/org/exolab/castor/builder/info/CollectionInfo.java =================================================================== --- main/java/org/exolab/castor/builder/info/CollectionInfo.java (Revision 6732) +++ main/java/org/exolab/castor/builder/info/CollectionInfo.java (Arbeitskopie) @@ -52,8 +52,12 @@ import org.exolab.castor.builder.SGTypes; import org.exolab.castor.builder.SourceGeneratorConstants; +import org.exolab.castor.builder.types.XSIdRef; +import org.exolab.castor.builder.types.XSIdRefs; import org.exolab.castor.builder.types.XSListType; import org.exolab.castor.builder.types.XSList; +import org.exolab.castor.builder.types.XSNMToken; +import org.exolab.castor.builder.types.XSNMTokens; import org.exolab.castor.builder.types.XSType; import org.exolab.castor.xml.JavaNaming; import org.exolab.javasource.JArrayType; @@ -117,6 +121,12 @@ final String elementName, final boolean useJava50) { super(new XSList(SourceGeneratorConstants.FIELD_INFO_VECTOR, contentType, useJava50), name); + if (contentType instanceof XSIdRef) { + setSchemaType(new XSIdRefs(SourceGeneratorConstants.FIELD_INFO_VECTOR, useJava50)); + } else if (contentType instanceof XSNMToken) { + setSchemaType(new XSNMTokens(SourceGeneratorConstants.FIELD_INFO_VECTOR, useJava50)); + } + if (elementName.charAt(0) == '_') { this._elementName = elementName.substring(1); } else { Index: main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java =================================================================== --- main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java (Revision 6732) +++ main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java (Arbeitskopie) @@ -56,7 +56,9 @@ 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.XSIdRefs; import org.exolab.castor.builder.types.XSListType; +import org.exolab.castor.builder.types.XSNMTokens; import org.exolab.castor.builder.types.XSType; import org.exolab.castor.xml.XMLConstants; import org.exolab.javasource.JClass; @@ -320,7 +322,7 @@ any = true; } - if (xsType.getType() == XSType.COLLECTION) { + if (xsType.isCollection()) { //Attributes can handle COLLECTION type for NMTOKENS or IDREFS for instance xsType = ((CollectionInfo) member).getContent().getSchemaType(); } @@ -486,7 +488,7 @@ jsc.add("desc.setImmutable(true);"); } else if (xsType.getType() == XSType.DECIMAL_TYPE) { jsc.add("desc.setImmutable(true);"); - } else if (member.getSchemaType().getType() == XSType.COLLECTION) { + } else if (member.getSchemaType().isCollection()) { //-- Handle special Collection Types such as NMTOKENS and IDREFS switch (xsType.getType()) { case XSType.NMTOKEN_TYPE: @@ -543,7 +545,7 @@ XSType xsType = member.getSchemaType(); //--handle collections - if ((xsType.getType() == XSType.COLLECTION)) { + if (xsType.isCollection()) { XSListType xsList = (XSListType) xsType; jsc.add("fieldValidator.setMinOccurs("); @@ -554,19 +556,6 @@ jsc.append(Integer.toString(xsList.getMaximumSize())); jsc.append(");"); } - - xsType = ((CollectionInfo) member).getContent().getSchemaType(); - //special handling for NMTOKEN - if (xsType.getType() == XSType.NMTOKEN_TYPE) { - return; - } - if (xsType.getType() == XSType.IDREF_TYPE) { - jsc.add("org.exolab.castor.xml.validators.IdRefsValidator typeValidator = " - + "new org.exolab.castor.xml.validators.IdRefsValidator();"); - jsc.add("fieldValidator.setValidator(typeValidator);"); - jsc.add("desc.setValidator(fieldValidator);"); - return; - } } else if (member.isRequired()) { jsc.add("fieldValidator.setMinOccurs(1);"); } Index: main/java/org/exolab/castor/builder/types/XSList.java =================================================================== --- main/java/org/exolab/castor/builder/types/XSList.java (Revision 6732) +++ main/java/org/exolab/castor/builder/types/XSList.java (Arbeitskopie) @@ -28,17 +28,12 @@ * @author Assaf Arkin * @author Keith Visco * @author Ralf Joachim + * @author Werner Guttmann * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ */ -public final class XSList extends XSListType { +public class XSList extends XSListType { //-------------------------------------------------------------------------- - /** Name of the IDREFS type. */ - public static final String IDREFS_NAME = "IDREFS"; - - /** name of the NMTOKENS type. */ - public static final String NMTOKENS_NAME = "NMTOKENS"; - /** Type number of this XSType. */ public static final short TYPE = XSType.COLLECTION; @@ -87,14 +82,7 @@ * {@inheritDoc} */ public String getName() { - short type = ((XSListType) this).getContentType().getType(); - if (type == NMTOKEN_TYPE) { - return NMTOKENS_NAME; - } else if (type == IDREF_TYPE) { - return IDREFS_NAME; - } else { - return _jType.getName(); - } + return _jType.getName(); } /** @@ -152,7 +140,7 @@ */ public void validationCode(final JSourceCode jsc, final String fixedValue, final String validatorInstanceName) { - // Not implemented + getContentType().validationCode(jsc, fixedValue, validatorInstanceName); } //-------------------------------------------------------------------------- Index: main/java/org/exolab/castor/builder/types/XSIdRefs.java =================================================================== --- main/java/org/exolab/castor/builder/types/XSIdRefs.java (Revision 0) +++ main/java/org/exolab/castor/builder/types/XSIdRefs.java (Revision 0) @@ -0,0 +1,56 @@ +package org.exolab.castor.builder.types; + +import org.exolab.javasource.JSourceCode; + +/** + * A collection of IDREF type. + * + * @author Werner Guttmann + * @since 1.1 + * @version $Revision: 6729 $ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ + */ +public class XSIdRefs extends XSList { + + /** Name of the IDREFS type. */ + public static final String IDREFS_NAME = "IDREFS"; + + /** + * Create a XSNMTokens instance. + * + * @param colType Type of collection to use. + * @param useJava50 If true, the collection will be generated using Java 5 + * features such as generics. + */ + public XSIdRefs(final String colType, final boolean useJava50) { + super(colType, new XSIdRef(), useJava50); + } + + /** + * {@inheritDoc} + */ + public String getName() { + return IDREFS_NAME; + } + + /** + * {@inheritDoc} + */ + public short getType() { + return XSType.IDREFS_TYPE; + } + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, + final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.IdRefsValidator typeValidator = " + + "new org.exolab.castor.xml.validators.IdRefsValidator();"); + jsc.add("fieldValidator.setValidator(typeValidator);"); + jsc.add("desc.setValidator(fieldValidator);"); + } + + + +} Index: main/java/org/exolab/castor/builder/types/XSNMTokens.java =================================================================== --- main/java/org/exolab/castor/builder/types/XSNMTokens.java (Revision 0) +++ main/java/org/exolab/castor/builder/types/XSNMTokens.java (Revision 0) @@ -0,0 +1,51 @@ +package org.exolab.castor.builder.types; + +import org.exolab.javasource.JSourceCode; + +/** + * A collection of NMToken type. + * + * @author Werner Guttmann + * @since 1.1 + * @version $Revision: 6729 $ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ + */ +public class XSNMTokens extends XSList { + + /** name of the NMTOKENS type. */ + public static final String NMTOKENS_NAME = "NMTOKENS"; + + /** + * Create a XSNMTokens instance. + * + * @param colType Type of collection to use. + * @param useJava50 If true, the collection will be generated using Java 5 + * features such as generics. + */ + public XSNMTokens(final String colType, final boolean useJava50) { + super(colType, new XSNMToken(), useJava50); + } + + /** + * {@inheritDoc} + */ + public String getName() { + return NMTOKENS_NAME; + } + + /** + * {@inheritDoc} + */ + public short getType() { + return XSType.NMTOKENS_TYPE; + } + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, + final String validatorInstanceName) { + // no special code + } + +} Index: main/java/org/exolab/castor/builder/types/XSListType.java =================================================================== --- main/java/org/exolab/castor/builder/types/XSListType.java (Revision 6732) +++ main/java/org/exolab/castor/builder/types/XSListType.java (Arbeitskopie) @@ -93,5 +93,14 @@ _minSize = size; } + /** + * {@inheritDoc} + */ + public boolean isCollection() { + return true; + } + + + //-------------------------------------------------------------------------- } Index: main/java/org/exolab/castor/builder/types/XSType.java =================================================================== --- main/java/org/exolab/castor/builder/types/XSType.java (Revision 6732) +++ main/java/org/exolab/castor/builder/types/XSType.java (Arbeitskopie) @@ -236,6 +236,15 @@ public abstract boolean isDateTime(); /** + * Returns true if this XSType represents a collection. + * + * @return True if this XSType represents a collection. + */ + public boolean isCollection() { + return false; + } + + /** * Returns the JType that this XSType represents. * * @return The JType that this XSType represents. Index: main/java/org/exolab/castor/builder/TypeConversion.java =================================================================== --- main/java/org/exolab/castor/builder/TypeConversion.java (Revision 6732) +++ main/java/org/exolab/castor/builder/TypeConversion.java (Arbeitskopie) @@ -67,12 +67,14 @@ import org.exolab.castor.builder.types.XSHexBinary; import org.exolab.castor.builder.types.XSId; import org.exolab.castor.builder.types.XSIdRef; +import org.exolab.castor.builder.types.XSIdRefs; import org.exolab.castor.builder.types.XSInt; import org.exolab.castor.builder.types.XSInteger; import org.exolab.castor.builder.types.XSList; import org.exolab.castor.builder.types.XSLong; import org.exolab.castor.builder.types.XSNCName; import org.exolab.castor.builder.types.XSNMToken; +import org.exolab.castor.builder.types.XSNMTokens; import org.exolab.castor.builder.types.XSNegativeInteger; import org.exolab.castor.builder.types.XSNonNegativeInteger; import org.exolab.castor.builder.types.XSNonPositiveInteger; @@ -199,15 +201,13 @@ case SimpleTypesFactory.IDREF_TYPE: //-- IDREF return new XSIdRef(); case SimpleTypesFactory.IDREFS_TYPE: //-- IDREFS - return new XSList(SourceGeneratorConstants.FIELD_INFO_VECTOR, - new XSIdRef(), useJava50); + return new XSIdRefs(SourceGeneratorConstants.FIELD_INFO_VECTOR, useJava50); case SimpleTypesFactory.NMTOKEN_TYPE: //-- NMTOKEN XSNMToken xsNMToken = new XSNMToken(); xsNMToken.setFacets(simpleType); return xsNMToken; case SimpleTypesFactory.NMTOKENS_TYPE: //-- NMTOKENS - return new XSList(SourceGeneratorConstants.FIELD_INFO_VECTOR, - new XSNMToken(), useJava50); + return new XSNMTokens(SourceGeneratorConstants.FIELD_INFO_VECTOR, useJava50); case SimpleTypesFactory.ANYURI_TYPE: //--AnyURI return new XSAnyURI(); case SimpleTypesFactory.BASE64BINARY_TYPE: //-- base64Bbinary