Package org.apache.xerces.impl.validation

Examples of org.apache.xerces.impl.validation.InvalidDatatypeValueException


    private void enumCheck(long d) throws InvalidDatatypeValueException {
        for (int i = 0; i < this.fEnumrecurringduration.length; i++) {
            if (d == fEnumrecurringduration[i]) return;
        }
        throw new InvalidDatatypeValueException(
                                               getErrorString(DatatypeMessageProvider.NotAnEnumValue,
                                                              DatatypeMessageProvider.MSG_NONE,
                                                              new Object [] { new Long(d )}));
    }
View Full Code Here


        StringTokenizer parsedList = new StringTokenizer( content );
        try {
            int numberOfTokens =  parsedList.countTokens();
            if ((fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0) {
                if (numberOfTokens > fMaxLength) {
                    throw new InvalidDatatypeValueException("Value '"+content+
                                                            "' with length ='"+  numberOfTokens + "' tokens"+
                                                            "' exceeds maximum length facet of '"+fMaxLength+"' tokens.");
                }
            }
            if ((fFacetsDefined & DatatypeValidator.FACET_MINLENGTH) != 0) {
                if (numberOfTokens < fMinLength) {
                    throw new InvalidDatatypeValueException("Value '"+content+
                                                            "' with length ='"+ numberOfTokens+ "' tokens" +
                                                            "' is less than minimum length facet of '"+fMinLength+"' tokens." );
                }
            }

            if ((fFacetsDefined & DatatypeValidator.FACET_LENGTH) != 0) {
                if (numberOfTokens != fLength) {
                    throw new InvalidDatatypeValueException("Value '"+content+
                                                            "' with length ='"+ numberOfTokens+ "' tokens" +
                                                            "' is not equal to length facet of '"+fLength+"' tokens.");
                }
            }

            if ((fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0) {
                // Enumerations are defined in the value space so the contains method
                // of vector doesn't really do the right thing, we really should check using compare
                if (fEnumeration.contains( content ) == false)
                    throw new InvalidDatatypeValueException("Value '"+
                                                            content+"' must be one of "+fEnumeration);
            }
            try {
                if (this.fDerivedByList) {
                    if( numberOfTokens == 0 ){
                        InvalidDatatypeValueException error = new InvalidDatatypeValueException( content );
                        throw error;
                    }
                    while (parsedList.hasMoreTokens()) {       //Check each token in list against base type
                        if (this.fBaseValidator != null) {//validate against parent type if any
                            this.fBaseValidator.validate( parsedList.nextToken(), state );
                        }
                    }
                } else {
                    if (this.fBaseValidator != null) {//validate against parent type if any
                        this.fBaseValidator.validate( content, state );
                    }
                }
            } catch (InvalidDatatypeValueException ex) { //Keep bubbling up exception but change content to list content
                                                         //Unfortunately we need to throw a new Exception
                InvalidDatatypeValueException error = new InvalidDatatypeValueException( content );//Need Message
                error.setKeyIntoReporter( ex.getKeyIntoReporter() );
                throw error;//type message repacked with the List content message
            }

        } catch (NoSuchElementException e) {
            e.printStackTrace();
View Full Code Here

            }


            if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
                if ( fRegex == null || fRegex.matches( content) == false )
                    throw new InvalidDatatypeValueException("Value'"+content+
                       "' does not match regular expression facet " + fRegex.getPattern() );
            }

            BigDecimal d = null; // Is content a Decimal
            try {
                d = new BigDecimal( stripPlusIfPresent( content));
            } catch (Exception nfe) {
                throw new InvalidDatatypeValueException(
                                                       getErrorString(DatatypeMessageProvider.NotDecimal,
                                                                      DatatypeMessageProvider.MSG_NONE,
                                                                      new Object[] { "'" + content +"'"}));
            }
            //}
            //catch (IOException ex ) {
            //  throw new InvalidDatatypeValueException(
            //  getErrorString(DatatypeMessageProvider.NotDecimal,
            // DatatypeMessageProvider.MSG_NONE,
            //                       new Object[] { "'" + content +"'"}));
            //}


            if ( isScaleDefined == true ) {
                if (d.scale() > fScale)
                    throw new InvalidDatatypeValueException(
                                                           getErrorString(DatatypeMessageProvider.ScaleExceeded,
                                                                          DatatypeMessageProvider.MSG_NONE,
                                                                          new Object[] { content}));
            }
            if ( isPrecisionDefined == true ) {
                int precision = d.movePointRight(d.scale()).toString().length() -
                                ((d.signum() < 0) ? 1 : 0); // account for minus sign

                if (precision > fPrecision)
                    throw new InvalidDatatypeValueException(
                             getErrorString(DatatypeMessageProvider.PrecisionExceeded,
                                 DatatypeMessageProvider.MSG_NONE,
                                 new Object[] { "'" + content + "'" + "with precision = '"+ precision +"'"
                                              , "'" + fPrecision + "'" } ));
            }
View Full Code Here

        } else{
            minOk = (!isMinInclusiveDefined && !isMinExclusiveDefined);
        }

        if (!(minOk && maxOk))
            throw new InvalidDatatypeValueException (
                                                    getErrorString(DatatypeMessageProvider.OutOfBounds,
                                                                   DatatypeMessageProvider.MSG_NONE,
                                                                   new Object [] { d.toString() ,  lowerBound ,
                                                                       upperBound, lowerBoundIndicator, upperBoundIndicator}));
View Full Code Here

            if (v.equals(fEnumDecimal[i] ))
            {
                return;
            }
        }
        throw new InvalidDatatypeValueException(
                                               getErrorString(DatatypeMessageProvider.NotAnEnumValue,
                                                              DatatypeMessageProvider.MSG_NONE,
                                                              new Object [] { v}));
    }
View Full Code Here

    private void checkContent( String content )throws InvalidDatatypeValueException
    {
        if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
            if ( content.length() > fMaxLength ) {
                throw new InvalidDatatypeValueException("Value '"+content+
                                                        "' with length '"+content.length()+
                                                        "' exceeds maximum length of "+fMaxLength+".");
            }
        }
        if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
            if ( fEnumeration.contains( content ) == false )
                throw new InvalidDatatypeValueException("Value '"+content+"' must be one of "+fEnumeration);
        }


        if ( isMaxExclusiveDefined == true ) {
            int comparisonResult;
            comparisonResult  = compare( content, fMaxExclusive );
            //System.out.println( "maxExc = " + comparisonResult );

            if ( comparisonResult >= 0 ) {
                throw new InvalidDatatypeValueException( "Value '"+content+ "'  must be " +
                                  "lexicographically less than '" + fMaxExclusive + "'."  );

            }

        }
        if ( isMaxInclusiveDefined == true ) {
            int comparisonResult;
            comparisonResult  = compare( content, fMaxInclusive );
            if ( comparisonResult > 0 )
                throw new InvalidDatatypeValueException( "Value '"+content+ "' must be " +
                                  "lexicographically less or equal than '" + fMaxInclusive +"'." );
        }

        if ( isMinExclusiveDefined == true ) {
            int comparisonResult;
            comparisonResult  = compare( content, fMinExclusive );
            //System.out.println( "minExc = " + comparisonResult );

            if ( comparisonResult <= 0 )
                throw new InvalidDatatypeValueException( "Value '"+content+ "' must be " +
                                                         "lexicographically greater than '" + fMinExclusive + "'." );
        }
        if ( isMinInclusiveDefined == true ) {
            int comparisonResult;
            comparisonResult = compare( content, fMinInclusive );
            //System.out.println( "minInc = " + comparisonResult );
            if ( comparisonResult < 0 )
                throw new InvalidDatatypeValueException( "Value '"+content+ "' must be " +
                                                         "lexicographically greater or equal than '" + fMinInclusive  + "'." );
        }


        if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
            if ( fRegex == null || fRegex.matches( content) == false )
               throw new InvalidDatatypeValueException("Value '"+content+
                                                        "' does not match regular expression facet '" + fPattern + "'." );
        }
    }
View Full Code Here

     * @see org.apache.xerces.validators.datatype.InvalidDatatypeValueException
     */
    public void validate(String content, Object state ) throws InvalidDatatypeValueException{
        int entityDeclIndex = -1;
        if (fGrammar == null) {
            InvalidDatatypeValueException error =
            new InvalidDatatypeValueException();//Need Message
            error.setKeyIntoReporter( "ENTITYFailedInitializeGrammar");
            throw error;
        }

        fEntityDecl.clear();//Reset Entity Decl struct

        entityDeclIndex = fGrammar.getEntityDeclIndex( content );

        if (entityDeclIndex > -1) {
            fGrammar.getEntityDecl( entityDeclIndex, fEntityDecl );
            if (fEntityDecl.notation == null) {// not unparsed entity
                InvalidDatatypeValueException error =
                new InvalidDatatypeValueException( content );
                error.setKeyIntoReporter( "ENTITYNotUnparsed" );
                throw error;
            }
        } else {
            InvalidDatatypeValueException error =
            new InvalidDatatypeValueException( content );
            error.setKeyIntoReporter( "ENTITYNotValid" );
            throw error;
        }
    }
View Full Code Here

         this.fBaseValidator.validate( content, state );
      }

      if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
         if ( content.length() > fMaxLength ) {
            throw new InvalidDatatypeValueException("Value '"+content+
                                                    "' with length '"+content.length()+
                                                    "' exceeds maximum length facet of '"+fMaxLength+"'.");
         }
      }
      if ( (fFacetsDefined & DatatypeValidator.FACET_MINLENGTH) != 0 ) {
         if ( content.length() < fMinLength ) {
            throw new InvalidDatatypeValueException("Value '"+content+
                                                    "' with length '"+content.length()+
                                                    "' is less than minimum length facet of '"+fMinLength+"'." );
         }
      }

      if ( (fFacetsDefined & DatatypeValidator.FACET_LENGTH) != 0 ) {
         if ( content.length() != fLength ) {
            throw new InvalidDatatypeValueException("Value '"+content+
                                                    "' with length '"+content.length()+
                                                    "' is not equal to length facet '"+fLength+"'.");
         }
      }



      if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 ) {
         if ( fEnumeration.contains( content ) == false )
            throw new InvalidDatatypeValueException("Value '"+content+"' must be one of "+fEnumeration);
      }
      /*  Per October 23 CR - facets don't apply to StringValidator
      if ( isMaxExclusiveDefined == true ) {
          int comparisonResult;
          comparisonResult  = compare( content, fMaxExclusive );
          if ( comparisonResult >= 0 ) {
              throw new InvalidDatatypeValueException( "MaxExclusive:Value '"+content+ "'  must be " +
                                                       "lexicographically less than" + fMaxExclusive );

          }

      }
      if ( isMaxInclusiveDefined == true ) {
          int comparisonResult;
          comparisonResult  = compare( content, fMaxInclusive );
          if ( comparisonResult > 0 )
              throw new InvalidDatatypeValueException( "MaxInclusive:Value '"+content+ "' must be " +
                                                       "lexicographically less or equal than" + fMaxInclusive );
      }

      if ( isMinExclusiveDefined == true ) {
          int comparisonResult;
          comparisonResult  = compare( content, fMinExclusive );

          //System.out.println( "exclusive = " + comparisonResult );

          if ( comparisonResult <= 0 )
              throw new InvalidDatatypeValueException( "MinExclusive:Value '"+content+ "' must be " +
                                                       "lexicographically greater than" + fMinExclusive );
      }
      if ( isMinInclusiveDefined == true ) {
          int comparisonResult;
          comparisonResult = compare( content, fMinInclusive );
          //System.out.println( "inclusive = " + comparisonResult );
          if ( comparisonResult < 0 )
              throw new InvalidDatatypeValueException( "MinInclusive:Value '"+content+ "' must be " +
                                                       "lexicographically greater or equal than '" + fMinInclusive  + "'." );
      }

        */

      if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
         //RegularExpression regex = new RegularExpression(fPattern );
         if ( fRegex == null || fRegex.matches( content) == false )
            throw new InvalidDatatypeValueException("Value '"+content+
                                                    "' does not match regular expression facet '" + fPattern + "'." );
      }

   }
View Full Code Here

        for ( int i = 0;i<fValueSpace.length;i++ ) {
            if ( content.equals(fValueSpace[i] ) )
                isContentInDomain = true;
        }
        if (isContentInDomain == false)
            throw new InvalidDatatypeValueException(
                                                   getErrorString(DatatypeMessageProvider.NotBoolean,
                                                                  DatatypeMessageProvider.MSG_NONE,
                                                                  new Object[] { content}));
        if ( (fFacetsDefined & DatatypeValidator.FACET_PATTERN ) != 0 ) {
            if ( fRegex == null || fRegex.matches( content) == false )
                throw new InvalidDatatypeValueException("Value'"+content+
                                                        "does not match regular expression facet" + fPattern );
        }
    }
View Full Code Here

    private void enumCheck(long d) throws InvalidDatatypeValueException {
        for (int i = 0; i < this.fEnumTimeDuration.length; i++) {
            if (d == fEnumTimeDuration[i]) return;
        }
        throw new InvalidDatatypeValueException(
      getErrorString(DatatypeMessageProvider.NotAnEnumValue,
                    DatatypeMessageProvider.MSG_NONE,
                    new Object [] { new Long( d ) }));
    }
View Full Code Here

TOP

Related Classes of org.apache.xerces.impl.validation.InvalidDatatypeValueException

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.