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: + *
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:
- *
this. The
- * DateTime SimpleType supports the following facets:
- * 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:
- * 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:
- * this. The
- * GMonth SimpleType supports the following facets:
- * this. The
- * GMonth SimpleType supports the following facets:
- * this. The
- * GYear SimpleType supports the following facets:
- * this. The
- * GYearMonth SimpleType supports the following facets:
- * 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:
- * 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:
- * 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 @@
]]>