Search in sources :

Example 1 with XLinkReference

use of eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.XLinkReference in project hale by halestudio.

the class XLinkReferenceValidator method validatePropertyConstraint.

@Override
public void validatePropertyConstraint(Object[] values, PropertyConstraint constraint, PropertyDefinition property, InstanceValidationContext context, ValidationLocation location) throws ValidationException {
    if (values == null) {
        return;
    }
    Object contextObj = context.getContext(XLinkReferenceValidator.class);
    XLinkReferenceContext ctx;
    if (contextObj instanceof XLinkReferenceContext) {
        ctx = (XLinkReferenceContext) contextObj;
    } else {
        ctx = new XLinkReferenceContext();
        context.putContext(XLinkReferenceValidator.class, ctx);
    }
    // collect local references
    Reference ref = property.getConstraint(Reference.class);
    if (ref instanceof XLinkReference && ref.isReference()) {
        for (Object value : values) {
            if (value != null) {
                String id = value.toString();
                if (id != null && id.startsWith("#")) {
                    ctx.addLocalReference(id.substring(1), location);
                }
            }
        }
    }
    // collect XML IDs
    Unique unique = property.getConstraint(Unique.class);
    if (unique instanceof XmlIdUnique && unique.isEnabled()) {
        for (Object value : values) {
            addIdentifier(value, ctx);
        }
    }
}
Also used : XmlIdUnique(eu.esdihumboldt.hale.io.xsd.constraint.XmlIdUnique) XLinkReference(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.XLinkReference) Reference(eu.esdihumboldt.hale.common.schema.model.constraint.property.Reference) XmlIdUnique(eu.esdihumboldt.hale.io.xsd.constraint.XmlIdUnique) Unique(eu.esdihumboldt.hale.common.schema.model.constraint.property.Unique) XLinkReference(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.XLinkReference)

Example 2 with XLinkReference

use of eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.XLinkReference in project hale by halestudio.

the class XmlSchemaReader method setMetadataAndConstraints.

/**
 * Set metadata and constraints for a property based on a XML attribute
 *
 * @param property the property
 * @param attribute the XML attribute
 * @param schemaLocation the schema location
 */
private void setMetadataAndConstraints(DefaultPropertyDefinition property, XmlSchemaAttribute attribute, String schemaLocation) {
    property.setConstraint(new XmlIdUnique(property));
    // set constraints
    property.setConstraint(XmlAttributeFlag.ENABLED);
    if (attribute.getUse() != null) {
        long maxOccurs = (attribute.getUse().getValue().equals(Constants.BlockConstants.PROHIBITED)) ? (0) : (1);
        long minOccurs = (attribute.getUse().getValue().equals(Constants.BlockConstants.REQUIRED)) ? (1) : (0);
        property.setConstraint(Cardinality.get(minOccurs, maxOccurs));
    }
    property.setConstraint(NillableFlag.DISABLED);
    // attributes)
    if (NAME_XLINK_REF.equals(property.getName())) {
        property.setConstraint(new XLinkReference());
    }
    // set metadata
    setMetadata(property, attribute, schemaLocation);
}
Also used : XmlIdUnique(eu.esdihumboldt.hale.io.xsd.constraint.XmlIdUnique) XLinkReference(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.XLinkReference)

Aggregations

XmlIdUnique (eu.esdihumboldt.hale.io.xsd.constraint.XmlIdUnique)2 XLinkReference (eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.XLinkReference)2 Reference (eu.esdihumboldt.hale.common.schema.model.constraint.property.Reference)1 Unique (eu.esdihumboldt.hale.common.schema.model.constraint.property.Unique)1