Package org.exolab.castor.xml.schema

Examples of org.exolab.castor.xml.schema.SchemaException


            --depth;
            return;
        }

        if (unmarshaller == null)
            throw new SchemaException("missing start element: " + name);
        else if (SchemaNames.ANNOTATION.equals(name)) {
            Annotation annotation = (Annotation)unmarshaller.getObject();
            _facet.addAnnotation(annotation);
        }
View Full Code Here


            }
            else {
                String err = "The value of the '" + SchemaNames.REF_ATTR +
                    "' attribute for attribute group must contain a " +
                    "valid value.";
                throw new SchemaException(err);
            }
        }
        else {
            AttributeGroupDecl attDecl = new AttributeGroupDecl(schema);
            _attributeGroup = attDecl;
View Full Code Here

                continue; // do not check against self
            }
            final String otherName = other.getName();
            if (otherName.equals(Facet.MIN_INCLUSIVE)) {
                // Schema Component Constraint: minInclusive and minExclusive
                throw new SchemaException(
                        "It is an error for both minInclusive and minExclusive "
                        + "to be specified for the same datatype.");
            } else if (otherName.equals(Facet.MAX_INCLUSIVE)
                    && getOwningType().isNumericType()
                    && this.toBigDecimal().compareTo(other.toBigDecimal()) >= 0) {
                // Schema Component Constraint: minExclusive < maxInclusive
                throw new SchemaException(
                        "It is an error for the value specified "
                        + "for minExclusive to be greater than "
                        + "or equal to the value specified for "
                        + "maxInclusive for the same datatype.");
            }
        }
        if (baseFacets != null) {
            while (baseFacets.hasMoreElements()) {
                final Facet other = (Facet) baseFacets.nextElement();
                final String otherName = other.getName();

                // Schema Component Constraint: minExclusive valid restriction
                //   It is an error if any of the following conditions is true:
                if (otherName.equals(Facet.MIN_EXCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) < 0) {
                    // [1]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "minExclusive is among the members of {facets} of "
                            + "{base type definition} and {value} is less than "
                            + "the {value} of the parent minExclusive.");
                } else if (otherName.equals(Facet.MAX_INCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) > 0) {
                    // [2]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "maxInclusive is among the members of {facets} of "
                            + "{base type definition} and {value} is greater than "
                            + "the {value} of the parent maxInclusive.");
                } else if (otherName.equals(Facet.MIN_INCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) < 0) {
                    // [3]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "minInclusive is among the members of {facets} of "
                            + "{base type definition} and {value} is less than "
                            + "the {value} of the parent minInclusive.");
                } else if (otherName.equals(Facet.MAX_EXCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) >= 0) {
                    // [4]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "maxExclusive is among the members of {facets} of "
                            + "{base type definition} and {value} is greater than "
                            + "or equal to the {value} of the parent maxExclusive.");
                }
View Full Code Here

                continue; // do not check against self
            }
            final String otherName = other.getName();
            if (otherName.equals(Facet.MAX_INCLUSIVE)) {
                // Schema Component Constraint: maxInclusive and maxExclusive
                throw new SchemaException(
                        "It is an error for both maxInclusive and maxExclusive "
                        + "to be specified in the same derivation step "
                        + "of a datatype definition.");
            } else if (otherName.equals(Facet.MIN_EXCLUSIVE)
                     && other.toBigDecimal().compareTo(this.toBigDecimal()) > 0) {
                // Schema Component Constraint: minExclusive <= maxExclusive
                throw new SchemaException(
                        "It is an error for the value specified "
                        + "for minExclusive to be greater than the value "
                        + "specified for maxExclusive for the same datatype.");
            }
        }
        if (baseFacets != null) {
            while (baseFacets.hasMoreElements()) {
                final Facet other = (Facet) baseFacets.nextElement();
                final String otherName = other.getName();

                // Schema Component Constraint: maxExclusive valid restriction
                //   It is an error if any of the following conditions is true:
                if (otherName.equals(Facet.MAX_EXCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) > 0) {
                    // [1]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "maxExclusive is among the members of {facets} "
                            + "of {base type definition} and {value} is greater than "
                            + "the {value} of the parent maxExclusive.");
                } else if (otherName.equals(Facet.MAX_INCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) > 0) {
                    // [2]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "maxInclusive is among the members of {facets} "
                            + "of {base type definition} and {value} is greater than "
                            + "the {value} of the parent maxInclusive.");
                } else if (otherName.equals(Facet.MIN_INCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) <= 0) {
                    // [3]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "minInclusive is among the members of {facets} "
                            + "of {base type definition} and {value} is less than "
                            + "or equal to the {value} of the parent minInclusive.");
                } else if (otherName.equals(Facet.MIN_EXCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) <= 0) {
                    // [4]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "minExclusive is among the members of {facets} "
                            + "of {base type definition} and {value} is less than "
                            + "or equal to the {value} of the parent minExclusive.");
                }
View Full Code Here

        String attValue = null;

        String nsURI = atts.getValue(SchemaNames.TARGET_NS_ATTR);
        if (nsURI != null &&  nsURI.length() == 0) {
            throw new SchemaException("empty string is not a legal namespace.");
        }
        if ((nsURI != null) && (nsURI.length() > 0)) {
            if (!_state.cacheIncludedSchemas) {
                //if we are including a schema we must take care
                //that the namespaces are the same
                if ((_include) && (!_schema.getTargetNamespace().equals(nsURI))) {
                    throw new SchemaException("The target namespace of the included "
                            + "components must be the same as the target namespace "
                            + "of the including schema");
                }
            }
               _schema.setTargetNamespace(nsURI);
View Full Code Here

        //-- check for name mismatches
        if ((_unmarshaller != null)) {
            if (!name.equals(_unmarshaller.elementName())) {
                String err = "error: missing end element for ";
                err += _unmarshaller.elementName();
                throw new SchemaException(err);
            }
        } else {
            String err = "error: missing start element for " + name;
            throw new SchemaException(err);
        }

        //-- call unmarshaller.finish() to perform any necessary cleanup
        _unmarshaller.finish();
View Full Code Here

        //-- check for name mismatches
        if ((unmarshaller != null) && (charUnmarshaller != unmarshaller)) {
            if (!name.equals(unmarshaller.elementName())) {
                String err = "missing end element for ";
                err += unmarshaller.elementName();
                throw new SchemaException(err);
            }
        }

        //-- call finish for any necessary cleanup
        unmarshaller.finish();
View Full Code Here

            final String otherName = other.getName();
            if (otherName.equals(Facet.MIN_INCLUSIVE)
                    && getOwningType().isNumericType()
                    && other.toBigDecimal().compareTo(this.toBigDecimal()) > 0) {
                // Schema Component Constraint: minInclusive <= maxInclusive
                throw new SchemaException(
                        "It is an error for the value specified "
                        + "for minInclusive to be greater than "
                        + "the value specified for maxInclusive "
                        + "for the same datatype.");
            }
        }
        if (baseFacets != null) {
            while (baseFacets.hasMoreElements()) {
                final Facet other = (Facet) baseFacets.nextElement();
                final String otherName = other.getName();

                // Schema Component Constraint: maxInclusive valid restriction
                //   It is an error if any of the following conditions is true:
                if (otherName.equals(Facet.MAX_INCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) > 0) {
                    // [1]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "maxInclusive is among the members of {facets} "
                            + "of {base type definition} and {value} is greater than "
                            + "the {value} of the parent maxInclusive.");
                } else if (otherName.equals(Facet.MAX_EXCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) >= 0) {
                    // [2]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "maxExclusive is among the members of {facets} "
                            + "of {base type definition} and {value} is greater than "
                            + "or equal to the {value} of the parent maxExclusive.");
                } else if (otherName.equals(Facet.MIN_INCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) < 0) {
                    // [3]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "minInclusive is among the members of {facets} "
                            + "of {base type definition} and {value} is less than "
                            + "the {value} of the parent minInclusive.");
                } else if (otherName.equals(Facet.MIN_EXCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) <= 0) {
                    // [4]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "minExclusive is among the members of {facets} "
                            + "of {base type definition} and {value} is less than "
                            + "or equal to the {value} of the parent minExclusive.");
                }
View Full Code Here

            final String otherName = other.getName();
            if (otherName.equals(Facet.MAX_EXCLUSIVE)
                    && getOwningType().isNumericType()
                    && this.toBigDecimal().compareTo(other.toBigDecimal()) >= 0) {
                // Schema Component Constraint: minInclusive < maxExclusive
                throw new SchemaException(
                        "It is an error for the value specified "
                        + "for minInclusive to be greater than "
                        + "or equal to the value specified for "
                        + "maxExclusive for the same datatype.");
            }
        }
        if (baseFacets != null) {
            while (baseFacets.hasMoreElements()) {
                final Facet other = (Facet) baseFacets.nextElement();
                final String otherName = other.getName();

                // Schema Component Constraint: minInclusive valid restriction
                //   It is an error if any of the following conditions is true:
                if (otherName.equals(Facet.MIN_INCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) < 0) {
                    // [1]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "minInclusive is among the members of {facets} of "
                            + "{base type definition} and {value} is less than "
                            + "the {value} of the parent minInclusive.");
                } else if (otherName.equals(Facet.MAX_INCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) > 0) {
                    // [2]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "maxInclusive is among the members of {facets} of "
                            + "{base type definition} and {value} is greater than "
                            + "the {value} of the parent maxInclusive.");
                } else if (otherName.equals(Facet.MIN_EXCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) <= 0) {
                    // [3]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "minExclusive is among the members of {facets} of "
                            + "{base type definition} and {value} is less than "
                            + "or equal to the {value} of the parent minExclusive.");
                } else if (otherName.equals(Facet.MAX_EXCLUSIVE)
                        && getOwningType().isNumericType()
                        && this.toBigDecimal().compareTo(other.toBigDecimal()) >= 0) {
                    // [4]
                    throw new SchemaException(
                            "It is an error if the following condition is true: "
                            + "maxExclusive is among the members of {facets} of "
                            + "{base type definition} and {value} is greater than "
                            + "or equal to the {value} of the parent maxExclusive.");
                }
View Full Code Here

        setURIResolver(uriResolver);
        URILocation uri = null;
    //-- Get schemaLocation
    String include = atts.getValue("schemaLocation");
    if (include == null)
      throw new SchemaException("'schemaLocation' attribute missing on 'include'");

    if (include.indexOf("\\") != -1) {
            String err = include+" is not a valid URI as defined by IETF RFC 2396.";
            err += "The URI must not contain '\\'.";
            throw new SchemaException(err);
    }

        try {
            String documentBase = locator.getSystemId();
            if (documentBase != null) {
                if (!documentBase.endsWith("/"))
                    documentBase = documentBase.substring(0, documentBase.lastIndexOf("/") +1 );
            }
        uri = getURIResolver().resolve(include, documentBase);
        } catch (URIException ure) {
            throw new XMLException(ure);
        }

        if (uri != null)
            include = uri.getAbsoluteURI();

        //-- Has this schema location been included yet?
        if (schema.includeProcessed(include)) {
            return;
        }
        else if (include.equals(schema.getSchemaLocation())) {
            return;
        }
       
        Schema includedSchema = null;
        boolean alreadyLoaded = false;

        //-- caching is on
        if (state.cacheIncludedSchemas) {
            if (uri instanceof SchemaLocation) {
            includedSchema = ((SchemaLocation)uri).getSchema();
            schema.cacheIncludedSchema(includedSchema);
            alreadyLoaded = true;
          }
          //-- Have we already imported this XML Schema file?
          if (state.processed(include)) {
            includedSchema = state.getSchema(include);
            schema.cacheIncludedSchema(includedSchema);
            alreadyLoaded = true;
          }
        }
     
        if (includedSchema == null)
        includedSchema = new Schema();
        else
          state.markAsProcessed(include, includedSchema);
       
        //-- keep track of the schemaLocation
        schema.addInclude(include);

        if (alreadyLoaded)
          return;
    Parser parser = null;
    try {
        parser = getSchemaContext().getParser();
    }
    catch(RuntimeException rte) {}
    if (parser == null) {
        throw new SchemaException("Error failed to create parser for include");
    }
    SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(getSchemaContext(), true, state, getURIResolver());

    if (state.cacheIncludedSchemas)
        schemaUnmarshaller.setSchema(includedSchema);
    else
      schemaUnmarshaller.setSchema(schema);
   
    Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
    parser.setDocumentHandler(handler);
    parser.setErrorHandler(handler);

    try {
            InputSource source = new InputSource(uri.getReader());
            source.setSystemId(uri.getAbsoluteURI());
            parser.parse(source);
    }
    catch(java.io.IOException ioe) {
        throw new SchemaException("Error reading include file '"+include+"'");
    }
    catch(org.xml.sax.SAXException sx) {
        throw new SchemaException(sx);
    }
    if (state.cacheIncludedSchemas) {
      String ns = includedSchema.getTargetNamespace();
      if (ns == null || ns == "")
        includedSchema.setTargetNamespace(schema.getTargetNamespace());
      else if (!ns.equals(schema.getTargetNamespace()))
        throw new SchemaException("The target namespace of the included components must be the same as the target namespace of the including schema");
      schema.cacheIncludedSchema(includedSchema);
    }
  }
View Full Code Here

TOP

Related Classes of org.exolab.castor.xml.schema.SchemaException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.