private void validateOwn() {
/*
* A state may optionally be defined to allow grant specification
*/
Type stateType = validateState();
/*
* The composite must be a singleton to define owns
*/
if (!getComposite().getOwnedComponents().isEmpty() && !getComposite().isSingleton()) {
error("invalid own expression, a composite must be a singleton to define "+quoted("own")+" clauses");
}
/*
* Check that a single own clause is defined for a component and its members
*/
Set<ComponentReference<?>> ownedComponents = new HashSet<ComponentReference<?>>();
for (OwnedComponentDeclaration ownDeclaration : getComposite().getOwnedComponents()) {
ComponentDeclaration owned = getComponent(ownDeclaration.getComponent(),true);
if (owned == null) {
error("invalid own expression, unknown component " + ownDeclaration.getComponent().getName());
continue;
}
/*
* Verify the property used to optionally filter owned components is declared, and is an enumeration
* that contains the specified values
*/
if (ownDeclaration.getProperty() != null) {
String propertyName = ownDeclaration.getProperty().getIdentifier();
PropertyDefinition property = owned.getPropertyDefinition(propertyName);
if (property == null) {
error("invalid own expression, undefined property "+ quoted(propertyName) +" in component "+ owned.getName());
continue;
}
Type propertyType = getType(property);
if (propertyType == null || !(propertyType instanceof EnumerationType)) {
error("invalid own expression, property "+ quoted(propertyName) + " of component " + owned.getName() + " is not an enumeration");
continue;
}
if (ownDeclaration.getValues().isEmpty()) {
error("invalid own expression, values not specified for property "+ quoted(propertyName) + " of component " + owned.getName());
continue;
}
for (String value : ownDeclaration.getValues()) {
if (propertyType.value(value) == null) {
error("invalid own expression, value "+quoted(value)+" is not valid for property "+ quoted(propertyName) + " of component " + owned.getName());
}
}
}