/** * Returns an XmlError for the given message, located at the XmlObject, with {@link #SEVERITY_ERROR}. * @param code the error code * @param args the arguments to use in formatting the error message * @param xobj the XmlObject representing the location of the error */ public static XmlError forObject(String code, Object[] args, XmlObject xobj) { return forObject(code, args, SEVERITY_ERROR, xobj); }
/** * Returns an XmlError for the given message, located at the XmlObject, with {@link #SEVERITY_ERROR}. * @param message the error message * @param xobj the XmlObject representing the location of the error */ public static XmlError forObject(String message, XmlObject xobj) { return forObject(message, SEVERITY_ERROR, xobj); }
public static void addWarning(Collection errorListener, String code, Object[] args, XmlObject location) { XmlError err = XmlError.forObject( code, args, XmlError.SEVERITY_WARNING, location); errorListener.add(err); }
public void invalid(String message) { _coll.add(XmlError.forObject(message, _loc)); } public void invalid(String code, Object[] args)
public void invalid(String code, Object[] args) { _coll.add(XmlError.forObject(code, args, _loc)); } }
public static void addError(Collection errorListener, String code, Object[] args, XmlObject location) { XmlError err = XmlError.forObject( code, args, XmlError.SEVERITY_ERROR, location); errorListener.add(err); }
public static void addError(Collection errorListener, String message, int code, XmlObject location) { XmlError err = XmlError.forObject( message, XmlError.SEVERITY_ERROR, location); errorListener.add(err); }
public static void addWarning(Collection errorListener, String message, int code, XmlObject location) { XmlError err = XmlError.forObject( message, XmlError.SEVERITY_WARNING, location); errorListener.add(err); }
private static boolean checkAllDerivationsForRestriction(SchemaType baseType, SchemaType derivedType, Collection errors, XmlObject context) { boolean allDerivationsAreRestrictions = true; SchemaType currentType = derivedType; // XMLBEANS-66: if baseType is a union, check restriction is of one of the constituant types Set possibleTypes = null; if (baseType.getSimpleVariety() == SchemaType.UNION) possibleTypes = new HashSet(Arrays.asList(baseType.getUnionConstituentTypes())); // run up the types hierarchy from derived Type to base Type and make sure that all are derived by // restriction. If any are not then this is not a valid restriction. while (!baseType.equals(currentType) && possibleTypes != null && !possibleTypes.contains(currentType)) { if (currentType.getDerivationType() == SchemaType.DT_RESTRICTION) { currentType = currentType.getBaseType(); } else { allDerivationsAreRestrictions = false; errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_RESTRICTION_NAME_AND_TYPE$TYPE_RESTRICTED, new Object[] { printType(derivedType), printType(baseType), printType(currentType) }, context)); break; } } return allDerivationsAreRestrictions; }
private static boolean typeDerivationOK(SchemaType baseType, SchemaType derivedType, Collection errors, XmlObject context){ boolean typeDerivationOK = false; // 1 If B and D are not the same type definition, then the {derivation method} of D must not be in the subset. // 2 One of the following must be true: // 2.1 B and D must be the same type definition. // 2.2 B must be D's {base type definition}. // 2.3 All of the following must be true: // 2.3.1 D's {base type definition} must not be the �ur-type definition�. // 2.3.2 The appropriate case among the following must be true: // 2.3.2.1 If D's {base type definition} is complex, then it must be validly derived from B given the subset as defined by this constraint. // 2.3.2.2 If D's {base type definition} is simple, then it must be validly derived from B given the subset as defined in Type Derivation OK (Simple) (�3.14.6). // This line will check if derivedType is a subType of baseType (should handle all of the 2.xx checks above) if (baseType.isAssignableFrom(derivedType)) { // Ok derived type is subtype but need to make sure that all of the derivations between the two types are by // Restriction. typeDerivationOK = checkAllDerivationsForRestriction(baseType, derivedType, errors, context); } else { // derived type is not a sub-type of base type typeDerivationOK = false; errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_RESTRICTION_NAME_AND_TYPE$TYPE_VALID, new Object[] { printType(derivedType), printType(baseType) }, context)); } return typeDerivationOK; }
private static boolean blockSetOK(SchemaLocalElement baseElement, SchemaLocalElement derivedElement, Collection errors, XmlObject context) { if (baseElement.blockRestriction() && !derivedElement.blockRestriction()) { errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_RESTRICTION_NAME_AND_TYPE$DISALLOWED_SUBSTITUTIONS, new Object[] { printParticle((SchemaParticle)derivedElement), "restriction", printParticle((SchemaParticle)baseElement) }, context)); return false; } if (baseElement.blockExtension() && !derivedElement.blockExtension()) { errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_RESTRICTION_NAME_AND_TYPE$DISALLOWED_SUBSTITUTIONS, new Object[] { printParticle((SchemaParticle)derivedElement), "extension", printParticle((SchemaParticle)baseElement) }, context)); return false; } if (baseElement.blockSubstitution() && !derivedElement.blockSubstitution()) { errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_RESTRICTION_NAME_AND_TYPE$DISALLOWED_SUBSTITUTIONS, new Object[] { printParticle((SchemaParticle)derivedElement), "substitution", printParticle((SchemaParticle)baseElement) }, context)); return false; } return true; }
private static boolean checkIdentityConstraints(SchemaLocalElement baseElement, SchemaLocalElement derivedElement, Collection errors, XmlObject context) { // 5 R's declaration's {identity-constraint definitions} is a subset of B's declaration's {identity-constraint definitions}, if any. boolean identityConstraintsOK = true; SchemaIdentityConstraint[] baseConstraints = baseElement.getIdentityConstraints(); SchemaIdentityConstraint[] derivedConstraints = derivedElement.getIdentityConstraints(); // cycle thru derived's identity constraints and check each to assure they in the array of base constraints for (int i = 0; i < derivedConstraints.length; i++) { SchemaIdentityConstraint derivedConstraint = derivedConstraints[i]; if (checkForIdentityConstraintExistence(baseConstraints, derivedConstraint)) { identityConstraintsOK = false; errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_RESTRICTION_NAME_AND_TYPE$IDENTITY_CONSTRAINTS, new Object[] { printParticle((SchemaParticle)derivedElement), printParticle((SchemaParticle)baseElement) }, context)); break; } } return identityConstraintsOK; }
private static boolean checkFixed(SchemaLocalElement baseModel, SchemaLocalElement derivedModel, Collection errors, XmlObject context) { // 4 either B's declaration's {value constraint} is absent, or is not fixed, // or R's declaration's {value constraint} is fixed with the same value. boolean checkFixed = false; if (baseModel.isFixed()) { if (baseModel.getDefaultText().equals(derivedModel.getDefaultText())) { // R's declaration's {value constraint} is fixed with the same value. checkFixed = true; } else { // The derived element has a fixed value that is different than the base element errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_RESTRICTION_NAME_AND_TYPE$FIXED, new Object[] { printParticle((SchemaParticle)derivedModel), derivedModel.getDefaultText(), printParticle((SchemaParticle)baseModel), baseModel.getDefaultText() }, context)); checkFixed = false; } } else { // B's declaration's {value constraint} is absent, or is not fixed, checkFixed = true; } return checkFixed; }
errors.add(XmlError.forObject(XmlErrorCodes.OCCURRENCE_RANGE$MIN_GTE_MIN, new Object[] { printParticle(derivedModel), printParticle(baseModel) }, context)); if (maxRange == UNBOUNDED) { groupOccurrenceOK = false; errors.add(XmlError.forObject(XmlErrorCodes.OCCURRENCE_RANGE$MAX_LTE_MAX, new Object[] { printParticle(derivedModel), printParticle(baseModel) }, context)); if (maxRange.compareTo(baseModel.getMaxOccurs()) > 0) { groupOccurrenceOK = false; errors.add(XmlError.forObject(XmlErrorCodes.OCCURRENCE_RANGE$MAX_LTE_MAX, new Object[] { printParticle(derivedModel), printParticle(baseModel) }, context));
} else { occurrenceRangeOK = false; errors.add(XmlError.forObject(XmlErrorCodes.OCCURRENCE_RANGE$MAX_LTE_MAX, new Object[] { printParticle(derivedParticle), printMaxOccurs(derivedParticle.getMaxOccurs()), printParticle(baseParticle), printMaxOccurs(baseParticle.getMaxOccurs()) }, errors.add(XmlError.forObject(XmlErrorCodes.OCCURRENCE_RANGE$MIN_GTE_MIN, new Object[] { printParticle(derivedParticle), derivedParticle.getMinOccurs().toString(), printParticle(baseParticle), baseParticle.getMinOccurs().toString() },
private static boolean nsCompat(SchemaParticle baseModel, SchemaLocalElement derivedElement, Collection errors, XmlObject context) { // nsCompat is called when base: ANY, derived: ELEMENT assert baseModel.getParticleType() == SchemaParticle.WILDCARD; boolean nsCompat = false; // For an element declaration particle to be a �valid restriction� of a wildcard particle all of the following must be true: // 1 The element declaration's {target namespace} is �valid� with respect to the wildcard's {namespace constraint} // as defined by Wildcard allows Namespace Name (�3.10.4). if (baseModel.getWildcardSet().contains(derivedElement.getName())) { // 2 R's occurrence range is a valid restriction of B's occurrence range as defined by Occurrence Range OK (�3.9.6). if (occurrenceRangeOK(baseModel, (SchemaParticle) derivedElement, errors, context)) { nsCompat = true; } else { // error already produced by occurrenceRangeOK //errors.add(XmlError.forObject(formatOccurenceRangeMinError(baseModel, (SchemaParticle) derivedElement), context)); } } else { nsCompat = false; errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_DERIVATION_NS_COMPAT$WILDCARD_VALID, new Object[] { printParticle((SchemaParticle)derivedElement), printParticle(baseModel) }, context)); } return nsCompat; }
private static boolean nsSubset(SchemaParticle baseModel, SchemaParticle derivedModel, Collection errors, XmlObject context) { // nsSubset is called when base: ANY, derived: ANY assert baseModel.getParticleType() == SchemaParticle.WILDCARD; assert derivedModel.getParticleType() == SchemaParticle.WILDCARD; boolean nsSubset = false; // For a wildcard particle to be a �valid restriction� of another wildcard particle all of the following must be true: // 1 R's occurrence range must be a valid restriction of B's occurrence range as defined by Occurrence Range OK (�3.9.6). if (occurrenceRangeOK(baseModel, derivedModel, errors, context)) { // 2 R's {namespace constraint} must be an intensional subset of B's {namespace constraint} as defined // by Wildcard Subset (�3.10.6). if (baseModel.getWildcardSet().inverse().isDisjoint(derivedModel.getWildcardSet())) { nsSubset = true; } else { nsSubset = false; errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_DERIVATION_NS_SUBST$WILDCARD_SUBSET, new Object[] { printParticle(derivedModel), printParticle(baseModel) }, context)); } } else { nsSubset = false; // error already produced by occurrenceRangeOK //errors.add(XmlError.forObject(formatNSIsNotSubsetError(baseModel, derivedModel), context)); } return nsSubset; }
errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_RESTRICTION_NAME_AND_TYPE$NAME, new Object[] { printParticle((SchemaParticle)derivedElement), printParticle((SchemaParticle)baseElement) }, context)); return false; errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_RESTRICTION_NAME_AND_TYPE$NILLABLE, new Object[] { printParticle((SchemaParticle)derivedElement), printParticle((SchemaParticle)baseElement) }, context)); return false;
errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_DERIVATION_RECURSE_LAX$MAP, new Object[] { printParticles(baseParticleArray, i) }, context));
private boolean validate_immutable(XmlOptions options) { Collection errorListener = options == null ? null : (Collection)options.get(XmlOptions.ERROR_LISTENER); XmlErrorWatcher watcher = new XmlErrorWatcher(errorListener); if (!(schemaType().isSimpleType() || options != null && options.hasOption(XmlOptions.VALIDATE_TEXT_ONLY))) { // cannot have any required attributes or elements SchemaProperty[] properties = schemaType().getProperties(); for (int i = 0; i < properties.length; i++) { if (properties[i].getMinOccurs().signum() > 0) { // KHK: error code? if (properties[i].isAttribute()) watcher.add(XmlError.forObject(XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE, new Object[]{QNameHelper.pretty(properties[i].getName()), }, this)); else watcher.add(XmlError.forObject(XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_ELEMENT, new Object[]{properties[i].getMinOccurs(), QNameHelper.pretty(properties[i].getName()), }, this)); } } if (schemaType().getContentType() != SchemaType.SIMPLE_CONTENT) return !watcher.hasError(); // don't validate non-simple-content } String text = (String)_textsource; if (text == null) text = ""; validate_simpleval(text, new ImmutableValueValidationContext(watcher, this)); return !watcher.hasError(); }