public boolean match(ValueExp exp) { Object thisValue = exp.dt.createValue(literal, context); if (!exp.dt.sameValue(thisValue, exp.value)) return false; // this type accepts me. if (refType != null) assignType(exp.dt); // if the type has ID semantics, report it. if (exp.dt.getIdType() != Datatype.ID_TYPE_NULL && context != null) // context can be legally null when this datatype is not context dependent. context.onID(exp.dt, this); return true; }
public void checkValid() throws DatatypeException { baseType.checkValid(buffer.toString(),context); }
public boolean matches(String value) { return dt.isValid(value, null); }
public Pattern caseValue(ValuePattern p) { Datatype dt = p.getDatatype(); Object value = dt.createValue(str, vc); if (value != null && dt.sameValue(p.getValue(), value)) return builder.makeEmpty(); if (fail != null) { if (value == null) { try { dt.checkValid(str, vc); } catch (DatatypeException e) { fail.add(new DataDerivFailure(dt, p.getDatatypeName(), e)); } } else fail.add(new DataDerivFailure(p)); } return builder.makeNotAllowed(); }
int idType = datatype.getIdType(); Location loc = mContext.getValidationLocation(); PrefixedName elemPName = getElementPName();
/** DataExp can consume this token if its datatype can accept this string */ public boolean match(DataExp exp) { if (!exp.dt.isValid(literal, context)) return false; // not accepted. if (exp.except != Expression.nullSet) { if (resCalc.calcResidual(exp.except, this) == Expression.epsilon) // due to the constraint imposed on the body of the 'except' clause, // comparing the residual with the epsilon is OK and cheap. // but it might be better to use the isEpsilonReducible method // for the robustness. return false; // this token is accepted by its 'except' clause } // this type accepts me. if (refType != null) assignType(exp.dt); // if the type has ID semantics, report it. if (exp.dt.getIdType() != Datatype.ID_TYPE_NULL && context != null) // context can be legally null when this datatype is not context dependent. context.onID(exp.dt, this); return true; }
PatternMemo dataDeriv(ValidatorPatternBuilder builder, Pattern p, String str, ValidationContext vc, List<DataDerivFailure> fail) { boolean isValid; final Datatype dt = dp.getDatatype(); DataDerivFailure ddf = null; if (fail != null) { try { dt.checkValid(str, vc); isValid = true; } catch (DatatypeException e) { isValid = false; ddf = new DataDerivFailure(dp, e); } } else isValid = dt.isValid(str, vc); if (isValid) { if (validMemo == null || (fail != null && validMemo.isNotAllowed())) validMemo = super.dataDeriv(builder, p, str, vc, fail); return validMemo; } else { if (invalidMemo == null) invalidMemo = super.dataDeriv(builder, p, str, vc, fail); else if (invalidMemo.isNotAllowed() && ddf != null) fail.add(ddf); return invalidMemo; } }
/** sets the value field. */ private void setValue( String lexical, Datatype type ) throws SAXException { if(value!=null) { // not the first match. doubleMatchError(); return; } if(type==null) { // this is possible only when we are recovering from errors. value = lexical; if(com.sun.msv.driver.textui.Debug.debug) System.out.println("no type info available"); } else value = type.createValue(lexical,owner); }
public Pattern makeValue(String datatypeLibrary, String type, String value, Context context, String ns, SourceLocation loc, AnnotationsImpl anno) throws BuildException { ValuePattern p = new ValuePattern(datatypeLibrary, type, value); DatatypeLibrary dl = dlf.createDatatypeLibrary(datatypeLibrary); if (dl != null) { try { DatatypeBuilder dtb = dl.createDatatypeBuilder(type); try { Datatype dt = dtb.createDatatype(); try { ValidationContext vc = dt.isContextDependent() ? new TraceValidationContext(p.getPrefixMap(), context, ns) : null; // use createValue rather than isValid so that default namespace gets used with QName if (dt.createValue(value, vc) == null) dt.checkValid(value, vc); } catch (DatatypeException e) { diagnoseDatatypeException("invalid_value_detail", "invalid_value", e, loc); } } catch (DatatypeException e) { diagnoseDatatypeException("invalid_params_detail", "invalid_params", e, loc); } } catch (DatatypeException e) { diagnoseDatatypeException("unsupported_datatype_detail", "unknown_datatype", e, loc); } } return finishPattern(p, loc, anno); }
PatternMemo dataDeriv(ValidatorPatternBuilder builder, Pattern p, String str, ValidationContext vc, List<DataDerivFailure> fail) { Object value = dt.createValue(str, vc); if (value == null) { if (noValue == null) noValue = super.dataDeriv(builder, p, str, vc, fail); else if (fail != null && noValue.isNotAllowed()) { try { dt.checkValid(str, vc); } catch (DatatypeException e) { fail.add(new DataDerivFailure(dt, dtName, e)); } } return noValue; } else { DatatypeValue dtv = new DatatypeValue(value, dt); if (valueMap == null) valueMap = new HashMap<DatatypeValue, PatternMemo>(); PatternMemo tem = valueMap.get(dtv); if (tem == null) { tem = super.dataDeriv(builder, p, str, vc, fail); valueMap.put(dtv, tem); } else if (tem.isNotAllowed() && fail != null) super.dataDeriv(builder, p, str, vc, fail); return tem; } }
public boolean equals(Object obj) { if (!(obj instanceof DatatypeValue)) return false; DatatypeValue other = (DatatypeValue)obj; if (other.dt != dt) return false; return dt.sameValue(value, other.value); } }
public void onValue( ValueExp exp ) { String text; if( exp.dt instanceof XSDatatype ) { XSDatatype xsd = (XSDatatype)exp.dt; text = xsd.convertToLexicalValue(exp.value,getContext()); } else { text = exp.value.toString(); if(!exp.dt.sameValue( exp.value, exp.dt.createValue(text,getContext()) ) ) throw new Error("unable to produce a value for the datatype:"+exp.name); } node.appendChild( domDoc.createTextNode(text) ); return; } public void onData( DataExp exp ) {
protected ValueExp( Datatype dt, StringPair typeName, Object value ) { super(dt.hashCode()+dt.valueHashCode(value)); this.dt=dt; this.name = typeName; this.value = value; }
private void check( Datatype dt, StringPair name ) { if(dt.isContextDependent()) { reportCompError( null, CERR_DEFVALUE_CONTEXT_DEPENDENT_TYPE, new Object[]{name.localName}); throw new Abort(); } } };
public Pattern caseValue(ValuePattern p) { Datatype dt = p.getDatatype(); Object value = dt.createValue(str, vc); if (value != null && dt.sameValue(p.getValue(), value)) return builder.makeEmpty(); if (fail != null) { if (value == null) { try { dt.checkValid(str, vc); } catch (DatatypeException e) { fail.add(new DataDerivFailure(dt, p.getDatatypeName(), e)); } } else fail.add(new DataDerivFailure(p)); } return builder.makeNotAllowed(); }
private void noteDatatype(Datatype dt) { if (dt.getIdType() != Datatype.ID_TYPE_NULL) idTypes = true; } }
/** DataExp can consume this token if its datatype can accept this string */ public boolean match(DataExp exp) { if (!exp.dt.isValid(literal, context)) return false; // not accepted. if (exp.except != Expression.nullSet) { if (resCalc.calcResidual(exp.except, this).isEpsilonReducible()) // handling whitespace correcly requires isEpsilonReducible() // with the following test case // <data type="string"><except><value/></except></data> // with "". return false; // this token is accepted by its 'except' clause } // this type accepts me. if (refType != null) assignType(exp.dt); // if the type has ID semantics, report it. if (exp.dt.getIdType() != Datatype.ID_TYPE_NULL && context != null) // context can be legally null when this datatype is not context dependent. context.onID(exp.dt, this); return true; }
PatternMemo dataDeriv(ValidatorPatternBuilder builder, Pattern p, String str, ValidationContext vc, List<DataDerivFailure> fail) { boolean isValid; final Datatype dt = dp.getDatatype(); DataDerivFailure ddf = null; if (fail != null) { try { dt.checkValid(str, vc); isValid = true; } catch (DatatypeException e) { isValid = false; ddf = new DataDerivFailure(dp, e); } } else isValid = dt.isValid(str, vc); if (isValid) { if (validMemo == null || (fail != null && validMemo.isNotAllowed())) validMemo = super.dataDeriv(builder, p, str, vc, fail); return validMemo; } else { if (invalidMemo == null) invalidMemo = super.dataDeriv(builder, p, str, vc, fail); else if (invalidMemo.isNotAllowed() && ddf != null) fail.add(ddf); return invalidMemo; } }
/** sets the value field. */ private void setValue( String lexical, Datatype type ) throws SAXException { if(value!=null) { // not the first match. doubleMatchError(); return; } if(type==null) { // this is possible only when we are recovering from errors. value = lexical; if(com.sun.msv.driver.textui.Debug.debug) System.out.println("no type info available"); } else value = type.createValue(lexical,owner); }
PatternMemo dataDeriv(ValidatorPatternBuilder builder, Pattern p, String str, ValidationContext vc, List<DataDerivFailure> fail) { Object value = dt.createValue(str, vc); if (value == null) { if (noValue == null) noValue = super.dataDeriv(builder, p, str, vc, fail); else if (fail != null && noValue.isNotAllowed()) { try { dt.checkValid(str, vc); } catch (DatatypeException e) { fail.add(new DataDerivFailure(dt, dtName, e)); } } return noValue; } else { DatatypeValue dtv = new DatatypeValue(value, dt); if (valueMap == null) valueMap = new HashMap<DatatypeValue, PatternMemo>(); PatternMemo tem = valueMap.get(dtv); if (tem == null) { tem = super.dataDeriv(builder, p, str, vc, fail); valueMap.put(dtv, tem); } else if (tem.isNotAllowed() && fail != null) super.dataDeriv(builder, p, str, vc, fail); return tem; } }