use of eu.esdihumboldt.hale.io.xsd.constraint.XmlIdUnique in project hale by halestudio.
the class XmlSchemaReader method setMetadataAndConstraints.
/**
* Set metadata and constraints for a property based on a XML element
*
* @param property the property
* @param element the XML element
* @param schemaLocation the schema location
*/
private void setMetadataAndConstraints(DefaultPropertyDefinition property, XmlSchemaElement element, String schemaLocation) {
property.setConstraint(new XmlIdUnique(property));
// set constraints
property.setConstraint(NillableFlag.get(element.isNillable()));
long max = (element.getMaxOccurs() == Long.MAX_VALUE) ? (Cardinality.UNBOUNDED) : (element.getMaxOccurs());
property.setConstraint(Cardinality.get(element.getMinOccurs(), max));
// set metadata
setMetadata(property, element, schemaLocation);
}
use of eu.esdihumboldt.hale.io.xsd.constraint.XmlIdUnique 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);
}
}
}
use of eu.esdihumboldt.hale.io.xsd.constraint.XmlIdUnique 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);
}
Aggregations