Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * Fabric3
  * Copyright (c) 2009 Metaform Systems
  *
  * Fabric3 is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as
  * published by the Free Software Foundation, either version 3 of
  * the License, or (at your option) any later version, with the
  * following exception:
 *
 * Linking this software statically or dynamically with other
 * modules is making a combined work based on this software.
 * Thus, the terms and conditions of the GNU General Public
 * License cover the whole combination.
 *
 * As a special exception, the copyright holders of this software
 * give you permission to link this software with independent
 * modules to produce an executable, regardless of the license
 * terms of these independent modules, and to copy and distribute
 * the resulting executable under terms of your choice, provided
 * that you also meet, for each linked independent module, the
 * terms and conditions of the license of that module. An
 * independent module is a module which is not derived from or
 * based on this software. If you modify this software, you may
 * extend this exception to your version of the software, but
 * you are not obligated to do so. If you do not wish to do so,
 * delete this exception statement from your version.
 *
 * Fabric3 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the
 * GNU General Public License along with Fabric3.
 * If not, see <http://www.gnu.org/licenses/>.
 */
 package org.fabric3.policy;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 

Version:
$Rev: 8456 $ $Date: 2009-12-22 23:20:21 +0100 (Tue, 22 Dec 2009) $
 
 public class DefaultPolicyResolver implements PolicyResolver {
     private static final QName IMPLEMENTATION_SYSTEM = new QName(."implementation.system");
     private static final QName IMPLEMENTATION_SINGLETON = new QName(."singleton");
     private static final PolicyResult EMPTY_RESULT = new NullPolicyResult();

    
Closure for filtering intercepted policies.
 
     private static final Closure<PolicySetBooleanINTERCEPTION = new Closure<PolicySetBoolean>() {
         public Boolean execute(PolicySet policySet) {
             return policySet.getPhase() == .;
         }
     };

    
Closure for filtering provided policies by bindings or implementations.
 
     private static final Closure<PolicySetBooleanPROVIDED = new Closure<PolicySetBoolean>() {
         public Boolean execute(PolicySet policySet) {
             return policySet.getPhase() == .;
         }
     };
 
 
    public DefaultPolicyResolver(@Reference InteractionPolicyResolver interactionResolver,
                                 @Reference ImplementationPolicyResolver implementationResolver,
                                 @Reference OperationResolver operationResolver) {
        this. = interactionResolver;
        this. = implementationResolver;
        this. = operationResolver;
    }
    public PolicyResult resolvePolicies(List<LogicalOperationoperations,
                                        LogicalBinding<?> sourceBinding,
                                        LogicalBinding<?> targetBinding,
                                        LogicalComponent<?> source,
                                        LogicalComponent<?> targetthrows PolicyResolutionException {
        if ((noPolicy(source) && noPolicy(target)) || sourceBinding.getDefinition() instanceof JMXBinding) {
            return ;
        }
        PolicyResultImpl policyResult = new PolicyResultImpl();
        resolveEndpointPolicies(policyResultsourceBindingtargetBinding);
        for (LogicalOperation operation : operations) {
            resolveOperationPolicies(operationpolicyResultsourceBindingtargetBindingtarget);
        }
        return policyResult;
    }

    
Resolves configured source and target intents and policies for an endpoint. Resolution will be performed against the bindings and ancestors.

Parameters:
policyResult the policy result to populate
sourceBinding the source binding
targetBinding the target binding
Throws:
org.fabric3.spi.policy.PolicyResolutionException if there is a resolution error
    private void resolveEndpointPolicies(PolicyResultImpl policyResultLogicalBinding<?> sourceBindingLogicalBinding<?> targetBinding)
            throws PolicyResolutionException {
        Set<IntentsourceEndpointIntents = .resolveProvidedIntents(sourceBinding);
        policyResult.addSourceEndpointIntents(sourceEndpointIntents);
        Set<IntenttargetEndpointIntents = .resolveProvidedIntents(targetBinding);
        policyResult.addTargetEndpointIntents(targetEndpointIntents);
        Set<PolicySetendpointPolicies = .resolvePolicySets(sourceBinding);
        policyResult.addSourceEndpointPolicySets(CollectionUtils.filter(endpointPolicies));
        policyResult.addInterceptedEndpointPolicySets(CollectionUtils.filter(endpointPolicies));
        endpointPolicies = .resolvePolicySets(targetBinding);
        policyResult.addTargetEndpointPolicySets(CollectionUtils.filter(endpointPolicies));
        policyResult.addInterceptedEndpointPolicySets(CollectionUtils.filter(endpointPolicies));
    }


    
Resolves configured source and target intents and policies for an operation.

Parameters:
operation the operation
policyResult the policy result to populate
sourceBinding the source binding
targetBinding the target binding
target the atrget component, or null if the operation invokes a remote service
Throws:
org.fabric3.spi.policy.PolicyResolutionException if there is a resolution error
    private void resolveOperationPolicies(LogicalOperation operation,
                                          PolicyResultImpl policyResult,
                                          LogicalBinding<?> sourceBinding,
                                          LogicalBinding<?> targetBinding,
                                          LogicalComponent<?> targetthrows PolicyResolutionException {
        Set<IntentsourceOperationIntents = .resolveProvidedIntents(operationsourceBinding);
        policyResult.addSourceIntents(operationsourceOperationIntents);
        Set<IntenttargetOperationIntents = .resolveProvidedIntents(operationtargetBinding);
        policyResult.addTargetIntents(operationtargetOperationIntents);
        if (target != null) {
            Set<IntentsourceImplementationIntents = .resolveProvidedIntents(targetoperation);
            policyResult.addSourceIntents(operationsourceImplementationIntents);
        }
        Set<PolicySetpolicies = .resolvePolicySets(operationsourceBinding);
        policyResult.addSourcePolicySets(operation, CollectionUtils.filter(policies));
        policyResult.addInterceptedPolicySets(operation, CollectionUtils.filter(policies));
        policies = .resolvePolicySets(operationtargetBinding);
        policyResult.addTargetPolicySets(operation, CollectionUtils.filter(policies));
        policyResult.addInterceptedPolicySets(operation, CollectionUtils.filter(policies));
        if (target != null) {
            Bindable parent = targetBinding.getParent();
            // resolve policies using the target (as opposed to source) operation so target implementaton policies are included
            LogicalOperation targetOperation = matchOperation(operationparent);
            policies = .resolvePolicySets(targettargetOperation);
            // add policy metadata to the result
            policyResult.getMetadata().addAll(targetOperation.getDefinition().getMetadata());
            // important: use reference side operation as the key
            policyResult.addTargetPolicySets(operation, CollectionUtils.filter(policies));
            policyResult.addInterceptedPolicySets(operation, CollectionUtils.filter(policies));
        }
    }

    
Matches operation definitions on the source and target sides of a wire so that policy sets and intents can be determined. Note that if the source operation belongs to a service, the wire is a callback wire.

Parameters:
operation the source operation to match against.
bindable the target bindable.
Returns:
the matching operation
Throws:
org.fabric3.spi.policy.PolicyResolutionException if there is a matching error
    private LogicalOperation matchOperation(LogicalOperation operationBindable bindablethrows PolicyResolutionException {
        String name = operation.getDefinition().getName();
        List<LogicalOperationoperations;
        if (bindable instanceof LogicalReference) {
            // target is a reference so this is a callback
            operations = bindable.getCallbackOperations();
        } else {
            operations = bindable.getOperations();
        }
        try {
            LogicalOperation matched = .resolve(operationoperations);
            if (matched == null) {
                throw new AssertionError("No matching operation for " + name);
            }
            return matched;
        } catch (OperationNotFoundException e) {
            throw new PolicyResolutionException(e);
        }
    }
    private boolean noPolicy(LogicalComponent<?> component) {
        return component != null && (component.getDefinition().getImplementation().isType()
                || component.getDefinition().getImplementation().isType());
    }
    private static class NullPolicyResult implements PolicyResult {
        private PolicyMetadata metadata = new PolicyMetadata();
        public List<PolicySetgetInterceptedPolicySets(LogicalOperation operation) {
            return Collections.emptyList();
        }
        public EffectivePolicy getSourcePolicy() {
            return new NullEffectivePolicy();
        }
        public EffectivePolicy getTargetPolicy() {
            return new NullEffectivePolicy();
        }
        public Set<PolicySetgetInterceptedEndpointPolicySets() {
            return Collections.emptySet();
        }
        public PolicyMetadata getMetadata() {
            return ;
        }
    }
    private static class NullEffectivePolicy implements EffectivePolicy {
        public Set<IntentgetEndpointIntents() {
            return Collections.emptySet();
        }
        public Set<PolicySetgetEndpointPolicySets() {
            return Collections.emptySet();
        }
        public List<IntentgetIntents(LogicalOperation operation) {
            return Collections.emptyList();
        }
        public List<PolicySetgetPolicySets(LogicalOperation operation) {
            return Collections.emptyList();
        }
        public List<IntentgetOperationIntents() {
            return Collections.emptyList();
        }
        public Map<LogicalOperationList<PolicySet>> getOperationPolicySets() {
            return Collections.emptyMap();
        }
    }
New to GrepCode? Check out our FAQ X