You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/11/16 22:04:48 UTC

svn commit: r475927 [1/2] - in /incubator/tuscany/java/sca/kernel: core/src/main/java/org/apache/tuscany/core/loader/ core/src/main/java/org/apache/tuscany/core/policy/ core/src/test/java/org/apache/tuscany/core/loader/ core/src/test/java/org/apache/tu...

Author: jmarino
Date: Thu Nov 16 13:04:45 2006
New Revision: 475927

URL: http://svn.apache.org/viewvc?view=rev&rev=475927
Log:
[PATCH] Tuscany-927 from Felix Ren for policy support

Added:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl
    incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/policy/
    incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySet.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySetReference.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Qualifier.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WSPolicyAttachment.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/IntentRegistry.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyEngine.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicySetContainer.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SCATypeManager.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java   (with props)

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+import org.osoa.sca.annotations.Constructor;
+
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.model.IntentMap;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.PolicySet;
+import org.apache.tuscany.spi.model.PolicySetReference;
+import org.apache.tuscany.spi.model.Qualifier;
+import org.apache.tuscany.spi.model.WSPolicyAttachment;
+
+/**
+ * Loads a PolicySet definition from an SCDL file.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicySetLoader extends LoaderExtension<PolicySet> {
+
+    private static final String WSPOLICY_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+
+    private static final QName POLICYSET = new QName(XML_NAMESPACE_1_0, "policySet");
+
+    private static final QName INTENTMAP = new QName(XML_NAMESPACE_1_0, "intentMap");
+
+    private static final QName QUALIFIER = new QName(XML_NAMESPACE_1_0, "qualifier");
+
+    private static final QName POLICYSETREFERENCE = new QName(XML_NAMESPACE_1_0, "policySetReference");
+
+    private static final QName WSPOLICYATTACHMENT = new QName(WSPOLICY_NAMESPACE, "PolicyAttachment");
+
+    @Constructor({"registry"})
+    public PolicySetLoader(@Autowire LoaderRegistry registry) {
+        super(registry);
+
+    }
+
+    @Override
+    public QName getXMLType() {
+        return POLICYSET;
+    }
+
+    public PolicySet load(CompositeComponent parent, ModelObject object, XMLStreamReader reader,
+                          DeploymentContext deploymentContext)
+        throws XMLStreamException {
+        assert POLICYSET.equals(reader.getName());
+        String name = reader.getAttributeValue(null, "name");
+        String provides = reader.getAttributeValue(null, "provides");
+        String appliesTo = reader.getAttributeValue(null, "appliesTo");
+        PolicySet policySet = new PolicySet(new QName(XML_NAMESPACE_1_0, name), parseIntentName(provides));
+        String[] appliesToArtifact = split(appliesTo);
+        for (String artifact : appliesToArtifact) {
+            policySet.addAppliedArtifacts(new QName(XML_NAMESPACE_1_0, artifact));
+        }
+        while (true) {
+            switch (reader.next()) {
+                case START_ELEMENT:
+                    QName qname = reader.getName();
+                    if (INTENTMAP.equals(qname)) {
+                        policySet.addIntentMap(loadIntentMap(reader, deploymentContext));
+                    } else if (POLICYSETREFERENCE.equals(qname)) {
+                        policySet.addPolicySetReference(loadPolicyReference(reader, deploymentContext));
+                    } else if (WSPOLICYATTACHMENT.equals(qname)) {
+                        policySet.addWsPolicyAttachment(loadWSPolicyAttachment(reader, deploymentContext));
+                    }
+
+                    reader.next();
+                    break;
+                case END_ELEMENT:
+                    if (reader.getName().equals(POLICYSET)) {
+                        return policySet;
+                    }
+                    break;
+            }
+        }
+
+    }
+
+    private PolicySetReference loadPolicyReference(XMLStreamReader reader, DeploymentContext deploymentContext)
+        throws XMLStreamException {
+        assert POLICYSETREFERENCE.equals(reader.getName());
+        String name = reader.getAttributeValue(null, "name");
+        LoaderUtil.skipToEndElement(reader);
+        return new PolicySetReference(new QName(XML_NAMESPACE_1_0, name));
+    }
+
+    private IntentMap loadIntentMap(XMLStreamReader reader, DeploymentContext deploymentContext)
+        throws XMLStreamException {
+        assert INTENTMAP.equals(reader.getName());
+        String defaultIntentAttr = reader.getAttributeValue(null, "default");
+        String provides = reader.getAttributeValue(null, "provides");
+        IntentMap intentMap = new IntentMap(defaultIntentAttr, java.util.Arrays.asList(split(provides)));
+        //parentPolicySet.addIntentMap(intentMap);
+
+        while (true) {
+            switch (reader.next()) {
+                case START_ELEMENT:
+                    QName qname = reader.getName();
+                    if (QUALIFIER.equals(qname)) {
+                        intentMap.addQualifier(loadQualifier(reader, deploymentContext));
+                    }
+                    reader.next();
+                    break;
+                case END_ELEMENT:
+                    if (reader.getName().equals(INTENTMAP)) {
+                        return intentMap;
+                    }
+            }
+        }
+
+    }
+
+    private Qualifier loadQualifier(XMLStreamReader reader, DeploymentContext deploymentContext)
+        throws XMLStreamException {
+        assert QUALIFIER.equals(reader.getName());
+        String name = reader.getAttributeValue(null, "name");
+        Qualifier qualifier = new Qualifier(name);
+        while (true) {
+            switch (reader.next()) {
+                case START_ELEMENT:
+                    QName qname = reader.getName();
+                    if (INTENTMAP.equals(qname)) {
+                        qualifier.setIntentMap(loadIntentMap(reader, deploymentContext));
+                    } else if (WSPOLICYATTACHMENT.equals(qname)) {
+                        qualifier.addWsPolicyAttachment(loadWSPolicyAttachment(reader, deploymentContext));
+                    }
+                    reader.next();
+                    break;
+                case END_ELEMENT:
+                    if (reader.getName().equals(QUALIFIER)) {
+                        return qualifier;
+                    }
+            }
+        }
+
+    }
+
+    private WSPolicyAttachment loadWSPolicyAttachment(XMLStreamReader reader, DeploymentContext deploymentContext)
+        throws XMLStreamException {
+        return new WSPolicyAttachment();
+    }
+
+    /**
+     * Split a string to string array separated by " "
+     */
+    private static String[] split(String string) {
+        if (string == null) {
+            return new String[0];
+        }
+        String[] intents = string.split("[ ]+");
+        return intents;
+    }
+
+    private static List<IntentName> parseIntentName(String attributes) {
+        String[] intents = split(attributes);
+        List<IntentName> result = new ArrayList<IntentName>(intents.length);
+        for (String intent : intents) {
+            result.add(new IntentName(intent));
+        }
+        return result;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.policy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.Intent;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.policy.IntentRegistry;
+
+/**
+ * The default implementation of a data intent registry
+ */
+public class IntentRegistryImpl implements IntentRegistry {
+    private final Map<IntentName, IntentEntry> intentRepo = new HashMap<IntentName, IntentEntry>();
+
+    public Collection<IntentName> getQualifiedIntents(final IntentName qualifiable, final QName artifact) {
+        List<IntentName> result = new ArrayList<IntentName>();
+        for (IntentName intentName : intentRepo.keySet()) {
+            if (intentRepo.get(intentName).getAppliedArtifacts().contains(artifact)
+                && PolicyHelper.isQualifiedIntentFor(intentName, qualifiable, true)) {
+                result.add(intentName);
+            }
+        }
+        return result;
+    }
+
+    public Collection<IntentName> inlineProfileIntent(final Collection<IntentName> intentNameList,
+                                                      final QName artifact) {
+
+        return getConcretIntentsInternal(intentNameList, artifact);
+    }
+
+    private Collection<IntentName> getConcretIntentsInternal(final Collection<IntentName> intentNameList,
+                                                             QName artifact) {
+        List<IntentName> result = new ArrayList<IntentName>();
+        for (IntentName intentName : intentNameList) {
+            IntentEntry intentEntry = intentRepo.get(intentName);
+            if (!intentEntry.isProfileIntent()) {
+                if (intentEntry.getAppliedArtifacts().contains(artifact)) {
+                    result.add(intentEntry.getName());
+                }
+            } else {
+                result.addAll(getConcretIntentsInternal(intentEntry.getRequriedIntents(), artifact));
+            }
+        }
+        return result;
+    }
+
+    public boolean isApplicable(IntentName intentName, QName artifact) {
+        if (intentRepo.containsKey(intentName)) {
+            return intentRepo.get(intentName).getAppliedArtifacts().contains(artifact);
+        }
+        return false;
+    }
+
+    public void register(Intent intent) {
+
+        IntentEntry entry = new IntentEntry(intent);
+        // if the qualified intents have been registered, make the intent qualifiable(unqualified)
+        if (!getQualifiedIntents(intent.getName()).isEmpty()) {
+            entry.setQualified(false);
+        }
+        intentRepo.put(intent.getName(), entry);
+        List<IntentName> qualifiables = getAllQualifiableIntent(intent.getName());
+        // set qualifiable intent of this intent unqualified
+        for (IntentName qualifiable : qualifiables) {
+            IntentEntry qualifiableEntry = intentRepo.get(qualifiable);
+            qualifiableEntry.setQualified(false);
+            for (QName artifact : intent.getAppliedArtifacts()) {
+                qualifiableEntry.addAppliedArtifacts(artifact);
+            }
+        }
+    }
+
+    public void unRegister(Intent intent) {
+        if (intentRepo.containsKey(intent.getName())) {
+            IntentEntry intentEntry = intentRepo.get(intent.getName());
+            List<QName> appliedArtifacts = intent.getAppliedArtifacts();
+            for (QName artifact : appliedArtifacts) {
+                if (intentEntry.getAppliedArtifacts().contains(artifact)) {
+                    intentEntry.removeappliedArtifact(artifact);
+                }
+            }
+            if (intentEntry.getAppliedArtifacts().isEmpty()) {
+                intentRepo.remove(intent.getName());
+            }
+        }
+    }
+
+    public boolean isQualifiedIntent(IntentName name) {
+        IntentEntry intentEntry = intentRepo.get(name);
+        return intentEntry.isQualified();
+    }
+
+    private List<IntentName> getQualifiedIntents(final IntentName qualifiable) {
+        List<IntentName> result = new ArrayList<IntentName>();
+        for (IntentName intentName : intentRepo.keySet()) {
+            if (PolicyHelper.isQualifiedIntentFor(intentName, qualifiable, true)) {
+                result.add(intentName);
+            }
+        }
+        return result;
+    }
+
+    private List<IntentName> getAllQualifiableIntent(final IntentName qualified) {
+
+        List<IntentName> result = new ArrayList<IntentName>();
+        for (IntentName intentName : intentRepo.keySet()) {
+            if (PolicyHelper.isQualifiedIntentFor(qualified, intentName, false)) {
+                result.add(intentName);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Wrapper class for intent used internally
+     */
+    private static final class IntentEntry extends Intent {
+
+        /**
+         * Whether this intent is qualified, defaults to true
+         */
+        private boolean isQualified = true;
+
+        private IntentEntry(Intent intent) {
+            super(intent.getName(), intent.getDescription());
+            appliedArtifacts.addAll(intent.getAppliedArtifacts());
+            requriedIntents.addAll(intent.getRequriedIntents());
+        }
+
+        public boolean isQualified() {
+            return isQualified;
+        }
+
+        public void setQualified(boolean isQualified) {
+            this.isQualified = isQualified;
+        }
+
+        public void removeappliedArtifact(QName artifact) {
+            appliedArtifacts.remove(artifact);
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,297 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.policy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.IntentMap;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.model.PolicyContentModel;
+import org.apache.tuscany.spi.model.PolicyModel;
+import org.apache.tuscany.spi.model.PolicySet;
+import org.apache.tuscany.spi.model.PolicySetReference;
+import org.apache.tuscany.spi.model.Qualifier;
+import org.apache.tuscany.spi.policy.IntentRegistry;
+import org.apache.tuscany.spi.policy.PolicyEngine;
+import org.apache.tuscany.spi.policy.PolicySetContainer;
+import org.apache.tuscany.spi.policy.SCATypeManager;
+
+/**
+ * Default implementation of a polciy engine
+ */
+public class PolicyEngineImpl implements PolicyEngine {
+    private final IntentRegistry intentRegistry;
+    private final PolicySetContainer policySetContainer;
+    private final SCATypeManager scaTypeManager;
+
+    public PolicyEngineImpl(IntentRegistry intentRegistry,
+                            PolicySetContainer policySetContainer,
+                            SCATypeManager scaTypeManager) {
+        this.intentRegistry = intentRegistry;
+        this.policySetContainer = policySetContainer;
+        this.scaTypeManager = scaTypeManager;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Collection<PolicyModel> getPolicy(final IntentName[] requires,
+                                             final QName[] policySetNames,
+                                             final QName artifactType) {
+        if (requires == null || requires.length == 0) {
+            return Collections.EMPTY_LIST;
+        }
+        Collection<PolicyModel> result = new ArrayList<PolicyModel>();
+        Collection<IntentName> requiredIntents = java.util.Arrays.asList(requires);
+        Collection<IntentName> matchings;
+
+        //handle profile intents
+        requiredIntents = intentRegistry.inlineProfileIntent(requiredIntents, artifactType);
+        //
+        if (policySetNames != null && policySetNames.length != 0) {
+            Collection<PolicySet> explicitPolicySet = getExplicitPolicySet(policySetNames);
+            matchings = calculateExplicitPolicySet(requiredIntents, explicitPolicySet, artifactType, result);
+            //remove satisfied intent
+            requiredIntents.removeAll(matchings);
+        }
+        //
+        if (requiredIntents.size() > 0) {
+            matchings = findingAdditionalMatching(requiredIntents, artifactType, result);
+            requiredIntents.removeAll(matchings);
+        }
+        //If no collection of policySets covers all required intents, the configuration is not valid.
+        if (requiredIntents.size() > 0) {
+            //TODO
+        }
+        return result;
+    }
+
+
+    private boolean introspectPolicySet(PolicySet policySet, IntentName intent, QName artifactType,
+                                        Collection<PolicyModel> matchings) {
+        Collection<QName> appliedArtifacts = policySet.getAppliedArtifacts();
+        boolean provide = false;
+        for (QName name : appliedArtifacts) {
+            if (this.scaTypeManager.isTypeOf(artifactType, name)) {
+                provide = true;
+                break;
+            }
+        }
+        if (!provide) {
+            return false;
+        }
+        //1. The required intent matches a provides intent in a policySet exactly.
+        if (policySet.getProvideIntents().contains(intent)) {
+            if (intentRegistry.isQualifiedIntent(intent)) {
+                addMatching(matchings, policySet);
+            } else {
+                Collection<IntentMap> intentMaps = policySet.getIntentMaps();
+                provide = searchIntentMaps(intent, intent, matchings, intentMaps);
+                if (provide) {
+                    return true;
+                }
+            }
+        } else if (provideAbstract(intent, policySet.getProvideIntents())) {
+            // 2. The provides intent is a parent (e.g. prefix) of the required intent (in this case the policySet must
+            // have an intentMap entry for the requested qualifier)
+            Collection<IntentMap> intentMaps = policySet.getIntentMaps();
+            IntentName satisfiedIntent = getSatisfiedIntent(intent, policySet.getProvideIntents());
+            provide = searchIntentMaps(intent, satisfiedIntent, matchings, intentMaps);
+            if (provide) {
+                return true;
+            }
+        } else if (provideQualifier(intent, policySet.getProvideIntents())) {
+            //3.   The provides intent is more qualified than the required intent
+            if (intentRegistry.isQualifiedIntent(intent)) {
+                addMatching(matchings, policySet);
+            } else {
+                //TODO
+            }
+        }
+
+        //handle PolicySetReference
+        Collection<PolicySetReference> policySetReferences = policySet.getPolicySetReferences();
+        for (PolicySetReference reference : policySetReferences) {
+            PolicySet referencedPolicySet = policySetContainer.getPolicySet(reference.getReference());
+            if (introspectPolicySet(referencedPolicySet, intent, artifactType, matchings)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    private void addMatching(Collection<PolicyModel> matching, PolicyContentModel policy) {
+        if (!policy.getWsPolicyAttachments().isEmpty()) {
+            matching.addAll(policy.getWsPolicyAttachments());
+        }
+        if (!policy.getPolicyExtensions().isEmpty()) {
+            matching.addAll(policy.getPolicyExtensions());
+        }
+    }
+
+    private boolean searchIntentMaps(IntentName require,
+                                     IntentName satisfiedIntent,
+                                     Collection<PolicyModel> matchings,
+                                     Collection<IntentMap> intentMaps) {
+        String qualifierName = getQualifierName(require, satisfiedIntent, intentMaps);
+        for (IntentMap intentMap : intentMaps) {
+            if (intentMap.getProvideIntents().contains(qualifierName)) {
+                Collection<Qualifier> qualifiers = intentMap.getQualifiers();
+                for (Qualifier qualifier : qualifiers) {
+                    String nextQualifier = getNextQualifier(require, satisfiedIntent, intentMap);
+                    if (qualifier.getName().equals(nextQualifier)) {
+                        if (intentRegistry
+                            .isQualifiedIntent(new IntentName(satisfiedIntent.toString() + "/" + nextQualifier))) {
+                            addMatching(matchings, qualifier);
+                            return true;
+                        } else {
+                            require = new IntentName(require.toString() + "/" + intentMap.getDefaultProvideIntent());
+                            satisfiedIntent = new IntentName(satisfiedIntent.toString() + "/" + qualifierName);
+                            intentMaps = new ArrayList<IntentMap>(0);
+                            intentMaps.add(qualifier.getIntentMap());
+                            searchIntentMaps(require, satisfiedIntent, matchings, intentMaps);
+                        }
+                        break;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    private String getQualifierName(IntentName require, IntentName satisfiedIntent, Collection<IntentMap> intentMaps) {
+        String[] requrieQualifiers = require.getQualifiedNames();
+        String[] satisfiedQualifiers = satisfiedIntent.getQualifiedNames();
+        if (requrieQualifiers.length == satisfiedQualifiers.length) {
+            return requrieQualifiers[requrieQualifiers.length - 1];
+        } else if (requrieQualifiers.length > satisfiedQualifiers.length) {
+            return satisfiedQualifiers[satisfiedQualifiers.length - 1];
+        }
+        //TODO raise exception
+        return null;
+    }
+
+    private String getNextQualifier(IntentName require, IntentName satisfiedIntent, IntentMap intentMap) {
+        String[] requrieQualifiers = require.getQualifiedNames();
+        String[] satisfiedQualifiers = satisfiedIntent.getQualifiedNames();
+        if (requrieQualifiers.length > satisfiedQualifiers.length) {
+            return requrieQualifiers[satisfiedQualifiers.length];
+        } else {
+            return intentMap.getDefaultProvideIntent();
+        }
+    }
+
+    private IntentName getSatisfiedIntent(IntentName require, Collection<IntentName> provides) {
+        for (IntentName name : provides) {
+            if (PolicyHelper.isQualifiedIntentFor(require, name, true)) {
+                return name;
+            }
+        }
+        //TODO raise exception
+        return null;
+    }
+
+    private boolean provideAbstract(IntentName require, Collection<IntentName> provides) {
+        for (IntentName name : provides) {
+            if (PolicyHelper.isQualifiedIntentFor(require, name, true)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean provideQualifier(IntentName require, Collection<IntentName> provides) {
+        for (IntentName name : provides) {
+            if (PolicyHelper.isQualifiedIntentFor(name, require, true)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private Collection<PolicySet> getExplicitPolicySet(QName[] policySetNames) {
+        Collection<PolicySet> result = new ArrayList<PolicySet>();
+        for (QName policySetName : policySetNames) {
+            PolicySet set = policySetContainer.getPolicySet(policySetName);
+            if (set != null) {
+                result.add(set);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Step C. Calculate the list of explicitly specified policySets that apply to the target element as follows: 1.
+     * Start with the list of policySets specified in the element's policySet attribute. 2. If any of these explicitly
+     * listed policySets has an XPath expression in its appliesTo attribute that does not match the target element
+     * (binding or implementation) then the composite is invalid. It does not match if the XPath returns a result set
+     * that corresponds to XPath false. For example, a policySet could have appliesTo=”binding.ws/soaphttp”. This would
+     * return false if the target element is a <binding.jms…/> element. 3. Include the values of policySet attributes
+     * from ancestor elements. 4. Remove any policySet where the XPath expression in that policySet’s appliesTo
+     * attribute does not match the target element.
+     * <p/>
+     *
+     * @param requires
+     * @param policies
+     * @return intent names was satisfied by this step.
+     */
+    private Collection<IntentName> calculateExplicitPolicySet(Collection<IntentName> requires,
+                                                              Collection<PolicySet> policies,
+                                                              QName artifactType,
+                                                              Collection<PolicyModel> matchings) {
+        Collection<IntentName> satisfied = new ArrayList<IntentName>();
+        for (IntentName intent : requires) {
+            for (PolicySet policySet : policies) {
+                if (introspectPolicySet(policySet, intent, artifactType, matchings)) {
+                    satisfied.add(intent);
+                }
+            }
+        }
+        return satisfied;
+    }
+
+    /**
+     * * The remaining required intents, if any, are provided by finding additional matching policySets within the SCA
+     * system. E. Choose the smallest collection of these policySets that match all remaining required intents. A
+     * policySet matches a required intent if any of the following are true: 1. The required intent matches a provides
+     * intent in a policySet exactly. 2. The provides intent is a parent (e.g. prefix) of the required intent (in this
+     * case the policySet must have an intentMap entry for the requested qualifier) 3. The provides intent is more
+     * qualified than the required intent All intents should now be satisfied.
+     *
+     * @param remainings
+     * @param artifactType
+     * @param matchings
+     */
+    private Collection<IntentName> findingAdditionalMatching(final Collection<IntentName> remainings,
+                                                             QName artifactType,
+                                                             Collection<PolicyModel> matchings) {
+        Collection<IntentName> satisfied = new ArrayList<IntentName>();
+        Collection<PolicySet> policies = this.policySetContainer.getAllPolicySet();
+        for (IntentName intent : remainings) {
+            for (PolicySet policySet : policies) {
+                if (introspectPolicySet(policySet, intent, artifactType, matchings)) {
+                    satisfied.add(intent);
+                }
+            }
+        }
+        return satisfied;
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.policy;
+
+import org.apache.tuscany.spi.model.IntentName;
+
+/**
+ * Contains utility methods for dealing with policies
+ */
+public final class PolicyHelper {
+
+    private PolicyHelper() {
+    }
+
+    /**
+     * Whether <code>qualified</code> is qualified intent for <code>qualifiable</code>
+     * <p/>
+     * For example: sec.confidentiality/message is direct qualifier for sec.confidentiality.
+     * sec.confidentiality/message/body is qualifier for sec.confidentiality, but not a direct qualifier
+     *
+     * @param qualified   qualified intent name
+     * @param qualifiable qualifiable intent name
+     * @param direct      indicate whether to expect <code>qualified</code> is direct qualified intent for
+     *                    <code>qualifiable</code>
+     * @return whether <code>qualified</code> is qualified intent for <code>qualifiable</code>
+     */
+    public static boolean isQualifiedIntentFor(final IntentName qualified,
+                                               final IntentName qualifiable,
+                                               boolean direct) {
+        if (qualified.equals(qualifiable) || !qualified.getDomain().equals(qualifiable.getDomain())) {
+            return false;
+        }
+        boolean result = true;
+        String[] shortArray = qualifiable.getQualifiedNames();
+        String[] longArray = qualified.getQualifiedNames();
+        if (longArray.length - shortArray.length < 1 && !direct) {
+            return false;
+        } else if (direct && longArray.length - shortArray.length != 1) {
+            return false;
+        }
+        for (int i = 0; i < shortArray.length; i++) {
+            if (!shortArray[i].equals(longArray[i])) {
+                result = false;
+                break;
+            }
+        }
+        return result;
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.util.Collection;
+import java.util.Iterator;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import org.apache.tuscany.spi.model.IntentMap;
+import org.apache.tuscany.spi.model.PolicySet;
+import org.apache.tuscany.spi.model.Qualifier;
+
+import junit.framework.TestCase;
+
+public class PolicySetLoaderTestCase extends TestCase {
+    private static final QName POLICYSET = new QName(XML_NAMESPACE_1_0, "policySet");
+
+    public void testLoader() throws Exception {
+        PolicySetLoader loader = new PolicySetLoader(null);
+        XMLInputFactory factory = XMLInputFactory.newInstance();
+        XMLStreamReader reader = factory.createXMLStreamReader(this.getClass().getResourceAsStream("testPolicy.scdl"));
+        while (true) {
+            int state = reader.next();
+            if (START_ELEMENT == state && reader.getName().equals(POLICYSET)) {
+                break;
+            }
+        }
+        PolicySet policySet = loader.load(null, null, reader, null);
+        assertNotNull(policySet);
+        assertEquals(2, policySet.getAppliedArtifacts().size());
+        assertTrue(policySet.getAppliedArtifacts().contains(new QName(XML_NAMESPACE_1_0, "binding.ws")));
+        assertTrue(policySet.getAppliedArtifacts().contains(new QName(XML_NAMESPACE_1_0, "binding.jms")));
+        Collection<IntentMap> intentMaps = policySet.getIntentMaps();
+        assertEquals(1, intentMaps.size());
+        IntentMap intentMap = intentMaps.iterator().next();
+        assertEquals("transport", intentMap.getDefaultProvideIntent());
+        assertTrue(intentMap.getProvideIntents().contains("sec.confidentiality"));
+        Collection<Qualifier> qualifiers = intentMap.getQualifiers();
+        assertEquals(2, qualifiers.size());
+        Iterator qit = qualifiers.iterator();
+        Qualifier qualifier1 = (Qualifier) qit.next();
+        assertEquals(2, qualifier1.getWsPolicyAttachments().size());
+        assertEquals("transport", qualifier1.getName());
+        Qualifier qualifier2 = (Qualifier) qit.next();
+        assertEquals("message", qualifier2.getName());
+        IntentMap messageMap = qualifier2.getIntentMap();
+        assertEquals(2, messageMap.getQualifiers().size());
+
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.policy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import javax.xml.namespace.QName;
+
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import org.apache.tuscany.spi.model.Intent;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.policy.IntentRegistry;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IntentRegistryImplTestCase extends TestCase {
+    private static final QName WS_BINDING = new QName(XML_NAMESPACE_1_0, "binding.ws");
+    private static final QName JMS_BINDING = new QName(XML_NAMESPACE_1_0, "binding.jms");
+    private IntentRegistry intentReg;
+
+    @Override
+    protected void setUp() throws Exception {
+        intentReg = new IntentRegistryImpl();
+
+        Intent bodyintent = new Intent(new IntentName("sec.confidentiality/message/body"), "test");
+        bodyintent.addAppliedArtifacts(WS_BINDING);
+        bodyintent.addAppliedArtifacts(JMS_BINDING);
+        intentReg.register(bodyintent);
+
+        Intent headintent = new Intent(new IntentName("sec.confidentiality/message/head"), "test");
+        headintent.addAppliedArtifacts(WS_BINDING);
+        headintent.addAppliedArtifacts(JMS_BINDING);
+        intentReg.register(headintent);
+
+        Intent confidentialityintent = new Intent(new IntentName("sec.confidentiality"), "test");
+        confidentialityintent.addAppliedArtifacts(WS_BINDING);
+        confidentialityintent.addAppliedArtifacts(JMS_BINDING);
+        intentReg.register(confidentialityintent);
+
+        Intent messageintent = new Intent(new IntentName("sec.confidentiality/message"), null);
+        messageintent.addAppliedArtifacts(WS_BINDING);
+        messageintent.addAppliedArtifacts(JMS_BINDING);
+        intentReg.register(messageintent);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        intentReg = null;
+    }
+
+//    public void testGetQualifiedIntent() {
+//        List<IntentName> intentNameList = new ArrayList<IntentName>();
+//        intentReg.get
+//        //intentReg.getConcretIntents(intentNameList, artifact)
+//    }
+
+    public void testGetConcretIntents() {
+        Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+        messageintent.addAppliedArtifacts(WS_BINDING);
+        messageintent.addAppliedArtifacts(JMS_BINDING);
+        intentReg.register(messageintent);
+
+        Intent allintent = new Intent(new IntentName("sec.confidentiality/all"), null);
+        allintent.addAppliedArtifacts(WS_BINDING);
+        allintent.addRequriedIntents(new IntentName("sec.confidentiality/message"));
+        allintent.addRequriedIntents(new IntentName("sec.confidentiality/transport"));
+
+
+        intentReg.register(allintent);
+        List<IntentName> intents = new ArrayList<IntentName>();
+        intents.add(new IntentName("sec.confidentiality/all"));
+        Collection<IntentName> concreteIntents = intentReg.inlineProfileIntent(intents, WS_BINDING);
+        assertEquals(2, concreteIntents.size());
+        assertTrue(concreteIntents.contains(new IntentName("sec.confidentiality/message")));
+        assertTrue(concreteIntents.contains(new IntentName("sec.confidentiality/transport")));
+        //fail("Not yet implemented");
+    }
+
+    public void testGetQualifiedIntents() {
+        IntentName message = new IntentName("sec.confidentiality/message");
+        Collection<IntentName> qualifiedIntents = intentReg.getQualifiedIntents(message, JMS_BINDING);
+        assertEquals(2, qualifiedIntents.size());
+        assertTrue(qualifiedIntents.contains(new IntentName("sec.confidentiality/message/body")));
+        assertTrue(qualifiedIntents.contains(new IntentName("sec.confidentiality/message/head")));
+        assertFalse(qualifiedIntents.contains(new IntentName("sec.confidentiality/message")));
+        assertFalse(qualifiedIntents.contains(new IntentName("sec.confidentiality")));
+    }
+
+    public void testIsApplicable() {
+        assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/message"), WS_BINDING));
+        assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING));
+        assertFalse(intentReg.isApplicable(new IntentName("test.confidentiality/transport"), WS_BINDING));
+    }
+
+    public void testRegister() {
+        Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+        messageintent.addAppliedArtifacts(WS_BINDING);
+        messageintent.addAppliedArtifacts(JMS_BINDING);
+        intentReg.register(messageintent);
+        assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING));
+        assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), JMS_BINDING));
+
+    }
+
+    public void testIsQualifiedIntent() {
+        Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+        messageintent.addAppliedArtifacts(WS_BINDING);
+        messageintent.addAppliedArtifacts(JMS_BINDING);
+        intentReg.register(messageintent);
+        Intent allintent = new Intent(new IntentName("sec.confidentiality/all"), null);
+        allintent.addAppliedArtifacts(WS_BINDING);
+
+        assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/transport")));
+        assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message/body")));
+        assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message/body")));
+        assertFalse(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message")));
+        assertFalse(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality")));
+    }
+
+    public void testUnRegister() {
+        Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+        messageintent.addAppliedArtifacts(WS_BINDING);
+        messageintent.addAppliedArtifacts(JMS_BINDING);
+        intentReg.register(messageintent);
+        intentReg.unRegister(messageintent);
+        assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING));
+        assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), JMS_BINDING));
+
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.policy;
+
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import org.apache.tuscany.spi.model.Intent;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.model.PolicyModel;
+import org.apache.tuscany.spi.model.PolicySet;
+import org.apache.tuscany.spi.policy.IntentRegistry;
+import org.apache.tuscany.spi.policy.PolicyEngine;
+import org.apache.tuscany.spi.policy.PolicySetContainer;
+import org.apache.tuscany.spi.policy.SCATypeManager;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.loader.PolicySetLoader;
+
+public class PolicyEngineImplTestCase extends TestCase {
+    private static final QName POLICYSET = new QName(XML_NAMESPACE_1_0, "policySet");
+    private static final QName WS_BINDING = new QName(XML_NAMESPACE_1_0, "binding.ws");
+    private IntentRegistry intentReg;
+    private PolicyEngine policyEngine;
+
+
+    public void testgetPolicy() throws Exception {
+        Collection<PolicyModel> policies =
+            policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication/cert")}, null, WS_BINDING);
+        assertEquals(2, policies.size());
+        policies =
+            policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication/basic")}, null, WS_BINDING);
+        assertEquals(1, policies.size());
+
+        //test for unqualified intent with default value on intentMap
+        policies = policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication")}, null, WS_BINDING);
+        assertEquals(2, policies.size());
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        PolicySetLoader loader = new PolicySetLoader(null);
+        XMLInputFactory factory = XMLInputFactory.newInstance();
+        InputStream resourceAsStream = this.getClass().getResourceAsStream("PolicySet.scdl");
+        XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
+        PolicySetContainerImpl psc = new PolicySetContainerImpl();
+        while (true) {
+            int state = reader.next();
+            if (state == XMLStreamConstants.END_DOCUMENT) {
+                break;
+            }
+            if (XMLStreamConstants.START_ELEMENT == state && reader.getName().equals(POLICYSET)) {
+                psc.addPolicySet(loader.load(null, null, reader, null));
+            }
+
+        }
+        resourceAsStream.close();
+        intentReg = new IntentRegistryImpl();
+        policyEngine = new PolicyEngineImpl(intentReg, psc, new SCATypeManagerImpl());
+
+        Intent bodyintent = new Intent(new IntentName("sec.confidentiality/message/body"), "test");
+        bodyintent.addAppliedArtifacts(WS_BINDING);
+        intentReg.register(bodyintent);
+
+        Intent allintent = new Intent(new IntentName("sec.confidentiality/message/all"), "test");
+        allintent.addAppliedArtifacts(WS_BINDING);
+        intentReg.register(allintent);
+
+        Intent confidentialityintent = new Intent(new IntentName("sec.confidentiality"), "test");
+        confidentialityintent.addAppliedArtifacts(WS_BINDING);
+        intentReg.register(confidentialityintent);
+
+        Intent messageintent = new Intent(new IntentName("sec.confidentiality/message"), null);
+        messageintent.addAppliedArtifacts(WS_BINDING);
+        intentReg.register(messageintent);
+
+        Intent authintent = new Intent(new IntentName("sec.authentication"), null);
+        authintent.addAppliedArtifacts(WS_BINDING);
+        intentReg.register(authintent);
+
+        Intent certintent = new Intent(new IntentName("sec.authentication/cert"), null);
+        certintent.addAppliedArtifacts(WS_BINDING);
+        intentReg.register(certintent);
+
+        Intent basicintent = new Intent(new IntentName("sec.authentication/basic"), null);
+        basicintent.addAppliedArtifacts(WS_BINDING);
+        intentReg.register(basicintent);
+
+    }
+
+    private class PolicySetContainerImpl implements PolicySetContainer {
+
+        private Map<QName, PolicySet> sets = new HashMap<QName, PolicySet>();
+
+        public Collection<PolicySet> getAllPolicySet() {
+            return sets.values();
+        }
+
+        public PolicySet getPolicySet(QName name) {
+            return sets.get(name);
+        }
+
+        public void addPolicySet(PolicySet pset) {
+            sets.put(pset.getName(), pset);
+        }
+
+    }
+
+    private class SCATypeManagerImpl implements SCATypeManager {
+
+        public boolean isTypeOf(QName subType, QName type) {
+            return subType.equals(type);
+        }
+
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl Thu Nov 16 13:04:45 2006
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+	* Licensed to the Apache Software Foundation (ASF) under one
+	* or more contributor license agreements.  See the NOTICE file
+	* distributed with this work for additional information
+	* regarding copyright ownership.  The ASF licenses this file
+	* to you under the Apache License, Version 2.0 (the
+	* "License"); you may not use this file except in compliance
+	* with the License.  You may obtain a copy of the License at
+	*
+	*   http://www.apache.org/licenses/LICENSE-2.0
+	*
+	* Unless required by applicable law or agreed to in writing,
+	* software distributed under the License is distributed on an
+	* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	* KIND, either express or implied.  See the License for the
+	* specific language governing permissions and limitations
+	* under the License.
+-->
+<!--
+	Default system configuration for the launcher environment.
+
+	$Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+           xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+           xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+           name="org.apache.tuscany.core.policy.testCase">
+    <policySet name="BasicAuthMsgProtSecurity"
+               provides="sec.confidentiality" appliesTo="binding.ws binding.jms"
+               xmlns="http://www.osoa.org/xmlns/sca/1.0">
+        <wsp:PolicyAttachment/>
+        <intentMap provides="sec.confidentiality" default="transport">
+            <qualifier name="transport">
+                <wsp:PolicyAttachment/>
+                <wsp:PolicyAttachment/>
+            </qualifier>
+            <qualifier name="message">
+                <intentMap provides="sec.confidentiality/message"
+                           default="all">
+                    <qualifier name="all">
+                        <wsp:PolicyAttachment/>
+                    </qualifier>
+                    <qualifier name="body">
+                        <wsp:PolicyAttachment/>
+                    </qualifier>
+                </intentMap>
+            </qualifier>
+        </intentMap>
+    </policySet>
+</composite>
\ No newline at end of file

Added: incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl Thu Nov 16 13:04:45 2006
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+	* Licensed to the Apache Software Foundation (ASF) under one
+	* or more contributor license agreements.  See the NOTICE file
+	* distributed with this work for additional information
+	* regarding copyright ownership.  The ASF licenses this file
+	* to you under the Apache License, Version 2.0 (the
+	* "License"); you may not use this file except in compliance
+	* with the License.  You may obtain a copy of the License at
+	*
+	*   http://www.apache.org/licenses/LICENSE-2.0
+	*
+	* Unless required by applicable law or agreed to in writing,
+	* software distributed under the License is distributed on an
+	* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	* KIND, either express or implied.  See the License for the
+	* specific language governing permissions and limitations
+	* under the License.
+-->
+<!--
+	Default system configuration for the launcher environment.
+
+	$Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+           xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+           xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+           name="org.apache.tuscany.core.policy.testCase">
+    <policySet name="BasicMsgProtSecurity"
+               provides="sec.confidentiality" appliesTo="binding.ws binding.jms"
+               xmlns="http://www.osoa.org/xmlns/sca/1.0">
+        <wsp:PolicyAttachment/>
+        <intentMap provides="sec.confidentiality" default="transport">
+            <qualifier name="transport">
+                <wsp:PolicyAttachment/>
+                <wsp:PolicyAttachment/>
+            </qualifier>
+            <qualifier name="message">
+                <intentMap provides="sec.confidentiality/message"
+                           default="all">
+                    <qualifier name="all">
+                        <wsp:PolicyAttachment/>
+                    </qualifier>
+                    <qualifier name="body">
+                        <wsp:PolicyAttachment/>
+                    </qualifier>
+                </intentMap>
+            </qualifier>
+        </intentMap>
+    </policySet>
+
+    <policySet name="Authentication"
+               provides="sec.authentication" appliesTo="binding.ws binding.jms">
+        <wsp:PolicyAttachment/>
+        <intentMap provides="authentication" default="cert">
+            <qualifier name="cert">
+                <wsp:PolicyAttachment/>
+                <wsp:PolicyAttachment/>
+            </qualifier>
+            <qualifier name="basic">
+                <wsp:PolicyAttachment/>
+            </qualifier>
+        </intentMap>
+    </policySet>
+
+</composite>
\ No newline at end of file

Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.util.ArrayList;
+import static java.util.Collections.unmodifiableList;
+import java.util.List;
+import javax.xml.namespace.QName;
+
+/**
+ * Model representation for intent. This class is used by intent loader only, other SCA model classes will not reference
+ * this class directly.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Intent {
+
+    /**
+     * name of intent.
+     */
+    protected IntentName name;
+
+    /**
+     * Description for this intent
+     */
+    protected String description;
+
+    /**
+     * QNames of artifacts this intent can apply to
+     */
+    protected List<QName> appliedArtifacts = new ArrayList<QName>();
+
+    /**
+     * intents required by this intent, only useful when this intent is a profile intent
+     */
+    protected List<IntentName> requriedIntents = new ArrayList<IntentName>();
+
+    /**
+     * Create a policy intent.
+     *
+     * @param name        name of the intent.
+     * @param description description of the intent.
+     */
+    public Intent(IntentName name, String description) {
+        this.name = name;
+        this.description = description;
+    }
+
+    public List<QName> getAppliedArtifacts() {
+        return unmodifiableList(appliedArtifacts);
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public IntentName getName() {
+        return name;
+    }
+
+    public List<IntentName> getRequriedIntents() {
+        return unmodifiableList(requriedIntents);
+    }
+
+    public void addRequriedIntents(IntentName intent) {
+        requriedIntents.add(intent);
+    }
+
+    public void addAppliedArtifacts(QName artifactName) {
+        appliedArtifacts.add(artifactName);
+    }
+
+    public boolean isProfileIntent() {
+        return !requriedIntents.isEmpty();
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import static java.util.Collections.unmodifiableCollection;
+
+/**
+ * Represents an IntentMap within PolicySet.
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntentMap extends PolicyModel {
+
+    /*  Name of default intent provied by this IntentMap */
+    private String defaultProvideIntent;
+
+    /* Name of intent provided by this IntentMap */
+    private Collection<String> provideIntents = new ArrayList<String>();
+
+    /* Qualifiers of this IntentMap */
+    private Collection<Qualifier> qualifiers = new ArrayList<Qualifier>();
+
+    public IntentMap(String defaultProvideIntent, Collection<String> provideIntents) {
+        super();
+        this.defaultProvideIntent = defaultProvideIntent;
+        this.provideIntents.addAll(provideIntents);
+    }
+
+    public Collection<String> getProvideIntents() {
+        return unmodifiableCollection(provideIntents);
+    }
+
+    public void addQualifier(Qualifier qualifier) {
+        qualifiers.add(qualifier);
+    }
+
+    public Collection<Qualifier> getQualifiers() {
+        return unmodifiableCollection(qualifiers);
+    }
+
+    public String getDefaultProvideIntent() {
+        return defaultProvideIntent;
+    }
+
+
+}

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.util.Arrays;
+
+/**
+ * Model class represents a name of a intent. An intent name has a domain name and one or more qualified names. For
+ * example, in "sec.confidentiality/message/body", the domain name is sec, and the qualified names are confidentiality,
+ * message and body
+ */
+@SuppressWarnings({"SerializableHasSerializationMethods"})
+public class IntentName implements java.io.Serializable {
+    private static final String QUALIFIED_SEPARATOR = "/";
+    private static final String DOMAIN_SEPARATOR = ".";
+    private static final long serialVersionUID = -7030021353149084879L;
+
+    /**
+     * domain of the intent
+     */
+    private String domain;
+
+    private String[] qualifiedNames;
+
+    /**
+     * Construct a IntentName from a string representation.
+     *
+     * @param intent string representation for a intent.
+     */
+    public IntentName(String intent) {
+        parse(intent);
+    }
+
+    /**
+     * Construct a IntentName from domain name and qualified names
+     *
+     * @param domain         domain name of the intent
+     * @param qualifiedNames qualified names of the intent
+     */
+    public IntentName(String domain, String[] qualifiedNames) {
+        this.domain = domain;
+        this.qualifiedNames = qualifiedNames;
+    }
+
+    public String getDomain() {
+        return domain;
+    }
+
+    public String[] getQualifiedNames() {
+        String[] results = new String[qualifiedNames.length];
+        System.arraycopy(qualifiedNames, 0, results, 0, qualifiedNames.length);
+        return results;
+    }
+
+    @Override
+    public String toString() {
+        return getName();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final IntentName other = (IntentName) obj;
+        if (domain == null) {
+            if (other.domain != null) {
+                return false;
+            }
+        } else if (!domain.equals(other.domain)) {
+            return false;
+        }
+        return Arrays.equals(qualifiedNames, other.qualifiedNames);
+    }
+
+    @Override
+    public int hashCode() {
+        final int PRIME = 17;
+        int result = 1;
+        result = PRIME * result + ((domain == null) ? 0 : domain.hashCode());
+        result = PRIME * result + Arrays.hashCode(qualifiedNames);
+        return result;
+    }
+
+    private String getName() {
+        StringBuilder sbd = new StringBuilder(domain);
+        for (int i = 0; i < qualifiedNames.length; i++) {
+            if (i == 0) {
+                sbd.append(DOMAIN_SEPARATOR);
+            } else {
+                sbd.append(QUALIFIED_SEPARATOR);
+            }
+            sbd.append(qualifiedNames[i]);
+        }
+
+        return sbd.toString();
+    }
+
+    /**
+     * Parse a string representation of intent.
+     *
+     * @param intent string representation of intent
+     */
+    private void parse(String intent) {
+        String iname = validateFormat(intent);
+        int domainIdx = iname.indexOf(DOMAIN_SEPARATOR);
+        domain = iname.substring(0, domainIdx);
+        String qualifNamesStr = iname.substring(domainIdx + 1);
+        qualifiedNames = qualifNamesStr.split(QUALIFIED_SEPARATOR);
+
+    }
+
+    private String validateFormat(String intent) {
+        // TODO validate and canonicalize intent name
+        return intent;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,21 @@
+package org.apache.tuscany.spi.model;
+
+import java.util.Collection;
+/**
+*
+* Represents capability of being attached with Intent and PolicySet.
+*
+*/
+public interface PolicyAttachable {
+    /**
+     * Get the name of PolicySet attached
+     * @return the name of PolicySet
+     */
+    String getPolicySet();
+    /**
+     * Get collection contains <code>IntentName</code> required.
+     * @return collection contains <code>IntentName</code> required.
+     */
+    Collection<IntentName> getRequiredIntents();
+
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.util.Collection;
+
+/**
+ * Base class for model classes which can be associated with Intent and PolicySet by specifing requires and policySet
+ * attributes on xml element.
+ */
+
+public abstract class PolicyAttachableModel extends ModelObject implements PolicyAttachable {
+    protected Collection<IntentName> requiredIntent;
+    protected String policySet;
+
+    public String getPolicySet() {
+        return policySet;
+    }
+
+    public void setPolicySet(String policySet) {
+        this.policySet = policySet;
+    }
+
+    public Collection<IntentName> getRequiredIntents() {
+        return requiredIntent;
+    }
+
+    public void addRequiredIntent(IntentName requiredIntent) {
+        this.requiredIntent.add(requiredIntent);
+    }
+
+
+}

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import static java.util.Collections.unmodifiableCollection;
+
+/**
+ * PolicyModel which contains concrete policy content in form of WSPolicyAttachment or other extensions.
+ */
+public abstract class PolicyContentModel extends PolicyModel {
+    /* WSPolicyAttachment contained in this Model */
+    protected Collection<WSPolicyAttachment> wsPolicyAttachments = new ArrayList<WSPolicyAttachment>();
+    /* Any policy model extensions besides standard intentMap, ws-policyattachment, etc. */
+    protected Collection<PolicyModel> extensions = new ArrayList<PolicyModel>();
+
+    public Collection<PolicyModel> getPolicyExtensions() {
+        return extensions;
+    }
+
+    public Collection<WSPolicyAttachment> getWsPolicyAttachments() {
+        return unmodifiableCollection(wsPolicyAttachments);
+    }
+
+    public void addWsPolicyAttachment(WSPolicyAttachment attachment) {
+        wsPolicyAttachments.add(attachment);
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java?view=auto&rev=475927
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java Thu Nov 16 13:04:45 2006
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+
+/**
+ * An abstract base class for all policy model representations.
+ * <p/>
+ * $Version$ $Date$
+ */
+public abstract class PolicyModel extends ModelObject {
+
+}

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Re: Patch from Felix for Policy support - commit: r475927

Posted by Felix Ren <re...@gmail.com>.
Hi Jim,

See replay inline.

On 11/17/06, Jim Marino <jm...@myromatours.com> wrote:
> Hi Felix,
>
> I committed your patch for Tuscany-927. Thanks a lot! I reformatted
> it slightly to pass checkstyle. On the QName, issue, yes we can add
> those to SCAObject but perhaps we should add it to PolicyAttachable
> instead since not all SCAObjects may have QNames?
>
Agreed, adding to PolicyAttachable(Model class ) is better than adding
to SCAObject. We will make PolicyAttachableObject the base classes for
other Model class which can be associated with policy via @requries
and/or @policySet attribute, when loaders execute, they should set the
values of require intent and policy set name. I still have a question
regarding this, in policy framework spec, it says,
1.4.2 Usage of @requires attribute for specifying intents
Stating intents with the @requires attribute of an element means that
those intents are additionally required by every relevant element
descendent.  For example, specifying requires="confidentiality" on a
<composite> element is the equivalent to adding that same intent to
the @requires list of every service and reference that is contained
within that composite, including the services and references inside
components.

So when we want to get the intent name required by an SCA model class
(or SCAObject, I'm not sure yet), we need to access the model classes
of the every element which are ancestor of the element. But the Model
classes do not have a hierarchy and SCAObject's hierarchy highly
depends on implementation of the SCAObject, it is not easy to get the
ancestor's model classes, any hint?

> A  couple of small comments:
>
> 1. Do you think it would be better to name PolicyModel "PolicyObject"
> since it is an object that pertains to policies as opposed to a model
> for them?
>
Agreed, I renamed it to "PolicyObject".

> 2. I noticed the is a comment on Intent which says that class is not
> referenced by model objects but it is in the "model" package. Should
> this class get moved under  the same package as IntentRegistry?
>
Yes, agreed.
> For next steps, let's see if we can start getting the policy
> infrastructure hooked into the runtime.

Yes, I'm considering this. Another problem is how we keep the scope of
intents.xml. My previous thought was to add an URL that points to
intents.xml to TuscanyRuntime, but Michael suggested that we'd better
not require the user specify a URI, for in the current policy
framework design it says that there is one top-level intents.xml file
per SCA "system". There is an issue about scope of intents.xml in spec
v0502. We may need a more flexible solution, any suggestion?

Thanks,
Felix


> Jim
>
>


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Patch from Felix for Policy support - commit: r475927

Posted by Jim Marino <jm...@myromatours.com>.
Hi Felix,

I committed your patch for Tuscany-927. Thanks a lot! I reformatted  
it slightly to pass checkstyle. On the QName, issue, yes we can add  
those to SCAObject but perhaps we should add it to PolicyAttachable  
instead since not all SCAObjects may have QNames?

A  couple of small comments:

1. Do you think it would be better to name PolicyModel "PolicyObject"  
since it is an object that pertains to policies as opposed to a model  
for them?

2. I noticed the is a comment on Intent which says that class is not  
referenced by model objects but it is in the "model" package. Should  
this class get moved under  the same package as IntentRegistry?


For next steps, let's see if we can start getting the policy  
infrastructure hooked into the runtime.

Jim
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org