Package com.sun.msv.datatype.xsd

Examples of com.sun.msv.datatype.xsd.XSDatatype


/*     */
/* 503 */     return factory;
/*     */   }
/*     */
/*     */   private XSDatatype getTypeByName(String type) {
/* 507 */     XSDatatype dataType = (XSDatatype)this.dataTypeCache.get(type);
/*     */
/* 509 */     if (dataType == null)
/*     */     {
/* 512 */       int idx = type.indexOf(':');
/*     */
View Full Code Here


/*  98 */     this.childrenXSDatatypes.put(qname, dataType);
/*     */   }
/*     */
/*     */   public Element createElement(QName qname)
/*     */   {
/* 106 */     XSDatatype dataType = getChildElementXSDatatype(qname);
/*     */
/* 108 */     if (dataType != null) {
/* 109 */       return new DatatypeElement(qname, dataType);
/*     */     }
/*     */
View Full Code Here

/*     */
/* 123 */     return super.createElement(qname);
/*     */   }
/*     */
/*     */   public Attribute createAttribute(Element owner, QName qname, String value) {
/* 127 */     XSDatatype dataType = getAttributeXSDatatype(qname);
/*     */
/* 129 */     if (dataType == null) {
/* 130 */       return super.createAttribute(owner, qname, value);
/*     */     }
/* 132 */     return new DatatypeAttribute(qname, dataType, value);
View Full Code Here

   *    values of this map are the names of other ElementExp/AttributeExps.
   *    This method has to return the unique name.
   */
  private static String computeName( Datatype dt, Map m ) {
    if( dt instanceof XSDatatype ) {
      XSDatatype xsdt = (XSDatatype)dt;
      if( xsdt.getName()!=null ) {
        String name = NameUtil.toIdentifier( xsdt.getName() );
        if(!m.containsValue(name) )  return name;
        else
          getNumberedName( name, 2, m );
      } else
        return getNumberedName( xsdt.displayName(), 2, m );
    }
   
    return getNumberedName( "", 0, m );
  }
View Full Code Here

                pattern.next();
                continue;
            }
           
            // derive a type with test facets.
            XSDatatype typeObj=null;
            try
            {
                typeObj = ti.derive("anonymousURI","anonymousLocal");
            }
            catch( DatatypeException bte )
            {
                err.reportTestCaseError(baseType,ti,bte);
            }

            {// make sure that the serialization works.
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(bos);
       
                // serialize it
                oos.writeObject( typeObj );
                oos.flush();
               
                // obtain byte array (just in case)
                ObjectInputStream ois = new ObjectInputStream(
                    new ByteArrayInputStream(bos.toByteArray()));
                typeObj = (XSDatatype)ois.readObject();
                ois.close();
            }
           
            if(typeObj!=null)
            {
                if( answer.length()!=values.length )
                    throw new IllegalStateException("answer and values have different length");

//                if( testCase.facets.isEmpty())    out.println("nofacet");
//                else    testCase.facets.dump(out);

                // test each value and see what happens
                for( int i=0; i<values.length; i++ )
                {
                    boolean v = typeObj.isValid(values[i],DummyContextProvider.theInstance);
                    boolean d;
                   
                    boolean roundTripError = false;
                   
                    Object o = typeObj.createValue(
                        values[i],DummyContextProvider.theInstance);
                   
                    try {
                        if(o!=null) {
                            // should be able to convert it back.
                            String s = typeObj.convertToLexicalValue(o,DummyContextProvider.theInstance);
                            // try round trip conversion.
                            Object o2 = typeObj.createValue(s,DummyContextProvider.theInstance);
                            if( o2==null || !o.equals(o2) )
                                roundTripError = true;
                        }
                    } catch( UnsupportedOperationException uoe ) {
                        // ignore this exception
                    } catch( IllegalArgumentException iae ) {
                        roundTripError = true;
                    }

                    Object jo = typeObj.createJavaObject( values[i], DummyContextProvider.theInstance );
                   
                    if( jo!=null ) {
                        if( !typeObj.getJavaObjectType().isAssignableFrom(jo.getClass()) ) {
                            System.out.println("type error");
                            roundTripError = true;
                        }
                       
                        String s = typeObj.serializeJavaObject( jo,
                                        DummyContextProvider.theInstance );
                        if(s==null) {
                            System.out.println("serializeJavaObject failed");
                            roundTripError = true;
                        } else {
                            Object o2 = typeObj.createJavaObject(s,DummyContextProvider.theInstance);
                            if( o2==null ) {
                                System.out.println("round-trip conversion failed");
                                roundTripError = true;
                            }
                        }
                    }
                   
                    try {
                        typeObj.checkValid(values[i],DummyContextProvider.theInstance);
                        d = true;
                    } catch( DatatypeException de ) {
                        d = false;
                    }
                   
                    // if convertToValueObject and verify method differs,
                    // it's always an error.
                    // roundTripError is always an error.
                    if(!roundTripError && (o!=null)==v && (jo!=null)==v ) {
                       
                        if(v && d && answer.charAt(i)=='o')
                            continue;    // as predicted
                        if(!v && !d && answer.charAt(i)=='.')
                            continue;    // as predicted
                   
                        if(completenessOnly && answer.charAt(i)=='.' && v==d )
                            continue;    // do not report error if
                                        // the validator accepts things that
                                        // may not be accepted.
                    }
                   
                    // dump error messages
                    if( !err.report( new UnexpectedResultException(
                            typeObj, baseType.getName(),
                            values[i], answer.charAt(i)=='o',
                            ti ) ) )
                    {
                        out.println("test aborted");
                        return;
                    }
                }

                // test each wrong values and makes sure that they are rejected.
                for( int i=0; i<wrongs.length; i++ ) {
                    boolean err = false;
                   
                    err = typeObj.isValid(wrongs[i],DummyContextProvider.theInstance);
                    try {
                        typeObj.checkValid(wrongs[i],DummyContextProvider.theInstance);
                        err = true;
                    } catch (DatatypeException de) {
                        ;    // it should throw an exception
                    }
                   
                    if( typeObj.createJavaObject(wrongs[i],DummyContextProvider.theInstance)!=null )
                        err = true;
                   
                    if( err ) {
                        if( !this.err.report( new UnexpectedResultException(
                            typeObj, baseType.getName(),
View Full Code Here

            unless it's absolutely necessary, so that the class loader doesn't load
            the datatype class easily.
       
            If we use a map, it makes the class loader loads all classes.
        */
        XSDatatype dt = null;
       
        if( typeName.equals("uriReference") )
            dt = com.sun.msv.datatype.xsd.AnyURIType.theInstance;
        else
        if( typeName.equals("number") )
            dt = com.sun.msv.datatype.xsd.NumberType.theInstance;
        else
        if( typeName.equals("timeDuration") )
            dt = com.sun.msv.datatype.xsd.DurationType.theInstance;
        else
        if( typeName.equals("CDATA") )
            dt = com.sun.msv.datatype.xsd.NormalizedStringType.theInstance;
        else
        if( typeName.equals("year") )
            dt = com.sun.msv.datatype.xsd.GYearType.theInstance;
        else
        if( typeName.equals("yearMonth") )
            dt = com.sun.msv.datatype.xsd.GYearMonthType.theInstance;
        else
        if( typeName.equals("month") )
            dt = com.sun.msv.datatype.xsd.GMonthType.theInstance;
        else
        if( typeName.equals("monthDay") )
            dt = com.sun.msv.datatype.xsd.GMonthDayType.theInstance;
        else
        if( typeName.equals("day") )
            dt = com.sun.msv.datatype.xsd.GDayType.theInstance;

        if( dt!=null )
            reportWarning( WRN_DEPRECATED_TYPENAME, typeName, dt.displayName() );
       
        return dt;
    }
View Full Code Here

                incubator = new XSDatatypeExp(StringType.theInstance,reader.pool).createIncubator();
            } else {
               
                // we need a special handling for built-in types
                if(reader.isSchemaNamespace(baseTypeName[0])) {
                    XSDatatype dt = reader.resolveBuiltinDataType(baseTypeName[1]);
                    if(dt!=null)
                        incubator = new XSDatatypeExp(dt,reader.pool).createIncubator();
                   
                    // maybe we are parsing the schema for schema.
                    // consult externally specified schema.
View Full Code Here

        }
       

        // we need a special handling for built-in types
        if(reader.isSchemaNamespace(baseTypeName[0])) {
            XSDatatype dt = reader.resolveBuiltinDataType(baseTypeName[1]);
            if(dt!=null) {
                parentDecl.simpleBaseType = new XSDatatypeExp(dt,reader.pool);
                return exp;
            }
        }
View Full Code Here

    public Object onMixed( MixedExp exp )                { return ANY_STRING; }
    public Object onList( ListExp exp )                { return SOME_STRING; }
    public Object onAnyString()                        { return ANY_STRING; }
    public Object onData( DataExp exp ) {
        if(exp.except==Expression.nullSet && exp.dt instanceof XSDatatype) {
            XSDatatype xdt = (XSDatatype)exp.dt;
            if(xdt.isAlwaysValid())
                return ANY_STRING;
        }
        return SOME_STRING;
    }
View Full Code Here

    public Expression visit( ExpressionVisitorExpression visitor )    { return visitor.onData(this); }
    public boolean visit( ExpressionVisitorBoolean visitor )        { return visitor.onData(this); }
    public void visit( ExpressionVisitorVoid visitor )                { visitor.onData(this); }

    protected boolean calcEpsilonReducibility() {
        XSDatatype xdt = (XSDatatype)dt;
        if(except==Expression.nullSet && xdt.isAlwaysValid())
            // because for such datatype we return STRING_IGNORE from StringCareLevelCalculator
            return true;
        return false;
    }
View Full Code Here

TOP

Related Classes of com.sun.msv.datatype.xsd.XSDatatype

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.