private AbstractPolicy matchPolicies(EvaluationCtx eval,
                                         Map<String, AbstractPolicy> policyList)
            throws TopLevelPolicyException {
        // setup a list of matching policies
        Map<String, AbstractPolicy> list =
                new HashMap<String, AbstractPolicy>();

        // get an iterator over all the identifiers
        for (String policyId : policyList.keySet()) {
            AbstractPolicy policy = policyList.get(policyId);

            MatchResult match = policy.match(eval);

            int result = match.getResult();
            if (result == MatchResult.INDETERMINATE) {
                throw new TopLevelPolicyException(match.getStatus());
            }

            // if we matched, we keep track of the matching policy...
            if (result == MatchResult.MATCH) {
                // ...first checking if this is the first match and if
                // we automatically nest policies
                if (m_combiningAlg == null && list.size() > 0) {
                    ArrayList<String> code = new ArrayList<String>();
                    code.add(Status.STATUS_PROCESSING_ERROR);
                    Status status =
                            new Status(code, "too many applicable"
                                    + " top-level policies");
                    throw new TopLevelPolicyException(status);
                }

                if (logger.isDebugEnabled()) {
                    logger.debug("Matched policy: {}", policyId);
                }

                list.put(policyId, policy);
            }
        }

        // no errors happened during the search, so now take the right
        // action based on how many policies we found
        switch (list.size()) {
            case 0:
                return null;
            case 1:
                Iterator<AbstractPolicy> i = list.values().iterator();
                AbstractPolicy p = i.next();
                return p;
            default:
                return new PolicySet(parentPolicyId,
                                     m_combiningAlg,
                                     m_target,
                                     new ArrayList<AbstractPolicy>(list
                                             .values()));
        }
    }
private AbstractPolicy matchPolicies ( EvaluationCtx eval , Map < String , AbstractPolicy > policyList ) throws TopLevelPolicyException { Map < String , AbstractPolicy > list = new HashMap < String , AbstractPolicy > ( ) ; for ( String policyId : policyList . keySet ( ) ) { AbstractPolicy policy = policyList . get ( policyId ) ; MatchResult match = policy . match ( eval ) ; int result = match . getResult ( ) ; if ( result == MatchResult . INDETERMINATE ) { throw new TopLevelPolicyException ( match . getStatus ( ) ) ; } if ( result == MatchResult . MATCH ) { if ( m_combiningAlg == null && list . size ( ) > 0 ) { ArrayList < String > code = new ArrayList < String > ( ) ; code . add ( Status . STATUS_PROCESSING_ERROR ) ; Status status = new Status ( code , "too many applicable" + " top-level policies" ) ; throw new TopLevelPolicyException ( status ) ; } if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Matched policy: {}" , policyId ) ; } list . put ( policyId , policy ) ; } } switch ( list . size ( ) ) { case 0 : return null ; case 1 : Iterator < AbstractPolicy > i = list . values ( ) . iterator ( ) ; AbstractPolicy p = i . next ( ) ; return p ; default : return new PolicySet ( parentPolicyId , m_combiningAlg , m_target , new ArrayList < AbstractPolicy > ( list . values ( ) ) ) ; } }
Given and Evaluation Context and a list of potential policies, this
method matches each policy against the Evaluation Context and extracts
only the ones that match. If there is more than one policy, a new dynamic
policy set is created and returned. Otherwise the policy that is found is
returned.

@param eval
the Evaluation Context
@param policyList
the list of policies as a map with PolicyId as key and policy as a
byte array as the value
@return the Policy/PolicySet that applies to this EvaluationCtx
@throws {@link TopLevelPolicyException}