* @param models - the subjects from which intents will be copied
*/
protected void inherit(PolicySubject policySubject, Intent.Type intentType, boolean ignoreExclusiveIntents, Object... models) {
for (Object model : models) {
if (model instanceof PolicySubject) {
PolicySubject subject = (PolicySubject)model;
if (!ignoreExclusiveIntents) {
// The intents are merged and the exclusion check will be done after
for (Intent intent : subject.getRequiredIntents()) {
if (!policySubject.getRequiredIntents().contains(intent)){
if ((intent.getType() != null) && (intentType != null) ) {
if (intent.getType().equals(intentType)){
policySubject.getRequiredIntents().add(intent);
}
} else {
policySubject.getRequiredIntents().add(intent);
}
}
}
} else {
Set<Intent> intents = new HashSet<Intent>();
for (Intent i1 : subject.getRequiredIntents()) {
boolean exclusive = false;
for (Intent i2 : policySubject.getRequiredIntents()) {
if (i1.getExcludedIntents().contains(i2) || i2.getExcludedIntents().contains(i1)) {
exclusive = true;
break;
}
}
if (!exclusive) {
if (!intents.contains(i1)){
if (intentType != null) {
if (i1.getType().equals(intentType)){
intents.add(i1);
}
} else {
intents.add(i1);
}
}
}
}
policySubject.getRequiredIntents().addAll(intents);
}
//FIXME this duplicates the intents for a implementation
//e.g <implementation.java requires="managedTransaction.local managedTransaction.local"
//becomes twice
//[{http://docs.oasis-open.org/ns/opencsa/sca/200912}managedTransaction.local,
//{http://docs.oasis-open.org/ns/opencsa/sca/200912}managedTransaction.local]
for (PolicySet policySet : subject.getPolicySets()){
if (!policySubject.getPolicySets().contains(policySet)){
policySubject.getPolicySets().add(policySet);
}
}
}