Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/MemberFactory.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/MemberFactory.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/MemberFactory.java (working copy) @@ -56,8 +56,8 @@ 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.XSListType; import org.exolab.castor.builder.types.XSClass; -import org.exolab.castor.builder.types.XSList; import org.exolab.castor.builder.types.XSString; import org.exolab.castor.builder.types.XSType; import org.exolab.castor.xml.schema.Annotated; @@ -134,7 +134,7 @@ if (any.getMaxOccurs() > 1 || any.getMaxOccurs() < 0) { result = this.getInfoFactory().createCollection(xsType, vName, "anyObject", useJava50); - XSList xsList = ((CollectionInfo) result).getXSList(); + XSListType xsList = ((CollectionInfo) result).getXSList(); xsList.setMinimumSize(any.getMinOccurs()); xsList.setMaximumSize(any.getMaxOccurs()); } else { @@ -198,9 +198,8 @@ String fieldName = "_content"; //new xsType()??? FieldInfo fInfo = null; if (xsType.getType() == XSType.COLLECTION) { - fInfo = this.getInfoFactory().createCollection(((XSList) xsType).getContentType(), - fieldName, - null, useJava50); + fInfo = this.getInfoFactory().createCollection( + ((XSListType) xsType).getContentType(), fieldName, null, useJava50); } else { fInfo = this.getInfoFactory().createFieldInfo(xsType, fieldName); } @@ -360,7 +359,7 @@ cInfo = this.getInfoFactory().createCollection(xsType, vName, memberName, component.getCollectionType(), useJava50); - XSList xsList = cInfo.getXSList(); + XSListType xsList = cInfo.getXSList(); if (!simpleTypeCollection) { xsList.setMaximumSize(maxOccurs); xsList.setMinimumSize(minOccurs); @@ -373,7 +372,7 @@ break; case XSType.COLLECTION: String collectionName = component.getCollectionType(); - XSType contentType = ((XSList) xsType).getContentType(); + XSType contentType = ((XSListType) xsType).getContentType(); fieldInfo = this.getInfoFactory().createCollection(contentType, memberName, memberName, collectionName, useJava50); Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/TypeConversion.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/TypeConversion.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/TypeConversion.java (working copy) @@ -49,7 +49,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.exolab.castor.builder.types.XSAnyURI; -import org.exolab.castor.builder.types.XSBinary; +import org.exolab.castor.builder.types.XSBase64Binary; import org.exolab.castor.builder.types.XSBoolean; import org.exolab.castor.builder.types.XSByte; import org.exolab.castor.builder.types.XSClass; @@ -64,6 +64,7 @@ import org.exolab.castor.builder.types.XSGMonthDay; import org.exolab.castor.builder.types.XSGYear; import org.exolab.castor.builder.types.XSGYearMonth; +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.XSInt; @@ -83,7 +84,7 @@ import org.exolab.castor.builder.types.XSTime; import org.exolab.castor.builder.types.XSType; import org.exolab.castor.builder.types.XSUnsignedByte; -import org.exolab.castor.builder.types.XSUnsignedInteger; +import org.exolab.castor.builder.types.XSUnsignedInt; import org.exolab.castor.builder.types.XSUnsignedLong; import org.exolab.castor.builder.types.XSUnsignedShort; import org.exolab.castor.xml.JavaNaming; @@ -133,7 +134,7 @@ * @return the XSType which represets the given Simpletype */ public XSType convertType(final SimpleType simpleType, final boolean useJava50) { - return convertType(simpleType, _config.usePrimitiveWrapper(), null, useJava50); + return convertType(simpleType, null, useJava50); } /** @@ -146,7 +147,7 @@ */ public XSType convertType(final SimpleType simpleType, final String packageName, final boolean useJava50) { - return convertType(simpleType, _config.usePrimitiveWrapper(), packageName, useJava50); + return convertType(simpleType, packageName, _config.usePrimitiveWrapper(), useJava50); } /** @@ -153,15 +154,15 @@ * Converts the given Simpletype to the appropriate XSType. * * @param simpleType the SimpleType to convert to an XSType instance + * @param packageName the packageName for any new class types * @param useWrapper a boolean that when true indicates that primitive * wrappers be used instead of the actual primitives (e.g. * java.lang.Integer instead of int) - * @param packageName the packageName for any new class types * @param useJava50 true if source code is to be generated for Java 5 * @return the XSType which represets the given Simpletype */ - public XSType convertType(final SimpleType simpleType, final boolean useWrapper, - final String packageName, final boolean useJava50) { + public XSType convertType(final SimpleType simpleType, final String packageName, + final boolean useWrapper, final boolean useJava50) { if (simpleType == null) { return null; } @@ -179,7 +180,7 @@ if (common == null) { return new XSClass(SGTypes.OBJECT); } - return convertType(common, useWrapper, packageName, useJava50); + return convertType(common, packageName, useWrapper, useJava50); } else if (base == null) { String className = JavaNaming.toJavaClassName(simpleType.getName()); return new XSClass(new JClass(className)); @@ -198,7 +199,8 @@ case SimpleTypesFactory.IDREF_TYPE: //-- IDREF return new XSIdRef(); case SimpleTypesFactory.IDREFS_TYPE: //-- IDREFS - return new XSList(new XSIdRef(), useJava50); + return new XSList(SourceGeneratorConstants.FIELD_INFO_VECTOR, + new XSIdRef(), useJava50); case SimpleTypesFactory.NMTOKEN_TYPE: //-- NMTOKEN XSNMToken xsNMToken = new XSNMToken(); xsNMToken.setFacets(simpleType); @@ -204,13 +206,14 @@ xsNMToken.setFacets(simpleType); return xsNMToken; case SimpleTypesFactory.NMTOKENS_TYPE: //-- NMTOKENS - return new XSList(new XSNMToken(), useJava50); + return new XSList(SourceGeneratorConstants.FIELD_INFO_VECTOR, + new XSNMToken(), useJava50); case SimpleTypesFactory.ANYURI_TYPE: //--AnyURI return new XSAnyURI(); case SimpleTypesFactory.BASE64BINARY_TYPE: //-- base64Bbinary - return new XSBinary(XSType.BASE64BINARY_TYPE, useJava50); + return new XSBase64Binary(useJava50); case SimpleTypesFactory.HEXBINARY_TYPE: //-- hexBinary - return new XSBinary(XSType.HEXBINARY_TYPE, useJava50); + return new XSHexBinary(useJava50); case SimpleTypesFactory.BOOLEAN_TYPE: //-- boolean return new XSBoolean(useWrapper); case SimpleTypesFactory.BYTE_TYPE: //--byte @@ -312,27 +315,27 @@ case SimpleTypesFactory.NCNAME_TYPE: //--NCName return new XSNCName(); case SimpleTypesFactory.NON_POSITIVE_INTEGER_TYPE: //-- nonPositiveInteger - XSInteger xsNPInteger = new XSNonPositiveInteger(useWrapper); + XSNonPositiveInteger xsNPInteger = new XSNonPositiveInteger(useWrapper); xsNPInteger.setFacets(simpleType); return xsNPInteger; case SimpleTypesFactory.NON_NEGATIVE_INTEGER_TYPE: //-- nonNegativeInteger - XSInteger xsNNInteger = new XSNonNegativeInteger(useWrapper); + XSNonNegativeInteger xsNNInteger = new XSNonNegativeInteger(useWrapper); xsNNInteger.setFacets(simpleType); return xsNNInteger; case SimpleTypesFactory.NEGATIVE_INTEGER_TYPE: //-- negative-integer - XSInteger xsNInteger = new XSNegativeInteger(useWrapper); + XSNegativeInteger xsNInteger = new XSNegativeInteger(useWrapper); xsNInteger.setFacets(simpleType); return xsNInteger; case SimpleTypesFactory.UNSIGNED_INT_TYPE: //-- unsigned-integer - XSLong xsUnsignedInteger = new XSUnsignedInteger(useWrapper); - xsUnsignedInteger.setFacets(simpleType); - return xsUnsignedInteger; + XSUnsignedInt xsUnsignedInt = new XSUnsignedInt(useWrapper); + xsUnsignedInt.setFacets(simpleType); + return xsUnsignedInt; case SimpleTypesFactory.UNSIGNED_SHORT_TYPE: //-- unsigned-short - XSInt xsUnsignedShort = new XSUnsignedShort(useWrapper); + XSUnsignedShort xsUnsignedShort = new XSUnsignedShort(useWrapper); xsUnsignedShort.setFacets(simpleType); return xsUnsignedShort; case SimpleTypesFactory.UNSIGNED_BYTE_TYPE: //-- unsigned-byte - XSShort xsUnsignedByte = new XSUnsignedByte(useWrapper); + XSUnsignedByte xsUnsignedByte = new XSUnsignedByte(useWrapper); xsUnsignedByte.setFacets(simpleType); return xsUnsignedByte; case SimpleTypesFactory.UNSIGNED_LONG_TYPE: //-- unsigned-long @@ -346,7 +349,7 @@ } return xsNormalString; case SimpleTypesFactory.POSITIVE_INTEGER_TYPE: //-- positive-integer - XSInteger xsPInteger = new XSPositiveInteger(useWrapper); + XSPositiveInteger xsPInteger = new XSPositiveInteger(useWrapper); xsPInteger.setFacets(simpleType); return xsPInteger; case SimpleTypesFactory.QNAME_TYPE: //-- QName Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/XMLFieldHandlerFactory.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/XMLFieldHandlerFactory.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/XMLFieldHandlerFactory.java (working copy) @@ -18,8 +18,8 @@ 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.XSListType; import org.exolab.castor.builder.types.XSClass; -import org.exolab.castor.builder.types.XSList; import org.exolab.castor.builder.types.XSType; import org.exolab.castor.xml.JavaNaming; import org.exolab.javasource.JClass; @@ -299,8 +299,8 @@ isAbstract = jClass.getModifiers().isAbstract(); } - if (!isAbstract && member.getSchemaType() instanceof XSList) { - XSList xsList = (XSList) member.getSchemaType(); + if (!isAbstract && member.getSchemaType() instanceof XSListType) { + XSListType xsList = (XSListType) member.getSchemaType(); if (xsList.getContentType().getJType() instanceof JClass) { JClass componentType = (JClass) xsList.getContentType().getJType(); if (componentType.getModifiers().isAbstract()) { Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/binding/XMLBindingComponent.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/binding/XMLBindingComponent.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/binding/XMLBindingComponent.java (working copy) @@ -1239,8 +1239,8 @@ packageName = _config.lookupPackageByNamespace(ns); } - result = _typeConversion.convertType((SimpleType) type, useWrapper, - packageName, _config.useJava50()); + result = _typeConversion.convertType((SimpleType) type, + packageName, useWrapper,_config.useJava50()); } } Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/descriptors/DescriptorSourceFactory.java (working copy) @@ -56,7 +56,7 @@ 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.XSList; +import org.exolab.castor.builder.types.XSListType; import org.exolab.castor.builder.types.XSType; import org.exolab.castor.xml.XMLConstants; import org.exolab.javasource.JClass; @@ -544,7 +544,7 @@ XSType xsType = member.getSchemaType(); //--handle collections if ((xsType.getType() == XSType.COLLECTION)) { - XSList xsList = (XSList) xsType; + XSListType xsList = (XSListType) xsType; jsc.add("fieldValidator.setMinOccurs("); jsc.append(Integer.toString(xsList.getMinimumSize())); Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfo.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfo.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfo.java (working copy) @@ -51,6 +51,8 @@ package org.exolab.castor.builder.info; import org.exolab.castor.builder.SGTypes; +import org.exolab.castor.builder.SourceGeneratorConstants; +import org.exolab.castor.builder.types.XSListType; import org.exolab.castor.builder.types.XSList; import org.exolab.castor.builder.types.XSType; import org.exolab.castor.xml.JavaNaming; @@ -113,7 +115,7 @@ */ public CollectionInfo(final XSType contentType, final String name, final String elementName, final boolean useJava50) { - super(new XSList(contentType, useJava50), name); + super(new XSList(SourceGeneratorConstants.FIELD_INFO_VECTOR, contentType, useJava50), name); if (elementName.charAt(0) == '_') { this._elementName = elementName.substring(1); @@ -194,8 +196,8 @@ * Returns the schema type represented by this collection. * @return the schema type represented by this collection. */ - public final XSList getXSList() { - return (XSList) this.getSchemaType(); + public final XSListType getXSList() { + return (XSListType) this.getSchemaType(); } /** Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfoJ2.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfoJ2.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfoJ2.java (working copy) @@ -50,7 +50,7 @@ package org.exolab.castor.builder.info; import org.exolab.castor.builder.SGTypes; -import org.exolab.castor.builder.types.XSListJ2; +import org.exolab.castor.builder.types.XSList; import org.exolab.castor.builder.types.XSType; import org.exolab.javasource.JClass; import org.exolab.javasource.JMethod; @@ -81,7 +81,7 @@ final boolean useJava50) { super(contentType, name, elementName, useJava50); // --override the schemaType - this.setSchemaType(new XSListJ2(contentType, collectionType, useJava50)); + this.setSchemaType(new XSList(collectionType, contentType, useJava50)); } // -- CollectionInfoJ2 /** Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfoODMG30.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfoODMG30.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/info/CollectionInfoODMG30.java (working copy) @@ -45,7 +45,8 @@ package org.exolab.castor.builder.info; import org.exolab.castor.builder.SGTypes; -import org.exolab.castor.builder.types.XSListODMG30; +import org.exolab.castor.builder.SourceGeneratorConstants; +import org.exolab.castor.builder.types.XSList; import org.exolab.castor.builder.types.XSType; import org.exolab.javasource.JClass; import org.exolab.javasource.JMethod; @@ -71,7 +72,8 @@ public CollectionInfoODMG30(final XSType contentType, final String name, final String elementName, final boolean useJava50) { super(contentType, name, elementName, useJava50); - this.setSchemaType(new XSListODMG30(contentType, useJava50)); + this.setSchemaType(new XSList(SourceGeneratorConstants.FIELD_INFO_ODMG, + contentType, useJava50)); } /** Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractDigitsFacet.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractDigitsFacet.java (revision 0) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractDigitsFacet.java (revision 0) @@ -0,0 +1,158 @@ +/* + * Copyright 2007 Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.exolab.castor.builder.types; + +import org.exolab.castor.xml.schema.Facet; +import org.exolab.javasource.JSourceCode; + +/** + * A base class for types which support the digits, range, whiteSpace and pattern facets. + * + * @author Ralf Joachim + * @version $Revision: 6662 $ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ + * @since 1.1 + */ +public abstract class AbstractDigitsFacet extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** If set to true only '0' is allowed for the fractionDigits facet. If set to false + * all positive values are allowed for fractionDigits facet. */ + private final boolean _fractionDigitsZeroOnly; + + /** Total number of digits. */ + private int _totalDigits = -1; + + /** Total number of fraction digits. */ + private int _fractionDigits = -1; + + //-------------------------------------------------------------------------- + + /** + * No-arg constructor. By default only '0' is supported for the fractionDigits facet. + */ + protected AbstractDigitsFacet() { + this(true); + } + + /** + * Construct a new AbstractDigitsFacet optionally allowing the fractionDigits facet to be set + * to all positive values. + * + * @param fractionDigitsZeroOnly If set to true only '0' is allowed for the fractionDigits + * facet. If set to false all positive values are allowed for fractionDigits facet. + */ + protected AbstractDigitsFacet(final boolean fractionDigitsZeroOnly) { + _fractionDigitsZeroOnly = fractionDigitsZeroOnly; + } + + //-------------------------------------------------------------------------- + + /** + * Returns the totalDigits facet value of this XSType. + * + * @return The totalDigits facet value of this XSType. + */ + public final int getTotalDigits() { + return _totalDigits; + } + + /** + * Sets the totalDigits facet for this XSType. + * + * @param totalDigits The value of totalDigits (must be >0). + */ + public final void setTotalDigits(final int totalDigits) { + if (totalDigits <= 0) { + throw new IllegalArgumentException( + getName() + ": the totalDigits facet must be positive: " + totalDigits); + } + _totalDigits = totalDigits; + } + + /** + * Returns the fractionDigits facet value of this XSType. + * + * @return The fractionDigits facet value of this XSType. + */ + public final int getFractionDigits() { + return _fractionDigits; + } + + /** + * Sets the fractionDigits facet for this XSType. + * + * @param fractionDigits The value of fractionDigits (must be >=0). + */ + public final void setFractionDigits(final int fractionDigits) { + if (fractionDigits < 0) { + throw new IllegalArgumentException( + getName() + ": the fractionDigits facet must be positive: " + fractionDigits); + } + if (_fractionDigitsZeroOnly && (fractionDigits > 0)) { + throw new IllegalArgumentException( + getName() + ": only '0' allowed for fractionDigits facet: " + fractionDigits); + } + _fractionDigits = fractionDigits; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + protected final void setFacet(final Facet facet) { + addPatternFacet(facet); + setWhiteSpaceFacet(facet); + setRangeFacet(facet); + setDigitsFacet(facet); + } + + /** + * Transfer given facet if it is a digits facet. + * + * @param facet The facet to transfer. + */ + protected final void setDigitsFacet(final Facet facet) { + String name = facet.getName(); + if (Facet.TOTALDIGITS.equals(name)) { + setTotalDigits(facet.toInt()); + } else if (Facet.FRACTIONDIGITS.equals(name)) { + setFractionDigits(facet.toInt()); + } + } + + /** + * Generate the source code for digits facet validation. + * + * @param jsc The JSourceCode to fill in. + * @param validatorName The name of the TypeValidator that the digits should be added to. + */ + protected final void codeDigitsFacet(final JSourceCode jsc, final String validatorName) { + //-- totalDigits + if (getTotalDigits() != -1) { + jsc.add("{0}.setTotalDigits({1});", + validatorName, Integer.toString(getTotalDigits())); + } + + //-- fractionDigits + if (!_fractionDigitsZeroOnly && (getFractionDigits() != -1)) { + jsc.add("{0}.setFractionDigits({1});", + validatorName, Integer.toString(getFractionDigits())); + } + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractLengthFacet.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractLengthFacet.java (revision 0) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractLengthFacet.java (revision 0) @@ -0,0 +1,197 @@ +/* + * Copyright 2007 Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.exolab.castor.builder.types; + +import org.exolab.castor.xml.schema.Facet; +import org.exolab.javasource.JSourceCode; + +/** + * A base class for types which support the length, whiteSpace and pattern facets. + * + * @author Ralf Joachim + * @version $Revision: 6662 $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ + * @since 1.1 + */ +public abstract class AbstractLengthFacet extends AbstractWhiteSpaceFacet { + //-------------------------------------------------------------------------- + + /** The length facet. */ + private int _length = 0; + + /** The max length facet. */ + private int _maxLength = -1; + + /** The min length facet. */ + private int _minLength = 0; + + //-------------------------------------------------------------------------- + + /** + * No-arg constructor. By default only 'collapse' is supported for the whiteSpace facet. + */ + protected AbstractLengthFacet() { + super(true); + } + + /** + * Construct a new AbstractXSLengthFacet optionally allowing the whiteSpace facet to be set + * to 'replace' and 'preserve' values in addition to 'collaps'. + * + * @param whiteSpaceCollapseOnly If set to true only 'collapse' is allowed for the whiteSpace + * facet. If set to false 'collaps', 'replace' and 'preserve' values are allowed for + * whiteSpace facet. + */ + protected AbstractLengthFacet(final boolean whiteSpaceCollapseOnly) { + super(whiteSpaceCollapseOnly); + } + + //-------------------------------------------------------------------------- + + /** + * Returns true if a length has been set. + * + * @return True if a length has been set. + */ + public final boolean hasLength() { + return (_length > 0); + } + + /** + * Returns the length that this type must have. + * + * @return The length that this type must have. + */ + public final int getLength() { + return _length; + } + + /** + * Sets the length of this type. While setting the length, the maxLength + * and minLength are also set up to this length. + * + * @param length The length to set. + */ + public final void setLength(final int length) { + _length = length; + + setMaxLength(length); + setMinLength(length); + } + + /** + * Returns true if a maximum length has been set. + * + * @return True if a maximum length has been set. + */ + public final boolean hasMaxLength() { + return (_maxLength >= 0); + } + + /** + * Returns the maximum length occurances of this type can be. A negative value denotes + * no maximum length. + * + * @return The maximum length facet. + */ + public final int getMaxLength() { + return _maxLength; + } + + /** + * Sets the maximum length of this type. To remove the max length facet, + * use a negative value. + * + * @param maxLength The maximum length for occurances of this type. + */ + public final void setMaxLength(final int maxLength) { + _maxLength = maxLength; + } + + /** + * Returns true if a minimum length has been set. + * + * @return True if a minimum length has been set. + */ + public final boolean hasMinLength() { + return (_minLength > 0); + } + + /** + * Returns the minimum length occurances of this type can be. + * + * @return The minimum length facet. + */ + public final int getMinLength() { + return _minLength; + } + + /** + * Sets the minimum length of this XSString. + * + * @param minLength The minimum length for occurances of this type. + */ + public final void setMinLength(final int minLength) { + _minLength = minLength; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + protected final void setFacet(final Facet facet) { + addPatternFacet(facet); + setWhiteSpaceFacet(facet); + setLengthFacet(facet); + } + + /** + * Transfer given facet if it is one of length, maxLength or minLength. + * + * @param facet The facet to transfer. + */ + protected final void setLengthFacet(final Facet facet) { + String name = facet.getName(); + if (Facet.LENGTH.equals(name)) { + setLength(facet.toInt()); + } else if (Facet.MAX_LENGTH.equals(name)) { + setMaxLength(facet.toInt()); + } else if (Facet.MIN_LENGTH.equals(name)) { + setMinLength(facet.toInt()); + } + } + + /** + * Generate the source code for length, maxLength or minLength facets validation. + * + * @param jsc The JSourceCode to fill in. + * @param validatorName The name of the TypeValidator that the patterns should be added to. + */ + protected final void codeLengthFacet(final JSourceCode jsc, final String validatorName) { + if (hasLength()) { + jsc.add("{0}.setLength({1});", validatorName, Integer.toString(getLength())); + } else { + if (hasMaxLength()) { + jsc.add("{0}.setMaxLength({1});", validatorName, Integer.toString(getMaxLength())); + } + if (hasMinLength()) { + jsc.add("{0}.setMinLength({1});", validatorName, Integer.toString(getMinLength())); + } + } + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractPatternFacet.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractPatternFacet.java (revision 0) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractPatternFacet.java (revision 0) @@ -0,0 +1,109 @@ +/* + * Copyright 2006-2007 Keith Visco, Edward Kuns + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.exolab.castor.builder.types; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.exolab.castor.xml.schema.Facet; +import org.exolab.javasource.JSourceCode; + +/** + * A base class for types which support the pattern facet. + * + * @author Keith Visco + * @author Edward Kuns + * @version $Revision: 6678 $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ + * @since 1.1 + */ +public abstract class AbstractPatternFacet extends XSType { + //-------------------------------------------------------------------------- + + /** The list of pattern facets. */ + private List _patterns = new LinkedList(); + + //-------------------------------------------------------------------------- + + /** + * Adds a pattern branch for this XSType. To successfully pass the pattern + * facets, only one branch needs to pass. + * + * @param pattern The regular expression for this XSType. + */ + public final void addPattern(final String pattern) { + _patterns.add(pattern); + } + + /** + * Get list of pattern facets. + * + * @return List of pattern facets. + */ + public final List getPatterns() { + return _patterns; + } + + //-------------------------------------------------------------------------- + + /** + * Transfer given facet if it is a pattern. + * + * @param facet The facet to transfer. + */ + protected final void addPatternFacet(final Facet facet) { + if (Facet.PATTERN.equals(facet.getName())) { addPattern(facet.getValue()); } + } + + /** + * Generate the source code for pattern facet validation. + * + * @param jsc The JSourceCode to fill in. + * @param validatorName The name of the TypeValidator that the patterns should be added to. + */ + protected final void codePatternFacet(final JSourceCode jsc, final String validatorName) { + for (Iterator i = _patterns.iterator(); i.hasNext(); ) { + jsc.add("{0}.addPattern(\"{1}\");", validatorName, escapePattern((String) i.next())); + } + } + + /** + * Escapes special characters in the given String so that it can be printed correctly. + * + * @param str The String to escape. + * @return The escaped String, or null if the given String was null. + */ + private static String escapePattern(final String str) { + if (str == null) { return str; } + + //-- make sure we have characters to escape + if (str.indexOf('\\') < 0 && str.indexOf('\"') < 0) { return str; } + + StringBuffer sb = new StringBuffer(); + + char[] chars = str.toCharArray(); + for (int i = 0; i < chars.length; i++) { + char ch = chars[i]; + if (ch == '\\') { sb.append(ch); } + if (ch == '\"') { sb.append('\\'); } + sb.append(ch); + } + + return sb.toString(); + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractRangeFacet.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractRangeFacet.java (revision 0) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractRangeFacet.java (revision 0) @@ -0,0 +1,194 @@ +/* + * Copyright 2007 Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.exolab.castor.builder.types; + +import org.exolab.castor.xml.schema.Facet; +import org.exolab.javasource.JSourceCode; + +/** + * A base class for types which support the range, whiteSpace and pattern facets. + * + * @author Ralf Joachim + * @version $Revision: 6623 $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ + * @since 1.1 + */ +public abstract class AbstractRangeFacet extends AbstractWhiteSpaceFacet { + //-------------------------------------------------------------------------- + + /** Maximum Date (exclusive). */ + private String _maxExclusive; + + /** Maximum Date (inclusive). */ + private String _maxInclusive; + + /** Minimum Date (exclusive). */ + private String _minExclusive; + + /** Minimum Date (inclusive). */ + private String _minInclusive; + + //-------------------------------------------------------------------------- + + /** + * Returns true if a maximum (inclusive or exclusive) has been set. + * + * @return True if a maximum (inclusive or exclusive) has been set. + */ + public final boolean hasMaximum() { + return (_maxInclusive != null) || (_maxExclusive != null); + } + + /** + * Returns the maximum exclusive value that this XSDate can hold. + * + * @return The maximum exclusive value that this XSDate can hold. If + * no maximum exclusive value has been set, Null will be returned. + */ + public final String getMaxExclusive() { + return _maxExclusive; + } + + /** + * Sets the maximum exclusive value that this XSDate can hold. + * + * @param max The maximum exclusive value this XSDate can be. + */ + public final void setMaxExclusive(final String max) { + _maxExclusive = max; + _maxInclusive = null; + } + + /** + * Returns the maximum inclusive value that this XSDate can hold. + * + * @return The maximum inclusive value that this XSDate can hold. If + * no maximum inclusive value has been set, Null will be returned. + */ + public final String getMaxInclusive() { + return _maxInclusive; + } + + /** + * Sets the maximum inclusive value that this XSDate can hold. + * + * @param max The maximum inclusive value this XSDate can be. + */ + public final void setMaxInclusive(final String max) { + _maxInclusive = max; + _maxExclusive = null; + } + + /** + * Returns true if a minimum (inclusive or exclusive) has been set. + * + * @return True if a minimum (inclusive or exclusive) has been set. + */ + public final boolean hasMinimum() { + return (_minInclusive != null) || (_minExclusive != null); + } + + /** + * Returns the minimum exclusive value that this XSDate can hold. + * + * @return The minimum exclusive value that this XSDate can hold. If + * no minimum exclusive value has been set, Null will be returned. + */ + public final String getMinExclusive() { + return _minExclusive; + } + + /** + * Sets the minimum exclusive value that this XSDate can hold. + * + * @param min The minimum exclusive value this XSDate can be. + */ + public final void setMinExclusive(final String min) { + _minExclusive = min; + _minInclusive = null; + } + + /** + * Returns the minimum inclusive value that this XSDate can hold. + * + * @return The minimum inclusive value that this XSDate can be. + */ + public final String getMinInclusive() { + return _minInclusive; + } + + /** + * Sets the minimum inclusive value that this XSDate can hold. + * + * @param min The minimum inclusive value this XSDate can be. + */ + public final void setMinInclusive(final String min) { + _minInclusive = min; + _minExclusive = null; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + protected void setFacet(final Facet facet) { + addPatternFacet(facet); + setWhiteSpaceFacet(facet); + setRangeFacet(facet); + } + + /** + * Transfer given facet if it is a range. + * + * @param facet The facet to transfer. + */ + protected final void setRangeFacet(final Facet facet) { + String name = facet.getName(); + if (Facet.MAX_EXCLUSIVE.equals(name)) { + setMaxExclusive(facet.getValue()); + } else if (Facet.MAX_INCLUSIVE.equals(name)) { + setMaxInclusive(facet.getValue()); + } else if (Facet.MIN_EXCLUSIVE.equals(name)) { + setMinExclusive(facet.getValue()); + } else if (Facet.MIN_INCLUSIVE.equals(name)) { + setMinInclusive(facet.getValue()); + } + } + + /** + * Generate the source code for pattern facet validation. + * + * @param jsc The JSourceCode to fill in. + * @param validatorName The name of the TypeValidator that the range should be added to. + */ + protected final void codeRangeFacet(final JSourceCode jsc, final String validatorName) { + // maxInclusive / maxExclusive facets (only one or the other, never both) + if (_maxInclusive != null) { + jsc.add("{0}.setMaxInclusive(\"{1}\");", validatorName, getMaxInclusive()); + } else if (_maxExclusive != null) { + jsc.add("{0}.setMaxExclusive(\"{1}\");", validatorName, getMaxExclusive()); + } + + // minInclusive / minExclusive facets (only one or the other, never both) + if (_minInclusive != null) { + jsc.add("{0}.setMinInclusive(\"{1}\");", validatorName, getMinInclusive()); + } else if (_minExclusive != null) { + jsc.add("{0}.setMinExclusive(\"{1}\");", validatorName, getMinExclusive()); + } + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractWhiteSpaceFacet.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractWhiteSpaceFacet.java (revision 0) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/AbstractWhiteSpaceFacet.java (revision 0) @@ -0,0 +1,141 @@ +/* + * Copyright 2007 Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.exolab.castor.builder.types; + +import org.exolab.castor.xml.schema.Facet; +import org.exolab.javasource.JSourceCode; + +/** + * A base class for types which support the whiteSpace and pattern facets. + * + * @author Ralf Joachim + * @version $Revision: 6678 $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ + * @since 1.1 + */ +public abstract class AbstractWhiteSpaceFacet extends AbstractPatternFacet { + //-------------------------------------------------------------------------- + + /** If set to true only 'collapse' is allowed for the whiteSpace facet. If set to false + * 'collaps', 'replace' and 'preserve' values are allowed for whiteSpace facet. */ + private final boolean _whiteSpaceCollapseOnly; + + /** The whiteSpace facet. */ + private String _whiteSpace = Facet.WHITESPACE_COLLAPSE; + + //-------------------------------------------------------------------------- + + /** + * No-arg constructor. By default only 'collapse' is supported for the whiteSpace facet. + */ + protected AbstractWhiteSpaceFacet() { + this(true); + } + + /** + * Construct a new AbstractXSPatternFacet optionally allowing the whiteSpace facet to be set + * to 'replace' and 'preserve' values in addition to 'collaps'. + * + * @param whiteSpaceCollapseOnly If set to true only 'collapse' is allowed for the whiteSpace + * facet. If set to false 'collaps', 'replace' and 'preserve' values are allowed for + * whiteSpace facet. + */ + protected AbstractWhiteSpaceFacet(final boolean whiteSpaceCollapseOnly) { + _whiteSpaceCollapseOnly = whiteSpaceCollapseOnly; + } + + //-------------------------------------------------------------------------- + + /** + * Returns true if the whiteSpace facet is used. + * + * @return True if the whiteSpace facet is used. + */ + public final boolean hasWhiteSpace() { + return (_whiteSpace != null); + } + + /** + * Returns the whiteSpace facet of this type. + * + * @return The whiteSpace facet of this type. + */ + public final String getWhiteSpace() { + return _whiteSpace; + } + + /** + * Sets the whiteSpace facet of this XSType. The value of the whiteSpace + * facet must be one of the following: + * + * Any other value will generate a warning and the whiteSpace facet keeps unchanged. + * + * @param value The value for the whiteSpace facet. + */ + public final void setWhiteSpace(final String value) { + if (Facet.WHITESPACE_COLLAPSE.equals(value)) { + _whiteSpace = value; + } else if (!_whiteSpaceCollapseOnly) { + if (Facet.WHITESPACE_REPLACE.equals(value)) { + _whiteSpace = value; + } else if (Facet.WHITESPACE_PRESERVE.equals(value)) { + _whiteSpace = value; + } else { + throw new IllegalArgumentException( + getName() + ": bad entry for whiteSpace facet: " + value); + } + } else { + throw new IllegalArgumentException( + getName() + ": only 'collapse' allowed for whiteSpace facet: " + value); + } + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + protected void setFacet(final Facet facet) { + addPatternFacet(facet); + setWhiteSpaceFacet(facet); + } + + /** + * Transfer given facet if it is a whiteSpace. + * + * @param facet The facet to transfer. + */ + protected final void setWhiteSpaceFacet(final Facet facet) { + if (Facet.WHITESPACE.equals(facet.getName())) { setWhiteSpace(facet.getValue()); } + } + + /** + * Generate the source code for pattern facet validation. + * + * @param jsc The JSourceCode to fill in. + * @param validatorName The name of the TypeValidator that the whiteSpace should be added to. + */ + protected final void codeWhiteSpaceFacet(final JSourceCode jsc, final String validatorName) { + if (!_whiteSpaceCollapseOnly && hasWhiteSpace()) { + jsc.add("{0}.setWhiteSpace(\"{1}\");", validatorName, getWhiteSpace()); + } + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSAnyURI.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSAnyURI.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSAnyURI.java (working copy) @@ -1,50 +1,20 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -50,78 +20,79 @@ import org.exolab.javasource.JType; /** - * The XML Schema xsd:anyURI type. + * The xsd:anyURI XML Schema type. * - * @author Arnaud Blandin + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSAnyURI extends XSType { - // FIXME This type does not appear to be implemented. +public final class XSAnyURI extends AbstractLengthFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "anyURI"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.ANYURI_TYPE; + + /** The JType represented by this XSType. */ + private static final JType JTYPE = new JClass("java.lang.String"); + + //-------------------------------------------------------------------------- /** - * The JType represented by this XSType. - * It could be better to use the org.apache.xerces.utils.URI - * pro : represent a real URI - * con : the source code generated must rely on Xerces + * {@inheritDoc} */ - private static final JType JTYPE = new JClass("java.lang.String"); + public String getName() { return NAME; } /** - * No-arg constructor. + * {@inheritDoc} */ - public XSAnyURI() { - super(XSType.ANYURI_TYPE); - } + public short getType() { return TYPE; } /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types. - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} + */ + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} */ - public String createFromJavaObjectCode(final String variableName) { - return "(java.lang.String) " + variableName; - } //-- fromJavaObject + public JType getJType() { return JTYPE; } /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - // Not implemented. + public String newInstanceCode() { + return "new java.lang.String();"; } - + /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSAnyURI.JTYPE; + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + return "(java.lang.String) " + variableName; } + //-------------------------------------------------------------------------- + /** - * Creates the validation code for an instance of this XSType. The - * validation code should, if necessary, create a newly configured - * TypeValidator that should then be added to the FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - // TODO VALIDATE THE URI + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + // Not implemented } - -} //-- XSAnyURI +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSBase64Binary.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSBase64Binary.java (revision 0) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSBase64Binary.java (revision 0) @@ -0,0 +1,115 @@ +/* + * Copyright 2007 Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.exolab.castor.builder.types; + +import org.exolab.javasource.JArrayType; +import org.exolab.javasource.JSourceCode; +import org.exolab.javasource.JType; + +/** + * The xsd:base64Binary XML Schema datatype. + * + * @author Ralf Joachim + * @version $Revision: 6623 $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ + * @since 1.1 + */ +public final class XSBase64Binary extends AbstractLengthFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "base64Binary"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.BASE64BINARY_TYPE; + + //-------------------------------------------------------------------------- + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- + + /** + * Create a new XSBase64Binary object. + * + * @param useJava50 If true, Java 5 code artifacts will be generated. + */ + public XSBase64Binary(final boolean useJava50) { + super(); + + _jType = new JArrayType(JType.BYTE, useJava50); + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + + /** + * {@inheritDoc} + */ + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new byte[] {};"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().toString() + ") " + variableName; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + // Not implemented + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSBinary.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSBinary.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSBinary.java (working copy) @@ -1,122 +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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ - */ -package org.exolab.castor.builder.types; - -import org.exolab.castor.xml.schema.SimpleType; -import org.exolab.javasource.JArrayType; -import org.exolab.javasource.JSourceCode; -import org.exolab.javasource.JType; - -/** - * The binary XML Schema datatype. - *

- * This class represents both xsd:hexBinary and xsd:base64Binary. No - * distinction is made between the two types. - * @author Keith Visco - * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ - */ -public final class XSBinary extends XSType { - - /** The JType represented by this XSType. */ - private final JType _jType; - - /** - * Create a new XSBinary object to represent either base64binary or - * hexbinary. - * - * @param type - * The type to use, must be one of XSType.BASE64BINARY_TYPE or - * XSType.HEXBINARY_TYPE. - * @param useJava50 - * if true, Java 5 code artifacts will be generated. - */ - public XSBinary(final short type, final boolean useJava50) { - super(type); - if (type != XSType.BASE64BINARY_TYPE && type != XSType.HEXBINARY_TYPE) { - throw new IllegalArgumentException("Value " + type - + " not allowed for an XML Schema binary."); - } - _jType = new JArrayType(JType.BYTE, useJava50); - } //-- XSBinary - - /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets - */ - public void setFacets(final SimpleType simpleType) { - // Not implemented. - } - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public JType getJType() { - return this._jType; - } //-- getJType - - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - //--TBD - } - -} //-- XSBinary Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSBoolean.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSBoolean.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSBoolean.java (working copy) @@ -1,50 +1,20 @@ /* - * 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. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -50,18 +20,31 @@ import org.exolab.javasource.JType; /** - * The boolean XML Schema datatype. + * The xsd:boolean XML Schema datatype. * - * @author Keith Visco + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ */ -public final class XSBoolean extends XSType { +public final class XSBoolean extends AbstractWhiteSpaceFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "boolean"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.BOOLEAN_TYPE; + + //-------------------------------------------------------------------------- /** The JType represented by this XSType. */ private final JType _jType; + /** True if this type is implemented using the wrapper class. */ private final boolean _asWrapper; + //-------------------------------------------------------------------------- + /** * No-arg constructor. */ @@ -71,12 +54,13 @@ /** * Constructs a new XSBoolean. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ public XSBoolean(final boolean asWrapper) { - super(XSType.BOOLEAN_TYPE); + super(); + _asWrapper = asWrapper; - if (_asWrapper) { _jType = new JClass("java.lang.Boolean"); } else { @@ -82,93 +66,76 @@ } else { _jType = JType.BOOLEAN; } - } //-- XSBoolean + } + + //-------------------------------------------------------------------------- /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return _jType; - } //-- getJType + public String getName() { return NAME; } /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - // Not implemented - } + public short getType() { return TYPE; } /** - * Returns the String necessary to convert an instance of this XSType to an - * Object. This method is really only useful for primitive types - * - * @param variableName - * the name of the instance variable - * @return the String necessary to convert an instance of this XSType to an - * Object + * {@inheritDoc} */ - public String createToJavaObjectCode(final String variableName) { - if (_asWrapper) { - return super.createToJavaObjectCode(variableName); - } + public boolean isPrimitive() { return true; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } - StringBuffer sb = new StringBuffer("("); - sb.append(variableName); - sb.append(" ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE)"); - return sb.toString(); - } //-- toJavaObject + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.Boolean(false);"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } + return "(" + variableName + " ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE)"; + } /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} */ public String createFromJavaObjectCode(final String variableName) { - StringBuffer sb = new StringBuffer("((java.lang.Boolean) "); - sb.append(variableName); - sb.append(")"); - if (!_asWrapper) { - sb.append(".booleanValue()"); - } - return sb.toString(); - } //-- fromJavaObject + if (_asWrapper) { return "((java.lang.Boolean) " + variableName + ")"; } + return "((java.lang.Boolean) " + variableName + ").booleanValue()"; + } + + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.BooleanValidator typeValidator" - + " = new org.exolab.castor.xml.validators.BooleanValidator();"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.BooleanValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.BooleanValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); if (fixedValue != null) { - Boolean.valueOf(fixedValue); - jsc.add("typeValidator.setFixed("); - jsc.append(fixedValue); - jsc.append(");"); + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); } - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); } -} //-- XSBoolean + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSByte.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSByte.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSByte.java (working copy) @@ -1,53 +1,20 @@ /* - * 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 2001-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -53,27 +20,36 @@ import org.exolab.javasource.JType; /** - * The XML Schema xsd:byte type. + * The xsd:byte XML Schema type. + * * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ */ -public final class XSByte extends XSPatternBase { +public final class XSByte extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- - /** Maximum byte (inclusive). */ - private Byte _maxInclusive = null; - /** Maximum byte (exclusive). */ - private Byte _maxExclusive = null; - /** Minimum byte (inclusive). */ - private Byte _minInclusive = null; - /** Minimum byte (exclusive). */ - private Byte _minExclusive = null; - /** Total number of digits. */ - private int _totalDigits = -1; + /** Name of this XSType. */ + public static final String NAME = "byte"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.BYTE_TYPE; + + /** A constant holding the minimum value an xsd:byte can have, -27. */ + public static final String MIN_VALUE = Byte.toString(Byte.MIN_VALUE); + + /** A constant holding the maximum value an xsd:byte can have, 27-1. */ + public static final String MAX_VALUE = Byte.toString(Byte.MAX_VALUE); + + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; /** The JType represented by this XSType. */ private final JType _jType; - /** True if this type is implemented using the wrapper class. */ - private final boolean _asWrapper; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -84,12 +60,13 @@ /** * Constructs a new XSByte. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ public XSByte(final boolean asWrapper) { - super(XSType.BYTE_TYPE); + super(); + _asWrapper = asWrapper; - if (_asWrapper) { _jType = new JClass("java.lang.Byte"); } else { @@ -95,322 +72,90 @@ } else { _jType = JType.BYTE; } - } //-- XSByte - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public JType getJType() { - return _jType; } - /** - * Returns the maximum exclusive value that this XSByte can hold. - * - * @return the maximum exclusive value that this XSByte can hold. If no - * maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive - */ - public Byte getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive + //-------------------------------------------------------------------------- /** - * Returns the maximum inclusive value that this XSByte can hold. - * - * @return the maximum inclusive value that this XSByte can hold. If no - * maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive + * {@inheritDoc} */ - public Byte getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive + public String getName() { return NAME; } /** - * Returns the minimum exclusive value that this XSByte can hold. - * - * @return the minimum exclusive value that this XSByte can hold. If no - * minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive() - * @see #setMaxInclusive(byte) + * {@inheritDoc} */ - public Byte getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + public short getType() { return TYPE; } /** - * Returns the minimum inclusive value that this XSByte can hold. - * - * @return the minimum inclusive value that this XSByte can hold. If no - * minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive + * {@inheritDoc} */ - public Byte getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive - + public boolean isPrimitive() { return true; } + /** - * Returns the totalDigits facet value of this XSInteger. - * @return the totalDigits facet value of this XSInteger. + * {@inheritDoc} */ - public int getTotalDigits() { - return _totalDigits; - } - + public boolean isDateTime() { return false; } + /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } //-- hasMaximum + public JType getJType() { return _jType; } /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; - } //-- hasMinimum - - /** - * Sets the maximum exclusive value that this XSByte can hold. - * - * @param max - * the maximum exclusive value this XSByte can be - * @see #setMaxInclusive(Byte) - */ - public void setMaxExclusive(final byte max) { - _maxExclusive = new Byte(max); - _maxInclusive = null; - } //-- setMaxExclusive - - /** - * Sets the maximum exclusive value that this XSByte can hold. - * - * @param max - * the maximum exclusive value this XSByte can be - * @see #setMaxInclusive(byte) - */ - public void setMaxExclusive(final Byte max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive - - /** - * Sets the maximum inclusive value that this XSByte can hold. - * - * @param max - * the maximum inclusive value this XSByte can be - * @see #setMaxExclusive(Byte) - */ - public void setMaxInclusive(final byte max) { - _maxInclusive = new Byte(max); - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the maximum inclusive value that this XSByte can hold. - * - * @param max - * the maximum inclusive value this XSByte can be - * @see #setMaxExclusive(byte) - */ - public void setMaxInclusive(final Byte max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - + public String newInstanceCode() { + return "new java.lang.Byte((byte) 0);"; + } + /** - * Sets the minimum exclusive value that this XSByte can hold. - * - * @param min - * the minimum exclusive value this XSByte can be - * @see #setMinInclusive(Byte) - */ - public void setMinExclusive(final byte min) { - _minExclusive = new Byte(min); - _minInclusive = null; - } //-- setMinExclusive - - /** - * Sets the minimum exclusive value that this XSByte can hold. - * - * @param min - * the minimum exclusive value this XSByte can be - * @see #setMinInclusive(byte) - */ - public void setMinExclusive(final Byte min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - - /** - * Sets the minimum inclusive value that this XSByte can hold. - * - * @param min - * the minimum inclusive value this XSByte can be - * @see #setMinExclusive(Byte) - */ - public void setMinInclusive(final byte min) { - _minInclusive = new Byte(min); - _minExclusive = null; - } //-- setMinInclusive - - /** - * Sets the minimum inclusive value that this XSByte can hold. - * - * @param min - * the minimum inclusive value this XSByte can be - * @see #setMinExclusive(byte) - */ - public void setMinInclusive(final Byte min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Sets the totalDigits facet for this XSByte. - * @param totalDig the value of totalDigits (must be > 0). - */ - public void setTotalDigits(final int totalDig) { - if (totalDig <= 0) { - throw new IllegalArgumentException(this.getName() - + ": the totalDigits facet must be positive"); - } - _totalDigits = totalDig; - } - - /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets - */ - public void setFacets(final SimpleType simpleType) { - //-- copy valid facets - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_EXCLUSIVE.equals(name)) { - setMaxExclusive(facet.toByte()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - setMaxInclusive(facet.toByte()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - setMinExclusive(facet.toByte()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - setMinInclusive(facet.toByte()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.TOTALDIGITS.equals(name)) { - setTotalDigits(facet.toInt()); - } else if (Facet.FRACTIONDIGITS.equals(name)) { - if (facet.toInt() != 0) { - throw new IllegalArgumentException("fractionDigits must be 0 for " - + this.getName()); - } - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - throw new IllegalArgumentException("Warning: The facet 'whitespace'" - + " can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'byte'."); - } - } - } - } //-- setFacets - - /** - * Returns the String necessary to convert an instance of this XSType to an - * Object. This method is really only useful for primitive types - * - * @param variableName - * the name of the instance variable - * @return the String necessary to convert an instance of this XSType to an - * Object + * {@inheritDoc} */ public String createToJavaObjectCode(final String variableName) { - if (_asWrapper) { - return super.createToJavaObjectCode(variableName); - } - - return "new Byte(" + variableName + ")"; - } //-- toJavaObject + if (_asWrapper) { return variableName; } + return "new java.lang.Byte(" + variableName + ")"; + } /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} */ public String createFromJavaObjectCode(final String variableName) { - StringBuffer sb = new StringBuffer("((Byte) " + variableName + ")"); - if (!_asWrapper) { - sb.append(".byteValue()"); - } - return sb.toString(); - } //-- fromJavaObject + if (_asWrapper) { return "((java.lang.Byte) " + variableName + ")"; } + return "((java.lang.Byte) " + variableName + ").byteValue()"; + } + + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.ByteValidator typeValidator" - + " = new org.exolab.castor.xml.validators.ByteValidator();"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.ByteValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.ByteValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (_minExclusive != null) { - jsc.add("typeValidator.setMinExclusive((byte) " + _minExclusive + ");"); - } else if (_minInclusive != null) { - jsc.add("typeValidator.setMinInclusive((byte) " + _minInclusive + ");"); + if (fixedValue != null) { + jsc.add("typeValidator.setFixed((byte) " + fixedValue + ");"); } - if (_maxExclusive != null) { - jsc.add("typeValidator.setMaxExclusive((byte) " + _maxExclusive + ");"); - } else if (_maxInclusive != null) { - jsc.add("typeValidator.setMaxInclusive((byte) " + _maxInclusive + ");"); - } + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - // fixed values - if (fixedValue != null) { - //-- make sure we have a valid value... - Byte.parseByte(fixedValue); - jsc.add("typeValidator.setFixed("); - jsc.append("(byte) "); - jsc.append(fixedValue); - jsc.append(");"); + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive((byte) " + getMinExclusive() + ");"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive((byte) " + getMinInclusive() + ");"); } - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - // totalDigits - int totalDigits = getTotalDigits(); - if (totalDigits != -1) { - jsc.add("typeValidator.setTotalDigits("); - jsc.append(Integer.toString(totalDigits)); - jsc.append(");"); + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive((byte) " + getMaxExclusive() + ");"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive((byte) " + getMaxInclusive() + ");"); } - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + codeDigitsFacet(jsc, "typeValidator"); } -} //-- XSByte + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSClass.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSClass.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSClass.java (working copy) @@ -1,50 +1,21 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import org.exolab.castor.xml.schema.SimpleType; +import org.exolab.castor.xml.schema.Facet; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -51,83 +22,117 @@ /** * The XML Schema user-defined archetype. - * @author Keith Visco + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $ */ public final class XSClass extends XSType { + //-------------------------------------------------------------------------- + + /** Type number of this XSType. */ + public static final short TYPE = XSType.CLASS; + + //-------------------------------------------------------------------------- + + /** Name of this type. */ + private final String _name; /** The JClass represented by this type. */ - private final JClass _jClass; - /** Name of this type. */ - private final String _name; + private final JClass _jClass; + + //-------------------------------------------------------------------------- /** * Creates a new XSClass with the given JClass reference. - * @param jClass the JClass type of this XSClass + * + * @param jClass The JClass type of this XSClass. */ public XSClass(final JClass jClass) { this(jClass, null); - } //-- XSClass + } /** * Creates a new XSClass with the given JClass reference. - * @param jClass the JClass associated with this XSType - * @param schemaTypeName The XML Schema type name + * + * @param jClass The JClass associated with this XSType. + * @param schemaTypeName The XML Schema type name. */ public XSClass(final JClass jClass, final String schemaTypeName) { - super(XSType.CLASS); - this._jClass = jClass; + super(); + + _jClass = jClass; if (schemaTypeName != null) { - this._name = schemaTypeName; + _name = schemaTypeName; } else { - this._name = jClass.getName(); + _name = jClass.getName(); } - } //-- XSClass + } + + //-------------------------------------------------------------------------- /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - // Not implemented? - } + public String getName() { return _name; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} + */ + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} */ - public JType getJType() { - return this._jClass; - } //-- getJType + public JType getJType() { return _jClass; } /** - * Returns the name of this class. - * @return the name of this class. + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new " + getJType().getName() + "();"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + + /** + * {@inheritDoc} */ - public String getName() { - return this._name; - } //-- getName + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().getName() + ") " + variableName; + } + + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - //--TBD + protected void setFacet(final Facet facet) { + // Not implemented } -} //-- XSClass + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + // Not implemented + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDate.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDate.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDate.java (working copy) @@ -1,54 +1,20 @@ /* - * 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 2000-2002 (C) Intalio, Inc. All Rights Reserved. - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -54,13 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema Date type. - * @author Arnaud Blandin + * The xsd:date XML Schema type. + * + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSDate extends XSPatternBase { - /** Jakarta's common-logging logger. */ - private static final Log LOG = LogFactory.getLog(XSDate.class); +public final class XSDate extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "date"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.DATE_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("org.exolab.castor.types.Date"); @@ -65,235 +38,106 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("org.exolab.castor.types.Date"); - /** Maximum Date (inclusive). */ - private String _maxInclusive; - /** Maximum Date (exclusive). */ - private String _maxExclusive; - /** Minimum Date (inclusive). */ - private String _minInclusive; - /** Minimum Date (exclusive). */ - private String _minExclusive; - - /** - * No-Arg constructor. - */ - public XSDate() { - super(XSType.DATE_TYPE); - } //-- XSDate - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public JType getJType() { - return XSDate.JTYPE; - } - - /** - * Returns the maximum exclusive value that this XSDate can hold. - * @return the maximum exclusive value that this XSDate can hold. If - * no maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive - */ - public String getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive - - /** - * Returns the maximum inclusive value that this XSDate can hold. - * @return the maximum inclusive value that this XSDate can hold. If - * no maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive - */ - public String getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive - - /** - * Returns the minimum exclusive value that this XSDate can hold. - * @return the minimum exclusive value that this XSDate can hold. If - * no minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive - */ - public String getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + //-------------------------------------------------------------------------- /** - * Returns the minimum inclusive value that this XSDate can hold. - * @return the minimum inclusive value that this XSDate can be. - * @see #getMinExclusive + * {@inheritDoc} */ - public String getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive + public String getName() { return NAME; } /** - * Sets the maximum exclusive value that this XSDate can hold. - * @param max the maximum exclusive value this XSDate can be - * @see #setMaxInclusive + * {@inheritDoc} */ - public void setMaxExclusive(final String max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive + public short getType() { return TYPE; } /** - * Sets the maximum inclusive value that this XSDate can hold. - * @param max the maximum inclusive value this XSDate can be - * @see #setMaxExclusive + * {@inheritDoc} */ - public void setMaxInclusive(final String max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - + public boolean isPrimitive() { return false; } + /** - * Sets the minimum exclusive value that this XSDate can hold. - * @param min the minimum exclusive value this XSDate can be - * @see #setMinInclusive + * {@inheritDoc} */ - public void setMinExclusive(final String min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - + public boolean isDateTime() { return true; } + /** - * Sets the minimum inclusive value that this XSDate can hold. - * @param min the minimum inclusive value this XSDate can be - * @see #setMinExclusive + * {@inheritDoc} */ - public void setMinInclusive(final String min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive + public JType getJType() { return JTYPE; } /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; + public String newInstanceCode() { + return "new " + getJType().getName() + "();"; } - + /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; + public String createToJavaObjectCode(final String variableName) { + return variableName; } - + /** - * Transfer facets from the provided simpleType to this. The - * Date SimpleType supports the following facets: - *

- * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().getName() + ") " + variableName; + } - if (Facet.MAX_EXCLUSIVE.equals(name)) { - this.setMaxExclusive(facet.getValue()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - this.setMaxInclusive(facet.getValue()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - this.setMinExclusive(facet.getValue()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - this.setMinInclusive(facet.getValue()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - LOG.warn("Warning: The facet 'whitespace' can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'date'."); - } - } - } //while - } //setFacets + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator =" - + " new org.exolab.castor.xml.validators.DateTimeValidator();"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DateTimeValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - boolean addTryCatch = _minInclusive != null || _minExclusive != null - || _maxInclusive != null || _maxExclusive != null || fixedValue != null; - - if (addTryCatch) { - jsc.add("try {"); - jsc.indent(); + if (fixedValue != null) { + jsc.add("try {\n" + + " typeValidator.setFixed({0});\n" + + "} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", fixedValue); } - // minInclusive / minExclusive facets (only one or the other, never both) - if (_minInclusive != null) { - jsc.add("org.exolab.castor.types.Date min = " - + "org.exolab.castor.types.Date.parseDate(\"" + _minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } else if (_minExclusive != null) { - jsc.add("org.exolab.castor.types.Date min = " - + "org.exolab.castor.types.Date.parseDate(\"" + _minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } - - // maxInclusive / maxExclusive facets (only one or the other, never both) - if (_maxInclusive != null) { - jsc.add("org.exolab.castor.types.Date max = " - + "org.exolab.castor.types.Date.parseDate(\"" + _maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); - } else if (_maxExclusive != null) { - jsc.add("org.exolab.castor.types.Date max = " - + "org.exolab.castor.types.Date.parseDate(\"" + _maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - // fixed values - if (fixedValue != null) { - jsc.add("typeValidator.setFixed(" + fixedValue + ");"); - } + if (hasMinimum() || hasMaximum()) { + jsc.add("try {"); - if (addTryCatch) { - jsc.unindent(); - jsc.add("} catch (java.text.ParseException pe) {"); - jsc.indent(); - jsc.add("System.out.println(\"ParseException\" + pe);"); - jsc.unindent(); - jsc.add("}"); - } + // minInclusive / minExclusive facets (only one or the other, never both) + if (getMinInclusive() != null) { + jsc.add(" org.exolab.castor.types.Date min;\n" + + " min = org.exolab.castor.types.Date.parseDate(\"{0}\");\n" + + " typeValidator.setMinInclusive(min);", getMinInclusive()); + } else if (getMinExclusive() != null) { + jsc.add(" org.exolab.castor.types.Date min;\n" + + " min = org.exolab.castor.types.Date.parseDate(\"{0}\");\n" + + " typeValidator.setMinExclusive(min);", getMinExclusive()); + } - // pattern facet - codePatternFacet(jsc, "typeValidator"); + // maxInclusive / maxExclusive facets (only one or the other, never both) + if (getMaxInclusive() != null) { + jsc.add(" org.exolab.castor.types.Date max;\n" + + " max = org.exolab.castor.types.Date.parseDate(\"{0}\");\n" + + " typeValidator.setMaxInclusive(max);", getMaxInclusive()); + } else if (getMaxExclusive() != null) { + jsc.add(" org.exolab.castor.types.Date max;\n" + + " max = org.exolab.castor.types.Date.parseDate(\"{0}\");\n" + + " typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + jsc.add("} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", ""); + } } -} //-- XSDate + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDateTime.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDateTime.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDateTime.java (working copy) @@ -1,55 +1,20 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -55,13 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema dateTime type. - * @author Keith Visco + * The xsd:dateTime XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ */ -public final class XSDateTime extends XSPatternBase { - /** Jakarta's common-logging logger. */ - private static final Log LOG = LogFactory.getLog(XSDateTime.class); +public final class XSDateTime extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "dateTime"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.DATETIME_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.util.Date"); @@ -66,252 +38,109 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.util.Date"); - /** Maximum Date (inclusive). */ - private String _maxInclusive; - /** Maximum Date (exclusive). */ - private String _maxExclusive; - /** Minimum Date (inclusive). */ - private String _minInclusive; - /** Minimum Date (exclusive). */ - private String _minExclusive; - - /** - * No-Arg constructor. - */ - public XSDateTime() { - super(XSType.DATETIME_TYPE); - } //-- XSDateTime - - /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType - */ - public String createFromJavaObjectCode(final String variableName) { - return "(java.util.Date) " + variableName; - } //-- fromJavaObject + //-------------------------------------------------------------------------- /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSDateTime.JTYPE; - } + public String getName() { return NAME; } /** - * Returns the maximum exclusive value that this XSDateTime can hold. - * @return the maximum exclusive value that this XSDateTime can hold. If - * no maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive + * {@inheritDoc} */ - public String getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive + public short getType() { return TYPE; } /** - * Returns the maximum inclusive value that this XSDateTime can hold. - * @return the maximum inclusive value that this XSDateTime can hold. If - * no maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive + * {@inheritDoc} */ - public String getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive - + public boolean isPrimitive() { return false; } + /** - * Returns the minimum exclusive value that this XSDateTime can hold. - * @return the minimum exclusive value that this XSDateTime can hold. If - * no minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive + * {@inheritDoc} */ - public String getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive - + public boolean isDateTime() { return true; } + /** - * Returns the minimum inclusive value that this XSDateTime can hold. - * @return the minimum inclusive value that this XSDateTime can be. - * @see #getMinExclusive + * {@inheritDoc} */ - public String getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive + public JType getJType() { return JTYPE; } /** - * Sets the maximum exclusive value that this XSDateTime can hold. - * @param max the maximum exclusive value this XSDateTime can hold. - * @see #setMaxInclusive + * {@inheritDoc} */ - public void setMaxExclusive(final String max) { - _maxExclusive = max; - _maxInclusive = null; + public String newInstanceCode() { + return "new java.util.Date();"; } - + /** - * Sets the maximum inclusive value that this XSDateTime can hold. - * @param max the maximum inclusive value this XSDateTime can hold. - * @see #setMaxExclusive + * {@inheritDoc} */ - public void setMaxInclusive(final String max) { - _maxExclusive = null; - _maxInclusive = max; + public String createToJavaObjectCode(final String variableName) { + return variableName; } /** - * Sets the minimum exclusive value that this XSDateTime can hold. - * @param min the minimum exclusive value this XSDateTime can hold. - * @see #setMinInclusive + * {@inheritDoc} */ - public void setMinExclusive(final String min) { - _minExclusive = min; - _minInclusive = null; + public String createFromJavaObjectCode(final String variableName) { + return "(java.util.Date) " + variableName; } + + //-------------------------------------------------------------------------- /** - * Sets the minimum inclusive value that this XSDateTime can hold. - * @param min the minimum inclusive value this XSDateTime can hold. - * @see #setMinExclusive + * {@inheritDoc} */ - public void setMinInclusive(final String min) { - _minExclusive = null; - _minInclusive = min; - } + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DateTimeValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. - */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } +// // TODO We can't validate on the fixed value as long as Castor treats DateTime as +// // java.util.Date because in the process any time zone information is discarded +// // and comparisons will fail. +// if (fixedValue != null) { +// jsc.add("try {\n" +// + " typeValidator.setFixed({0});\n" +// + "} catch (java.text.ParseException pe) {\n" +// + " System.out.println(\"ParseException\" + pe);\n" +// + "}", fixedValue.replaceFirst(".toDate\\(\\)", "")); +// } - /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. - */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; - } + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - /** - * Transfer facets from the provided simpleType to this. The - * DateTime SimpleType supports the following facets: - * - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets - */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); + if (hasMinimum() || hasMaximum()) { + jsc.add("try {"); - if (Facet.MAX_EXCLUSIVE.equals(name)) { - setMaxExclusive(facet.getValue()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - setMaxInclusive(facet.getValue()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - setMinExclusive(facet.getValue()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - setMinInclusive(facet.getValue()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - LOG.warn("Warning: The facet 'whitespace' can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for DateTime."); - } + // minInclusive / minExclusive facets (only one or the other, never both) + if (getMinInclusive() != null) { + jsc.add(" org.exolab.castor.types.DateTime min;\n" + + " min = new org.exolab.castor.types.DateTime(\"{0}\");\n" + + " typeValidator.setMinInclusive(min);", getMinInclusive()); + } else if (getMinExclusive() != null) { + jsc.add(" org.exolab.castor.types.DateTime min;\n" + + " min = new org.exolab.castor.types.DateTime(\"{0}\");\n" + + " typeValidator.setMinExclusive(min);", getMinExclusive()); } - } - } - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param jsc - * the JSourceCode to fill in. - * @param fixedValue - * a fixed value to use if any - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator =" - + " new org.exolab.castor.xml.validators.DateTimeValidator();"); - - boolean addTryCatch = _minInclusive != null || _minExclusive != null - || _maxInclusive != null || _maxExclusive != null /* || fixedValue != null */; - - if (addTryCatch) { - jsc.add("try {"); - jsc.indent(); - } - - // minInclusive / minExclusive facets (only one or the other, never both) - if (_minInclusive != null) { - jsc.add("org.exolab.castor.types.DateTime min = " - + "new org.exolab.castor.types.DateTime(\"" + _minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } else if (_minExclusive != null) { - jsc.add("org.exolab.castor.types.DateTime min = " - + "new org.exolab.castor.types.DateTime(\"" + _minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } - - // maxInclusive / maxExclusive facets (only one or the other, never both) - if (_maxInclusive != null) { - jsc.add("org.exolab.castor.types.DateTime max = " - + "new org.exolab.castor.types.DateTime(\"" + _maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); - } else if (_maxExclusive != null) { - jsc.add("org.exolab.castor.types.DateTime max = " - + "new org.exolab.castor.types.DateTime(\"" + _maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } - -// TODO We can't validate on the fixed value as long as Castor treats DateTime as java.util.Date -// because in the process any time zone information is discarded and comparisons will fail. -// // fixed values -// if (fixedValue != null) { -// jsc.add("typeValidator.setFixed("); -// jsc.append(fixedValue.replaceFirst(".toDate\\(\\)", "")); -// jsc.append(");"); -// } + // maxInclusive / maxExclusive facets (only one or the other, never both) + if (getMaxInclusive() != null) { + jsc.add(" org.exolab.castor.types.DateTime max;\n" + + " max = new org.exolab.castor.types.DateTime(\"{0}\");\n" + + " typeValidator.setMaxInclusive(max);", getMaxInclusive()); + } else if (getMaxExclusive() != null) { + jsc.add(" org.exolab.castor.types.DateTime max;\n" + + " max = new org.exolab.castor.types.DateTime(\"{0}\");\n" + + " typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } - if (addTryCatch) { - jsc.unindent(); - jsc.add("} catch (java.text.ParseException pe) {"); - jsc.indent(); - jsc.add("System.out.println(\"ParseException\" + pe);"); - jsc.unindent(); - jsc.add("}"); + jsc.add("} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", ""); } - - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); } -} //-- XSDateTime + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDecimal.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDecimal.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDecimal.java (working copy) @@ -1,56 +1,20 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ - * Date Author Changes - * 06/01/2001 Arnaud Blandin Upgrade to XML Schema Recommendation - * 10/31/200 Arnaud Blandin support for min/max, scale&precision facets + * Copyright 2007 Andrew Fawcett, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -57,9 +21,19 @@ /** * The xsd:decimal XML Schema datatype. - * @author Andrew Fawcett + * + * @author Andrew Fawcett + * @author Ralf Joachim + * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ */ -public final class XSDecimal extends XSPatternBase { +public final class XSDecimal extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "decimal"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.DECIMAL_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.math.BigDecimal"); @@ -64,18 +38,7 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.math.BigDecimal"); - /** Maximum decimal (inclusive). */ - private java.math.BigDecimal _maxInclusive = null; - /** Maximum decimal (exclusive). */ - private java.math.BigDecimal _maxExclusive = null; - /** Minimum decimal (inclusive). */ - private java.math.BigDecimal _minInclusive = null; - /** Minimum decimal (exclusive). */ - private java.math.BigDecimal _minExclusive = null; - /** Total number of digits. */ - private int _totalDigits = -1; - /** Total number of fraction digits. */ - private int _fractionDigits = -1; + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -81,295 +44,93 @@ * No-arg constructor. */ public XSDecimal() { - super(XSType.DECIMAL_TYPE); - } //-- XSNMToken - - /** - * Returns the Java code neccessary to create a new instance of the JType - * associated with this XSType. - * - * @return the Java code neccessary to create a new instance of the JType - * associated with this XSType. - */ - public String newInstanceCode() { - String result = "new java.math.BigDecimal(0);"; - return result; + super(false); } - - /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType - */ - public String createFromJavaObjectCode(final String variableName) { - return "(java.math.BigDecimal) " + variableName; - } //-- fromJavaObject - - /** - * Returns the maximum exclusive value that this XSInteger can hold. - * - * @return the maximum exclusive value that this XSInteger can hold. If no - * maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive - */ - public java.math.BigDecimal getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive - - /** - * Returns the maximum inclusive value that this XSInteger can hold. - * - * @return the maximum inclusive value that this XSInteger can hold. If no - * maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive - */ - public java.math.BigDecimal getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive + + //-------------------------------------------------------------------------- /** - * Returns the minimum exclusive value that this XSInteger can hold. - * - * @return the minimum exclusive value that this XSInteger can hold. If no - * minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive - * @see #setMaxInclusive - */ - public java.math.BigDecimal getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive - - /** - * Returns the minimum inclusive value that this XSInteger can hold. - * - * @return the minimum inclusive value that this XSInteger can hold. If no - * minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive - */ - public java.math.BigDecimal getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive - /** - * Returns the totalDigits facet value of this XSInteger. - * @return the totalDigits facet value of this XSInteger. + * {@inheritDoc} */ - public int getTotalDigits() { - return _totalDigits; - } + public String getName() { return NAME; } /** - * Returns the fractionDigits facet value of this XSInteger. - * @return the fractionDigits facet value of this XSInteger. + * {@inheritDoc} */ - public int getFractionDigits() { - return _fractionDigits; - } + public short getType() { return TYPE; } /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } //-- hasMaximum - + public boolean isPrimitive() { return false; } + /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; - } //-- hasMinimum - + public boolean isDateTime() { return false; } + /** - * Sets the maximum exclusive value that this XSDecimal can hold. - * - * @param max - * the maximum exclusive value this XSDecimal can be - * @see #setMaxInclusive + * {@inheritDoc} */ - public void setMaxExclusive(final java.math.BigDecimal max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive + public JType getJType() { return JTYPE; } /** - * Sets the maximum inclusive value that this XSDecimal can hold. - * - * @param max - * the maximum inclusive value this XSDecimal can be - * @see #setMaxExclusive + * {@inheritDoc} */ - public void setMaxInclusive(final java.math.BigDecimal max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the minimum exclusive value that this XSDecimal can hold. - * - * @param min - * the minimum exclusive value this XSDecimal can be - * @see #setMinInclusive - */ - public void setMinExclusive(final java.math.BigDecimal min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - - /** - * Sets the minimum inclusive value that this XSDecimalcan hold. - * - * @param min - * the minimum inclusive value this XSDecimal can be - * @see #setMinExclusive - */ - public void setMinInclusive(final java.math.BigDecimal min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Sets the totalDigits facet for this XSInteger. - * @param totalDig the value of totalDigits (must be >0) - */ - public void setTotalDigits(final int totalDig) { - if (totalDig <= 0) { - throw new IllegalArgumentException(this.getName() - + ": the totalDigits facet must be positive"); - } - _totalDigits = totalDig; + public String newInstanceCode() { + return "new java.math.BigDecimal(0);"; } /** - * Sets the fractionDigits facet for this XSInteger. - * @param fractionDig the value of fractionDigits (must be >=0) + * {@inheritDoc} */ - public void setFractionDigits(final int fractionDig) { - if (fractionDig < 0) { - throw new IllegalArgumentException(this.getName() - + ": the fractionDigits facet must be positive"); - } - _fractionDigits = fractionDig; + public String createToJavaObjectCode(final String variableName) { + return variableName; } /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_EXCLUSIVE.equals(name)) { - setMaxExclusive(new java.math.BigDecimal(facet.getValue())); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - setMaxInclusive(new java.math.BigDecimal(facet.getValue())); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - setMinExclusive(new java.math.BigDecimal(facet.getValue())); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - setMinInclusive(new java.math.BigDecimal(facet.getValue())); - } else if (Facet.TOTALDIGITS.equals(name)) { - setTotalDigits(facet.toInt()); - } else if (Facet.FRACTIONDIGITS.equals(name)) { - setFractionDigits(facet.toInt()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - throw new IllegalArgumentException("Warning: The facet 'whitespace'" - + " can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'decimal'."); - } - } - } - } //-- setFacets - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public JType getJType() { - return XSDecimal.JTYPE; + public String createFromJavaObjectCode(final String variableName) { + return "(java.math.BigDecimal) " + variableName; } + + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DecimalValidator typeValidator" - + " = new org.exolab.castor.xml.validators.DecimalValidator();"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DecimalValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DecimalValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (_minExclusive != null) { - jsc.add("java.math.BigDecimal min = new java.math.BigDecimal(\"" - + _minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } else if (_minInclusive != null) { - jsc.add("java.math.BigDecimal min = new java.math.BigDecimal(\"" - + _minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } - - if (_maxExclusive != null) { - jsc.add("java.math.BigDecimal max = new java.math.BigDecimal(\"" - + _maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } else if (_maxInclusive != null) { - jsc.add("java.math.BigDecimal max = new java.math.BigDecimal(\"" - + _maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); } - //-- totalDigits - int totalDigits = getTotalDigits(); - - if (totalDigits != -1) { - jsc.add("typeValidator.setTotalDigits("); - jsc.append(Integer.toString(totalDigits)); - jsc.append(");"); - } + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - //-- fractionDigits - int fractionDigits = getFractionDigits(); - if (fractionDigits != -1) { - jsc.add("typeValidator.setFractionDigits("); - jsc.append(Integer.toString(fractionDigits)); - jsc.append(");"); + if (getMinExclusive() != null) { + jsc.add("java.math.BigDecimal min = new java.math.BigDecimal(\"{0}\");\n" + + "typeValidator.setMinExclusive(min);", getMinExclusive()); + } else if (getMinInclusive() != null) { + jsc.add("java.math.BigDecimal min = new java.math.BigDecimal(\"{0}\");\n" + + "typeValidator.setMinInclusive(min);", getMinInclusive()); } - //-- fixed values - if (fixedValue != null) { - jsc.add("typeValidator.setFixed("); - jsc.append(fixedValue); - jsc.append(");"); + if (getMaxExclusive() != null) { + jsc.add("java.math.BigDecimal max = new java.math.BigDecimal(\"{0}\");\n" + + "typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } else if (getMaxInclusive() != null) { + jsc.add("java.math.BigDecimal max = new java.math.BigDecimal(\"{0}\");\n" + + "typeValidator.setMaxInclusive(max);", getMaxInclusive()); } - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + codeDigitsFacet(jsc, "typeValidator"); } - + + //-------------------------------------------------------------------------- } Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDouble.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDouble.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDouble.java (working copy) @@ -1,53 +1,20 @@ /* - * 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. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -53,27 +20,37 @@ import org.exolab.javasource.JType; /** - * The XML Schema xsd:double type. + * The xsd:double XML Schema type. * - * @author Keith Visco + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ */ -public final class XSDouble extends XSPatternBase { +public final class XSDouble extends AbstractRangeFacet { + //-------------------------------------------------------------------------- - /** Maximum double (inclusive). */ - private Double _maxInclusive = null; - /** Maximum double (exclusive). */ - private Double _maxExclusive = null; - /** Minimum double (inclusive). */ - private Double _minInclusive = null; - /** Minimum double (exclusive). */ - private Double _minExclusive = null; + /** Name of this XSType. */ + public static final String NAME = "double"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.DOUBLE_TYPE; - /** The JType represented by this XSType. */ - private final JType _jType; + /** A constant holding the minimum value an xsd:float can have. */ + public static final String MIN_VALUE = Double.toString(-Double.MAX_VALUE); + + /** A constant holding the maximum value an xsd:float can have. */ + public static final String MAX_VALUE = Double.toString(Double.MAX_VALUE); + + //-------------------------------------------------------------------------- + /** True if this type is implemented using the wrapper class. */ private final boolean _asWrapper; + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- + /** * No-arg constructor. */ @@ -84,13 +61,12 @@ /** * Constructs a new XSDouble. * - * @param asWrapper - * if true, use the java.lang wrapper class. + * @param asWrapper If true, use the java.lang wrapper class. */ public XSDouble(final boolean asWrapper) { - super(XSType.DOUBLE_TYPE); + super(); + _asWrapper = asWrapper; - if (_asWrapper) { _jType = new JClass("java.lang.Double"); } else { @@ -96,280 +72,91 @@ } else { _jType = JType.DOUBLE; } - } // -- XSDouble - /** - * Returns the JType that this XSType represents. - * - * @return the JType that this XSType represents. - */ - public JType getJType() { - return _jType; + setMinInclusive(MIN_VALUE); + setMaxInclusive(MAX_VALUE); } - /** - * Returns the maximum exclusive value that this XSDouble can hold. - * - * @return the maximum exclusive value that this XSDouble can hold. If no - * maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive - */ - public Double getMaxExclusive() { - return _maxExclusive; - } // -- getMaxExclusive - - /** - * Returns the maximum inclusive value that this XSDouble can hold. - * - * @return the maximum inclusive value that this XSDouble can hold. If no - * maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive - */ - public Double getMaxInclusive() { - return _maxInclusive; - } // -- getMaxInclusive - - /** - * Returns the minimum exclusive value that this XSDouble can hold. - * - * @return the minimum exclusive value that this XSDouble can hold. If no - * minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive - * @see #setMaxInclusive(Double) - */ - public Double getMinExclusive() { - return _minExclusive; - } // -- getMinExclusive - - /** - * Returns the minimum inclusive value that this XSDouble can hold. - * - * @return the minimum inclusive value that this XSDouble can hold. If no - * minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive - */ - public Double getMinInclusive() { - return _minInclusive; - } // -- getMinInclusive - - /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. - */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } // -- hasMaximum - - /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. - */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; - } // -- hasMinimum - - /** - * Sets the maximum exclusive value that this XSDouble can hold. - * - * @param max - * the maximum exclusive value this XSDouble can be - * @see #setMaxInclusive(Double) - */ - public void setMaxExclusive(final double max) { - _maxExclusive = new Double(max); - } // -- setMaxExclusive + //-------------------------------------------------------------------------- /** - * Sets the maximum exclusive value that this XSDouble can hold. - * - * @param max - * the maximum exclusive value this XSDouble can be - * @see #setMaxInclusive(double) + * {@inheritDoc} */ - public void setMaxExclusive(final Double max) { - _maxExclusive = max; - } // -- setMaxExclusive + public String getName() { return NAME; } /** - * Sets the maximum inclusive value that this XSDouble can hold. - * - * @param max - * the maximum inclusive value this XSDouble can be - * @see #setMaxExclusive(Double) + * {@inheritDoc} */ - public void setMaxInclusive(final double max) { - _maxInclusive = new Double(max); - } // -- setMaxInclusive + public short getType() { return TYPE; } /** - * Sets the maximum inclusive value that this XSDouble can hold. - * - * @param max - * the maximum inclusive value this XSDouble can be - * @see #setMaxExclusive(double) + * {@inheritDoc} */ - public void setMaxInclusive(final Double max) { - _maxInclusive = max; - } // -- setMaxInclusive - + public boolean isPrimitive() { return true; } + /** - * Sets the minimum exclusive value that this XSDouble can hold. - * - * @param min - * the minimum exclusive value this XSDouble can be - * @see #setMinInclusive(Double) + * {@inheritDoc} */ - public void setMinExclusive(final double min) { - _minExclusive = new Double(min); - } // -- setMinExclusive - + public boolean isDateTime() { return false; } + /** - * Sets the minimum exclusive value that this XSDouble can hold. - * - * @param min - * the minimum exclusive value this XSDouble can be - * @see #setMinInclusive(double) - */ - public void setMinExclusive(final Double min) { - _minExclusive = min; - } // -- setMinExclusive - - /** - * Sets the minimum inclusive value that this XSDouble can hold. - * - * @param min - * the minimum inclusive value this XSDouble can be - * @see #setMinExclusive(Double) + * {@inheritDoc} */ - public void setMinInclusive(final double min) { - _minInclusive = new Double(min); - } // -- setMinInclusive + public JType getJType() { return _jType; } /** - * Sets the minimum inclusive value that this XSDouble can hold. - * - * @param min - * the minimum inclusive value this XSDouble can be - * @see #setMinExclusive(double) + * {@inheritDoc} */ - public void setMinInclusive(final Double min) { - _minInclusive = min; - } // -- setMinInclusive - - /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets - */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_EXCLUSIVE.equals(name)) { - setMaxExclusive(facet.toDouble()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - setMaxInclusive(facet.toDouble()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - setMinExclusive(facet.toDouble()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - setMinInclusive(facet.toDouble()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - throw new IllegalArgumentException("Warning: The facet 'whitespace'" - + " can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'double'."); - } - } - } + public String newInstanceCode() { + return "new java.lang.Double(0.0);"; } - + /** - * Returns the String necessary to convert an instance of this XSType to an - * Object. This method is really only useful for primitive types - * - * @param variableName - * the name of the instance variable - * @return the String necessary to convert an instance of this XSType to an - * Object + * {@inheritDoc} */ public String createToJavaObjectCode(final String variableName) { - if (_asWrapper) { - return super.createToJavaObjectCode(variableName); - } - + if (_asWrapper) { return variableName; } return "new java.lang.Double(" + variableName + ")"; - } // -- toJavaObject + } /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} */ public String createFromJavaObjectCode(final String variableName) { - StringBuffer sb = new StringBuffer("((java.lang.Double) "); - sb.append(variableName); - sb.append(")"); - if (!_asWrapper) { - sb.append(".doubleValue()"); - } - return sb.toString(); - } // -- fromJavaObject + if (_asWrapper) { return "((java.lang.Double) " + variableName + ")"; } + return "((java.lang.Double) " + variableName + ").doubleValue()"; + } + + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DoubleValidator typeValidator" - + " = new org.exolab.castor.xml.validators.DoubleValidator();"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DoubleValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DoubleValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (_minExclusive != null) { - jsc.add("typeValidator.setMinExclusive(" + _minExclusive + ");"); - } else if (_minInclusive != null) { - jsc.add("typeValidator.setMinInclusive(" + _minInclusive + ");"); + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); } - if (_maxExclusive != null) { - jsc.add("typeValidator.setMaxExclusive(" + _maxExclusive + ");"); - } else if (_maxInclusive != null) { - jsc.add("typeValidator.setMaxInclusive(" + _maxInclusive + ");"); + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive(" + getMinExclusive() + ");"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive(" + getMinInclusive() + ");"); } - // -- fixed values - if (fixedValue != null) { - // -- make sure we have a valid value... - new Double(fixedValue); - jsc.add("typeValidator.setFixed("); - jsc.append(fixedValue); - jsc.append(");"); + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive(" + getMaxExclusive() + ");"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive(" + getMaxInclusive() + ");"); } - - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); } -} // -- XSDouble + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDuration.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDuration.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSDuration.java (working copy) @@ -1,57 +1,20 @@ /* - * 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 2001-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ - * Date Author Changes - * 05/22/2001 Arnaud Blandin Created + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -57,13 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema duration type. - * @author Arnaud Blandin + * The xsd:duration XML Schema type. + * + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSDuration extends XSPatternBase { - /** Jakarta's common-logging logger. */ - private static final Log LOG = LogFactory.getLog(XSDuration.class); +public final class XSDuration extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "duration"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.DURATION_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("org.exolab.castor.types.Duration"); @@ -68,235 +38,106 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("org.exolab.castor.types.Duration"); - /** Maximum Day (inclusive). */ - private String _maxInclusive; - /** Maximum Day (exclusive). */ - private String _maxExclusive; - /** Minimum Day (inclusive). */ - private String _minInclusive; - /** Minimum Day (exclusive). */ - private String _minExclusive; - - /** - * No-Arg constructor. - */ - public XSDuration() { - super(XSType.DURATION_TYPE); - } - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public JType getJType() { - return XSDuration.JTYPE; - } - - /** - * Returns the maximum exclusive value that this XSDuration can hold. - * @return the maximum exclusive value that this XSDuration can hold. If - * no maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive - */ - public String getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive - - /** - * Returns the maximum inclusive value that this XSDuration can hold. - * @return the maximum inclusive value that this XSDuration can hold. If - * no maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive - */ - public String getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive + //-------------------------------------------------------------------------- /** - * Returns the minimum exclusive value that this XSDuration can hold. - * @return the minimum exclusive value that this XSDuration can hold. If - * no minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive + * {@inheritDoc} */ - public String getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + public String getName() { return NAME; } /** - * Returns the minimum inclusive value that this XSDuration can hold. - * @return the minimum inclusive value that this XSDuration be. - * @see #getMinExclusive + * {@inheritDoc} */ - public String getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive + public short getType() { return TYPE; } /** - * Sets the maximum exclusive value that this XSDuration can hold. - * @param max the maximum exclusive value this XSDuration can be - * @see #setMaxInclusive + * {@inheritDoc} */ - public void setMaxExclusive(final String max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive - + public boolean isPrimitive() { return false; } + /** - * Sets the maximum inclusive value that this XSDuration can hold. - * @param max the maximum inclusive value this XSDuration can be - * @see #setMaxExclusive + * {@inheritDoc} */ - public void setMaxInclusive(final String max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - + public boolean isDateTime() { return true; } + /** - * Sets the minimum exclusive value that this XSDuration can hold. - * @param min the minimum exclusive value this XSDuration can be - * @see #setMinInclusive + * {@inheritDoc} */ - public void setMinExclusive(final String min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive + public JType getJType() { return JTYPE; } /** - * Sets the minimum inclusive value that this XSDuration can hold. - * @param min the minimum inclusive value this XSDuration can be - * @see #setMinExclusive + * {@inheritDoc} */ - public void setMinInclusive(final String min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. - */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; + public String newInstanceCode() { + return "new " + getJType().getName() + "();"; } - + /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; + public String createToJavaObjectCode(final String variableName) { + return variableName; } - + /** - * Transfer facets from the provided simpleType to this. The - * Duration SimpleType supports the following facets: - * - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().getName() + ") " + variableName; + } - if (Facet.MAX_EXCLUSIVE.equals(name)) { - this.setMaxExclusive(facet.getValue()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - this.setMaxInclusive(facet.getValue()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - this.setMinExclusive(facet.getValue()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - this.setMinInclusive(facet.getValue()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - LOG.warn("Warning: The facet 'whitespace' can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for duration."); - } - } - } //while - } //setFacets + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DurationValidator typeValidator =" - + " new org.exolab.castor.xml.validators.DurationValidator();"); - - boolean addTryCatch = _minInclusive != null || _minExclusive != null - || _maxInclusive != null || _maxExclusive != null || fixedValue != null; + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DurationValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DurationValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (addTryCatch) { - jsc.add("try {"); - jsc.indent(); + if (fixedValue != null) { + jsc.add("try {\n" + + " typeValidator.setFixed({0});\n" + + "} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", fixedValue); } - // minInclusive / minExclusive facets (only one or the other, never both) - if (_minInclusive != null) { - jsc.add("org.exolab.castor.types.Duration min = " - + "org.exolab.castor.types.Duration.parseDuration(\"" + _minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } else if (_minExclusive != null) { - jsc.add("org.exolab.castor.types.Duration min = " - + "org.exolab.castor.types.Duration.parseDuration(\"" + _minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - // maxInclusive / maxExclusive facets (only one or the other, never both) - if (_maxInclusive != null) { - jsc.add("org.exolab.castor.types.Duration max = " - + "org.exolab.castor.types.Duration.parseDuration(\"" + _maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); - } else if (_maxExclusive != null) { - jsc.add("org.exolab.castor.types.Duration max = " - + "org.exolab.castor.types.Duration.parseDuration(\"" + _maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } + if (hasMinimum() || hasMaximum()) { + jsc.add("try {"); - // fixed values - if (fixedValue != null) { - jsc.add("typeValidator.setFixed(" + fixedValue + ");"); - } + // minInclusive / minExclusive facets (only one or the other, never both) + if (getMinInclusive() != null) { + jsc.add(" org.exolab.castor.types.Duration min;\n" + + " min = org.exolab.castor.types.Duration.parseDuration(\"{0}\");\n" + + " typeValidator.setMinInclusive(min);", getMinInclusive()); + } else if (getMinExclusive() != null) { + jsc.add(" org.exolab.castor.types.Duration min;\n" + + " min = org.exolab.castor.types.Duration.parseDuration(\"{0}\");\n" + + " typeValidator.setMinExclusive(min);", getMinExclusive()); + } - if (addTryCatch) { - jsc.unindent(); - jsc.add("} catch (java.text.ParseException pe) {"); - jsc.indent(); - jsc.add("System.out.println(\"ParseException\" + pe);"); - jsc.unindent(); - jsc.add("}"); + // maxInclusive / maxExclusive facets (only one or the other, never both) + if (getMaxInclusive() != null) { + jsc.add(" org.exolab.castor.types.Duration max;\n" + + " max = org.exolab.castor.types.Duration.parseDuration(\"{0}\");\n" + + " typeValidator.setMaxInclusive(max);", getMaxInclusive()); + } else if (getMaxExclusive() != null) { + jsc.add(" org.exolab.castor.types.Duration max;\n" + + " max = org.exolab.castor.types.Duration.parseDuration(\"{0}\");\n" + + " typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } + + jsc.add("} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", ""); } - - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); } -} //--XSDuration + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSFloat.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSFloat.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSFloat.java (working copy) @@ -1,55 +1,20 @@ /* - * 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 2000-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ - * Date Author Changes - * 12/06/2000 Arnaud Blandin Created + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -55,27 +20,37 @@ import org.exolab.javasource.JType; /** - * The XML Schema xsd:float type. + * The xsd:float XML Schema type. * - * @author Keith Visco + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ */ -public final class XSFloat extends XSPatternBase { +public final class XSFloat extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "float"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.FLOAT_TYPE; + + /** A constant holding the minimum value an xsd:float can have. */ + public static final String MIN_VALUE = Float.toString(-Float.MAX_VALUE); + + /** A constant holding the maximum value an xsd:float can have. */ + public static final String MAX_VALUE = Float.toString(Float.MAX_VALUE); - /** Maximum float (inclusive). */ - private Float _maxInclusive = null; - /** Maximum float (inclusive). */ - private Float _maxExclusive = null; - /** Maximum float (inclusive). */ - private Float _minInclusive = null; - /** Maximum float (inclusive). */ - private Float _minExclusive = null; + //-------------------------------------------------------------------------- - /** The JType represented by this XSType. */ - private final JType _jType; /** True if this type is implemented using the wrapper class. */ private final boolean _asWrapper; + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- + /** * No-arg constructor. */ @@ -86,13 +61,12 @@ /** * Constructs a new XSFloat. * - * @param asWrapper - * if true, use the java.lang wrapper class. + * @param asWrapper If true, use the java.lang wrapper class. */ public XSFloat(final boolean asWrapper) { - super(XSType.FLOAT_TYPE); + super(); + _asWrapper = asWrapper; - if (_asWrapper) { _jType = new JClass("java.lang.Float"); } else { @@ -98,307 +72,91 @@ } else { _jType = JType.FLOAT; } - } // -- XSFloat - /** - * Returns the JType that this XSType represents. - * - * @return the JType that this XSType represents. - */ - public JType getJType() { - return _jType; + setMinInclusive(MIN_VALUE); + setMaxInclusive(MAX_VALUE); } - /** - * Returns the maximum exclusive value that this XSFloat can hold. - * - * @return the maximum exclusive value that this XSFloat can hold. If no - * maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive - */ - public Float getMaxExclusive() { - return _maxExclusive; - } // -- getMaxExclusive - - /** - * Returns the maximum inclusive value that this XSFloat can hold. - * - * @return the maximum inclusive value that this XSFloat can hold. If no - * maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive - */ - public Float getMaxInclusive() { - return _maxInclusive; - } // -- getMaxInclusive - - /** - * Returns the minimum exclusive value that this XSFloat can hold. - * - * @return the minimum exclusive value that this XSFloat can hold. If no - * minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive() - * @see #setMaxInclusive(float) - */ - public Float getMinExclusive() { - return _minExclusive; - } // -- getMinExclusive - - /** - * Returns the minimum inclusive value that this XSFloat can hold. - * - * @return the minimum inclusive value that this XSFloat can hold. If no - * minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive - */ - public Float getMinInclusive() { - return _minInclusive; - } // -- getMinInclusive - - /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. - */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } // -- hasMaximum - - /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. - */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; - } // -- hasMinimum - - /** - * Sets the maximum exclusive value that this XSFloat can hold. - * - * @param max - * the maximum exclusive value this XSFloat can be - * @see #setMaxInclusive(Float) - */ - public void setMaxExclusive(final float max) { - _maxExclusive = new Float(max); - } // -- setMaxExclusive - - /** - * Sets the maximum exclusive value that this XSFloat can hold. - * - * @param max - * the maximum exclusive value this XSFloat can be - * @see #setMaxInclusive(float) - */ - public void setMaxExclusive(final Float max) { - _maxExclusive = max; - } // -- setMaxExclusive - - /** - * Sets the maximum inclusive value that this XSFloat can hold. - * - * @param max - * the maximum inclusive value this XSFloat can be - * @see #setMaxExclusive(Float) - */ - public void setMaxInclusive(final float max) { - _maxInclusive = new Float(max); - } // -- setMaxInclusive + //-------------------------------------------------------------------------- /** - * Sets the maximum inclusive value that this XSFloat can hold. - * - * @param max - * the maximum inclusive value this XSFloat can be - * @see #setMaxExclusive(float) + * {@inheritDoc} */ - public void setMaxInclusive(final Float max) { - _maxInclusive = max; - } // -- setMaxInclusive + public String getName() { return NAME; } /** - * Sets the minimum exclusive value that this XSFloat can hold. - * - * @param min - * the minimum exclusive value this XSFloat can be - * @see #setMinInclusive(Float) + * {@inheritDoc} */ - public void setMinExclusive(final float min) { - _minExclusive = new Float(min); - } // -- setMinExclusive + public short getType() { return TYPE; } /** - * Sets the minimum exclusive value that this XSFloat can hold. - * - * @param min - * the minimum exclusive value this XSFloat can be - * @see #setMinInclusive(float) + * {@inheritDoc} */ - public void setMinExclusive(final Float min) { - _minExclusive = min; - } // -- setMinExclusive - + public boolean isPrimitive() { return true; } + /** - * Sets the minimum inclusive value that this XSFloat can hold. - * - * @param min - * the minimum inclusive value this XSFloat can be - * @see #setMinExclusive(Float) + * {@inheritDoc} */ - public void setMinInclusive(final float min) { - _minInclusive = new Float(min); - } // -- setMinInclusive - + public boolean isDateTime() { return false; } + /** - * Sets the minimum inclusive value that this XSFloat can hold. - * - * @param min - * the minimum inclusive value this XSFloat can be - * @see #setMinExclusive(float) + * {@inheritDoc} */ - public void setMinInclusive(final Float min) { - _minInclusive = min; - } // -- setMinInclusive + public JType getJType() { return _jType; } /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - // -- copy valid facets - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_EXCLUSIVE.equals(name)) { - setMaxExclusive(facet.toFloat()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - setMaxInclusive(facet.toFloat()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - setMinExclusive(facet.toFloat()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - setMinInclusive(facet.toFloat()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - throw new IllegalArgumentException("Warning: The facet 'whitespace'" - + " can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'float'."); - } - } - } + public String newInstanceCode() { + return "new java.lang.Float(0.0);"; } - + /** - * Returns the String necessary to convert an instance of this XSType to an - * Object. This method is really only useful for primitive types - * - * @param variableName - * the name of the instance variable - * @return the String necessary to convert an instance of this XSType to an - * Object + * {@inheritDoc} */ public String createToJavaObjectCode(final String variableName) { - if (_asWrapper) { - return super.createToJavaObjectCode(variableName); - } - StringBuffer sb = new StringBuffer("new java.lang.Float("); - sb.append(variableName); - sb.append(")"); - return sb.toString(); - } // -- toJavaObject + if (_asWrapper) { return variableName; } + return "new java.lang.Float(" + variableName + ")"; + } /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} */ public String createFromJavaObjectCode(final String variableName) { - StringBuffer sb = new StringBuffer("((java.lang.Float) "); - sb.append(variableName); - sb.append(")"); - if (!_asWrapper) { - sb.append(".floatValue()"); - } - return sb.toString(); - } // -- fromJavaObject + if (_asWrapper) { return "((java.lang.Float) " + variableName + ")"; } + return "((java.lang.Float) " + variableName + ").floatValue()"; + } + + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.FloatValidator typeValidator" - + " = new org.exolab.castor.xml.validators.FloatValidator();"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.FloatValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.FloatValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (hasMinimum()) { - Float min = getMinExclusive(); - if (min != null) { - jsc.add("typeValidator.setMinExclusive("); - } else { - min = getMinInclusive(); - jsc.add("typeValidator.setMinInclusive("); - } - if ((min.equals(new Float(Float.NEGATIVE_INFINITY)))) { - jsc.append("Float.NEGATIVE_INFINITY"); - } else if ((min.equals(new Float(Float.POSITIVE_INFINITY)))) { - jsc.append("Float.POSITIVE_INFINITY"); - } else { - jsc.append(min.toString() + "f"); - } - jsc.append(");"); - } - if (hasMaximum()) { - Float max = getMaxExclusive(); - if (max != null) { - jsc.add("typeValidator.setMaxExclusive("); - } else { - max = getMaxInclusive(); - jsc.add("typeValidator.setMaxInclusive("); - } - if ((max.equals(new Float(Float.NEGATIVE_INFINITY)))) { - jsc.append("Float.NEGATIVE_INFINITY"); - } else if ((max.equals(new Float(Float.POSITIVE_INFINITY)))) { - jsc.append("Float.POSITIVE_INFINITY"); - } else { - jsc.append(max.toString() + "f"); - } - jsc.append(");"); + if (fixedValue != null) { + jsc.add("typeValidator.setFixed((float) " + fixedValue + ");"); } - // -- fixed values - if (fixedValue != null) { + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - // -- make sure we've got a good value - new Float(fixedValue); - jsc.add("typeValidator.setFixed("); - jsc.append(fixedValue); - jsc.append("f);"); + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive((float) " + getMinExclusive() + ");"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive((float) " + getMinInclusive() + ");"); } - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive((float) " + getMaxExclusive() + ");"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive((float) " + getMaxInclusive() + ");"); + } } - -} // -- XStype + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGDay.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGDay.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGDay.java (working copy) @@ -1,54 +1,20 @@ /* - * 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 2001-2002 (C) Intalio, Inc. All Rights Reserved. - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -54,13 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema gDay type. - * @author Arnaud Blandin + * The xsd:gDay XML Schema type. + * + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSGDay extends XSPatternBase { - /** Jakarta's common-logging logger. */ - private static final Log LOG = LogFactory.getLog(XSGDay.class); +public final class XSGDay extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "gDay"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.GDAY_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("org.exolab.castor.types.GDay"); @@ -65,237 +38,106 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("org.exolab.castor.types.GDay"); - /** Maximum Day (inclusive). */ - private String _maxInclusive = null; - /** Maximum Day (exclusive). */ - private String _maxExclusive = null; - /** Minimum Day (inclusive). */ - private String _minInclusive = null; - /** Minimum Day (exclusive). */ - private String _minExclusive = null; + //-------------------------------------------------------------------------- /** - * No-Arg constructor. + * {@inheritDoc} */ - public XSGDay() { - super(XSType.GDAY_TYPE); - } + public String getName() { return NAME; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSGDay.JTYPE; - } + public short getType() { return TYPE; } /** - * Returns the maximum exclusive value that this XSGDay can hold. - * @return the maximum exclusive value that this XSGDay can hold. If - * no maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive + * {@inheritDoc} */ - public String getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive - + public boolean isPrimitive() { return false; } + /** - * Returns the maximum inclusive value that this XSGDay can hold. - * @return the maximum inclusive value that this XSGDay can hold. If - * no maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive + * {@inheritDoc} */ - public String getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive - + public boolean isDateTime() { return true; } + /** - * Returns the minimum exclusive value that this XSGDay can hold. - * @return the minimum exclusive value that this XSGDay can hold. If - * no minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive - * @see #setMaxInclusive + * {@inheritDoc} */ - public String getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + public JType getJType() { return JTYPE; } /** - * Returns the minimum inclusive value that this XSGDay can hold. - * @return the minimum inclusive value that this can XSGDay hold. If - * no minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive + * {@inheritDoc} */ - public String getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive - + public String newInstanceCode() { + return "new " + getJType().getName() + "();"; + } + /** - * Sets the maximum exclusive value that this XSGDay can hold. - * @param max the maximum exclusive value this XSGDay can be - * @see #setMaxInclusive + * {@inheritDoc} */ - public void setMaxExclusive(final String max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive - - /** - * Sets the maximum inclusive value that this XSGDay can hold. - * @param max the maximum inclusive value this XSGDay can be - * @see #setMaxExclusive - */ - public void setMaxInclusive(final String max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the minimum exclusive value that this XSGDay can hold. - * @param min the minimum exclusive value this XSGDay can be - * @see #setMinInclusive - */ - public void setMinExclusive(final String min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + /** - * Sets the minimum inclusive value that this XSGDay can hold. - * @param min the minimum inclusive value this XSGDay can be - * @see #setMinExclusive + * {@inheritDoc} */ - public void setMinInclusive(final String min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. - */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().getName() + ") " + variableName; } - /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. - */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } + //-------------------------------------------------------------------------- /** - * Transfer facets from the provided simpleType to this. The - * GDay SimpleType supports the following facets: - * - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DateTimeValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (Facet.MAX_EXCLUSIVE.equals(name)) { - this.setMaxExclusive(facet.getValue()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - this.setMaxInclusive(facet.getValue()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - this.setMinExclusive(facet.getValue()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - this.setMinInclusive(facet.getValue()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - LOG.warn("Warning: The facet 'whitespace' can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'gDay'."); - } - } - } //while - } //setFacets + if (fixedValue != null) { + jsc.add("try {\n" + + " typeValidator.setFixed({0});\n" + + "} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", fixedValue); + } - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator =" - + " new org.exolab.castor.xml.validators.DateTimeValidator();"); - - boolean addTryCatch = _minInclusive != null || _minExclusive != null - || _maxInclusive != null || _maxExclusive != null || fixedValue != null; + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - if (addTryCatch) { + if (hasMinimum() || hasMaximum()) { jsc.add("try {"); - jsc.indent(); - } - - // minInclusive / minExclusive facets (only one or the other, never both) - if (_minInclusive != null) { - jsc.add("org.exolab.castor.types.GDay min = " - + "org.exolab.castor.types.GDay.parseGDay(\"" + _minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } else if (_minExclusive != null) { - jsc.add("org.exolab.castor.types.GDay min = " - + "org.exolab.castor.types.GDay.parseGDay(\"" + _minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } - // maxInclusive / maxExclusive facets (only one or the other, never both) - if (_maxInclusive != null) { - jsc.add("org.exolab.castor.types.GDay max = " - + "org.exolab.castor.types.GDay.parseGDay(\"" + _maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); - } else if (_maxExclusive != null) { - jsc.add("org.exolab.castor.types.GDay max = " - + "org.exolab.castor.types.GDay.parseGDay(\"" + _maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } + // minInclusive / minExclusive facets (only one or the other, never both) + if (getMinInclusive() != null) { + jsc.add(" org.exolab.castor.types.GDay min;\n" + + " min = org.exolab.castor.types.GDay.parseGDay(\"{0}\");\n" + + " typeValidator.setMinInclusive(min);", getMinInclusive()); + } else if (getMinExclusive() != null) { + jsc.add(" org.exolab.castor.types.GDay min;\n" + + " min = org.exolab.castor.types.GDay.parseGDay(\"{0}\");\n" + + " typeValidator.setMinExclusive(min);", getMinExclusive()); + } - // fixed values - if (fixedValue != null) { - jsc.add("typeValidator.setFixed(" + fixedValue + ");"); - } + // maxInclusive / maxExclusive facets (only one or the other, never both) + if (getMaxInclusive() != null) { + jsc.add(" org.exolab.castor.types.GDay max;\n" + + " max = org.exolab.castor.types.GDay.parseGDay(\"{0}\");\n" + + " typeValidator.setMaxInclusive(max);", getMaxInclusive()); + } else if (getMaxExclusive() != null) { + jsc.add(" org.exolab.castor.types.GDay max;\n" + + " max = org.exolab.castor.types.GDay.parseGDay(\"{0}\");\n" + + " typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } - if (addTryCatch) { - jsc.unindent(); - jsc.add("} catch (java.text.ParseException pe) {"); - jsc.indent(); - jsc.add("System.out.println(\"ParseException\" + pe);"); - jsc.unindent(); - jsc.add("}"); + jsc.add("} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", ""); } - - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); } -} //-- XSGDay + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGMonth.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGMonth.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGMonth.java (working copy) @@ -1,54 +1,20 @@ /* - * 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 2001-2002(C) Intalio, Inc. All Rights Reserved. - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -54,13 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema gMonth type. - * @author Arnaud Blandin + * The xsd:gMonth XML Schema type. + * + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSGMonth extends XSPatternBase { - /** Jakarta's common-logging logger. */ - private static final Log LOG = LogFactory.getLog(XSGMonth.class); +public final class XSGMonth extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "gMonth"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.GMONTH_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass ("org.exolab.castor.types.GMonth"); @@ -65,237 +38,106 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass ("org.exolab.castor.types.GMonth"); - /** Maximum Month (inclusive). */ - private String _maxInclusive; - /** Maximum Month (exclusive). */ - private String _maxExclusive; - /** Maximum Month (inclusive). */ - private String _minInclusive; - /** Maximum Month (exclusive). */ - private String _minExclusive; + //-------------------------------------------------------------------------- /** - * No-Arg constructor. + * {@inheritDoc} */ - public XSGMonth() { - super(XSType.GMONTH_TYPE); - } + public String getName() { return NAME; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSGMonth.JTYPE; - } + public short getType() { return TYPE; } /** - * Returns the maximum exclusive value that this XSGMonth can hold. - * @return the maximum exclusive value that this XSGMonth can hold. If - * no maximum exclusive value has been set, null will be returned - * @see #getMaxInclusive + * {@inheritDoc} */ - public String getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive - + public boolean isPrimitive() { return false; } + /** - * Returns the maximum inclusive value that this XSGMonth can hold. - * @return the maximum inclusive value that this XSGMonth can hold. If - * no maximum inclusive value has been set, null will be returned - * @see #getMaxExclusive + * {@inheritDoc} */ - public String getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive - + public boolean isDateTime() { return true; } + /** - * Returns the minimum exclusive value that this XSGMonth can hold. - * @return the minimum exclusive value that this XSGMonth can hold. If - * no minimum exclusive value has been set, null will be returned - * @see #getMinInclusive - * @see #setMaxInclusive + * {@inheritDoc} */ - public String getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + public JType getJType() { return JTYPE; } /** - * Returns the minimum inclusive value that this XSGMonth can hold. - * @return the minimum inclusive value that this can XSGMonth hold. If - * no minimum inclusive value has been set, null will be returned - * @see #getMinExclusive + * {@inheritDoc} */ - public String getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive - + public String newInstanceCode() { + return "new " + getJType().getName() + "();"; + } + /** - * Sets the maximum exclusive value that this XSGMonth can hold. - * @param max the maximum exclusive value this XSGMonth can be - * @see #setMaxInclusive + * {@inheritDoc} */ - public void setMaxExclusive(final String max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive - - /** - * Sets the maximum inclusive value that this XSGMonth can hold. - * @param max the maximum inclusive value this XSGMonth can be - * @see #setMaxExclusive - */ - public void setMaxInclusive(final String max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the minimum exclusive value that this XSGMonth can hold. - * @param min the minimum exclusive value this XSGMonth can be - * @see #setMinInclusive - */ - public void setMinExclusive(final String min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + /** - * Sets the minimum inclusive value that this XSGMonth can hold. - * @param min the minimum inclusive value this XSGMonth can be - * @see #setMinExclusive + * {@inheritDoc} */ - public void setMinInclusive(final String min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. - */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().getName() + ") " + variableName; } - /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. - */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } + //-------------------------------------------------------------------------- /** - * Transfer facets from the provided simpleType to this. The - * GMonth SimpleType supports the following facets: - * - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DateTimeValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (Facet.MAX_EXCLUSIVE.equals(name)) { - this.setMaxExclusive(facet.getValue()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - this.setMaxInclusive(facet.getValue()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - this.setMinExclusive(facet.getValue()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - this.setMinInclusive(facet.getValue()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - LOG.warn("Warning: The facet 'whitespace' can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'gMonth'."); - } - } - } //while - } //setFacets + if (fixedValue != null) { + jsc.add("try {\n" + + " typeValidator.setFixed({0});\n" + + "} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", fixedValue); + } - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator =" - + " new org.exolab.castor.xml.validators.DateTimeValidator();"); - - boolean addTryCatch = _minInclusive != null || _minExclusive != null - || _maxInclusive != null || _maxExclusive != null || fixedValue != null; + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - if (addTryCatch) { + if (hasMinimum() || hasMaximum()) { jsc.add("try {"); - jsc.indent(); - } - - // minInclusive / minExclusive facets (only one or the other, never both) - if (_minInclusive != null) { - jsc.add("org.exolab.castor.types.GMonth min = " - + "org.exolab.castor.types.GMonth.parseGMonth(\"" + _minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } else if (_minExclusive != null) { - jsc.add("org.exolab.castor.types.GMonth min = " - + "org.exolab.castor.types.GMonth.parseGMonth(\"" + _minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } - // maxInclusive / maxExclusive facets (only one or the other, never both) - if (_maxInclusive != null) { - jsc.add("org.exolab.castor.types.GMonth max = " - + "org.exolab.castor.types.GMonth.parseGMonth(\"" + _maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); - } else if (_maxExclusive != null) { - jsc.add("org.exolab.castor.types.GMonth max = " - + "org.exolab.castor.types.GMonth.parseGMonth(\"" + _maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } + // minInclusive / minExclusive facets (only one or the other, never both) + if (getMinInclusive() != null) { + jsc.add(" org.exolab.castor.types.GMonth min;\n" + + " min = org.exolab.castor.types.GMonth.parseGMonth(\"{0}\");\n" + + " typeValidator.setMinInclusive(min);", getMinInclusive()); + } else if (getMinExclusive() != null) { + jsc.add(" org.exolab.castor.types.GMonth min;\n" + + " min = org.exolab.castor.types.GMonth.parseGMonth(\"{0}\");\n" + + " typeValidator.setMinExclusive(min);", getMinExclusive()); + } - // fixed values - if (fixedValue != null) { - jsc.add("typeValidator.setFixed(" + fixedValue + ");"); - } + // maxInclusive / maxExclusive facets (only one or the other, never both) + if (getMaxInclusive() != null) { + jsc.add(" org.exolab.castor.types.GMonth max;\n" + + " max = org.exolab.castor.types.GMonth.parseGMonth(\"{0}\");\n" + + " typeValidator.setMaxInclusive(max);", getMaxInclusive()); + } else if (getMaxExclusive() != null) { + jsc.add(" org.exolab.castor.types.GMonth max;\n" + + " max = org.exolab.castor.types.GMonth.parseGMonth(\"{0}\");\n" + + " typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } - if (addTryCatch) { - jsc.unindent(); - jsc.add("} catch (java.text.ParseException pe) {"); - jsc.indent(); - jsc.add("System.out.println(\"ParseException\" + pe);"); - jsc.unindent(); - jsc.add("}"); + jsc.add("} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", ""); } - - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); } -} //-- XSGMonth + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGMonthDay.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGMonthDay.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGMonthDay.java (working copy) @@ -1,54 +1,20 @@ /* - * 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 2001-2002 (C) Intalio, Inc. All Rights Reserved. - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -54,13 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema gMonthDay type. - * @author Arnaud Blandin + * The xsd:gMonthDay XML Schema type. + * + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSGMonthDay extends XSPatternBase { - /** Jakarta's common-logging logger. */ - private static final Log LOG = LogFactory.getLog(XSGMonthDay.class); +public final class XSGMonthDay extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "gMonthDay"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.GMONTHDAY_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass ("org.exolab.castor.types.GMonthDay"); @@ -65,241 +38,106 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass ("org.exolab.castor.types.GMonthDay"); - /** Maximum MonthDay (inclusive). */ - private String _maxInclusive; - /** Maximum MonthDay (exclusive). */ - private String _maxExclusive; - /** Minimum MonthDay (inclusive). */ - private String _minInclusive; - /** Minimum MonthDay (exclusive). */ - private String _minExclusive; + //-------------------------------------------------------------------------- /** - * No-Arg constructor. + * {@inheritDoc} */ - public XSGMonthDay() { - super(XSType.GMONTHDAY_TYPE); - } + public String getName() { return NAME; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSGMonthDay.JTYPE; - } + public short getType() { return TYPE; } /** - * Returns the maximum exclusive value that this XSGMonthDay can hold. - * @return the maximum exclusive value that this XSGMonthDay can hold. If - * no maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive + * {@inheritDoc} */ - public String getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive - + public boolean isPrimitive() { return false; } + /** - * Returns the maximum inclusive value that this XSGMonthDay can hold. - * @return the maximum inclusive value that this XSGMonthDay can hold. If - * no maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive + * {@inheritDoc} */ - public String getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive - + public boolean isDateTime() { return true; } + /** - * Returns the minimum exclusive value that this XSGMonthDay can hold. - * @return the minimum exclusive value that this XSGMonthDay can hold. If - * no minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive - * @see #setMaxInclusive + * {@inheritDoc} */ - public String getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + public JType getJType() { return JTYPE; } /** - * Returns the minimum inclusive value that this XSGMonthDay can hold. - * @return the minimum inclusive value that this can XSGMonthDay hold. If - * no minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive + * {@inheritDoc} */ - public String getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive - + public String newInstanceCode() { + return "new " + getJType().getName() + "();"; + } + /** - * Sets the maximum exclusive value that this XSGMonthDay can hold. - * @param max the maximum exclusive value this XSGMonthDay can be - * @see #setMaxInclusive + * {@inheritDoc} */ - public void setMaxExclusive(final String max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive - - /** - * Sets the maximum inclusive value that this XSGMonthDay can hold. - * @param max the maximum inclusive value this XSGMonthDay can be - * @see #setMaxExclusive - */ - public void setMaxInclusive(final String max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the minimum exclusive value that this XSGMonthDay can hold. - * @param min the minimum exclusive value this XSGMonthDay can be - * @see #setMinInclusive - */ - public void setMinExclusive(final String min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + /** - * Sets the minimum inclusive value that this XSGMonthDay can hold. - * @param min the minimum inclusive value this XSGMonthDay can be - * @see #setMinExclusive + * {@inheritDoc} */ - public void setMinInclusive(final String min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. - */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().getName() + ") " + variableName; } - /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. - */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } + //-------------------------------------------------------------------------- /** - * Transfer facets from the provided simpleType to this. The - * GMonth SimpleType supports the following facets: - * - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DateTimeValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (Facet.MAX_EXCLUSIVE.equals(name)) { - this.setMaxExclusive(facet.getValue()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - this.setMaxInclusive(facet.getValue()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - this.setMinExclusive(facet.getValue()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - this.setMinInclusive(facet.getValue()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - LOG.warn("Warning: The facet 'whitespace' can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'gMonthDay'."); - } - } - } //while - } //setFacets + if (fixedValue != null) { + jsc.add("try {\n" + + " typeValidator.setFixed({0});\n" + + "} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", fixedValue); + } - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator =" - + " new org.exolab.castor.xml.validators.DateTimeValidator();"); - - boolean addTryCatch = _minInclusive != null || _minExclusive != null - || _maxInclusive != null || _maxExclusive != null || fixedValue != null; + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - if (addTryCatch) { + if (hasMinimum() || hasMaximum()) { jsc.add("try {"); - jsc.indent(); - } - - // minInclusive / minExclusive facets (only one or the other, never both) - if (_minInclusive != null) { - jsc.add("org.exolab.castor.types.GMonthDay min = " - + "org.exolab.castor.types.GMonthDay.parseGMonthDay(\"" - + _minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } else if (_minExclusive != null) { - jsc.add("org.exolab.castor.types.GMonthDay min = " - + "org.exolab.castor.types.GMonthDay.parseGMonthDay(\"" - + _minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } - // maxInclusive / maxExclusive facets (only one or the other, never both) - if (_maxInclusive != null) { - jsc.add("org.exolab.castor.types.GMonthDay max = " - + "org.exolab.castor.types.GMonthDay.parseGMonthDay(\"" - + _maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); - } else if (_maxExclusive != null) { - jsc.add("org.exolab.castor.types.GMonthDay max = " - + "org.exolab.castor.types.GMonthDay.parseGMonthDay(\"" - + _maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } + // minInclusive / minExclusive facets (only one or the other, never both) + if (getMinInclusive() != null) { + jsc.add(" org.exolab.castor.types.GMonthDay min;\n" + + " min = org.exolab.castor.types.GMonthDay.parseGMonthDay(\"{0}\");\n" + + " typeValidator.setMinInclusive(min);", getMinInclusive()); + } else if (getMinExclusive() != null) { + jsc.add(" org.exolab.castor.types.GMonthDay min;\n" + + " min = org.exolab.castor.types.GMonthDay.parseGMonthDay(\"{0}\");\n" + + " typeValidator.setMinExclusive(min);", getMinExclusive()); + } - // fixed values - if (fixedValue != null) { - jsc.add("typeValidator.setFixed(" + fixedValue + ");"); - } + // maxInclusive / maxExclusive facets (only one or the other, never both) + if (getMaxInclusive() != null) { + jsc.add(" org.exolab.castor.types.GMonthDay max;\n" + + " max = org.exolab.castor.types.GMonthDay.parseGMonthDay(\"{0}\");\n" + + "typeValidator.setMaxInclusive(max);", getMaxInclusive()); + } else if (getMaxExclusive() != null) { + jsc.add(" org.exolab.castor.types.GMonthDay max;\n" + + " max = org.exolab.castor.types.GMonthDay.parseGMonthDay(\"{0}\");\n" + + " typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } - if (addTryCatch) { - jsc.unindent(); - jsc.add("} catch (java.text.ParseException pe) {"); - jsc.indent(); - jsc.add("System.out.println(\"ParseException\" + pe);"); - jsc.unindent(); - jsc.add("}"); + jsc.add("} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", ""); } - - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); } + //-------------------------------------------------------------------------- } Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGYear.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGYear.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGYear.java (working copy) @@ -1,54 +1,20 @@ /* - * 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 2001-2002 (C) Intalio, Inc. All Rights Reserved. - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -54,13 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema gYear type. - * @author Arnaud Blandin + * The xsd:gYear XML Schema type. + * + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSGYear extends XSPatternBase { - /** Jakarta's common-logging logger. */ - private static final Log LOG = LogFactory.getLog(XSGYear.class); +public final class XSGYear extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "gYear"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.GYEAR_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass ("org.exolab.castor.types.GYear"); @@ -65,237 +38,106 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass ("org.exolab.castor.types.GYear"); - /** Maximum Year (inclusive). */ - private String _maxInclusive; - /** Maximum MonthDay (exclusive). */ - private String _maxExclusive; - /** Minimum MonthDay (inclusive). */ - private String _minInclusive; - /** Minimum MonthDay (exclusive). */ - private String _minExclusive; + //-------------------------------------------------------------------------- /** - * No-Arg constructor. + * {@inheritDoc} */ - public XSGYear() { - super(XSType.GYEAR_TYPE); - } + public String getName() { return NAME; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSGYear.JTYPE; - } + public short getType() { return TYPE; } /** - * Returns the maximum exclusive value that this XSGYear can hold. - * @return the maximum exclusive value that this XSGYear can hold. If - * no maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive + * {@inheritDoc} */ - public String getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive - + public boolean isPrimitive() { return false; } + /** - * Returns the maximum inclusive value that this XSGYear can hold. - * @return the maximum inclusive value that this XSGYear can hold. If - * no maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive + * {@inheritDoc} */ - public String getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive - + public boolean isDateTime() { return true; } + /** - * Returns the minimum exclusive value that this XSGYear can hold. - * @return the minimum exclusive value that this XSGYear can hold. If - * no minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive - * @see #setMaxInclusive + * {@inheritDoc} */ - public String getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + public JType getJType() { return JTYPE; } /** - * Returns the minimum inclusive value that this XSGYear can hold. - * @return the minimum inclusive value that this can XSGYear hold. If - * no minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive + * {@inheritDoc} */ - public String getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive - + public String newInstanceCode() { + return "new " + getJType().getName() + "();"; + } + /** - * Sets the maximum exclusive value that this XSGYear can hold. - * @param max the maximum exclusive value this XSGYear can be - * @see #setMaxInclusive + * {@inheritDoc} */ - public void setMaxExclusive(final String max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive - - /** - * Sets the maximum inclusive value that this XSGYear can hold. - * @param max the maximum inclusive value this XSGYear can be - * @see #setMaxExclusive - */ - public void setMaxInclusive(final String max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the minimum exclusive value that this XSGYear can hold. - * @param min the minimum exclusive value this XSGYear can be - * @see #setMinInclusive - */ - public void setMinExclusive(final String min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + /** - * Sets the minimum inclusive value that this XSGYear can hold. - * @param min the minimum inclusive value this XSGYear can be - * @see #setMinExclusive + * {@inheritDoc} */ - public void setMinInclusive(final String min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. - */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().getName() + ") " + variableName; } - /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. - */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } + //-------------------------------------------------------------------------- /** - * Transfer facets from the provided simpleType to this. The - * GYear SimpleType supports the following facets: - * - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DateTimeValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (Facet.MAX_EXCLUSIVE.equals(name)) { - this.setMaxExclusive(facet.getValue()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - this.setMaxInclusive(facet.getValue()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - this.setMinExclusive(facet.getValue()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - this.setMinInclusive(facet.getValue()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - LOG.warn("Warning: The facet 'whitespace' can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'gYear'."); - } - } - } //while - } //setFacets + if (fixedValue != null) { + jsc.add("try {\n" + + " typeValidator.setFixed({0});\n" + + "} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", fixedValue); + } - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator =" - + " new org.exolab.castor.xml.validators.DateTimeValidator();"); - - boolean addTryCatch = _minInclusive != null || _minExclusive != null - || _maxInclusive != null || _maxExclusive != null || fixedValue != null; + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - if (addTryCatch) { + if (hasMinimum() || hasMaximum()) { jsc.add("try {"); - jsc.indent(); - } - - // minInclusive / minExclusive facets (only one or the other, never both) - if (_minInclusive != null) { - jsc.add("org.exolab.castor.types.GYear min = " - + "org.exolab.castor.types.GYear.parseGYear(\"" + _minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } else if (_minExclusive != null) { - jsc.add("org.exolab.castor.types.GYear min = " - + "org.exolab.castor.types.GYear.parseGYear(\"" + _minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } - // maxInclusive / maxExclusive facets (only one or the other, never both) - if (_maxInclusive != null) { - jsc.add("org.exolab.castor.types.GYear max = " - + "org.exolab.castor.types.GYear.parseGYear(\"" + _maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); - } else if (_maxExclusive != null) { - jsc.add("org.exolab.castor.types.GYear max = " - + "org.exolab.castor.types.GYear.parseGYear(\"" + _maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } + // minInclusive / minExclusive facets (only one or the other, never both) + if (getMinInclusive() != null) { + jsc.add(" org.exolab.castor.types.GYear min;\n" + + " min = org.exolab.castor.types.GYear.parseGYear(\"{0}\");\n" + + " typeValidator.setMinInclusive(min);", getMinInclusive()); + } else if (getMinExclusive() != null) { + jsc.add(" org.exolab.castor.types.GYear min;\n" + + " min = org.exolab.castor.types.GYear.parseGYear(\"{0}\");\n" + + " typeValidator.setMinExclusive(min);", getMinExclusive()); + } - // fixed values - if (fixedValue != null) { - jsc.add("typeValidator.setFixed(" + fixedValue + ");"); - } + // maxInclusive / maxExclusive facets (only one or the other, never both) + if (getMaxInclusive() != null) { + jsc.add(" org.exolab.castor.types.GYear max;\n" + + " max = org.exolab.castor.types.GYear.parseGYear(\"{0}\");\n" + + " typeValidator.setMaxInclusive(max);", getMaxInclusive()); + } else if (getMaxExclusive() != null) { + jsc.add(" org.exolab.castor.types.GYear max;\n" + + " max = org.exolab.castor.types.GYear.parseGYear(\"{0}\");\n" + + " typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } - if (addTryCatch) { - jsc.unindent(); - jsc.add("} catch (java.text.ParseException pe) {"); - jsc.indent(); - jsc.add("System.out.println(\"ParseException\" + pe);"); - jsc.unindent(); - jsc.add("}"); + jsc.add("} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", ""); } - - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); } -} //-- XSGYear + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGYearMonth.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGYearMonth.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSGYearMonth.java (working copy) @@ -1,54 +1,20 @@ /* - * 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 2001-2002 (C) Intalio, Inc. All Rights Reserved. - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -54,13 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema gYearMonth type. - * @author Arnaud Blandin + * The xsd:gYearMonth XML Schema type. + * + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSGYearMonth extends XSPatternBase { - /** Jakarta's common-logging logger. */ - private static final Log LOG = LogFactory.getLog(XSGYearMonth.class); +public final class XSGYearMonth extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "gYearMonth"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.GYEARMONTH_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("org.exolab.castor.types.GYearMonth"); @@ -65,241 +38,106 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("org.exolab.castor.types.GYearMonth"); - /** Maximum YearMonth (inclusive). */ - private String _maxInclusive; - /** Maximum YearMonth (exclusive). */ - private String _maxExclusive; - /** Minimum YearMonth (inclusive). */ - private String _minInclusive; - /** Minimum YearMonth (exclusive). */ - private String _minExclusive; + //-------------------------------------------------------------------------- /** - * No-Arg constructor. + * {@inheritDoc} */ - public XSGYearMonth() { - super(XSType.GYEARMONTH_TYPE); - } + public String getName() { return NAME; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSGYearMonth.JTYPE; - } + public short getType() { return TYPE; } /** - * Returns the maximum exclusive value that this XSGYearMonth can hold. - * @return the maximum exclusive value that this XSGYearMonth can hold. If - * no maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive + * {@inheritDoc} */ - public String getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive - + public boolean isPrimitive() { return false; } + /** - * Returns the maximum inclusive value that this XSGYearMonth can hold. - * @return the maximum inclusive value that this XSGYearMonth can hold. If - * no maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive + * {@inheritDoc} */ - public String getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive - + public boolean isDateTime() { return true; } + /** - * Returns the minimum exclusive value that this XSGYearMonth can hold. - * @return the minimum exclusive value that this XSGYearMonth can hold. If - * no minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive - * @see #setMaxInclusive + * {@inheritDoc} */ - public String getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + public JType getJType() { return JTYPE; } /** - * Returns the minimum inclusive value that this XSGYearMonth can hold. - * @return the minimum inclusive value that this can XSGYearMonth hold. If - * no minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive + * {@inheritDoc} */ - public String getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive - - /** - * Sets the maximum exclusive value that this XSGYearMonth can hold. - * @param max the maximum exclusive value this XSGYearMonth can be - * @see #setMaxInclusive - */ - public void setMaxExclusive(final String max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive - + public String newInstanceCode() { + return "new " + getJType().getName() + "();"; + } + /** - * Sets the maximum inclusive value that this XSGYearMonth can hold. - * @param max the maximum inclusive value this XSGYearMonth can be - * @see #setMaxExclusive - */ - public void setMaxInclusive(final String max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the minimum exclusive value that this XSGYearMonth can hold. - * @param min the minimum exclusive value this XSGYearMonth can be - * @see #setMinInclusive - */ - public void setMinExclusive(final String min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - - /** - * Sets the minimum inclusive value that this XSGYearMonth can hold. - * @param min the minimum inclusive value this XSGYearMonth can be - * @see #setMinExclusive - */ - public void setMinInclusive(final String min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; + public String createToJavaObjectCode(final String variableName) { + return variableName; } - + /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().getName() + ") " + variableName; } + //-------------------------------------------------------------------------- + /** - * Transfer facets from the provided simpleType to this. The - * GYearMonth SimpleType supports the following facets: - * - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_EXCLUSIVE.equals(name)) { - this.setMaxExclusive(facet.getValue()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - this.setMaxInclusive(facet.getValue()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - this.setMinExclusive(facet.getValue()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - this.setMinInclusive(facet.getValue()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - LOG.warn("Warning: The facet 'whitespace' can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'gYearMonth'."); - } - } - } //while - } //setFacets + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DateTimeValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator =" - + " new org.exolab.castor.xml.validators.DateTimeValidator();"); + if (fixedValue != null) { + jsc.add("try {\n" + + " typeValidator.setFixed({0});\n" + + "} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", fixedValue); + } - boolean addTryCatch = _minInclusive != null || _minExclusive != null - || _maxInclusive != null || _maxExclusive != null || fixedValue != null; + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - if (addTryCatch) { + if (hasMinimum() || hasMaximum()) { jsc.add("try {"); - jsc.indent(); - } - // minInclusive / minExclusive facets (only one or the other, never both) - if (_minInclusive != null) { - jsc.add("org.exolab.castor.types.GYearMonth min = " - + "org.exolab.castor.types.GYearMonth.parseGYearMonth(\"" - + _minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } else if (_minExclusive != null) { - jsc.add("org.exolab.castor.types.GYearMonth min = " - + "org.exolab.castor.types.GYearMonth.parseGYearMonth(\"" - + _minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } + // minInclusive / minExclusive facets (only one or the other, never both) + if (getMinInclusive() != null) { + jsc.add(" org.exolab.castor.types.GYearMonth min;\n" + + " min = org.exolab.castor.types.GYearMonth.parseGYearMonth(\"{0}\");\n" + + " typeValidator.setMinInclusive(min);", getMinInclusive()); + } else if (getMinExclusive() != null) { + jsc.add(" org.exolab.castor.types.GYearMonth min;\n" + + " min = org.exolab.castor.types.GYearMonth.parseGYearMonth(\"{0}\");\n" + + " typeValidator.setMinExclusive(min);", getMinExclusive()); + } - // maxInclusive / maxExclusive facets (only one or the other, never both) - if (_maxInclusive != null) { - jsc.add("org.exolab.castor.types.GYearMonth max = " - + "org.exolab.castor.types.GYearMonth.parseGYearMonth(\"" - + _maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); - } else if (_maxExclusive != null) { - jsc.add("org.exolab.castor.types.GYearMonth max = " - + "org.exolab.castor.types.GYearMonth.parseGYearMonth(\"" - + _maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } - - // fixed values - if (fixedValue != null) { - jsc.add("typeValidator.setFixed(" + fixedValue + ");"); - } + // maxInclusive / maxExclusive facets (only one or the other, never both) + if (getMaxInclusive() != null) { + jsc.add(" org.exolab.castor.types.GYearMonth max;\n" + + " max = org.exolab.castor.types.GYearMonth.parseGYearMonth(\"{0}\");\n" + + " typeValidator.setMaxInclusive(max);", getMaxInclusive()); + } else if (getMaxExclusive() != null) { + jsc.add(" org.exolab.castor.types.GYearMonth max;\n" + + " max = org.exolab.castor.types.GYearMonth.parseGYearMonth(\"{0}\");\n" + + " typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } - if (addTryCatch) { - jsc.unindent(); - jsc.add("} catch (java.text.ParseException pe) {"); - jsc.indent(); - jsc.add("System.out.println(\"ParseException\" + pe);"); - jsc.unindent(); - jsc.add("}"); + jsc.add("} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", ""); } - - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); } + //-------------------------------------------------------------------------- } Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSHexBinary.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSHexBinary.java (revision 0) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSHexBinary.java (revision 0) @@ -0,0 +1,115 @@ +/* + * Copyright 2007 Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.exolab.castor.builder.types; + +import org.exolab.javasource.JArrayType; +import org.exolab.javasource.JSourceCode; +import org.exolab.javasource.JType; + +/** + * The xsd:hexBinary XML Schema datatype. + * + * @author Ralf Joachim + * @version $Revision: 6623 $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ + * @since 1.1 + */ +public final class XSHexBinary extends AbstractLengthFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "hexBinary"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.HEXBINARY_TYPE; + + //-------------------------------------------------------------------------- + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- + + /** + * Create a new XSHexBinary object. + * + * @param useJava50 If true, Java 5 code artifacts will be generated. + */ + public XSHexBinary(final boolean useJava50) { + super(); + + _jType = new JArrayType(JType.BYTE, useJava50); + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + + /** + * {@inheritDoc} + */ + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new byte[] {};"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().toString() + ") " + variableName; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + // Not implemented + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSId.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSId.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSId.java (working copy) @@ -1,50 +1,20 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -50,11 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema ID type. - * @author Keith Visco + * The xsd:ID XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSId extends XSType { +public final class XSId extends AbstractLengthFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "ID"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.ID_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); @@ -59,51 +38,73 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + /** - * No-arg constructor. + * {@inheritDoc} */ - public XSId() { - super(XSType.ID_TYPE); - } //-- XSId + public short getType() { return TYPE; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} + */ + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} */ - public JType getJType() { - return XSId.JTYPE; + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return JTYPE; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.String();"; } - + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - // not implemented + public String createFromJavaObjectCode(final String variableName) { + return "(java.lang.String) " + variableName; } + //-------------------------------------------------------------------------- + /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.IdValidator typeValidator" - + " = new org.exolab.castor.xml.validators.IdValidator();"); - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.IdValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.IdValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); + } + + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + codeLengthFacet(jsc, "typeValidator"); } -} //-- XSId + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSIdRef.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSIdRef.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSIdRef.java (working copy) @@ -1,50 +1,20 @@ -/** - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ +/* + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -50,11 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema IDREF type. - * @author Keith Visco + * The xsd:IDREF XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSIdRef extends XSType { +public final class XSIdRef extends AbstractLengthFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "IDREF"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.IDREF_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.Object"); @@ -59,47 +38,74 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.Object"); + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + /** - * No-arg constructor. + * {@inheritDoc} */ - public XSIdRef() { - super(XSType.IDREF_TYPE); - } //-- XSId + public short getType() { return TYPE; } /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - // Not implemented + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return JTYPE; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.Object();"; } - + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSIdRef.JTYPE; + public String createFromJavaObjectCode(final String variableName) { + return variableName; } + //-------------------------------------------------------------------------- + /** - * Creates the validation code for an instance of this XSType. The validation - * code should if necessary create a newly configured TypeValidator, that - * should then be added to a FieldValidator instance whose name is provided. - * - * @param fixedValue a fixed value to use if any - * @param jsc the JSourceCode to fill in. - * @param fieldValidatorInstanceName the name of the FieldValidator - * that the configured TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.IdRefValidator typeValidator = " - + "new org.exolab.castor.xml.validators.IdRefValidator();"); - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.IdRefValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.IdRefValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + // Not supported by IdRefValidator yet + // if (fixedValue != null) { + // jsc.add("typeValidator.setFixed(" + fixedValue + ");"); + // } + + // codePatternFacet(jsc, "typeValidator"); + // codeWhiteSpaceFacet(jsc, "typeValidator"); + // codeLengthFacet(jsc, "typeValidator"); } -} //-- XSIdRef + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSInt.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSInt.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSInt.java (working copy) @@ -1,54 +1,20 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ - package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -54,28 +20,36 @@ import org.exolab.javasource.JType; /** - * The XML Schema 'Int' type. + * The xsd:int XML Schema type. * - * @author Keith Visco + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ */ -public class XSInt extends XSPatternBase { +public final class XSInt extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- - /** Maximum integer (inclusive). */ - private Integer _maxInclusive = null; - /** Maximum integer (exclusive). */ - private Integer _maxExclusive = null; - /** Minimum integer (inclusive). */ - private Integer _minInclusive = null; - /** Minimum integer (exclusive). */ - private Integer _minExclusive = null; - /** Maximum (inclusive) number of digits. */ - private int _totalDigits = -1; + /** Name of this XSType. */ + public static final String NAME = "int"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.INT_TYPE; + + /** A constant holding the minimum value an xsd:int can have, -231. */ + public static final String MIN_VALUE = Integer.toString(Integer.MIN_VALUE); + + /** A constant holding the maximum value an xsd:int can have, 231-1. */ + public static final String MAX_VALUE = Integer.toString(Integer.MAX_VALUE); + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; + /** The JType represented by this XSType. */ private final JType _jType; - /** True if this type is implemented using the wrapper class. */ - private final boolean _asWrapper; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -86,353 +60,105 @@ /** * Constructs a new XSInt. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ public XSInt(final boolean asWrapper) { - this(asWrapper, XSType.INT_TYPE); - } // -- XSInt - - /** - * Constructs a new XSInt. This constructor is used by derived - * classes. - * @param asWrapper if true, use the java.lang wrapper class. - * @param type the type code to be constructed, either XSType.INT_TYPE - * or one of the types derived from it. - */ - protected XSInt(final boolean asWrapper, final short type) { - super(type); - _asWrapper = asWrapper; - - if (_asWrapper) { - _jType = new JClass("java.lang.Integer"); - } else { - _jType = JType.INT; - } - - setMinInclusive(Integer.MIN_VALUE); - setMaxInclusive(Integer.MAX_VALUE); - } //-- XSInteger - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public final JType getJType() { - return _jType; - } - - /** - * Returns the maximum exclusive value that this XSInt can hold. - * - * @return the maximum exclusive value that this XSInt can hold. If no - * maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive - */ - public final Integer getMaxExclusive() { - return _maxExclusive; - } // -- getMaxExclusive - - /** - * Returns the maximum inclusive value that this XSInt can hold. - * - * @return the maximum inclusive value that this XSInt can hold. If no - * maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive - */ - public final Integer getMaxInclusive() { - return _maxInclusive; - } // -- getMaxInclusive - - /** - * Returns the minimum exclusive value that this XSInt can hold. - * - * @return the minimum exclusive value that this XSInt can hold. If no - * minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive() - * @see #setMaxInclusive(int) - */ - public final Integer getMinExclusive() { - return _minExclusive; - } // -- getMinExclusive - - /** - * Returns the minimum inclusive value that this XSInt can hold. - * - * @return the minimum inclusive value that this XSInt can hold. If no - * minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive - */ - public final Integer getMinInclusive() { - return _minInclusive; - } // -- getMinInclusive - - /** - * Returns the totalDigits facet value of this XSInteger. - * @return the totalDigits facet value of this XSInteger. - */ - public final int getTotalDigits() { - return _totalDigits; + super(); + + _asWrapper = asWrapper; + if (_asWrapper) { + _jType = new JClass("java.lang.Integer"); + } else { + _jType = JType.INT; + } + + setMinInclusive(MIN_VALUE); + setMaxInclusive(MAX_VALUE); } - /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. - */ - public final boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } //-- hasMaximum + //-------------------------------------------------------------------------- /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public final boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; - } //-- hasMinimum + public String getName() { return NAME; } /** - * Sets the maximum exclusive value that this XSInt can hold. - * - * @param max - * the maximum exclusive value this XSInt can be - * @see #setMaxInclusive(Integer) + * {@inheritDoc} */ - public final void setMaxExclusive(final int max) { - _maxExclusive = new Integer(max); - _maxInclusive = null; - } // -- setMaxExclusive + public short getType() { return TYPE; } /** - * Sets the maximum exclusive value that this XSInt can hold. - * - * @param max - * the maximum exclusive value this XSInt can be - * @see #setMaxInclusive(int) + * {@inheritDoc} */ - public final void setMaxExclusive(final Integer max) { - _maxExclusive = max; - _maxInclusive = null; - } // -- setMaxExclusive - + public boolean isPrimitive() { return true; } + /** - * Sets the maximum inclusive value that this XSInt can hold. - * - * @param max - * the maximum inclusive value this XSInt can be - * @see #setMaxExclusive(Integer) + * {@inheritDoc} */ - public final void setMaxInclusive(final int max) { - _maxInclusive = new Integer(max); - _maxExclusive = null; - } // -- setMaxInclusive - + public boolean isDateTime() { return false; } + /** - * Sets the maximum inclusive value that this XSInt can hold. - * - * @param max - * the maximum inclusive value this XSInt can be - * @see #setMaxExclusive(int) + * {@inheritDoc} */ - public final void setMaxInclusive(final Integer max) { - _maxInclusive = max; - _maxExclusive = null; - } // -- setMaxInclusive + public JType getJType() { return _jType; } /** - * Sets the minimum exclusive value that this XSInt can hold. - * - * @param min - * the minimum exclusive value this XSInt can be - * @see #setMinInclusive(Integer) + * {@inheritDoc} */ - public final void setMinExclusive(final int min) { - _minExclusive = new Integer(min); - _minInclusive = null; - } // -- setMinExclusive - - /** - * Sets the minimum exclusive value that this XSInt can hold. - * - * @param min - * the minimum exclusive value this XSInt can be - * @see #setMinInclusive(int) - */ - public final void setMinExclusive(final Integer min) { - _minExclusive = min; - _minInclusive = null; - } // -- setMinExclusive - - /** - * Sets the minimum inclusive value that this XSInt can hold. - * - * @param min - * the minimum inclusive value this XSInt can be - * @see #setMinExclusive(Integer) - */ - public final void setMinInclusive(final int min) { - _minInclusive = new Integer(min); - _minExclusive = null; - } // -- setMinInclusive - - /** - * Sets the minimum inclusive value that this XSInt can hold. - * - * @param min - * the minimum inclusive value this XSInt can be - * @see #setMinExclusive(int) - */ - public final void setMinInclusive(final Integer min) { - _minInclusive = min; - _minExclusive = null; - } // -- setMinInclusive - - /** - * Sets the totalDigits facet for this XSInteger. - * @param totalDig the value of totalDigits (must be > 0) - */ - public final void setTotalDigits(final int totalDig) { - if (totalDig <= 0) { - throw new IllegalArgumentException(this.getName() - + ": the totalDigits facet must be positive"); - } - _totalDigits = totalDig; - } - - /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets - */ - public final void setFacets(final SimpleType simpleType) { - // -- copy valid facets - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_EXCLUSIVE.equals(name)) { - setMaxExclusive(facet.toInt()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - setMaxInclusive(facet.toInt()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - setMinExclusive(facet.toInt()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - setMinInclusive(facet.toInt()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.TOTALDIGITS.equals(name)) { - setTotalDigits(facet.toInt()); - } else if (Facet.FRACTIONDIGITS.equals(name)) { - if (facet.toInt() != 0) { - throw new IllegalArgumentException("fractionDigits must be 0 for " - + this.getName()); - } - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - throw new IllegalArgumentException("Warning: The facet 'whitespace'" - + " can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for '" - + this.getName() + "'."); - } - } - } - } // -- toXSInt - + public String newInstanceCode() { + return "new java.lang.Integer(0);"; + } + /** - * Returns the String necessary to convert an instance of this XSType to an - * Object. This method is really only useful for primitive types. - * - * @param variableName - * the name of the instance variable - * @return the String necessary to convert an instance of this XSType to an - * Object + * {@inheritDoc} */ - public final String createToJavaObjectCode(final String variableName) { - if (_asWrapper) { - return super.createToJavaObjectCode(variableName); - } - + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } return "new java.lang.Integer(" + variableName + ")"; - } // -- toJavaObject + } /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} */ - public final String createFromJavaObjectCode(final String variableName) { - StringBuffer sb = new StringBuffer("((java.lang.Integer) "); - sb.append(variableName); - sb.append(")"); - if (!_asWrapper) { - sb.append(".intValue()"); - } - return sb.toString(); - } // -- fromJavaObject + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Integer) " + variableName + ")"; } + return "((java.lang.Integer) " + variableName + ").intValue()"; + } + + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public final void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.IntValidator typeValidator" - + " = new org.exolab.castor.xml.validators.IntValidator();"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.IntValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.IntValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (_minExclusive != null) { - jsc.add("typeValidator.setMinExclusive(" + _minExclusive + ");"); - } else if (_minInclusive != null) { - jsc.add("typeValidator.setMinInclusive(" + _minInclusive + ");"); - } - - if (_maxExclusive != null) { - jsc.add("typeValidator.setMaxExclusive(" + _maxExclusive + ");"); - } else if (_maxInclusive != null) { - jsc.add("typeValidator.setMaxInclusive(" + _maxInclusive + ");"); - } - - // -- fixed values if (fixedValue != null) { - // -- make sure we have a valid value... - // -- Only if we are not using Object - if (_jType == JType.INT) { - Integer.parseInt(fixedValue); - } - - jsc.add("typeValidator.setFixed("); - jsc.append(fixedValue); - jsc.append(");"); + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); } - // pattern facet codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive(" + getMinExclusive() + ");"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive(" + getMinInclusive() + ");"); + } - // -- totalDigits - int totalDigits = getTotalDigits(); - if (totalDigits != -1) { - jsc.add("typeValidator.setTotalDigits("); - jsc.append(Integer.toString(totalDigits)); - jsc.append(");"); + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive(" + getMaxExclusive() + ");"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive(" + getMaxInclusive() + ");"); } - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + codeDigitsFacet(jsc, "typeValidator"); } -} // -- XSInt + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSInteger.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSInteger.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSInteger.java (working copy) @@ -1,53 +1,20 @@ /* - * 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/). + * Copyright 2007 Keith Visco, Ralf Joachim * - * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved. + * http://www.apache.org/licenses/LICENSE-2.0 * - * $Id$ + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -53,27 +20,30 @@ import org.exolab.javasource.JType; /** - * The XML Schema Integer type. - * @author Keith Visco + * The xsd:integer XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ */ -public class XSInteger extends XSPatternBase { +public final class XSInteger extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- - /** Maximum integer (inclusive). */ - private Long _maxInclusive = null; - /** Maximum integer (exclusive). */ - private Long _maxExclusive = null; - /** Minimum integer (inclusive). */ - private Long _minInclusive = null; - /** Minimum integer (exclusive). */ - private Long _minExclusive = null; - /** Total number of digits. */ - private int _totalDigits = -1; + /** Name of this XSType. */ + public static final String NAME = "integer"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.INTEGER_TYPE; - /** The JType represented by this XSType. */ - private final JType _jType; + //-------------------------------------------------------------------------- + /** True if this type is implemented using the wrapper class. */ private final boolean _asWrapper; + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -84,331 +54,102 @@ /** * Constructs a new XSInteger. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ public XSInteger(final boolean asWrapper) { - super(XSType.INTEGER_TYPE); - _asWrapper = asWrapper; - - if (_asWrapper) { - _jType = new JClass("java.lang.Long"); - } else { - _jType = JType.LONG; - } - } //-- XSInteger - - /** - * Constructs a new XSInteger. This constructor is used by derived - * classes. - * @param asWrapper if true, use the java.lang wrapper class. - * @param type the type code to be constructed, either XSType.INTEGER_TYPE - * or one of the types derived from it. - */ - protected XSInteger(final boolean asWrapper, final short type) { - super(type); - _asWrapper = asWrapper; - - if (_asWrapper) { - _jType = new JClass("java.lang.Long"); - } else { - _jType = JType.LONG; - } - } //-- XSInteger - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public final JType getJType() { - return _jType; + super(); + + _asWrapper = asWrapper; + if (_asWrapper) { + _jType = new JClass("java.lang.Long"); + } else { + _jType = JType.LONG; + } } - /** - * Returns the maximum exclusive value that this XSInteger can hold. - * @return the maximum exclusive value that this XSInteger can hold. If - * no maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive - */ - public final Long getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive + //-------------------------------------------------------------------------- /** - * Returns the maximum inclusive value that this XSInteger can hold. - * @return the maximum inclusive value that this XSInteger can hold. If - * no maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive + * {@inheritDoc} */ - public final Long getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive + public String getName() { return NAME; } /** - * Returns the minimum exclusive value that this XSInteger can hold. - * @return the minimum exclusive value that this XSInteger can hold. If - * no minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive() - * @see #setMaxInclusive(int) + * {@inheritDoc} */ - public final Long getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + public short getType() { return TYPE; } /** - * Returns the minimum inclusive value that this XSInteger can hold. - * @return the minimum inclusive value that this XSInteger can hold. If - * no minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive + * {@inheritDoc} */ - public final Long getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive - + public boolean isPrimitive() { return true; } + /** - * Returns the totalDigits facet value of this XSInteger. - * @return the totalDigits facet value of this XSInteger. + * {@inheritDoc} */ - public final int getTotalDigits() { - return _totalDigits; - } - + public boolean isDateTime() { return false; } + /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public final boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } //-- hasMaximum - + public JType getJType() { return _jType; } + /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public final boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; - } //-- hasMinimum - - /** - * Sets the maximum exclusive value that this XSInteger can hold. - * @param max the maximum exclusive value this XSInteger can be - * @see #setMaxInclusive(Integer) - */ - public final void setMaxExclusive(final long max) { - _maxExclusive = new Long(max); - _maxInclusive = null; - } //-- setMaxExclusive - - /** - * Sets the maximum exclusive value that this XSInteger can hold. - * @param max the maximum exclusive value this XSInteger can be - * @see #setMaxInclusive(int) - */ - public final void setMaxExclusive(final Long max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive - - /** - * Sets the maximum inclusive value that this XSInteger can hold. - * @param max the maximum inclusive value this XSInteger can be - * @see #setMaxExclusive(Integer) - */ - public final void setMaxInclusive(final long max) { - _maxInclusive = new Long(max); - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the maximum inclusive value that this XSInteger can hold. - * @param max the maximum inclusive value this XSInteger can be - * @see #setMaxExclusive(int) - */ - public final void setMaxInclusive(final Long max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the minimum exclusive value that this XSInteger can hold. - * @param min the minimum exclusive value this XSInteger can be - * @see #setMinInclusive(Integer) - */ - public final void setMinExclusive(final long min) { - _minExclusive = new Long(min); - _minInclusive = null; - } //-- setMinExclusive - + public String newInstanceCode() { + return "new java.lang.Long(0);"; + } + /** - * Sets the minimum exclusive value that this XSInteger can hold. - * @param min the minimum exclusive value this XSInteger can be - * @see #setMinInclusive(int) + * {@inheritDoc} */ - public final void setMinExclusive(final Long min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - - /** - * Sets the minimum inclusive value that this XSInteger can hold. - * @param min the minimum inclusive value this XSInteger can be - * @see #setMinExclusive(Integer) - */ - public final void setMinInclusive(final long min) { - _minInclusive = new Long(min); - _minExclusive = null; - } //-- setMinInclusive - - /** - * Sets the minimum inclusive value that this XSInteger can hold. - * @param min the minimum inclusive value this XSInteger can be - * @see #setMinExclusive(int) - */ - public final void setMinInclusive(final Long min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Sets the totalDigits facet for this XSInteger. - * @param totalDig the value of totalDigits (must be > 0) - */ - public final void setTotalDigits(final int totalDig) { - if (totalDig <= 0) { - throw new IllegalArgumentException(this.getName() - + ": the totalDigits facet must be positive"); - } - _totalDigits = totalDig; - } - - /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets - */ - public final void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_EXCLUSIVE.equals(name)) { - setMaxExclusive(facet.toLong()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - setMaxInclusive(facet.toLong()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - setMinExclusive(facet.toLong()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - setMinInclusive(facet.toLong()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.TOTALDIGITS.equals(name)) { - setTotalDigits(facet.toInt()); - } else if (Facet.FRACTIONDIGITS.equals(name)) { - if (facet.toInt() != 0) { - throw new IllegalArgumentException("fractionDigits must be 0 for " - + this.getName()); - } - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - throw new IllegalArgumentException("Warning: The facet 'whitespace'" - + " can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for '" - + this.getName() + "'."); - } - } - } - } //-- setFacets - - /** - * Returns the String necessary to convert an instance of this XSType - * to an Object. This method is really only useful for primitive types - * @param variableName the name of the instance variable - * @return the String necessary to convert an instance of this XSType - * to an Object - */ - public final String createToJavaObjectCode(final String variableName) { - if (_asWrapper) { - return super.createToJavaObjectCode(variableName); - } - + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } return "new java.lang.Long(" + variableName + ")"; - } //-- toJavaObject + } /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} */ - public final String createFromJavaObjectCode(final String variableName) { - StringBuffer sb = new StringBuffer("((java.lang.Long) "); - sb.append(variableName); - sb.append(")"); - if (!_asWrapper) { - sb.append(".intValue()"); - } - return sb.toString(); - } //-- fromJavaObject + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Long) " + variableName + ")"; } + return "((java.lang.Long) " + variableName + ").longValue()"; + } + + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The validation - * code should if necessary create a newly configured TypeValidator, that - * should then be added to a FieldValidator instance whose name is provided. - * - * @param fixedValue a fixed value to use if any - * @param jsc the JSourceCode to fill in. - * @param fieldValidatorInstanceName the name of the FieldValidator - * that the configured TypeValidator should be added to. + * {@inheritDoc} */ - public final void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.IntegerValidator typeValidator" - + " = new org.exolab.castor.xml.validators.IntegerValidator();"); - - if (_minExclusive != null) { - jsc.add("typeValidator.setMinExclusive(" + _minExclusive + ");"); - } else if (_minInclusive != null) { - jsc.add("typeValidator.setMinInclusive(" + _minInclusive + ");"); - } + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.LongValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.LongValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (_maxExclusive != null) { - jsc.add("typeValidator.setMaxExclusive(" + _maxExclusive + ");"); - } else if (_maxInclusive != null) { - jsc.add("typeValidator.setMaxInclusive(" + _maxInclusive + ");"); - } - - // -- fixed values if (fixedValue != null) { - // -- make sure we have a valid value... - // -- Only if we are not using Object - - if (this._jType == JType.LONG) { - Long.parseLong(fixedValue); - } - - jsc.add("typeValidator.setFixed("); - jsc.append(fixedValue); - jsc.append(");"); + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); } - // pattern facet codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive(" + getMinExclusive() + "L);"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive(" + getMinInclusive() + "L);"); + } - // -- totalDigits - int totalDigits = getTotalDigits(); - if (totalDigits != -1) { - jsc.add("typeValidator.setTotalDigits("); - jsc.append(Integer.toString(totalDigits)); - jsc.append(");"); + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive(" + getMaxExclusive() + "L);"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive(" + getMaxInclusive() + "L);"); } - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + codeDigitsFacet(jsc, "typeValidator"); } - -} // -- XSInteger + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSList.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSList.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSList.java (working copy) @@ -1,50 +1,23 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Assaf Arkin, Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import org.exolab.castor.xml.schema.SimpleType; +import org.exolab.castor.builder.SourceGeneratorConstants; +import org.exolab.castor.xml.schema.Facet; +import org.exolab.javasource.JClass; import org.exolab.javasource.JCollectionType; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -50,93 +23,127 @@ import org.exolab.javasource.JType; /** - * A list type....this will change soon. - * @author Keith Visco + * A list type. + * + * @author Assaf Arkin + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ */ -public class XSList extends XSType { +public final 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"; - /** Maximum size of this list. */ - private int _maxSize = -1; //-- undefined - /** Minimum size of this list. */ - private int _minSize = 0; + /** Type number of this XSType. */ + public static final short TYPE = XSType.COLLECTION; - /** Content type of the collection. */ - private final XSType _contentType; + //-------------------------------------------------------------------------- + /** The JType represented by this XSType. */ private final JType _jType; + //-------------------------------------------------------------------------- + /** - * Creates a Java 1 style collection. + * Create a XSList. * - * @param contentType - * type of the collection members - * @param useJava50 - * if true, the collection will be generated using Java 5 - * features such as generics. + * @param colType Type of collection to use. + * @param contentType Type of the collection members. + * @param useJava50 If true, the collection will be generated using Java 5 + * features such as generics. */ - public XSList(final XSType contentType, final boolean useJava50) { - super(XSType.COLLECTION); - this._contentType = contentType; - this._jType = new JCollectionType("java.util.Vector", contentType.getJType(), useJava50); - } //-- XSList + public XSList(final String colType, final XSType contentType, final boolean useJava50) { + super(contentType); + + if (colType.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_ARRAY_LIST)) { + _jType = new JCollectionType("java.util.List", "java.util.ArrayList", + contentType.getJType(), useJava50); + } else if (colType.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_COLLECTION)) { + _jType = new JCollectionType("java.util.Collection", "java.util.LinkedList", + contentType.getJType(), useJava50); + } else if (colType.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_SET)) { + _jType = new JCollectionType("java.util.Set", "java.util.HashSet", + contentType.getJType(), useJava50); + } else if (colType.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_SORTED_SET)) { + _jType = new JCollectionType("java.util.SortedSet", "java.util.TreeSet", + contentType.getJType(), useJava50); + } else if (colType.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_VECTOR)) { + _jType = new JCollectionType("java.util.Vector", contentType.getJType(), useJava50); + } else if (colType.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_ODMG)) { + _jType = new JClass("org.odmg.DArray"); + } else { + _jType = null; + } + } + + //-------------------------------------------------------------------------- /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return this._jType; + 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(); + } } - + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + /** - * Returns the minimum allowed size for this list. - * @return the minimum allowed size for this list. + * {@inheritDoc} */ - public final int getMinimumSize() { - return _minSize; - } //-- getMinimumSize - + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + /** - * Returns the maximum allowed size for this list. - * @return the maximum allowed size for this list. + * {@inheritDoc} */ - public final int getMaximumSize() { - return _maxSize; - } //-- getMaximumSize + public JType getJType() { return _jType; } /** - * Returns the type contained in the list. - * @return the type contained in the list. + * {@inheritDoc} */ - public final XSType getContentType() { - return _contentType; + public String newInstanceCode() { + return "null;"; } - + /** - * Sets the maximum allowed size for this list. - * @param size new maximum size for this list + * {@inheritDoc} */ - public final void setMaximumSize(final int size) { - _maxSize = size; - } //-- setMaximumSize - + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + /** - * Sets the minimum allowed size for this list. - * @param size new minimum size for this list + * {@inheritDoc} */ - public final void setMinimumSize(final int size) { - _minSize = size; - } //-- setMinimumSize + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().toString() + ") " + variableName; + } + + //-------------------------------------------------------------------------- /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public final void setFacets(final SimpleType simpleType) { + protected void setFacet(final Facet facet) { // Not implemented } @@ -141,22 +148,12 @@ } /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public final void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - //--TBD + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + // Not implemented } - -} //-- XSList + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSListJ2.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSListJ2.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSListJ2.java (working copy) @@ -1,89 +0,0 @@ -/* - * Copyright 2000 (C) Intalio Inc. All Rights Reserved. - * - * 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 "Castor" - * nor may "Castor" appear in their names without prior written - * permission of Intalio Inc. Exolab, Castor and Intalio are - * trademarks of Intalio Inc. - * 5. Due credit should be given to the ExoLab Project - * (http://www.exolab.org/). - * THIS SOFTWARE IS PROVIDED BY INTALIO 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 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. - */ -package org.exolab.castor.builder.types; - -import org.exolab.javasource.JCollectionType; -import org.exolab.javasource.JType; - -/** - * A list type for Java 2 collections that adapts the Castor preset list type. - * We hide the _jType field of our base class. - * @author Assaf Arkin - * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ - */ -public final class XSListJ2 extends XSList { - - /** The JType represented by this XSType. */ - private final JType _jType; - - /** - * Creates a Java 1 style collection. - * - * @param contentType - * type of the collection members - * @param collectionType type of collection to use - * @param useJava50 - * if true, the collection will be generated using Java 5 - * features such as generics. - */ - public XSListJ2(final XSType contentType, final String collectionType, - final boolean useJava50) { - super(contentType, useJava50); - if (collectionType.equalsIgnoreCase("arraylist")) { - this._jType = new JCollectionType("java.util.List", "java.util.ArrayList", - contentType.getJType(), useJava50); - } else if (collectionType.equalsIgnoreCase("collection")) { - this._jType = new JCollectionType("java.util.Collection", "java.util.LinkedList", - contentType.getJType(), useJava50); - } else if (collectionType.equalsIgnoreCase("set")) { - this._jType = new JCollectionType("java.util.Set", "java.util.HashSet", - contentType.getJType(), useJava50); - } else if (collectionType.equalsIgnoreCase("sortedset")) { - this._jType = new JCollectionType("java.util.SortedSet", "java.util.TreeSet", - contentType.getJType(), useJava50); - } else { - this._jType = null; - } - } //-- XSListJ2 - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public JType getJType() { - return this._jType; - } - -} //-- XSListJ2 Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSListODMG30.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSListODMG30.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSListODMG30.java (working copy) @@ -1,80 +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. - */ -package org.exolab.castor.builder.types; - -import org.exolab.javasource.JClass; -import org.exolab.javasource.JType; - -/** - * A list type for ODMG 3.0 that adapts the Castor preset list type. - * We do not use the _jType field of our base class. - * @author Frank Thelen - * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ - */ -public final class XSListODMG30 extends XSList { - - /** The JType represented by this XSType. */ - private static final JType JTYPE = new JClass("org.odmg.DArray"); - - /** - * Creates a collection type for ODMG 3.0. - * - * @param contentType - * type of the collection members - * @param useJava50 - * if true, the collection will be generated using Java 5 - * features such as generics. - */ - public XSListODMG30(final XSType contentType, final boolean useJava50) { - super(contentType, useJava50); - } //-- XSListODMG30 - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public JType getJType() { - return XSListODMG30.JTYPE; - } - -} //-- XSListODMG30 Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSListType.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSListType.java (revision 0) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSListType.java (revision 0) @@ -0,0 +1,97 @@ +/* + * Copyright 2007 Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.exolab.castor.builder.types; + +/** + * A base class for all list types. + * + * @author Ralf Joachim + * @version $Revision: 6678 $ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ + */ +public abstract class XSListType extends XSType { + //-------------------------------------------------------------------------- + + /** Content type of the collection. */ + private final XSType _contentType; + + /** Maximum size of this list. If set to -1 the maximum size is undefined. */ + private int _maxSize = -1; + + /** Minimum size of this list. */ + private int _minSize = 0; + + //-------------------------------------------------------------------------- + + /** + * Create a AbstractXSList. + * + * @param contentType Type of the collection members. + */ + public XSListType(final XSType contentType) { + super(); + + _contentType = contentType; + } + + //-------------------------------------------------------------------------- + + /** + * Returns the type contained in the list. + * + * @return The type contained in the list. + */ + public final XSType getContentType() { + return _contentType; + } + + /** + * Returns the maximum allowed size for this list. + * + * @return The maximum allowed size for this list. + */ + public final int getMaximumSize() { + return _maxSize; + } + + /** + * Sets the maximum allowed size for this list. + * + * @param size New maximum size for this list + */ + public final void setMaximumSize(final int size) { + _maxSize = size; + } + + /** + * Returns the minimum allowed size for this list. + * + * @return The minimum allowed size for this list. + */ + public final int getMinimumSize() { + return _minSize; + } + + /** + * Sets the minimum allowed size for this list. + * + * @param size New minimum size for this list + */ + public final void setMinimumSize(final int size) { + _minSize = size; + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSLong.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSLong.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSLong.java (working copy) @@ -1,5 +1,5 @@ /* - * Copyright 2006 Edward Kuns + * Copyright 2006-2007 Edward Kuns, Ralf Joachim * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,17 +12,44 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * $Id$ */ package org.exolab.castor.builder.types; +import org.exolab.javasource.JClass; +import org.exolab.javasource.JSourceCode; +import org.exolab.javasource.JType; + /** - * The XML Schema "long" type. - * @author Edward Kuns + * The xsd:long XML Schema type. + * + * @author Edward Kuns + * @author Ralf Joachim * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ */ -public class XSLong extends XSInteger { +public final class XSLong extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "long"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.LONG_TYPE; + + /** A constant holding the minimum value an xsd:long can have, -263. */ + public static final String MIN_VALUE = Long.toString(Long.MIN_VALUE); + + /** A constant holding the maximum value an xsd:long can have, 263-1. */ + public static final String MAX_VALUE = Long.toString(Long.MAX_VALUE); + + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -34,11 +61,104 @@ /** * Construct a new XSLong optionally using the wrapper class implementation. * - * @param asWrapper - * if true, this class will be implemented using a wrapper. + * @param asWrapper If true, this class will be implemented using a wrapper. */ public XSLong(final boolean asWrapper) { - super(asWrapper, XSType.LONG_TYPE); + super(); + + _asWrapper = asWrapper; + if (_asWrapper) { + _jType = new JClass("java.lang.Long"); + } else { + _jType = JType.LONG; + } + + setMinInclusive(MIN_VALUE); + setMaxInclusive(MAX_VALUE); } -} //-- XSNegativeInteger + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + + /** + * {@inheritDoc} + */ + public boolean isPrimitive() { return true; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.Long(0);"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } + return "new java.lang.Long(" + variableName + ")"; + } + + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Long) " + variableName + ")"; } + return "((java.lang.Long) " + variableName + ").longValue()"; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.LongValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.LongValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); + } + + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive(" + getMinExclusive() + "L);"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive(" + getMinInclusive() + "L);"); + } + + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive(" + getMaxExclusive() + "L);"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive(" + getMaxInclusive() + "L);"); + } + + codeDigitsFacet(jsc, "typeValidator"); + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNCName.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNCName.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNCName.java (working copy) @@ -1,50 +1,20 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -50,11 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema xsd:NCName type. - * @author Keith Visco + * The xsd:NCName XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSNCName extends XSType { +public final class XSNCName extends AbstractLengthFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "NCName"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.NCNAME_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); @@ -59,65 +38,74 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); + //-------------------------------------------------------------------------- + /** - * No-arg constructor. + * {@inheritDoc} */ - public XSNCName() { - super(XSType.NCNAME_TYPE); - } //-- XSNCName + public String getName() { return NAME; } /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types. - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} */ - public String createFromJavaObjectCode(final String variableName) { - return "(java.lang.String) " + variableName; - } //-- fromJavaObject + public short getType() { return TYPE; } /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - // Nothing to do ?? - } + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return JTYPE; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.String();"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + + /** + * {@inheritDoc} */ - public JType getJType() { - return XSNCName.JTYPE; + public String createFromJavaObjectCode(final String variableName) { + return "(java.lang.String) " + variableName; } + //-------------------------------------------------------------------------- + /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.NameValidator typeValidator =" - + " new org.exolab.castor.xml.validators.NameValidator(" - + "org.exolab.castor.xml.XMLConstants.NAME_TYPE_NCNAME);"); - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.NameValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.NameValidator(\n" + + " org.exolab.castor.xml.XMLConstants.NAME_TYPE_NCNAME);\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); + } + + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + codeLengthFacet(jsc, "typeValidator"); } -} //-- XSNCName + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNMToken.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNMToken.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNMToken.java (working copy) @@ -1,53 +1,20 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -53,11 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema xsd:NMToken type. - * @author Keith Visco + * The xsd:NMToken XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSNMToken extends XSType { +public final class XSNMToken extends AbstractLengthFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "NMTOKEN"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.NMTOKEN_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); @@ -62,188 +38,74 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); - /** The length facet. */ - private int _length = 0; - /** The max length facet. */ - private int _maxLength = -1; - /** The min length facet. */ - private int _minLength = 0; + //-------------------------------------------------------------------------- /** - * No-arg constructor. + * {@inheritDoc} */ - public XSNMToken() { - super(XSType.NMTOKEN_TYPE); - } //-- XSNMToken + public String getName() { return NAME; } /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types, - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} */ - public String createFromJavaObjectCode(final String variableName) { - return "(java.lang.String) " + variableName; - } //-- fromJavaObject + public short getType() { return TYPE; } /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_LENGTH.equals(name)) { - setMaxLength(facet.toInt()); - } else if (Facet.MIN_LENGTH.equals(name)) { - setMinLength(facet.toInt()); - } else if (Facet.LENGTH.equals(name)) { - setLength(facet.toInt()); - } - } - } - + public boolean isPrimitive() { return false; } + /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSNMToken.JTYPE; - } - + public boolean isDateTime() { return false; } + /** - * Returns true if a maximum length has been set. - * @return true if a maximum length has been set. + * {@inheritDoc} */ - public boolean hasMaxLength() { - return (_maxLength >= 0); - } //-- hasMaxLength + public JType getJType() { return JTYPE; } /** - * Returns true if a minimum length has been set. - * @return true if a minimum length has been set. + * {@inheritDoc} */ - public boolean hasMinLength() { - return (_minLength > 0); - } //-- hasMinLength - + public String newInstanceCode() { + return "new java.lang.String();"; + } + /** - * Returns true if a length has been set. - * @return true if a length has been set. + * {@inheritDoc} */ - public boolean hasLength() { - return (_length > 0); + public String createToJavaObjectCode(final String variableName) { + return variableName; } - + /** - * Sets the length of this XSNMToken. While setting the length, the - * maxLength and minLength are also set up to this length. - * - * @param length - * the length to set - * @see #setMaxLength - * @see #setMinLength + * {@inheritDoc} */ - public void setLength(final int length) { - this._length = length; - setMaxLength(length); - setMinLength(length); + public String createFromJavaObjectCode(final String variableName) { + return "(java.lang.String) " + variableName; } - /** - * Sets the maximum length of this XSString. To remove the max length facet, - * use a negative value. - * - * @param maxLength - * the maximum length for occurances of this type - */ - public void setMaxLength(final int maxLength) { - this._maxLength = maxLength; - } //-- setMaxLength - - /** - * Sets the minimum length of this XSString. - * - * @param minLength - * the minimum length for occurances of this type - */ - public void setMinLength(final int minLength) { - this._minLength = minLength; - } //-- setMinLength - - /** - * Returns the maximum length occurances of this type can be. A negative - * value denotes no maximum length. - * - * @return the maximum length facet - */ - public int getMaxLength() { - return _maxLength; - } //-- getMaxLength + //-------------------------------------------------------------------------- /** - * Returns the minimum length occurances of this type can be. - * @return the minimum length facet + * {@inheritDoc} */ - public int getMinLength() { - return _minLength; - } //-- getMinLength + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.NameValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.NameValidator(\n" + + " org.exolab.castor.xml.XMLConstants.NAME_TYPE_NMTOKEN);\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - /** - * Returns the length that this type must have. - * @return the length that this type must have. - */ - public int getLength() { - return this._length; - } - - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.NameValidator typeValidator =" - + " new org.exolab.castor.xml.validators.NameValidator(" - + "org.exolab.castor.xml.XMLConstants.NAME_TYPE_NMTOKEN);"); - - if (hasLength()) { - jsc.add("typeValidator.setLength("); - jsc.append(Integer.toString(getLength())); - jsc.append(");"); - } else { - if (hasMinLength()) { - jsc.add("typeValidator.setMinLength("); - jsc.append(Integer.toString(getMinLength())); - jsc.append(");"); - } - if (hasMaxLength()) { - jsc.add("typeValidator.setMaxLength("); - jsc.append(Integer.toString(getMaxLength())); - jsc.append(");"); - } + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); } - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + codeLengthFacet(jsc, "typeValidator"); } -} //-- XSNMToken + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNegativeInteger.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNegativeInteger.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNegativeInteger.java (working copy) @@ -1,55 +1,52 @@ /* - * 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/). + * Copyright 2007 Keith Visco, Ralf Joachim * - * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright 1999-2003 (C) Intalio, Inc. All Rights Reserved. + * http://www.apache.org/licenses/LICENSE-2.0 * - * $Id$ + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.exolab.castor.builder.types; +import org.exolab.javasource.JClass; +import org.exolab.javasource.JSourceCode; +import org.exolab.javasource.JType; + /** - * The XML Schema "negative-integer" type. - * @author Keith Visco + * The xsd:negativeInteger XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ */ -public final class XSNegativeInteger extends XSInteger { +public final class XSNegativeInteger extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "negativeInteger"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.NEGATIVE_INTEGER_TYPE; + + /** A constant holding the maximum value an xsd:negativeInteger can have, -1. */ + public static final String MAX_VALUE = "-1"; + + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -56,15 +53,108 @@ */ public XSNegativeInteger() { this(false); - } //-- XSInteger + } /** * Constructs a new XSNegativeInteger. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ public XSNegativeInteger(final boolean asWrapper) { - super(asWrapper, XSType.NEGATIVE_INTEGER_TYPE); - super.setMaxInclusive(MAX_NEGATIVE_INTEGER); - } //-- XSInteger + super(); + + _asWrapper = asWrapper; + if (_asWrapper) { + _jType = new JClass("java.lang.Long"); + } else { + _jType = JType.LONG; + } + + setMaxInclusive(MAX_VALUE); + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + + /** + * {@inheritDoc} + */ + public boolean isPrimitive() { return true; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.Long(-1);"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } + return "new java.lang.Long(" + variableName + ")"; + } -} //-- XSNegativeInteger + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Long) " + variableName + ")"; } + return "((java.lang.Long) " + variableName + ").longValue()"; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.LongValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.LongValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); + } + + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive(" + getMinExclusive() + "L);"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive(" + getMinInclusive() + "L);"); + } + + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive(" + getMaxExclusive() + "L);"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive(" + getMaxInclusive() + "L);"); + } + + codeDigitsFacet(jsc, "typeValidator"); + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNonNegativeInteger.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNonNegativeInteger.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNonNegativeInteger.java (working copy) @@ -1,55 +1,52 @@ /* - * 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. + * Copyright 2007 Keith Visco, Ralf Joachim * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Copyright 2000-2003 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.exolab.castor.builder.types; +import org.exolab.javasource.JClass; +import org.exolab.javasource.JSourceCode; +import org.exolab.javasource.JType; + /** - * The XML Schema "non-negative-integer" type. - * @author Keith Visco - * @version $Revision$ $Date: $ + * The xsd:nonNegativeInteger XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim + * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public class XSNonNegativeInteger extends XSInteger { +public final class XSNonNegativeInteger extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "nonNegativeInteger"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.NON_NEGATIVE_INTEGER_TYPE; + + /** A constant holding the minimum value an xsd:nonNegativeInteger can have, 0. */ + public static final String MIN_VALUE = "0"; + + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -60,11 +57,104 @@ /** * Constructs a new XSNonNegativeInteger. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ public XSNonNegativeInteger(final boolean asWrapper) { - super(asWrapper, XSType.NON_NEGATIVE_INTEGER_TYPE); - setMinInclusive(MIN_NON_NEGATIVE_INTEGER); + super(); + + _asWrapper = asWrapper; + if (_asWrapper) { + _jType = new JClass("java.lang.Long"); + } else { + _jType = JType.LONG; + } + + setMinInclusive(MIN_VALUE); + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + + /** + * {@inheritDoc} + */ + public boolean isPrimitive() { return true; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.Long(0);"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } + return "new java.lang.Long(" + variableName + ")"; } + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Long) " + variableName + ")"; } + return "((java.lang.Long) " + variableName + ").longValue()"; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.LongValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.LongValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); + } + + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive(" + getMinExclusive() + "L);"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive(" + getMinInclusive() + "L);"); + } + + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive(" + getMaxExclusive() + "L);"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive(" + getMaxInclusive() + "L);"); + } + + codeDigitsFacet(jsc, "typeValidator"); + } + + //-------------------------------------------------------------------------- } Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNonPositiveInteger.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNonPositiveInteger.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNonPositiveInteger.java (working copy) @@ -1,55 +1,52 @@ /* - * 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. + * Copyright 2007 Keith Visco, Ralf Joachim * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Copyright 2000-2003 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.exolab.castor.builder.types; +import org.exolab.javasource.JClass; +import org.exolab.javasource.JSourceCode; +import org.exolab.javasource.JType; + /** - * The XML Schema "non-positive-integer" type. - * @author Keith Visco - * @version $Revision$ $Date: $ + * The xsd:nonPositiveInteger XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim + * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public class XSNonPositiveInteger extends XSInteger { +public final class XSNonPositiveInteger extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "nonPositiveInteger"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.NON_POSITIVE_INTEGER_TYPE; + + /** A constant holding the maximum value an xsd:nonPositiveInteger can have, 0. */ + public static final String MAX_VALUE = "0"; + + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -60,11 +57,104 @@ /** * Constructs a new XSNonPositiveInteger. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ public XSNonPositiveInteger(final boolean asWrapper) { - super(asWrapper, XSType.NON_POSITIVE_INTEGER_TYPE); - setMaxExclusive(MAX_NON_POSITIVE_INTEGER); + super(); + + _asWrapper = asWrapper; + if (_asWrapper) { + _jType = new JClass("java.lang.Long"); + } else { + _jType = JType.LONG; + } + + setMaxExclusive(MAX_VALUE); } + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + + /** + * {@inheritDoc} + */ + public boolean isPrimitive() { return true; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.Long(0);"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } + return "new java.lang.Long(" + variableName + ")"; + } + + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Long) " + variableName + ")"; } + return "((java.lang.Long) " + variableName + ").longValue()"; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.LongValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.LongValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); + } + + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive(" + getMinExclusive() + "L);"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive(" + getMinInclusive() + "L);"); + } + + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive(" + getMaxExclusive() + "L);"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive(" + getMaxInclusive() + "L);"); + } + + codeDigitsFacet(jsc, "typeValidator"); + } + + //-------------------------------------------------------------------------- } Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNormalizedString.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNormalizedString.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSNormalizedString.java (working copy) @@ -1,53 +1,21 @@ /* - * 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 2000-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -53,12 +21,21 @@ import org.exolab.javasource.JType; /** - * The XSType representing a normalizedString type. - * normalizedString is simply a XSString with some specific validation. - * @author Arnaud Blandin + * The xsd:normalizedString XML Schema type. It is simply a XSString with some + * specific validation. + * + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision$ $Date: 2006-03-16 10:34:22 -0700 (Thu, 16 Mar 2006) $ */ -public final class XSNormalizedString extends XSPatternBase { +public final class XSNormalizedString extends AbstractLengthFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "normalizedString"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.NORMALIZEDSTRING_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); @@ -63,198 +40,85 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); - /** The length facet. */ - private int _length = 0; - /** The max length facet. */ - private int _maxLength = -1; - /** The min length facet. */ - private int _minLength = 0; + //-------------------------------------------------------------------------- /** - * Creates a new XSString. + * No-arg constructor. */ public XSNormalizedString() { - super(XSType.NORMALIZEDSTRING_TYPE); + super(false); + + setWhiteSpace(Facet.WHITESPACE_PRESERVE); } + + //-------------------------------------------------------------------------- /** - * Returns the source necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types. - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} */ - public String createFromJavaObjectCode(final String variableName) { - return "(java.lang.String) " + variableName; - } //-- fromJavaObject + public String getName() { return NAME; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSNormalizedString.JTYPE; - } //-- getJType + public short getType() { return TYPE; } /** - * Returns the maximum length occurances of this type can be. - * A negative value denotes no maximum length. - * @return the maximum length facet + * {@inheritDoc} */ - public int getMaxLength() { - return _maxLength; - } //-- getMaxLength - + public boolean isPrimitive() { return false; } + /** - * Returns the minimum length occurances of this type can be. - * @return the minimum length facet. + * {@inheritDoc} */ - public int getMinLength() { - return _minLength; - } //-- getMinLength - + public boolean isDateTime() { return false; } + /** - * Returns the length that this type must have. - * @return the length that this type must have. + * {@inheritDoc} */ - public int getLength() { - return this._length; - } + public JType getJType() { return JTYPE; } /** - * Returns true if a maximum length has been set. - * @return true if a maximum length has been set. + * {@inheritDoc} */ - public boolean hasMaxLength() { - return (_maxLength >= 0); - } //-- hasMaxLength - - /** - * Returns true if a minimum length has been set. - * @return true if a minimum length has been set. - */ - public boolean hasMinLength() { - return (_minLength > 0); - } //-- hasMinLength - - /** - * Returns true if a length has been set. - * @return true if a length has been set. - */ - public boolean hasLength() { - return (_length > 0); + public String newInstanceCode() { + return "new java.lang.String();"; } - + /** - * Sets the length of this XSNormalizedString. While setting the length, the - * maxLength and minLength are also set up to this length. - * - * @param length - * the length to set - * @see #setMaxLength - * @see #setMinLength + * {@inheritDoc} */ - public void setLength(final int length) { - this._length = length; - setMaxLength(length); - setMinLength(length); + public String createToJavaObjectCode(final String variableName) { + return variableName; } - + /** - * Sets the maximum length of this XSNormalizedString. To remove the max - * length facet, use a negative value. - * - * @param maxLength - * the maximum length for occurances of this type + * {@inheritDoc} */ - public void setMaxLength(final int maxLength) { - this._maxLength = maxLength; - } //-- setMaxLength - - /** - * Sets the minimum length of this XSNormalizedString. - * @param minLength the minimum length for occurances of this type - */ - public void setMinLength(final int minLength) { - this._minLength = minLength; - } //-- setMinLength - - /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets - */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); + public String createFromJavaObjectCode(final String variableName) { + return "(java.lang.String) " + variableName; + } - if (Facet.MAX_LENGTH.equals(name)) { - setMaxLength(facet.toInt()); - } else if (Facet.MIN_LENGTH.equals(name)) { - setMinLength(facet.toInt()); - } else if (Facet.LENGTH.equals(name)) { - setLength(facet.toInt()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } - } - } + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.NameValidator typeValidator = " - + "new org.exolab.castor.xml.validators.NameValidator(" - + "org.exolab.castor.xml.XMLConstants.NAME_TYPE_CDATA);"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.NameValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.NameValidator(\n" + + " org.exolab.castor.xml.XMLConstants.NAME_TYPE_CDATA);\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (hasLength()) { - jsc.add("typeValidator.setLength("); - jsc.append(Integer.toString(getLength())); - jsc.append(");"); - } else { - if (hasMinLength()) { - jsc.add("typeValidator.setMinLength("); - jsc.append(Integer.toString(getMinLength())); - jsc.append(");"); - } - if (hasMaxLength()) { - jsc.add("typeValidator.setMaxLength("); - jsc.append(Integer.toString(getMaxLength())); - jsc.append(");"); - } - } - - //-- fixed values if (fixedValue != null) { - jsc.add("typeValidator.setFixed("); - //fixed should be "the value" - jsc.append(fixedValue); - jsc.append(");"); + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); } - // pattern facet codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + codeLengthFacet(jsc, "typeValidator"); } -} //-- XSNormalizedString + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSPatternBase.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSPatternBase.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSPatternBase.java (working copy) @@ -1,95 +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 2000-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ - */ -package org.exolab.castor.builder.types; - -import java.util.Iterator; -import java.util.LinkedList; - -import org.exolab.javasource.JSourceCode; - -/** - * A base class for types which support the pattern facet. - * @author Keith Visco - * @author Edward Kuns - * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ - */ -public abstract class XSPatternBase extends XSType { - - /** The value of the pattern facet. */ - private LinkedList _patterns = new LinkedList(); - - /** - * Creates a new XSPatternBase with the given type. - * @param type that this XSType represents - */ - protected XSPatternBase(final short type) { - super(type); - } //-- XSPatternBase - - /** - * Adds a pattern branch for this XSType. To successfully pass the pattern - * facets, only one branch needs to pass. - * @param pattern the regular expression for this XSType. - */ - public final void addPattern(final String pattern) { - _patterns.add(pattern); - } //-- setPattern - - /** - * Generate the source code for pattern facet validation. - * - * @param jsc - * the JSourceCode to fill in. - * @param validatorName - * the name of the TypeValidator that the patterns should be - * added to. - */ - public final void codePatternFacet(final JSourceCode jsc, final String validatorName) { - for (Iterator i = _patterns.iterator(); i.hasNext(); ) { - jsc.add(validatorName + ".addPattern(\"" + escapePattern((String) i.next()) + "\");"); - } - } - -} //-- XSPatternBase Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSPositiveInteger.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSPositiveInteger.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSPositiveInteger.java (working copy) @@ -1,55 +1,52 @@ /* - * 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/). + * Copyright 2007 Keith Visco, Ralf Joachim * - * 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. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright 1999-2003 (C) Intalio, Inc. All Rights Reserved. + * http://www.apache.org/licenses/LICENSE-2.0 * - * $Id$ + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.exolab.castor.builder.types; +import org.exolab.javasource.JClass; +import org.exolab.javasource.JSourceCode; +import org.exolab.javasource.JType; + /** - * The XML Schema "positive-integer" type. - * @author Keith Visco + * The xsd:positiveInteger XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSPositiveInteger extends XSInteger { +public final class XSPositiveInteger extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "positiveInteger"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.POSITIVE_INTEGER_TYPE; + + /** A constant holding the minimum value an xsd:positiveInteger can have, 1. */ + public static final String MIN_VALUE = "1"; + + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -56,15 +53,108 @@ */ public XSPositiveInteger() { this(false); - } //-- XSInteger + } /** * Constructs a new XSPositiveInteger. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ public XSPositiveInteger(final boolean asWrapper) { - super(asWrapper, XSType.POSITIVE_INTEGER_TYPE); - setMinInclusive(MIN_POSITIVE_INTEGER); - } //-- XSInteger + super(); + + _asWrapper = asWrapper; + if (_asWrapper) { + _jType = new JClass("java.lang.Long"); + } else { + _jType = JType.LONG; + } + + setMinInclusive(MIN_VALUE); + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + + /** + * {@inheritDoc} + */ + public boolean isPrimitive() { return true; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.Long(1);"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } + return "new java.lang.Long(" + variableName + ")"; + } -} //-- XSPositiveInteger + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Long) " + variableName + ")"; } + return "((java.lang.Long) " + variableName + ").longValue()"; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.LongValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.LongValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); + } + + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive(" + getMinExclusive() + "L);"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive(" + getMinInclusive() + "L);"); + } + + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive(" + getMaxExclusive() + "L);"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive(" + getMaxInclusive() + "L);"); + } + + codeDigitsFacet(jsc, "typeValidator"); + } + + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSQName.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSQName.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSQName.java (working copy) @@ -1,53 +1,20 @@ /* - * 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 2000-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -53,13 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema QName type. Note : A QName (prefix:NCName) is mapped in memory - * {URI}NCName. + * The xsd:QName XML Schema type. A QName (prefix:NCName) is mapped in memory {URI}NCName. * - * @author Arnaud Blandin + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSQName extends XSPatternBase { +public final class XSQName extends AbstractLengthFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "QName"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.QNAME_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); @@ -64,199 +38,74 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); - /** The length facet. */ - private int _length = 0; - /** The max length facet. */ - private int _maxLength = -1; - /** The min length facet. */ - private int _minLength = 0; - - /** - * No-arg constructor. - */ - public XSQName() { - super(XSType.QNAME_TYPE); - } //-- XSNCName - - /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types. - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType - */ - public String createFromJavaObjectCode(final String variableName) { - return "(java.lang.String) " + variableName; - } //-- fromJavaObject + //-------------------------------------------------------------------------- /** - * Returns the maximum length occurances of this type can be. A negative - * value denotes no maximum length. - * - * @return the maximum length facet + * {@inheritDoc} */ - public int getMaxLength() { - return _maxLength; - } //-- getMaxLength + public String getName() { return NAME; } /** - * Returns the minimum length occurances of this type can be. - * @return the minimum length facet. + * {@inheritDoc} */ - public int getMinLength() { - return _minLength; - } //-- getMinLength - + public short getType() { return TYPE; } + /** - * Returns the length that this type must have. - * @return the length that this type must have. + * {@inheritDoc} */ - public int getLength() { - return this._length; - } - + public boolean isPrimitive() { return false; } + /** - * Returns true if a maximum length has been set. - * @return true if a maximum length has been set. + * {@inheritDoc} */ - public boolean hasMaxLength() { - return (_maxLength >= 0); - } //-- hasMaxLength - + public boolean isDateTime() { return false; } + /** - * Returns true if a minimum length has been set. - * @return true if a minimum length has been set. + * {@inheritDoc} */ - public boolean hasMinLength() { - return (_minLength > 0); - } //-- hasMinLength + public JType getJType() { return JTYPE; } /** - * Returns true if a length has been set. - * @return true if a length has been set. + * {@inheritDoc} */ - public boolean hasLength() { - return (_length > 0); + public String newInstanceCode() { + return "new java.lang.String();"; } - + /** - * Sets the length of this XSString. While setting the length, the maxLength - * and minLength are also set up to this length. - * - * @param length - * the length to set - * @see #setMaxLength - * @see #setMinLength + * {@inheritDoc} */ - public void setLength(final int length) { - this._length = length; - setMaxLength(length); - setMinLength(length); + public String createToJavaObjectCode(final String variableName) { + return variableName; } - + /** - * Sets the maximum length of this XSString. To remove the max length facet, - * use a negative value. - * - * @param maxLength - * the maximum length for occurances of this type + * {@inheritDoc} */ - public void setMaxLength(final int maxLength) { - this._maxLength = maxLength; - } //-- setMaxLength - - /** - * Sets the minimum length of this XSString. - * @param minLength the minimum length for occurances of this type - */ - public void setMinLength(final int minLength) { - this._minLength = minLength; - } //-- setMinLength - - /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets - */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_LENGTH.equals(name)) { - setMaxLength(facet.toInt()); - } else if (Facet.MIN_LENGTH.equals(name)) { - setMinLength(facet.toInt()); - } else if (Facet.LENGTH.equals(name)) { - setLength(facet.toInt()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } - } + public String createFromJavaObjectCode(final String variableName) { + return "(java.lang.String) " + variableName; } - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public JType getJType() { - return XSQName.JTYPE; - } + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.NameValidator typeValidator = " - + "new org.exolab.castor.xml.validators.NameValidator(" - + "org.exolab.castor.xml.XMLConstants.NAME_TYPE_QNAME);"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.NameValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.NameValidator(\n" + + " org.exolab.castor.xml.XMLConstants.NAME_TYPE_QNAME);\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (hasLength()) { - jsc.add("typeValidator.setLength("); - jsc.append(Integer.toString(getLength())); - jsc.append(");"); - } else { - if (hasMinLength()) { - jsc.add("typeValidator.setMinLength("); - jsc.append(Integer.toString(getMinLength())); - jsc.append(");"); - } - if (hasMaxLength()) { - jsc.add("typeValidator.setMaxLength("); - jsc.append(Integer.toString(getMaxLength())); - jsc.append(");"); - } - } - - //-- fixed values if (fixedValue != null) { - jsc.add("typeValidator.setFixed("); - //fixed should be "the value" - jsc.append(fixedValue); - jsc.append(");"); + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); } - // pattern facet codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + codeLengthFacet(jsc, "typeValidator"); } -} //-- XSQName + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSShort.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSShort.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSShort.java (working copy) @@ -1,53 +1,20 @@ /* - * 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 2000-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -53,27 +20,36 @@ import org.exolab.javasource.JType; /** - * The XML Schema Short type. - * @author Keith Visco + * The xsd:short XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ */ -public class XSShort extends XSPatternBase { +public final class XSShort extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- - /** Maximum short (inclusive). */ - private Short _maxInclusive = null; - /** Maximum short (exclusive). */ - private Short _maxExclusive = null; - /** Minimum short (inclusive). */ - private Short _minInclusive = null; - /** Minimum short (exclusive). */ - private Short _minExclusive = null; - /** Total number of digits. */ - private int _totalDigits = -1; + /** Name of this XSType. */ + public static final String NAME = "short"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.SHORT_TYPE; + + /** A constant holding the minimum value an xsd:short can have, -215. */ + public static final String MIN_VALUE = Short.toString(Short.MIN_VALUE); + + /** A constant holding the maximum value an xsd:short can have, 215-1. */ + public static final String MAX_VALUE = Short.toString(Short.MAX_VALUE); + + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; /** The JType represented by this XSType. */ private final JType _jType; - /** True if this type is implemented using the wrapper class. */ - private final boolean _asWrapper; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -84,12 +60,13 @@ /** * Constructs a new XSShort. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ public XSShort(final boolean asWrapper) { - super(XSType.SHORT_TYPE); + super(); + _asWrapper = asWrapper; - if (asWrapper) { _jType = new JClass("java.lang.Short"); } else { @@ -95,312 +72,93 @@ } else { _jType = JType.SHORT; } - } //-- XSShort - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public final JType getJType() { - return _jType; + + setMinInclusive(MIN_VALUE); + setMaxInclusive(MAX_VALUE); } - /** - * Returns the maximum exclusive value that this XSShort can hold. - * - * @return the maximum exclusive value that this XSShort can hold. If no - * maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive - */ - public final Short getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive + //-------------------------------------------------------------------------- /** - * Returns the maximum inclusive value that this XSShort can hold. - * - * @return the maximum inclusive value that this XSShort can hold. If no - * maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive + * {@inheritDoc} */ - public final Short getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive + public String getName() { return NAME; } /** - * Returns the minimum exclusive value that this XSShort can hold. - * - * @return the minimum exclusive value that this XSShort can hold. If no - * minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive() - * @see #setMaxInclusive(short) + * {@inheritDoc} */ - public final Short getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive - + public short getType() { return TYPE; } + /** - * Returns the minimum inclusive value that this XSShort can hold. - * - * @return the minimum inclusive value that this XSShort can hold. If no - * minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive + * {@inheritDoc} */ - public final Short getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive - + public boolean isPrimitive() { return true; } + /** - * Returns the totalDigits facet value of this XSInteger. - * @return the totalDigits facet value of this XSInteger. + * {@inheritDoc} */ - public final int getTotalDigits() { - return _totalDigits; - } - + public boolean isDateTime() { return false; } + /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public final boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } //-- hasMaximum + public JType getJType() { return _jType; } /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public final boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; - } //-- hasMinimum - + public String newInstanceCode() { + return "new java.lang.Short((short) 0);"; + } + /** - * Sets the maximum exclusive value that this XSShort can hold. - * @param max the maximum exclusive value this XSShort can be - * @see #setMaxInclusive(Short) + * {@inheritDoc} */ - public final void setMaxExclusive(final short max) { - _maxExclusive = new Short(max); - _maxInclusive = null; - } //-- setMaxExclusive + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } + return "new java.lang.Short(" + variableName + ")"; + } /** - * Sets the maximum exclusive value that this XSShort can hold. - * @param max the maximum exclusive value this XSShort can be - * @see #setMaxInclusive(short) + * {@inheritDoc} */ - public final void setMaxExclusive(final Short max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Short) " + variableName + ")"; } + return "((java.lang.Short) " + variableName + ").shortValue()"; + } - /** - * Sets the maximum inclusive value that this XSShort can hold. - * @param max the maximum inclusive value this XSShort can be - * @see #setMaxExclusive(Short) - */ - public final void setMaxInclusive(final short max) { - _maxInclusive = new Short(max); - _maxExclusive = null; - } //-- setMaxInclusive + //-------------------------------------------------------------------------- /** - * Sets the maximum inclusive value that this XSShort can hold. - * @param max the maximum inclusive value this XSShort can be - * @see #setMaxExclusive(short) + * {@inheritDoc} */ - public final void setMaxInclusive(final Short max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.ShortValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.ShortValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - /** - * Sets the minimum exclusive value that this XSShort can hold. - * @param min the minimum exclusive value this XSShort can be - * @see #setMinInclusive(Short) - */ - public final void setMinExclusive(final short min) { - _minExclusive = new Short(min); - _minInclusive = null; - } //-- setMinExclusive - - /** - * Sets the minimum exclusive value that this XSShort can hold. - * @param min the minimum exclusive value this XSShort can be - * @see #setMinInclusive(short) - */ - public final void setMinExclusive(final Short min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - - /** - * Sets the minimum inclusive value that this XSShort can hold. - * @param min the minimum inclusive value this XSShort can be - * @see #setMinExclusive(Short) - */ - public final void setMinInclusive(final short min) { - _minInclusive = new Short(min); - _minExclusive = null; - } //-- setMinInclusive - - /** - * Sets the minimum inclusive value that this XSShort can hold. - * @param min the minimum inclusive value this XSShort can be - * @see #setMinExclusive(short) - */ - public final void setMinInclusive(final Short min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Sets the totalDigits facet for this XSShort. - * @param totalDig the value of totalDigits (must be > 0) - */ - public final void setTotalDigits(final int totalDig) { - if (totalDig <= 0) { - throw new IllegalArgumentException(this.getName() - + ": the totalDigits facet must be positive"); - } - _totalDigits = totalDig; - } - - /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets - */ - public final void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_EXCLUSIVE.equals(name)) { - setMaxExclusive(facet.toShort()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - setMaxInclusive(facet.toShort()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - setMinExclusive(facet.toShort()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - setMinInclusive(facet.toShort()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.TOTALDIGITS.equals(name)) { - setTotalDigits(facet.toInt()); - } else if (Facet.FRACTIONDIGITS.equals(name)) { - if (facet.toInt() != 0) { - throw new IllegalArgumentException("fractionDigits must be 0 for " - + this.getName()); - } - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - throw new IllegalArgumentException("Warning: The facet 'whitespace'" - + " can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for '" - + this.getName() + "'."); - } - } - } - } //-- toXSShort - - /** - * Returns the String necessary to convert an instance of this XSType to an - * Object. This method is really only useful for primitive types - * - * @param variableName - * the name of the instance variable - * @return the String necessary to convert an instance of this XSType to an - * Object - */ - public final String createToJavaObjectCode(final String variableName) { - if (_asWrapper) { - return super.createToJavaObjectCode(variableName); + if (fixedValue != null) { + jsc.add("typeValidator.setFixed((short) " + fixedValue + ");"); } - StringBuffer sb = new StringBuffer("new java.lang.Short("); - sb.append(variableName); - sb.append(")"); - return sb.toString(); - } //-- toJavaObject - - /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType - */ - public final String createFromJavaObjectCode(final String variableName) { - StringBuffer sb = new StringBuffer("((java.lang.Short) "); - sb.append(variableName); - sb.append(")"); - if (!_asWrapper) { - sb.append(".shortValue()"); - } - return sb.toString(); - } //-- fromJavaObject - - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public final void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.ShortValidator typeValidator" - + " = new org.exolab.castor.xml.validators.ShortValidator();"); - - if (_minExclusive != null) { - jsc.add("typeValidator.setMinExclusive((short) " + _minExclusive + ");"); - } else if (_minInclusive != null) { - jsc.add("typeValidator.setMinInclusive((short) " + _minInclusive + ");"); - } - - if (_maxExclusive != null) { - jsc.add("typeValidator.setMaxExclusive((short) " + _maxExclusive + ");"); - } else if (_maxInclusive != null) { - jsc.add("typeValidator.setMaxInclusive((short) " + _maxInclusive + ");"); - } - - //-- fixed values - if (fixedValue != null) { - //-- make sure we have a valid value... - Short.parseShort(fixedValue); + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - jsc.add("typeValidator.setFixed("); - jsc.append("(short)"); - jsc.append(fixedValue); - jsc.append(");"); + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive((short) " + getMinExclusive() + ");"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive((short) " + getMinInclusive() + ");"); } - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - // -- totalDigits - int totalDigits = getTotalDigits(); - if (totalDigits != -1) { - jsc.add("typeValidator.setTotalDigits("); - jsc.append(Integer.toString(totalDigits)); - jsc.append(");"); + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive((short) " + getMaxExclusive() + ");"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive((short) " + getMaxInclusive() + ");"); } - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + codeDigitsFacet(jsc, "typeValidator"); } -} //-- XSShort + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSString.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSString.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSString.java (working copy) @@ -1,55 +1,21 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -55,261 +21,102 @@ import org.exolab.javasource.JType; /** - * The XML Schema String type. - * @author Keith Visco + * The xsd:string XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSString extends XSPatternBase { +public final class XSString extends AbstractLengthFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "string"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.STRING_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.lang.String"); - /** Jakarta's common-logging logger. */ - private static final Log LOG = LogFactory.getLog(XSString.class); - - /** The length facet. */ - private int _length = 0; - /** The max length facet. */ - private int _maxLength = -1; - /** The min length facet. */ - private int _minLength = 0; - /** the whiteSpace facet. */ - private String _whiteSpace = "preserve"; + + //-------------------------------------------------------------------------- /** - * Creates a new XSString. + * No-arg constructor. */ public XSString() { - super(XSType.STRING_TYPE); + super(false); + + setWhiteSpace(Facet.WHITESPACE_PRESERVE); } + + //-------------------------------------------------------------------------- /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types. - * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * {@inheritDoc} */ - public String createFromJavaObjectCode(final String variableName) { - return "(java.lang.String) " + variableName; - } //-- fromJavaObject + public String getName() { return NAME; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSString.JTYPE; - } //-- getJType - + public short getType() { return TYPE; } + /** - * Returns the maximum length occurances of this type can be. - * A negative value denotes no maximum length. - * @return the maximum length facet + * {@inheritDoc} */ - public int getMaxLength() { - return _maxLength; - } //-- getMaxLength - + public boolean isPrimitive() { return false; } + /** - * Returns the minimum length occurances of this type can be. - * @return the minimum length facet + * {@inheritDoc} */ - public int getMinLength() { - return _minLength; - } //-- getMinLength - + public boolean isDateTime() { return false; } + /** - * Returns the length that this type must have. - * @return the length that this type must have. + * {@inheritDoc} */ - public int getLength() { - return this._length; - } + public JType getJType() { return JTYPE; } /** - * Returns the whiteSpace facet of this type. - * @return the whiteSpace facet of this type. + * {@inheritDoc} */ - public String getWhiteSpace() { - return this._whiteSpace; + public String newInstanceCode() { + return "new java.lang.String();"; } - - /** - * Returns true if a maximum length has been set. - * @return true if a maximum length has been set. - */ - public boolean hasMaxLength() { - return (_maxLength >= 0); - } //-- hasMaxLength - - /** - * Returns true if a minimum length has been set. - * @return true if a minimum length has been set. - */ - public boolean hasMinLength() { - return (_minLength > 0); - } //-- hasMinLength - + /** - * Returns true if a length has been set. - * @return true if a length has been set. + * {@inheritDoc} */ - public boolean hasLength() { - return (_length > 0); + public String createToJavaObjectCode(final String variableName) { + return variableName; } - + /** - * Returns true if the whiteSpace facet is used. - * @return true if the whiteSpace facet is used. + * {@inheritDoc} */ - public boolean hasWhiteSpace() { - return (_whiteSpace != null); - } - - /** - * Sets the length of this XSString. While setting the length, the maxLength - * and minLength are also set up to this length. - * - * @param length - * the length to set - * @see #setMaxLength - * @see #setMinLength - */ - public void setLength(final int length) { - this._length = length; - setMaxLength(length); - setMinLength(length); - } - - /** - * Sets the maximum length of this XSString. To remove the max length facet, - * use a negative value. - * - * @param maxLength - * the maximum length for occurances of this type - */ - public void setMaxLength(final int maxLength) { - this._maxLength = maxLength; - } //-- setMaxLength - - /** - * Sets the minimum length of this XSString. - * @param minLength the minimum length for occurances of this type - */ - public void setMinLength(final int minLength) { - this._minLength = minLength; - } //-- setMinLength - - /** - * Sets the whiteSpace facet of this XSString. The value of the whiteSpace - * facet must be one of the following: - * - * Any other value will generate a Warning and set the whiteSpace to - * "preserve". - * @param value the whiteSpace value - */ - public void setWhiteSpace(final String value) { - if (value.equals("preserve")) { - this._whiteSpace = value; - } else if (value.equals("replace")) { - this._whiteSpace = value; - } else if (value.equals("collapse")) { - this._whiteSpace = value; - } else { - // TODO consider throwing an exception/implement exception handling strategy - LOG.warn("Warning : " + value + " is a bad entry for the whiteSpace value"); - this._whiteSpace = value; - } + public String createFromJavaObjectCode(final String variableName) { + return "(java.lang.String) " + variableName; } - /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets - */ - public void setFacets(final SimpleType simpleType) { - //-- copy valid facets - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_LENGTH.equals(name)) { - setMaxLength(facet.toInt()); - } else if (Facet.MIN_LENGTH.equals(name)) { - setMinLength(facet.toInt()); - } else if (Facet.LENGTH.equals(name)) { - setLength(facet.toInt()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - setWhiteSpace(facet.getValue()); - } - } - } + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.StringValidator typeValidator =" - + " new org.exolab.castor.xml.validators.StringValidator();"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.StringValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.StringValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (hasLength()) { - jsc.add("typeValidator.setLength("); - jsc.append(Integer.toString(getLength())); - jsc.append(");"); - } else { - if (hasMinLength()) { - jsc.add("typeValidator.setMinLength("); - jsc.append(Integer.toString(getMinLength())); - jsc.append(");"); - } - if (hasMaxLength()) { - jsc.add("typeValidator.setMaxLength("); - jsc.append(Integer.toString(getMaxLength())); - jsc.append(");"); - } - } - - if (hasWhiteSpace()) { - jsc.add("typeValidator.setWhiteSpace(\""); - jsc.append(getWhiteSpace()); - jsc.append("\");"); - } - - //-- fixed values if (fixedValue != null) { - jsc.add("typeValidator.setFixed("); - //fixed should be "the value" - jsc.append(fixedValue); - jsc.append(");"); + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); } - // pattern facet codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + codeLengthFacet(jsc, "typeValidator"); } -} //-- XSString + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSTime.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSTime.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSTime.java (working copy) @@ -1,54 +1,20 @@ /* - * 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 2000-2002 (C) Intalio, Inc. All Rights Reserved. - * $Id$ + * Copyright 2007 Arnaud Blandin, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -54,13 +20,20 @@ import org.exolab.javasource.JType; /** - * The XML Schema time type. - * @author Arnaud Blandin + * The xsd:time XML Schema type. + * + * @author Arnaud Blandin + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ -public final class XSTime extends XSPatternBase { - /** Jakarta's common-logging logger. */ - private static final Log LOG = LogFactory.getLog(XSTime.class); +public final class XSTime extends AbstractRangeFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "time"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.TIME_TYPE; /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("org.exolab.castor.types.Time"); @@ -65,243 +38,106 @@ /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("org.exolab.castor.types.Time"); - /** Maximum Time (inclusive). */ - private String _maxInclusive; - /** Maximum Time (exclusive). */ - private String _maxExclusive; - /** Minimum Time (inclusive). */ - private String _minInclusive; - /** Minimum Time (exclusive). */ - private String _minExclusive; + //-------------------------------------------------------------------------- /** - * No-Arg constructor. + * {@inheritDoc} */ - public XSTime() { - super(XSType.TIME_TYPE); - } //-- XSTime + public String getName() { return NAME; } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * {@inheritDoc} */ - public JType getJType() { - return XSTime.JTYPE; - } - + public short getType() { return TYPE; } + /** - * Returns the maximum exclusive value that this XSTime can hold. - * - * @return the maximum exclusive value that this XSTime can hold. If no - * maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive + * {@inheritDoc} */ - public String getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive - + public boolean isPrimitive() { return false; } + /** - * Returns the maximum inclusive value that this XSTime can hold. - * - * @return the maximum inclusive value that this XSTime can hold. If no - * maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive + * {@inheritDoc} */ - public String getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive - + public boolean isDateTime() { return true; } + /** - * Returns the minimum exclusive value that this XSTime can hold. - * - * @return the minimum exclusive value that this XSTime can hold. If no - * minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive - * @see #setMaxInclusive + * {@inheritDoc} */ - public String getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + public JType getJType() { return JTYPE; } /** - * Returns the minimum inclusive value that this XSTime can hold. - * - * @return the minimum inclusive value that this can XSTime hold. If no - * minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive + * {@inheritDoc} */ - public String getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive - + public String newInstanceCode() { + return "new " + getJType().getName() + "();"; + } + /** - * Sets the maximum exclusive value that this XSTime can hold. - * - * @param max - * the maximum exclusive value this XSTime can be - * @see #setMaxInclusive + * {@inheritDoc} */ - public void setMaxExclusive(final String max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive - - /** - * Sets the maximum inclusive value that this XSTime can hold. - * @param max the maximum inclusive value this XSTime can be - * @see #setMaxExclusive - */ - public void setMaxInclusive(final String max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the minimum exclusive value that this XSTime can hold. - * @param min the minimum exclusive value this XSTime can be - * @see #setMinInclusive - */ - public void setMinExclusive(final String min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + /** - * Sets the minimum inclusive value that this XSTime can hold. - * @param min the minimum inclusive value this XSTime can be - * @see #setMinExclusive + * {@inheritDoc} */ - public void setMinInclusive(final String min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. - */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; + public String createFromJavaObjectCode(final String variableName) { + return "(" + getJType().getName() + ") " + variableName; } - /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. - */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } + //-------------------------------------------------------------------------- /** - * Transfer facets from the provided simpleType to this. The - * Time SimpleType supports the following facets: - * - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.DateTimeValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (Facet.MAX_EXCLUSIVE.equals(name)) { - this.setMaxExclusive(facet.getValue()); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - this.setMaxInclusive(facet.getValue()); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - this.setMinExclusive(facet.getValue()); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - this.setMinInclusive(facet.getValue()); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - LOG.warn("Warning: The facet 'whitespace' can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for 'time'."); - } - } - } //while - } //setFacets + if (fixedValue != null) { + jsc.add("try {\n" + + " typeValidator.setFixed({0});\n" + + "} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", fixedValue); + } - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator =" - + " new org.exolab.castor.xml.validators.DateTimeValidator();"); - - boolean addTryCatch = _minInclusive != null || _minExclusive != null - || _maxInclusive != null || _maxExclusive != null || fixedValue != null; + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - if (addTryCatch) { + if (hasMinimum() || hasMaximum()) { jsc.add("try {"); - jsc.indent(); - } - - // minInclusive / minExclusive facets (only one or the other, never both) - if (_minInclusive != null) { - jsc.add("org.exolab.castor.types.Time min = " - + "org.exolab.castor.types.Time.parseTime(\"" + _minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } else if (_minExclusive != null) { - jsc.add("org.exolab.castor.types.Time min = " - + "org.exolab.castor.types.Time.parseTime(\"" + _minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } - // maxInclusive / maxExclusive facets (only one or the other, never both) - if (_maxInclusive != null) { - jsc.add("org.exolab.castor.types.Time max = " - + "org.exolab.castor.types.Time.parseTime(\"" + _maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); - } else if (_maxExclusive != null) { - jsc.add("org.exolab.castor.types.Time max = " - + "org.exolab.castor.types.Time.parseTime(\"" + _maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } + // minInclusive / minExclusive facets (only one or the other, never both) + if (getMinInclusive() != null) { + jsc.add(" org.exolab.castor.types.Time min;\n" + + " min = org.exolab.castor.types.Time.parseTime(\"{0}\");\n" + + " typeValidator.setMinInclusive(min);", getMinInclusive()); + } else if (getMinExclusive() != null) { + jsc.add(" org.exolab.castor.types.Time min;\n" + + " min = org.exolab.castor.types.Time.parseTime(\"{0}\");\n" + + " typeValidator.setMinExclusive(min);", getMinExclusive()); + } - // fixed values - if (fixedValue != null) { - jsc.add("typeValidator.setFixed(" + fixedValue + ");"); - } + // maxInclusive / maxExclusive facets (only one or the other, never both) + if (getMaxInclusive() != null) { + jsc.add(" org.exolab.castor.types.Time max;\n" + + " max = org.exolab.castor.types.Time.parseTime(\"{0}\");\n" + + " typeValidator.setMaxInclusive(max);", getMaxInclusive()); + } else if (getMaxExclusive() != null) { + jsc.add(" org.exolab.castor.types.Time max;\n" + + " max = org.exolab.castor.types.Time.parseTime(\"{0}\");\n" + + " typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } - if (addTryCatch) { - jsc.unindent(); - jsc.add("} catch (java.text.ParseException pe) {"); - jsc.indent(); - jsc.add("System.out.println(\"ParseException\" + pe);"); - jsc.unindent(); - jsc.add("}"); + jsc.add("} catch (java.text.ParseException pe) {\n" + + " System.out.println(\"ParseException\" + pe);\n" + + "}", ""); } - - // pattern facet - codePatternFacet(jsc, "typeValidator"); - - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); } -} //-- XSTime + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSType.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSType.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSType.java (working copy) @@ -1,46 +1,17 @@ /* - * 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-2002(C) Intalio, Inc. All Rights Reserved. - * - * $Id$ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; @@ -46,6 +17,7 @@ import java.util.Enumeration; +import org.exolab.castor.xml.schema.Facet; import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -52,221 +24,162 @@ /** * The base XML Schema Type class. - * @author Keith Visco + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ */ public abstract class XSType { - - ////////////primitive types///////////////////// - - /** The name of the string type. */ - public static final String STRING_NAME = "string"; - /** The name of the boolean type. */ - public static final String BOOLEAN_NAME = "boolean"; - /** The name of the float type. */ - public static final String FLOAT_NAME = "float"; - /** The name of the double type. */ - public static final String DOUBLE_NAME = "double"; - /** The name of the decimal type. */ - public static final String DECIMAL_NAME = "decimal"; - /** the name of the duration type. */ - public static final String DURATION_NAME = "duration"; - /** The name of the the dateTime type. */ - public static final String DATETIME_NAME = "dateTime"; - /** the name of the time type. */ - public static final String TIME_NAME = "time"; - /** The name of the date type. */ - public static final String DATE_NAME = "date"; - /** The name of the gYearMonth type. */ - public static final String GYEARMONTH_NAME = "gYearMonth"; - /** The name of the gYear type. */ - public static final String GYEAR_NAME = "gYear"; - /** The name of the gMonthDay type. */ - public static final String GMONTHDAY_NAME = "gMonthDay"; - /** The name of the gDay type. */ - public static final String GDAY_NAME = "gDay"; - /** The name of the gMonth type. */ - public static final String GMONTH_NAME = "gMonth"; - /** The name of the hexBinary type. */ - public static final String HEXBINARY_NAME = "hexBinary"; - /** The name of the base64Binary type. */ - public static final String BASE64BINARY_NAME = "base64Binary"; - /** the name of the anyURI type. */ - public static final String ANYURI_NAME = "anyURI"; - /** the name of the QName type. */ - public static final String QNAME_NAME = "QName"; - /** the name of the notation type. */ - public static final String NOTATION_NAME = "NOTATION"; - - /////////////derived types////////////////////// - - /** The name of the normalizedString type. */ - public static final String NORMALIZEDSTRING_NAME = "normalizedString"; - /** The name of the token type. */ - public static final String TOKEN_NAME = "token"; - /** The name of the language type. */ - public static final String LANGUAGE_NAME = "language"; - /** The Name of the IDREFS type. */ - public static final String IDREFS_NAME = "IDREFS"; - /** The name of the NMTOKEN type. */ - public static final String NMTOKEN_NAME = "NMTOKEN"; - /** The name of the NMTOKENS type. */ - public static final String NMTOKENS_NAME = "NMTOKENS"; - /** The name of the Name type. */ - public static final String NAME_NAME = "Name"; - /** The name of the NCName type. */ - public static final String NCNAME_NAME = "NCName"; - /** The name of the ID type. */ - public static final String ID_NAME = "ID"; - /** The name of the IDREF type. */ - public static final String IDREF_NAME = "IDREF"; - /** The name of the integer type. */ - public static final String INTEGER_NAME = "integer"; - /** The name of the non-positive-integer type. */ - public static final String NON_NEGATIVE_INTEGER_NAME = "nonNegativeInteger"; - /** The name of the non-positive-integer type. */ - public static final String NON_POSITIVE_INTEGER_NAME = "nonPositiveInteger"; - /** The name of the negative-integer type. */ - public static final String NEGATIVE_INTEGER_NAME = "negativeInteger"; - /** The name of the long type. */ - public static final String LONG_NAME = "long"; - /** The name of the int type. */ - public static final String INT_NAME = "int"; - /** The name of the short type. */ - public static final String SHORT_NAME = "short"; - /** The name of the byte type. */ - public static final String BYTE_NAME = "byte"; - /** The name of the positive-integer type. */ - public static final String POSITIVE_INTEGER_NAME = "positiveInteger"; - /** The name of the unsigned-long type. */ - public static final String UNSIGNED_LONG_NAME = "unsignedLong"; - /** The name of the unsigned-short type. */ - public static final String UNSIGNED_SHORT_NAME = "unsignedShort"; + //-------------------------------------------------------------------------- + + // special types /** Value meaning the type is unassigned. */ - public static final short NULL = -1; + public static final short NULL = -1; /** A user-defined type. */ - public static final short CLASS = 0; + public static final short CLASS = 0; - // Primitive types + // primitive types + /** xsd:string. */ - public static final short STRING_TYPE = 1; + public static final short STRING_TYPE = 1; + /** xsd:duration. */ - public static final short DURATION_TYPE = 2; + public static final short DURATION_TYPE = 2; + /** xsd:dateTime. */ - public static final short DATETIME_TYPE = 3; + public static final short DATETIME_TYPE = 3; + /** xsd:time. */ - public static final short TIME_TYPE = 4; + public static final short TIME_TYPE = 4; + /** xsd:date. */ - public static final short DATE_TYPE = 5; + public static final short DATE_TYPE = 5; + /** xsd:gYearMonth. */ - public static final short GYEARMONTH_TYPE = 6; + public static final short GYEARMONTH_TYPE = 6; + /** xsd:gYear. */ - public static final short GYEAR_TYPE = 7; + public static final short GYEAR_TYPE = 7; + /** xsd:gMonthDay. */ - public static final short GMONTHDAY_TYPE = 8; + public static final short GMONTHDAY_TYPE = 8; + /** xsd:gDay. */ - public static final short GDAY_TYPE = 9; + public static final short GDAY_TYPE = 9; + /** xsd:gMonth. */ - public static final short GMONTH_TYPE = 10; + public static final short GMONTH_TYPE = 10; + /** xsd:boolean. */ - public static final short BOOLEAN_TYPE = 11; + public static final short BOOLEAN_TYPE = 11; + /** xsd:base64Binary. */ - public static final short BASE64BINARY_TYPE = 12; + public static final short BASE64BINARY_TYPE = 12; + /** xsd:hexBinary. */ - public static final short HEXBINARY_TYPE = 13; + public static final short HEXBINARY_TYPE = 13; + /** xsd:float. */ - public static final short FLOAT_TYPE = 14; + public static final short FLOAT_TYPE = 14; + /** xsd:double. */ - public static final short DOUBLE_TYPE = 15; + public static final short DOUBLE_TYPE = 15; + /** xsd:decimal. */ - public static final short DECIMAL_TYPE = 16; + public static final short DECIMAL_TYPE = 16; + /** xsd:anyURI. */ - public static final short ANYURI_TYPE = 17; + public static final short ANYURI_TYPE = 17; + /** xsd:QName. */ - public static final short QNAME_TYPE = 18; + public static final short QNAME_TYPE = 18; + /** xsd:notation. */ - public static final short NOTATION_TYPE = 19; + public static final short NOTATION_TYPE = 19; - // Derived datatypes + // derived types + /** xsd:normalizedString. */ - public static final short NORMALIZEDSTRING_TYPE = 20; + public static final short NORMALIZEDSTRING_TYPE = 20; + /** xsd:token. */ - public static final short TOKEN_TYPE = 21; + public static final short TOKEN_TYPE = 21; + /** xsd:language. */ - public static final short LANGUAGE_TYPE = 22; + public static final short LANGUAGE_TYPE = 22; + /** xsd:name. */ - public static final short NAME_TYPE = 23; + public static final short NAME_TYPE = 23; + /** xsd:NCNAME. */ - public static final short NCNAME_TYPE = 24; + public static final short NCNAME_TYPE = 24; + /** xsd:ID. */ - public static final short ID_TYPE = 25; + public static final short ID_TYPE = 25; + /** xsd:IDREF. */ - public static final short IDREF_TYPE = 26; + public static final short IDREF_TYPE = 26; + /** xsd:IDREFS. */ - public static final short IDREFS_TYPE = 27; + public static final short IDREFS_TYPE = 27; + /** xsd:ENTITY. */ - public static final short ENTITY = 28; + public static final short ENTITY = 28; + /** xsd:ENTITIES. */ - public static final short ENTITIES = 29; + public static final short ENTITIES = 29; + /** xsd:NMTOKEN. */ - public static final short NMTOKEN_TYPE = 30; + public static final short NMTOKEN_TYPE = 30; + /** xsd:NMTOKENS. */ - public static final short NMTOKENS_TYPE = 31; + public static final short NMTOKENS_TYPE = 31; + /** xsd:integer. */ - public static final short INTEGER_TYPE = 32; + public static final short INTEGER_TYPE = 32; + /** xsd:nonPositiveInteger. */ - public static final short NON_POSITIVE_INTEGER_TYPE = 33; + public static final short NON_POSITIVE_INTEGER_TYPE = 33; + /** xsd:negativeInteger. */ - public static final short NEGATIVE_INTEGER_TYPE = 34; + public static final short NEGATIVE_INTEGER_TYPE = 34; + /** xsd:long. */ - public static final short LONG_TYPE = 35; + public static final short LONG_TYPE = 35; + /** xsd:int. */ - public static final short INT_TYPE = 36; + public static final short INT_TYPE = 36; + /** xsd:short. */ - public static final short SHORT_TYPE = 37; + public static final short SHORT_TYPE = 37; + /** xsd:byte. */ - public static final short BYTE_TYPE = 38; + public static final short BYTE_TYPE = 38; + /** xsd:nonNegativeInteger. */ - public static final short NON_NEGATIVE_INTEGER_TYPE = 39; + public static final short NON_NEGATIVE_INTEGER_TYPE = 39; + /** xsd:positiveInteger. */ - public static final short POSITIVE_INTEGER_TYPE = 44; + public static final short POSITIVE_INTEGER_TYPE = 44; + /** A collection type. */ - public static final short COLLECTION = 45; + public static final short COLLECTION = 45; + /** xsd:unsignedLong. */ - public static final short UNSIGNED_LONG_TYPE = 46; + public static final short UNSIGNED_LONG_TYPE = 46; + /** xsd:unsignedShort. */ - public static final short UNSIGNED_SHORT_TYPE = 47; - - /** Maximum non-positive integer. */ - public static final long MAX_NON_POSITIVE_INTEGER = 0L; - /** Minimum non-negative integer. */ - public static final long MIN_NON_NEGATIVE_INTEGER = 0L; - /** Maximum negative integer. */ - public static final long MAX_NEGATIVE_INTEGER = -1L; - /** Minimum positive integer. */ - public static final long MIN_POSITIVE_INTEGER = 1L; - /** Minimum unsigned short. */ - public static final long MIN_UNSIGNED_INTEGER = 0L; - /** Maximum unsigned short. */ - public static final long MAX_UNSIGNED_INTEGER = 4294967295L; - /** Minimum unsigned short. */ - public static final int MIN_UNSIGNED_SHORT = 0; - /** Maximum unsigned short. */ - public static final int MAX_UNSIGNED_SHORT = 65535; - /** Maximum negative integer. */ - public static final int MIN_INTEGER = -2147483647; - /** Maximum negative integer. */ - public static final int MAX_INTEGER = 2147483647; - /** Minimum unsigned byte. */ - public static final short MIN_UNSIGNED_BYTE = 0; - /** Maximum unsigned byte. */ - public static final short MAX_UNSIGNED_BYTE = 255; + public static final short UNSIGNED_SHORT_TYPE = 47; + /** xsd:unsignedByte. */ + public static final short UNSIGNED_BYTE_TYPE = 48; - /** The type of the element. */ - private final short _type; + /** xsd:unsignedInt. */ + public static final short UNSIGNED_INT_TYPE = 49; + + //-------------------------------------------------------------------------- /** Flag signaling an enumerated type. */ private boolean _enumerated = false; @@ -271,58 +184,63 @@ /** Flag signaling an enumerated type. */ private boolean _enumerated = false; + //-------------------------------------------------------------------------- + /** - * Creates a new XSType of the given type. - * @param type The type to create. + * Returns true if this XSType represents an enumerated type. + * + * @return True if this XSType represents an enumerated type. */ - protected XSType(final short type) { - this._type = type; - } //-- XSType + public final boolean isEnumerated() { + return _enumerated; + } /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. + * Sets the enumerated flag for this XSClass. + * + * @param enumerated A boolean indicating whether or not this XSClass represents an + * enumerated type. */ - public abstract JType getJType(); + public final void setAsEnumerated(final boolean enumerated) { + _enumerated = enumerated; + } + + //-------------------------------------------------------------------------- /** - * Reads and sets the facets for XSType. - * @param simpleType the SimpleType containing the facets + * Returns the name of this XSType. + * + * @return The name of this XSType. */ - public abstract void setFacets(SimpleType simpleType); + public abstract String getName(); /** * Returns the type of this XSType. + * * @return the type of this XSType. */ - public final short getType() { - return this._type; - } //-- getType + public abstract short getType(); /** - * Returns a list of Facets from the simpleType, not including facets - * from base types. - * - * @param simpleType - * the Simpletype we want the facets for - * @return Unique list of facets from the simple type + * Returns true if this XSType represents a primitive type. + * + * @return True if this XSType represents a primitive type. + */ + public abstract boolean isPrimitive(); + + /** + * Returns true if the XSType represents an XML Schema date/time type. + * + * @return True if the XSType represents an XML Schema date/time type. */ - protected static Enumeration getFacets(final SimpleType simpleType) { - return simpleType.getLocalFacets(); - } + public abstract boolean isDateTime(); /** - * Returns the String necessary to convert an instance of this XSType to an - * Object. This method is really only useful for primitive types. - * - * @param variableName - * the name of the instance variable - * @return the String necessary to convert an instance of this XSType to an - * Object + * Returns the JType that this XSType represents. + * + * @return The JType that this XSType represents. */ - public String createToJavaObjectCode(final String variableName) { - return variableName; - } //-- toJavaObject + public abstract JType getJType(); /** * Returns the Java code neccessary to create a new instance of the JType @@ -328,84 +246,39 @@ * Returns the Java code neccessary to create a new instance of the JType * associated with this XSType. * - * @return the Java code neccessary to create a new instance. + * @return The Java code neccessary to create a new instance. */ - public String newInstanceCode() { - return "new " + getJType().getName() + "();"; - } //-- newInstanceCode + public abstract String newInstanceCode(); /** - * Returns the String necessary to convert an Object to an instance of this - * XSType. This method is really only useful for primitive types + * Returns the string necessary to convert an instance of this XSType to an + * Object. This method is really only useful for primitive types. * - * @param variableName - * the name of the Object - * @return the String necessary to convert an Object to an instance of this - * XSType + * @param variableName The name of the instance variable. + * @return The String necessary to convert an instance of this XSType to an Object. */ - public String createFromJavaObjectCode(final String variableName) { - StringBuffer sb = new StringBuffer(); - - JType jType = getJType(); - if (jType != null) { - sb.append('('); - sb.append(jType.toString()); - sb.append(") "); - } - sb.append(variableName); - return sb.toString(); - } //-- fromJavaObject + public abstract String createToJavaObjectCode(final String variableName); /** - * Returns true if this XSType represents an enumerated type. - * @return true if this XSType represents an enumerated type. + * Returns the string necessary to convert an Object to an instance of this + * XSType. This method is really only useful for primitive types. + * + * @param variableName The name of the Object. + * @return The String necessary to convert an Object to an instance of this XSType. */ - public final boolean isEnumerated() { - return _enumerated; - } //-- isEnumerated + public abstract String createFromJavaObjectCode(final String variableName); - /** - * Returns true if this XSType represents a primitive type. - * @return true if this XSType represents a primitive type. - */ - public final boolean isPrimitive() { - switch (_type) { - case BOOLEAN_TYPE: - case BYTE_TYPE: - case DOUBLE_TYPE: - case FLOAT_TYPE: - case INTEGER_TYPE: - case LONG_TYPE: - case NON_NEGATIVE_INTEGER_TYPE: - case NON_POSITIVE_INTEGER_TYPE: - case NEGATIVE_INTEGER_TYPE: - case POSITIVE_INTEGER_TYPE: - case SHORT_TYPE: - case INT_TYPE: - return true; - default: - return false; - } - } + //-------------------------------------------------------------------------- /** - * Returns true if the XSType represents an XML Schema date/time type. - * @return true if the XSType represents an XML Schema date/time type. + * Reads and sets the facets for XSType. + * + * @param simpleType The SimpleType containing the facets. */ - public final boolean isDateTime() { - switch (_type) { - case DATETIME_TYPE: - case DURATION_TYPE: - case DATE_TYPE: - case GDAY_TYPE: - case GMONTHDAY_TYPE: - case GMONTH_TYPE: - case GYEARMONTH_TYPE: - case GYEAR_TYPE: - case TIME_TYPE: - return true; - default: - return false; + public final void setFacets(final SimpleType simpleType) { + Enumeration enumeration = simpleType.getLocalFacets(); + while (enumeration.hasMoreElements()) { + setFacet((Facet) enumeration.nextElement()); } } @@ -410,123 +283,24 @@ } /** - * Returns the name of this XSType. - * @return the name of this XSType. + * Set the given facet for XSType if applicable. + * + * @param facet The facet to set for XSType. */ - public String getName() { - switch (_type) { - case STRING_TYPE: return STRING_NAME; - case DURATION_TYPE: return DURATION_NAME; - case DATETIME_TYPE: return DATETIME_NAME; - case TIME_TYPE: return TIME_NAME; - case DATE_TYPE: return DATE_NAME; - case GYEARMONTH_TYPE: return GYEARMONTH_NAME; - case GYEAR_TYPE: return GYEAR_NAME; - case GMONTHDAY_TYPE: return GMONTHDAY_NAME; - case GDAY_TYPE: return GDAY_NAME; - case GMONTH_TYPE: return GMONTH_NAME; - case BOOLEAN_TYPE: return BOOLEAN_NAME; - case BASE64BINARY_TYPE: return BASE64BINARY_NAME; - case HEXBINARY_TYPE: return HEXBINARY_NAME; - case FLOAT_TYPE: return FLOAT_NAME; - case DOUBLE_TYPE: return DOUBLE_NAME; - case DECIMAL_TYPE: return DECIMAL_NAME; - case ANYURI_TYPE: return ANYURI_NAME; - case QNAME_TYPE: return QNAME_NAME; - case NORMALIZEDSTRING_TYPE: return NORMALIZEDSTRING_NAME; - case TOKEN_TYPE: return TOKEN_NAME; - case LANGUAGE_TYPE: return LANGUAGE_NAME; - case NAME_TYPE: return NAME_NAME; - case NCNAME_TYPE: return NCNAME_NAME; - case ID_TYPE: return ID_NAME; - case IDREF_TYPE: return IDREF_NAME; - case IDREFS_TYPE: return IDREFS_NAME; - case NMTOKENS_TYPE: return NMTOKENS_NAME; - case NMTOKEN_TYPE: return NMTOKEN_NAME; - case INTEGER_TYPE: return INTEGER_NAME; - case NON_POSITIVE_INTEGER_TYPE: return NON_POSITIVE_INTEGER_NAME; - case NEGATIVE_INTEGER_TYPE: return NEGATIVE_INTEGER_NAME; - case LONG_TYPE: return LONG_NAME; - case INT_TYPE: return INTEGER_NAME; - case SHORT_TYPE: return SHORT_NAME; - case BYTE_TYPE: return BYTE_NAME; - case NON_NEGATIVE_INTEGER_TYPE: return NON_NEGATIVE_INTEGER_NAME; - case POSITIVE_INTEGER_TYPE: return POSITIVE_INTEGER_NAME; - case UNSIGNED_LONG_TYPE: return UNSIGNED_LONG_NAME; - case UNSIGNED_SHORT_TYPE: return UNSIGNED_SHORT_NAME; - case COLLECTION: - short type = ((XSList) this).getContentType().getType(); - if (type == NMTOKEN_TYPE) { - return NMTOKENS_NAME; - } else if (type == IDREF_TYPE) { - return IDREFS_NAME; - } else { - return null; - } - default: - return null; - } - } //-- getName - + protected abstract void setFacet(final Facet facet); + /** - * Sets the enumerated flag for this XSClass. + * Creates the validation code for an instance of this XSType. If necessary the validation + * code should create a newly configured TypeValidator, that should then be added to a + * FieldValidator instance whose name is provided. * - * @param enumerated - * a boolean indicating whether or not this XSClass represents an - * enumerated type + * @param jsc The JSourceCode to fill in. + * @param fixedValue A fixed value to use if any. + * @param validatorInstanceName The name of the FieldValidator that the configured + * TypeValidator should be added to. */ - public final void setAsEnumerated(final boolean enumerated) { - this._enumerated = enumerated; - } //-- setAsEnumerated - - /** - * Creates the validation code for an instance of this XSType. The - * validation code should if necessary create a newly configured - * TypeValidator, that should then be added to a FieldValidator instance - * whose name is provided. - * - * @param fixedValue - * a fixed value to use if any - * @param jsc - * the JSourceCode to fill in. - * @param fieldValidatorInstanceName - * the name of the FieldValidator that the configured - * TypeValidator should be added to. - */ - public abstract void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName); + public abstract void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName); - /** - * Escapes special characters in the given String so that it can - * be printed correctly. - * - * @param str the String to escape - * @return the escaped String, or null if the given String was null. - */ - protected static String escapePattern(final String str) { - if (str == null) { - return str; - } - - //-- make sure we have characters to escape - if (str.indexOf('\\') < 0 && str.indexOf('\"') < 0) { - return str; - } - - StringBuffer sb = new StringBuffer(); - - char[] chars = str.toCharArray(); - for (int i = 0; i < chars.length; i++) { - char ch = chars[i]; - if (ch == '\\') { - sb.append(ch); - } - if (ch == '\"') { - sb.append('\\'); - } - sb.append(ch); - } - return sb.toString(); - } //-- escape - -} //-- XSType + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedByte.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedByte.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedByte.java (working copy) @@ -1,5 +1,5 @@ /* - * Copyright 2005 Werner Guttmann + * Copyright 2005-2007 Werner Guttmann, Ralf Joachim * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,41 @@ */ package org.exolab.castor.builder.types; +import org.exolab.javasource.JClass; +import org.exolab.javasource.JSourceCode; +import org.exolab.javasource.JType; + /** - * The XML Schema "unsigned-byte" type. + * The xsd:unsignedByte XML Schema type. * * @author Werner Guttmann + * @author Ralf Joachim * @version $Revision: 5951 $ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ */ -public final class XSUnsignedByte extends XSShort { +public final class XSUnsignedByte extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "unsignedByte"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.UNSIGNED_BYTE_TYPE; + + /** A constant holding the minimum value an xsd:unsignedByte can have, 0. */ + public static final String MIN_VALUE = "0"; + + /** A constant holding the maximum value an xsd:unsignedByte can have, 255. */ + public static final String MAX_VALUE = "255"; + + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -35,9 +63,101 @@ * @param asWrapper if true, use the java.lang wrapper class. */ public XSUnsignedByte(final boolean asWrapper) { - super(asWrapper); - setMinInclusive(MIN_UNSIGNED_BYTE); - setMaxInclusive(MAX_UNSIGNED_BYTE); + super(); + + _asWrapper = asWrapper; + if (asWrapper) { + _jType = new JClass("java.lang.Short"); + } else { + _jType = JType.SHORT; + } + + setMinInclusive(MIN_VALUE); + setMaxInclusive(MAX_VALUE); + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + + /** + * {@inheritDoc} + */ + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.Short((short) 0);"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } + return "new java.lang.Short(" + variableName + ")"; + } + + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Short) " + variableName + ")"; } + return "((java.lang.Short) " + variableName + ").shortValue()"; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.ShortValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.ShortValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + if (fixedValue != null) { + jsc.add("typeValidator.setFixed((short) " + fixedValue + ");"); + } + + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive((short) " + getMinExclusive() + ");"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive((short) " + getMinInclusive() + ");"); + } + + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive((short) " + getMaxExclusive() + ");"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive((short) " + getMaxInclusive() + ");"); + } + + codeDigitsFacet(jsc, "typeValidator"); } + //-------------------------------------------------------------------------- } Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedInt.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedInt.java (revision 6723) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedInt.java (working copy) @@ -1,5 +1,5 @@ /* - * Copyright 2005 Werner Guttmann + * Copyright 2005-2007 Werner Guttmann, Ralf Joachim * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,18 +15,46 @@ */ package org.exolab.castor.builder.types; +import org.exolab.javasource.JClass; +import org.exolab.javasource.JSourceCode; +import org.exolab.javasource.JType; + /** - * The XML Schema "unsigned-integer" type. + * The xsd:unsignedInt XML Schema type. * * @author Werner Guttmann + * @author Ralf Joachim * @version $Revision: 5951 $ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ */ -public final class XSUnsignedInteger extends XSLong { +public final class XSUnsignedInt extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- + /** Name of this XSType. */ + public static final String NAME = "unsignedInt"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.UNSIGNED_INT_TYPE; + + /** A constant holding the minimum value an xsd:unsignedInt can have, 0. */ + public static final String MIN_VALUE = "0"; + + /** A constant holding the maximum value an xsd:unsignedInt can have, 4294967295. */ + public static final String MAX_VALUE = "4294967295"; + + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- + /** * No-arg constructor. */ - public XSUnsignedInteger() { + public XSUnsignedInt() { this(false); } @@ -32,12 +60,105 @@ /** * Constructs a new XSUnsignedInteger. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ - public XSUnsignedInteger(final boolean asWrapper) { - super(asWrapper); - setMinInclusive(MIN_UNSIGNED_INTEGER); - setMaxInclusive(MAX_UNSIGNED_INTEGER); + public XSUnsignedInt(final boolean asWrapper) { + super(); + + _asWrapper = asWrapper; + if (_asWrapper) { + _jType = new JClass("java.lang.Long"); + } else { + _jType = JType.LONG; + } + + setMinInclusive(MIN_VALUE); + setMaxInclusive(MAX_VALUE); } + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + + /** + * {@inheritDoc} + */ + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.Long(0);"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } + return "new java.lang.Long(" + variableName + ")"; + } + + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Long) " + variableName + ")"; } + return "((java.lang.Long) " + variableName + ").longValue()"; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.LongValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.LongValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); + } + + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive(" + getMinExclusive() + "L);"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive(" + getMinInclusive() + "L);"); + } + + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive(" + getMaxExclusive() + "L);"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive(" + getMaxInclusive() + "L);"); + } + + codeDigitsFacet(jsc, "typeValidator"); + } + + //-------------------------------------------------------------------------- } Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedInteger.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedInteger.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedInteger.java (working copy) @@ -1,43 +0,0 @@ -/* - * Copyright 2005 Werner Guttmann - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.exolab.castor.builder.types; - -/** - * The XML Schema "unsigned-integer" type. - * - * @author Werner Guttmann - * @version $Revision: 5951 $ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ - */ -public final class XSUnsignedInteger extends XSLong { - - /** - * No-arg constructor. - */ - public XSUnsignedInteger() { - this(false); - } - - /** - * Constructs a new XSUnsignedInteger. - * @param asWrapper if true, use the java.lang wrapper class. - */ - public XSUnsignedInteger(final boolean asWrapper) { - super(asWrapper); - setMinInclusive(MIN_UNSIGNED_INTEGER); - setMaxInclusive(MAX_UNSIGNED_INTEGER); - } - -} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedLong.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedLong.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedLong.java (working copy) @@ -1,54 +1,20 @@ /* - * 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-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: XSLong.java 6317 2006-10-17 14:24:18Z wguttmn $ + * Copyright 2007 Keith Visco, Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package org.exolab.castor.builder.types; -import java.math.BigInteger; -import java.util.Enumeration; - -import org.exolab.castor.xml.schema.Facet; -import org.exolab.castor.xml.schema.SimpleType; import org.exolab.javasource.JClass; import org.exolab.javasource.JSourceCode; import org.exolab.javasource.JType; @@ -54,26 +20,32 @@ import org.exolab.javasource.JType; /** - * The XML Schema unsigned long type. - * @author Keith Visco + * The xsd:unsignedLong XML Schema type. + * + * @author Keith Visco + * @author Ralf Joachim * @version $Revision: 6317 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ */ -public final class XSUnsignedLong extends XSPatternBase { +public final class XSUnsignedLong extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- - /** Maximum Unsigned Long (inclusive). */ - private BigInteger _maxInclusive = null; - /** Maximum Unsigned Long (exclusive). */ - private BigInteger _maxExclusive = null; - /** Minimum Unsigned Long (inclusive). */ - private BigInteger _minInclusive = null; - /** Minimum Unsigned Long (exclusive). */ - private BigInteger _minExclusive = null; - /** Total number of digits. */ - private int _totalDigits = -1; - + /** Name of this XSType. */ + public static final String NAME = "unsignedLong"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.UNSIGNED_LONG_TYPE; + /** The JType represented by this XSType. */ private static final JType JTYPE = new JClass("java.math.BigInteger"); + /** A constant holding the minimum value an xsd:long can have, 0. */ + public static final String MIN_VALUE = "0"; + + /** A constant holding the maximum value an xsd:long can have, 264-1. */ + public static final String MAX_VALUE = "18446744073709551615"; + + //-------------------------------------------------------------------------- + /** * No-arg constructor. */ @@ -78,280 +50,96 @@ * No-arg constructor. */ public XSUnsignedLong() { - super(XSType.UNSIGNED_LONG_TYPE); - setMinInclusive(BigInteger.valueOf(0)); - setMaxInclusive(new BigInteger("18446744073709551615")); - } //-- XSLong - - /** - * Returns the Java code necessary to create a new instance of the JType - * associated with this XSType. - * - * @return the Java code necessary to create a new instance of the JType - * associated with this XSType. - */ - public String newInstanceCode() { - return "new " + getJType().getName() + "(\"0\");"; - } - - /** - * Returns the JType that this XSType represents. - * @return the JType that this XSType represents. - */ - public JType getJType() { - return JTYPE; + super(); + + setMinInclusive(MIN_VALUE); + setMaxInclusive(MAX_VALUE); } - /** - * Returns the maximum exclusive value that this XSLong can hold. - * - * @return the maximum exclusive value that this XSLong can hold. If no - * maximum exclusive value has been set, Null will be returned - * @see #getMaxInclusive - */ - public BigInteger getMaxExclusive() { - return _maxExclusive; - } //-- getMaxExclusive - - /** - * Returns the maximum inclusive value that this XSLong can hold. - * - * @return the maximum inclusive value that this XSLong can hold. If no - * maximum inclusive value has been set, Null will be returned - * @see #getMaxExclusive - */ - public BigInteger getMaxInclusive() { - return _maxInclusive; - } //-- getMaxInclusive - - /** - * Returns the minimum exclusive value that this XSLong can hold. - * - * @return the minimum exclusive value that this XSLong can hold. If no - * minimum exclusive value has been set, Null will be returned - * @see #getMinInclusive() - * @see #setMaxInclusive(long) - */ - public BigInteger getMinExclusive() { - return _minExclusive; - } //-- getMinExclusive + //-------------------------------------------------------------------------- /** - * Returns the minimum inclusive value that this XSLong can hold. - * - * @return the minimum inclusive value that this XSLong can hold. If no - * minimum inclusive value has been set, Null will be returned - * @see #getMinExclusive + * {@inheritDoc} */ - public BigInteger getMinInclusive() { - return _minInclusive; - } //-- getMinInclusive + public String getName() { return NAME; } /** - * Returns the totalDigits facet value of this XSInteger. - * @return the totalDigits facet value of this XSInteger. + * {@inheritDoc} */ - public int getTotalDigits() { - return _totalDigits; - } - + public short getType() { return TYPE; } + /** - * Returns true if a maximum (inclusive or exclusive) has been set. - * @return true if a maximum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMaximum() { - return _maxInclusive != null || _maxExclusive != null; - } //-- hasMaximum - + public boolean isPrimitive() { return false; } + /** - * Returns true if a minimum (inclusive or exclusive) has been set. - * @return true if a minimum (inclusive or exclusive) has been set. + * {@inheritDoc} */ - public boolean hasMinimum() { - return _minInclusive != null || _minExclusive != null; - } //-- hasMinimum - + public boolean isDateTime() { return false; } + /** - * Sets the maximum exclusive value that this XSLong can hold. - * - * @param max - * the maximum exclusive value this XSLong can be - * @see #setMaxInclusive(Long) + * {@inheritDoc} */ - public void setMaxExclusive(final BigInteger max) { - _maxExclusive = max; - _maxInclusive = null; - } //-- setMaxExclusive - + public JType getJType() { return JTYPE; } + /** - * Sets the maximum inclusive value that this XSLong can hold. - * - * @param max - * the maximum inclusive value this XSLong can be - * @see #setMaxExclusive(Long) + * {@inheritDoc} */ - public void setMaxInclusive(final BigInteger max) { - _maxInclusive = max; - _maxExclusive = null; - } //-- setMaxInclusive - - /** - * Sets the minimum exclusive value that this XSLong can hold. - * - * @param min - * the minimum exclusive value this XSLong can be - * @see #setMinInclusive(Long) - */ - public void setMinExclusive(final BigInteger min) { - _minExclusive = min; - _minInclusive = null; - } //-- setMinExclusive - - /** - * Sets the minimum inclusive value that this XSLong can hold. - * - * @param min - * the minimum inclusive value this XSLong can be - * @see #setMinExclusive(long) - */ - public void setMinInclusive(final BigInteger min) { - _minInclusive = min; - _minExclusive = null; - } //-- setMinInclusive - - /** - * Sets the totalDigits facet for this XSInteger. - * @param totalDig the value of totalDigits (must be > 0) - */ - public void setTotalDigits(final int totalDig) { - if (totalDig <= 0) { - throw new IllegalArgumentException(this.getName() - + ": the totalDigits facet must be positive"); - } - _totalDigits = totalDig; - } + public String newInstanceCode() { + return "new java.math.BigInteger(\"0\");"; + } /** - * Transfer facets from the provided simpleType to this. - * - * @param simpleType - * The SimpleType containing our facets. - * @see org.exolab.castor.builder.types.XSType#getFacets + * {@inheritDoc} */ - public void setFacets(final SimpleType simpleType) { - Enumeration enumeration = getFacets(simpleType); - while (enumeration.hasMoreElements()) { - Facet facet = (Facet) enumeration.nextElement(); - String name = facet.getName(); - - if (Facet.MAX_EXCLUSIVE.equals(name)) { - setMaxExclusive(new BigInteger(facet.getValue())); - } else if (Facet.MAX_INCLUSIVE.equals(name)) { - setMaxInclusive(new BigInteger(facet.getValue())); - } else if (Facet.MIN_EXCLUSIVE.equals(name)) { - BigInteger min = new BigInteger(facet.getValue()); - if (min.compareTo(new BigInteger("-1")) == -1) { - throw new IllegalArgumentException("minExclusive must be > -1 for " - + this.getName()); - } - setMinExclusive(min); - } else if (Facet.MIN_INCLUSIVE.equals(name)) { - BigInteger min = new BigInteger(facet.getValue()); - if (min.compareTo(new BigInteger("0")) == -1) { - throw new IllegalArgumentException("minInclusive must be > 0 for " - + this.getName()); - } - setMinInclusive(min); - } else if (Facet.PATTERN.equals(name)) { - addPattern(facet.getValue()); - } else if (Facet.TOTALDIGITS.equals(name)) { - setTotalDigits(facet.toInt()); - } else if (Facet.FRACTIONDIGITS.equals(name)) { - if (facet.toInt() != 0) { - throw new IllegalArgumentException("fractionDigits must be 0 for " - + this.getName()); - } - } else if (Facet.WHITESPACE.equals(name)) { - // If this facet is set correctly, we don't need to do anything - if (!facet.getValue().equals(Facet.WHITESPACE_COLLAPSE)) { - throw new IllegalArgumentException("Warning: The facet 'whitespace'" - + " can only be set to '" - + Facet.WHITESPACE_COLLAPSE + "' for '" - + this.getName() + "'."); - } - } - } //setFacets - } //-- readLongFacets - + public String createToJavaObjectCode(final String variableName) { + return variableName; + } + /** - * Returns the String necessary to convert an Object to - * an instance of this XSType. This method is really only useful - * for primitive types - * @param variableName the name of the Object - * @return the String necessary to convert an Object to an - * instance of this XSType + * {@inheritDoc} */ public String createFromJavaObjectCode(final String variableName) { return "((java.math.BigInteger) " + variableName + ")"; - } //-- fromJavaObject + } + + //-------------------------------------------------------------------------- /** - * Creates the validation code for an instance of this XSType. The validation - * code should if necessary create a newly configured TypeValidator, that - * should then be added to a FieldValidator instance whose name is provided. - * - * @param fixedValue a fixed value to use if any - * @param jsc the JSourceCode to fill in. - * @param fieldValidatorInstanceName the name of the FieldValidator - * that the configured TypeValidator should be added to. + * {@inheritDoc} */ - public void validationCode(final JSourceCode jsc, final String fixedValue, - final String fieldValidatorInstanceName) { - jsc.add("org.exolab.castor.xml.validators.BigIntegerValidator typeValidator" - + " = new org.exolab.castor.xml.validators.BigIntegerValidator();"); + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.BigIntegerValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.BigIntegerValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); - if (_minExclusive != null) { - jsc.add("java.math.BigInteger min = new java.math.BigInteger(\""); - jsc.append(_minExclusive + "\");"); - jsc.add("typeValidator.setMinExclusive(min);"); - } else if (_minInclusive != null) { - jsc.add("java.math.BigInteger min = new java.math.BigInteger(\""); - jsc.append(_minInclusive + "\");"); - jsc.add("typeValidator.setMinInclusive(min);"); - } - - if (_maxExclusive != null) { - jsc.add("java.math.BigInteger max = new java.math.BigInteger(\""); - jsc.append(_maxExclusive + "\");"); - jsc.add("typeValidator.setMaxExclusive(max);"); - } else if (_maxInclusive != null) { - jsc.add("java.math.BigInteger max = new java.math.BigInteger(\""); - jsc.append(_maxInclusive + "\");"); - jsc.add("typeValidator.setMaxInclusive(max);"); - } - - //-- fixed values if (fixedValue != null) { - //-- just make sure we have a valid value... - new BigInteger(fixedValue); - - jsc.add("typeValidator.setFixed(new BigInteger(\""); - jsc.append(fixedValue); - jsc.append("\");"); + jsc.add("typeValidator.setFixed(new BigInteger(\"" + fixedValue + "\");"); } - // pattern facet codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); - // -- totalDigits - int totalDigits = getTotalDigits(); - if (totalDigits != -1) { - jsc.add("typeValidator.setTotalDigits("); - jsc.append(Integer.toString(totalDigits)); - jsc.append(");"); + if (getMinExclusive() != null) { + jsc.add("java.math.BigInteger min = new java.math.BigInteger(\"{0}\");\n" + + "typeValidator.setMinExclusive(min);", getMinExclusive()); + } else if (getMinInclusive() != null) { + jsc.add("java.math.BigInteger min = new java.math.BigInteger(\"{0}\");\n" + + "typeValidator.setMinInclusive(min);", getMinInclusive()); } - jsc.add(fieldValidatorInstanceName + ".setValidator(typeValidator);"); + if (getMaxExclusive() != null) { + jsc.add("java.math.BigInteger max = new java.math.BigInteger(\"{0}\");\n" + + "typeValidator.setMaxExclusive(max);", getMaxExclusive()); + } else if (getMaxInclusive() != null) { + jsc.add("java.math.BigInteger max = new java.math.BigInteger(\"{0}\");\n" + + "typeValidator.setMaxInclusive(max);", getMaxInclusive()); + } + + codeDigitsFacet(jsc, "typeValidator"); } -} //-- XSLong + //-------------------------------------------------------------------------- +} Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedShort.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedShort.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/castor/builder/types/XSUnsignedShort.java (working copy) @@ -1,5 +1,5 @@ /* - * Copyright 2005 Werner Guttmann + * Copyright 2005-2007 Werner Guttmann, Ralf Joachim * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,41 @@ */ package org.exolab.castor.builder.types; +import org.exolab.javasource.JClass; +import org.exolab.javasource.JSourceCode; +import org.exolab.javasource.JType; + /** - * The XML Schema "unsigned-short" type. + * The xsd:unsignedShort XML Schema type. * * @author Werner Guttmann + * @author Ralf Joachim * @version $Revision: 5951 $ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $ */ -public final class XSUnsignedShort extends XSInt { +public final class XSUnsignedShort extends AbstractDigitsFacet { + //-------------------------------------------------------------------------- + + /** Name of this XSType. */ + public static final String NAME = "unsignedShort"; + + /** Type number of this XSType. */ + public static final short TYPE = XSType.UNSIGNED_SHORT_TYPE; + + /** A constant holding the minimum value an xsd:unsignedShort can have, 0. */ + public static final String MIN_VALUE = "0"; + + /** A constant holding the maximum value an xsd:unsignedShort can have, 65535. */ + public static final String MAX_VALUE = "65535"; + + //-------------------------------------------------------------------------- + + /** True if this type is implemented using the wrapper class. */ + private final boolean _asWrapper; + + /** The JType represented by this XSType. */ + private final JType _jType; + + //-------------------------------------------------------------------------- /** * No-arg constructor. @@ -32,12 +60,105 @@ /** * Constructs a new XSUnsignedShort. - * @param asWrapper if true, use the java.lang wrapper class. + * + * @param asWrapper If true, use the java.lang wrapper class. */ public XSUnsignedShort(final boolean asWrapper) { - super(asWrapper, XSType.UNSIGNED_SHORT_TYPE); - setMinInclusive(MIN_UNSIGNED_SHORT); - setMaxInclusive(MAX_UNSIGNED_SHORT); + super(); + + _asWrapper = asWrapper; + if (_asWrapper) { + _jType = new JClass("java.lang.Integer"); + } else { + _jType = JType.INT; + } + + setMinInclusive(MIN_VALUE); + setMaxInclusive(MAX_VALUE); } + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public String getName() { return NAME; } + + /** + * {@inheritDoc} + */ + public short getType() { return TYPE; } + + /** + * {@inheritDoc} + */ + public boolean isPrimitive() { return false; } + + /** + * {@inheritDoc} + */ + public boolean isDateTime() { return false; } + + /** + * {@inheritDoc} + */ + public JType getJType() { return _jType; } + + /** + * {@inheritDoc} + */ + public String newInstanceCode() { + return "new java.lang.Integer(0);"; + } + + /** + * {@inheritDoc} + */ + public String createToJavaObjectCode(final String variableName) { + if (_asWrapper) { return variableName; } + return "new java.lang.Integer(" + variableName + ")"; + } + + /** + * {@inheritDoc} + */ + public String createFromJavaObjectCode(final String variableName) { + if (_asWrapper) { return "((java.lang.Integer) " + variableName + ")"; } + return "((java.lang.Integer) " + variableName + ").intValue()"; + } + + //-------------------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void validationCode(final JSourceCode jsc, + final String fixedValue, final String validatorInstanceName) { + jsc.add("org.exolab.castor.xml.validators.IntValidator typeValidator;\n" + + "typeValidator = new org.exolab.castor.xml.validators.IntValidator();\n" + + "{0}.setValidator(typeValidator);", validatorInstanceName); + + if (fixedValue != null) { + jsc.add("typeValidator.setFixed(" + fixedValue + ");"); + } + + codePatternFacet(jsc, "typeValidator"); + codeWhiteSpaceFacet(jsc, "typeValidator"); + + if (getMinExclusive() != null) { + jsc.add("typeValidator.setMinExclusive(" + getMinExclusive() + ");"); + } else if (getMinInclusive() != null) { + jsc.add("typeValidator.setMinInclusive(" + getMinInclusive() + ");"); + } + + if (getMaxExclusive() != null) { + jsc.add("typeValidator.setMaxExclusive(" + getMaxExclusive() + ");"); + } else if (getMaxInclusive() != null) { + jsc.add("typeValidator.setMaxInclusive(" + getMaxInclusive() + ");"); + } + + codeDigitsFacet(jsc, "typeValidator"); + } + + //-------------------------------------------------------------------------- } Index: C:/Java/castor-2/codegen/src/main/java/org/exolab/javasource/JSourceCode.java =================================================================== --- C:/Java/castor-2/codegen/src/main/java/org/exolab/javasource/JSourceCode.java (revision 6728) +++ C:/Java/castor-2/codegen/src/main/java/org/exolab/javasource/JSourceCode.java (working copy) @@ -143,7 +143,7 @@ indent(); addWithIndent(pattern.substring(1), arguments); unindent(); - } else if ((pattern.indexOf('{') >= 0) && (pattern.indexOf('}') >= 0)) { + } else if ((pattern.indexOf('{') + 2) == pattern.indexOf('}')) { add(MessageFormat.format(pattern, arguments)); } else { add(pattern); Index: C:/Java/castor-2/src/doc/release-notes.xml =================================================================== --- C:/Java/castor-2/src/doc/release-notes.xml (revision 6728) +++ C:/Java/castor-2/src/doc/release-notes.xml (working copy) @@ -53,6 +53,26 @@ ]]> + + + Refactored org.exolab.castor.builder.types package. + + + Ralf Joachim + ralf.joachim@syscon-world.de + + + Ralf Joachim + ralf.joachim@syscon-world.de + + + Ralf Joachim + ralf.joachim@syscon-world.de + + Enh. + XML + 20070109 + Added support for XML serialization using Xerces as bundled with JDK 5.0 Index: C:/Java/castor-2/src/etc/CHANGELOG =================================================================== --- C:/Java/castor-2/src/etc/CHANGELOG (revision 6728) +++ C:/Java/castor-2/src/etc/CHANGELOG (working copy) @@ -1,6 +1,11 @@ SVN ------------------------------- +XML: Resolved issue CASTOR-1813 using contribution from Ralf Joachim [Ralf.joachim@syscon-world.de] + Refactored org.exolab.castor.builder.types package. + Details: http://jira.codehaus.org/browse/CASTOR-1813 + (Ralf - 20070109) + XML: Resolved issue CASTOR-1814 using contribution from Werner Guttmann [werner.guttmann@gmx.net] Added support for XML serialization using Xerces as bundled with JDK 5.0. Details: http://jira.codehaus.org/browse/CASTOR-1814 Index: C:/Java/castor-2/src/main/java/org/exolab/castor/xml/validators/IntegerValidator.java =================================================================== --- C:/Java/castor-2/src/main/java/org/exolab/castor/xml/validators/IntegerValidator.java (revision 6728) +++ C:/Java/castor-2/src/main/java/org/exolab/castor/xml/validators/IntegerValidator.java (working copy) @@ -228,7 +228,7 @@ * @param maxValue * the maximum (exclusive) value for xsd:integer validation. */ - public void setMaxExclusive(final int maxValue) { + public void setMaxExclusive(final long maxValue) { _useMax = true; _max = maxValue - 1; } // -- setMaxExclusive