if (getGroupRelation().getTarget() instanceof ResourceReference) {
/*
* If the group targets a resource
*/
ResourceReference groupTarget = getGroupRelation().getTarget().as(ResourceReference.class);
/*
* and the refinement targets a resource it must match
*/
if (targetIsResource() && !getTargetReference().equals(groupTarget)) {
error("Invalid target refinement in relation " + quoted(getRelation().getIdentifier()) + ", "+getTargetReference()+ " is not compatible with "+groupTarget);
}
/*
* and the refinement targets a component, it must provide the resource
*/
if (targetIsComponent() && getTarget() != null && !getTarget().getProvidedResources().contains(groupTarget)) {
error("Invalid target refinement in relation " + quoted(getRelation().getIdentifier()) + ", "+getTargetReference()+ " doesn't provide the resource specified in the group "+groupTarget);
}
}
if (getGroupRelation().getTarget() instanceof ComponentReference) {
/*
* If the group targets a component
*/
ComponentDeclaration groupTarget = getComponent(getGroupRelation().getTarget().as(ComponentReference.class),true);
/*
* and the refinement targets a resource, it must be provided by the component
*/
if (targetIsResource() && groupTarget != null && !groupTarget.getProvidedResources().contains(getTargetReference())) {
error("Invalid target refinement in relation " + quoted(getRelation().getIdentifier()) + ", "+getTargetReference()+ " is not provided by the component specified in the group "+groupTarget.getName());
}
if (targetIsComponent() && getTarget() != null && groupTarget != null) {
/*
* and the refinement targets a most concrete component, it must be a descendant
*/
if (groupTarget.getKind().isMoreAbstractThan(getTarget().getKind()) && ! isAncestor(getTarget(), groupTarget.getReference(),true)) {
error("Invalid target refinement in relation " + quoted(getRelation().getIdentifier()) + ", "+getTargetReference()+ " is not a descendant of the component specified in the group "+groupTarget.getName());
}
/*
* and the refinement targets a most abstract component, it must be an ancestor
*/
if (getTarget().getKind().isMoreAbstractThan(groupTarget.getKind()) && ! isAncestor(groupTarget,getTarget().getReference(),true)) {
error("Invalid target refinement in relation " + quoted(getRelation().getIdentifier()) + ", "+getTargetReference()+ " is not a ancestor of the component specified in the group "+groupTarget.getName());
}
/*
* and the refinement targets a equally abstract component, it must be the samer
*/
if (getTarget().getKind().equals(groupTarget.getKind()) && ! getTarget().equals(groupTarget)) {
error("Invalid target refinement in relation " + quoted(getRelation().getIdentifier()) + ", "+getTargetReference()+ " is not compatible with the component specified in the group "+groupTarget.getName());
}
}
}