On Mon, Jul 26, 2010 at 5:40 AM,  <[email protected]> wrote:
> Author: bdaniel
> Date: Mon Jul 26 04:40:48 2010
> New Revision: 979157
>
> URL: http://svn.apache.org/viewvc?rev=979157&view=rev
> Log:
> Fix up appliesTo processing. Need to save each separate composite document as 
> a dom and check endpoints
>
> Modified:
>    
> tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAppliesToBuilderImpl.java
>
> Modified: 
> tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAppliesToBuilderImpl.java
> URL: 
> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAppliesToBuilderImpl.java?rev=979157&r1=979156&r2=979157&view=diff
> ==============================================================================
> --- 
> tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAppliesToBuilderImpl.java
>  (original)
> +++ 
> tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAppliesToBuilderImpl.java
>  Mon Jul 26 04:40:48 2010
> @@ -83,44 +83,47 @@ public class PolicyAppliesToBuilderImpl
>         }
>     }
>
> -    private Composite checkAppliesTo(Document document, Map<PolicySet, 
> List<PolicySubject>> appliesToSubjects, Composite composite, BuilderContext 
> context) throws Exception {
> -        // look at policies recursively
> -        for (Component component : composite.getComponents()) {
> -            Implementation implementation = component.getImplementation();
> -            if (implementation instanceof Composite) {
> -                checkAppliesTo(document, appliesToSubjects, 
> (Composite)implementation, context);
> -            }
> -        }
> +    private Composite checkAppliesTo(Document document, Map<PolicySet, 
> List<PolicySubject>> appliesToSubjects, Composite topComposite, 
> BuilderContext context) throws Exception {
> +
> +       for ( Component component : topComposite.getComponents() ) {
> +               if ( component.getImplementation() instanceof Composite ) {
> +                       Composite nested = (Composite) 
> component.getImplementation();
> +                       checkAppliesTo(saveAsDOM(nested),new 
> HashMap<PolicySet, List<PolicySubject>>(), nested, context );
> +               }
> +       }
>
> -        for (Component component : composite.getComponents()) {
> +       for (Component component : topComposite.getComponents()) {
>
> -            for (ComponentService componentService : 
> component.getServices()) {
> -                for (Endpoint ep : componentService.getEndpoints()) {
> -                    if (ep.getBinding() instanceof PolicySubject) {
> -                        checkAppliesToSubject(document, appliesToSubjects, 
> composite, (PolicySubject)ep.getBinding(), ep.getPolicySets());
> -                    }
> -                }
> -            }
> +               for (ComponentService componentService : 
> component.getServices()) {
> +                       for (Endpoint ep : componentService.getEndpoints()) {
> +                               checkAppliesToSubject(document, 
> appliesToSubjects, topComposite, (PolicySubject)ep, ep.getPolicySets());
> +                               if (ep.getBinding() instanceof PolicySubject) 
> {
> +                                       checkAppliesToSubject(document, 
> appliesToSubjects, topComposite, (PolicySubject)ep.getBinding(), 
> ep.getPolicySets());
> +                               }
> +                       }
> +               }
>
> -            for (ComponentReference componentReference : 
> component.getReferences()) {
> -                for (EndpointReference epr : 
> componentReference.getEndpointReferences()) {
> -                    if (epr.getBinding() instanceof PolicySubject) {
> -                        checkAppliesToSubject(document, appliesToSubjects, 
> composite, (PolicySubject)epr.getBinding(), epr.getPolicySets());
> -                    }
> -                }
> -            }
> +               for (ComponentReference componentReference : 
> component.getReferences()) {
> +                       for (EndpointReference epr : 
> componentReference.getEndpointReferences()) {
> +                               checkAppliesToSubject(document, 
> appliesToSubjects, topComposite, (PolicySubject)epr, epr.getPolicySets());
> +                               if (epr.getBinding() instanceof 
> PolicySubject) {
> +                                       checkAppliesToSubject(document, 
> appliesToSubjects, topComposite, (PolicySubject)epr.getBinding(), 
> epr.getPolicySets());
> +                               }
> +                       }
> +               }
>
> -            Implementation implementation = component.getImplementation();
> -            if (implementation != null &&
> -                implementation instanceof PolicySubject) {
> -                checkAppliesToSubject(document, appliesToSubjects, 
> composite, implementation, implementation.getPolicySets());
> -            }
> -        }
> -
> -        return composite;
> +               Implementation implementation = component.getImplementation();
> +               if (implementation != null &&
> +                               implementation instanceof PolicySubject) {
> +                       checkAppliesToSubject(document, appliesToSubjects, 
> topComposite, implementation, implementation.getPolicySets());
> +               }
> +       }
> +
> +        return topComposite;
>     }
>
> -    /**
> +
> +       /**
>      * Checks that all the provided policy sets apply to the provided policy 
> subject
>      *
>      * @param document
> @@ -150,7 +153,8 @@ public class PolicyAppliesToBuilderImpl
>                         Node node = nodes.item(i);
>                         String index = getStructuralURI(node);
>                         PolicySubject subject = lookup(composite, index);
> -                        subjects.add(subject);
> +                        if ( subject != null )
> +                               subjects.add(subject);
>                     }
>                 }
>             }
>
>
>

Hi Brent

A couple of questions about this change... The line that kicks off the
nested processing:

+                       checkAppliesTo(saveAsDOM(nested),new
HashMap<PolicySet, List<PolicySubject>>(), nested, context );

Now creates a new dom and an empty cache. Is this necessary. I thought
the top level DOM conversion produced a DOM for the whole hierarchy
and that the cache would then be populated for all levels in one go?

I also notice that line to check eprs and ep have been added, e.g.

> +                               checkAppliesToSubject(document, 
> appliesToSubjects, topComposite, (PolicySubject)epr, epr.getPolicySets());

I think in the case the subject that is passed in should be
epr.getReference() as the reference object will be stored in the cache
rather than the epr itself. I'll check in a fix for this part.

Regards

Simon

-- 
Apache Tuscany committer: tuscany.apache.org
Co-author of a book about Tuscany and SCA: tuscanyinaction.com

Reply via email to