private boolean noPolicy(LogicalComponent<?> component) { return component != null && (component.getDefinition().getImplementation().isType(IMPLEMENTATION_SYSTEM) || component.getDefinition().getImplementation().isType(IMPLEMENTATION_SINGLETON)); }
public IntentPair resolveIntents(LogicalComponent<?> component, LogicalOperation operation) throws PolicyResolutionException { Implementation<?> implementation = component.getDefinition().getImplementation(); QName type = implementation.getType(); ImplementationType implementationType = policyRegistry.getDefinition(type, ImplementationType.class); Set<QName> mayProvidedIntents; if (implementationType == null) { // tolerate not having a registered implementation type definition mayProvidedIntents = Collections.emptySet(); } else { mayProvidedIntents = implementationType.getMayProvide(); } Set<Intent> requiredIntents = getRequestedIntents(component, operation); Set<Intent> intentsToBeProvided = new LinkedHashSet<>(); for (Intent intent : requiredIntents) { if (mayProvidedIntents.contains(intent.getName())) { intentsToBeProvided.add(intent); } } return new IntentPair(requiredIntents, intentsToBeProvided); }
private Set<Intent> getRequestedIntents(LogicalComponent<?> logicalComponent, LogicalOperation operation) throws PolicyResolutionException { // Aggregate all the intents from the ancestors Set<QName> intentNames = new LinkedHashSet<>(); intentNames.addAll(operation.getIntents()); ComponentDefinition<? extends Implementation<?>> definition = logicalComponent.getDefinition(); Implementation<?> implementation = definition.getImplementation(); ComponentType componentType = implementation.getComponentType(); intentNames.addAll(implementation.getIntents()); intentNames.addAll(componentType.getIntents()); intentNames.addAll(aggregateIntents(logicalComponent)); // Expand all the profile intents Set<Intent> requiredIntents = resolveIntents(intentNames); // Remove intents not applicable to the artifact filterInvalidIntents(Intent.IMPLEMENTATION, requiredIntents); filterMutuallyExclusiveIntents(requiredIntents); return requiredIntents; }
} else if (localName.startsWith("implementation.")) { LogicalComponent<?> component = (LogicalComponent<?>) contextNode; if (localName.equals(component.getDefinition().getImplementation().getType().getLocalPart())) { return new SingleObjectIterator(component);
public Set<PolicySet> resolvePolicySets(LogicalComponent<?> component, LogicalOperation operation) throws PolicyResolutionException { Implementation<?> implementation = component.getDefinition().getImplementation(); QName type = implementation.getType(); ImplementationType implementationType = policyRegistry.getDefinition(type, ImplementationType.class);
private void containsIntents(List<String> intentArgs, LogicalComponent<?> component, Set<LogicalScaArtifact> artifacts) { if (containsIntents(intentArgs, component.getDefinition().getImplementation().getIntents())) { artifacts.add(component); } if (containsIntents(intentArgs, component.getDefinition().getIntents())) { artifacts.add(component); } if (containsIntents(intentArgs, component.getIntents())) { artifacts.add(component); } for (LogicalService service : component.getServices()) { if (containsIntents(intentArgs, service.getIntents())) { artifacts.add(service); } } for (LogicalReference reference : component.getReferences()) { if (containsIntents(intentArgs, reference.getIntents())) { artifacts.add(reference); } } if (component instanceof LogicalCompositeComponent) { LogicalCompositeComponent composite = (LogicalCompositeComponent) component; for (LogicalComponent<?> childComponent : composite.getComponents()) { containsIntents(intentArgs, childComponent, artifacts); } } }
/** * Aggregate intents from ancestors of a component. Components are handled differently than other SCA artifacts as implementation intents are inherited. * * @param component the logical artifact to aggregate intents for * @return the aggregated intents */ protected Set<QName> aggregateIntents(LogicalComponent<?> component) { LogicalComponent<?> current = component; Set<QName> aggregatedIntents = new LinkedHashSet<>(); while (current != null) { Set<QName> currentIntents = current.getIntents(); processIntents(currentIntents, aggregatedIntents); ComponentDefinition<? extends Implementation<?>> definition = current.getDefinition(); if (definition != null) { processIntents(definition.getIntents(), aggregatedIntents); Implementation<?> implementation = definition.getImplementation(); if (implementation != null) { processIntents(implementation.getIntents(), aggregatedIntents); ComponentType componentType = implementation.getComponentType(); if (componentType != null) { processIntents(componentType.getIntents(), aggregatedIntents); } } } current = current.getParent(); } return aggregatedIntents; }
if (definition != null) { processIntents(definition.getIntents(), aggregatedIntents); Implementation<?> implementation = definition.getImplementation(); if (implementation != null) { processIntents(implementation.getIntents(), aggregatedIntents);
if (definition != null) { processIntents(definition.getIntents(), aggregatedIntents); Implementation<?> implementation = definition.getImplementation(); if (implementation != null) { processIntents(implementation.getIntents(), aggregatedIntents);
policyResult.addInterceptedPolicySets(operation, CollectionUtils.filter(policies, INTERCEPTION)); if (target != null && !(target.getDefinition().getImplementation() instanceof RemoteImplementation)) { Bindable parent = targetBinding.getParent(); Implementation<?> parentImplementation = parentDefinition.getImplementation(); metadata.addAll(parentImplementation.getMetadata());
public PolicyResult resolvePolicies(LogicalConsumer consumer) throws PolicyResolutionException { LogicalComponent<?> component = consumer.getParent(); if (noPolicy(component)) { return EMPTY_RESULT; } // synthesize an operation and binding PolicyResultImpl policyResult = new PolicyResultImpl(); LogicalOperation operation = new LogicalOperation(DEFINITION, consumer); IntentPair targetOperationIntentPair = interactionResolver.resolveIntents(operation, LocalBindingDefinition.INSTANCE.getType()); policyResult.addTargetProvidedIntents(operation, targetOperationIntentPair.getProvidedIntents()); IntentPair sourceImplementationIntentPair = implementationResolver.resolveIntents(component, operation); policyResult.addSourceProvidedIntents(operation, sourceImplementationIntentPair.getProvidedIntents()); Set<PolicySet> policies = interactionResolver.resolvePolicySets(operation, consumer, LocalBindingDefinition.INSTANCE.getType()); policyResult.addTargetPolicySets(operation, CollectionUtils.filter(policies, PROVIDED)); policyResult.addInterceptedPolicySets(operation, CollectionUtils.filter(policies, INTERCEPTION)); // resolve policies using the target (as opposed to source) operation so target implementation policies are included policies = implementationResolver.resolvePolicySets(component, operation); // add policy metadata to the result PolicyMetadata metadata = policyResult.getMetadata(operation); metadata.addAll(operation.getDefinition().getMetadata()); // add metadata from implementation metadata.addAll(operation.getParent().getParent().getDefinition().getImplementation().getMetadata()); // important: use reference side operation as the key policyResult.addTargetPolicySets(operation, CollectionUtils.filter(policies, PROVIDED)); policyResult.addInterceptedPolicySets(operation, CollectionUtils.filter(policies, INTERCEPTION)); overrideDirectIfExternalAttachedPolicies(policyResult); return policyResult; }