You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sv...@apache.org on 2008/04/21 09:00:28 UTC
svn commit: r650027 - in
/incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy:
Intent.java impl/IntentImpl.java util/PolicyComputationUtils.java
Author: svkrish
Date: Mon Apr 21 00:00:27 2008
New Revision: 650027
URL: http://svn.apache.org/viewvc?rev=650027&view=rev
Log:
https://issues.apache.org/jira/browse/TUSCANY-2239
Modified:
incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java
incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java
incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java
Modified: incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java?rev=650027&r1=650026&r2=650027&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java (original)
+++ incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java Mon Apr 21 00:00:27 2008
@@ -70,6 +70,13 @@
List<QName> getConstrains();
/**
+ * Returns the list of intents which are mutually exclusive with this intent.
+ *
+ * @return the list of mutually exclusive intents.
+ */
+ List<Intent> getExcludedIntents();
+
+ /**
* Returns the list of children qualified intents.
*
* @return the list of children qualified intents.
Modified: incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java?rev=650027&r1=650026&r2=650027&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java (original)
+++ incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java Mon Apr 21 00:00:27 2008
@@ -40,6 +40,7 @@
private String description;
private List<Intent> qualifiedIntents = new ArrayList<Intent>();
// private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private List<Intent> excludedIntents = new ArrayList<Intent>();
private boolean unresolved = true;
private String domain;
private String[] qualifiedNames;
@@ -92,6 +93,10 @@
public List<Intent> getQualifiedIntents() {
return qualifiedIntents;
+ }
+
+ public List<Intent> getExcludedIntents() {
+ return excludedIntents;
}
public boolean isUnresolved() {
Modified: incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java?rev=650027&r1=650026&r2=650027&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java (original)
+++ incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java Mon Apr 21 00:00:27 2008
@@ -28,8 +28,10 @@
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;
@@ -47,7 +49,10 @@
import javax.xml.xpath.XPathExpressionException;
import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.ProfileIntent;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -63,7 +68,15 @@
private static String POLICY_SETS_ATTR = "policySets";
private static String APPLICABLE_POLICYSET_ATTR_PREFIX = "tuscany";
private static String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
-
+
+ /**
+ * This method unconditionally adds intents from the source list to the target list.
+ * It is used for intermediate intent inheritance between promotion levels
+ * (e.g. between a composite service and a component service). It does not check
+ * whether there are conflicting (mutually exclusive) intents. This is because
+ * promotion cannot override intents. If the resulting target list has conflicting
+ * intents, this will be detected later during policy computation.
+ */
public static void addInheritedIntents(List<Intent> sourceList, List<Intent> targetList) {
if (sourceList != null) {
targetList.addAll(sourceList);
@@ -96,6 +109,122 @@
} else {
targetList.addAll(sourceList);
}
+ }
+
+ /**
+ * This method is used to inherit intents and policy sets between hierarchical levels
+ * within the same composite (e.g. between a component and its services and references).
+ * In this case the source intents and policy sets provide defaults which are inherited
+ * into the target lists only when there is no conflict. For example consider a component
+ * with 3 references. The component level requires intent 'propagatesTransaction'.
+ * Reference 1 and 2 do not specify an intent, but reference 3 requires 'suspendsTransaction'.
+ * In this case the 'propagatesTransaction' intent is inherited by reference 1 and 2
+ * but not by reference 3.
+ */
+ public static void addDefaultPolicies(List<Intent> sourceIntents,
+ List<PolicySet> sourcePolicySets,
+ List<Intent> targetIntents,
+ List<PolicySet> targetPolicySets)
+ {
+ // form a list of all intents required by the target
+ List<Intent> combinedTargetIntents = new ArrayList<Intent>();
+ combinedTargetIntents.addAll(findAndExpandProfileIntents(targetIntents));
+ for (PolicySet targetPolicySet : targetPolicySets) {
+ combinedTargetIntents.addAll(findAndExpandProfileIntents(targetPolicySet.getProvidedIntents()));
+ }
+
+ // inherit intents in the source list that do not conflict with intents already in the target list
+ for (Intent sourceIntent : findAndExpandProfileIntents(sourceIntents)) {
+ boolean conflict = false;
+ for (Intent excluded : sourceIntent.getExcludedIntents()) {
+ if (combinedTargetIntents.contains(excluded)) {
+ conflict = true;
+ break;
+ }
+ }
+ if (!conflict) {
+ targetIntents.add(sourceIntent);
+ }
+ }
+
+ // inherit policy sets in the source list that do not conflict with policy sets or intents
+ // in the target list
+ for (PolicySet sourcePolicySet : sourcePolicySets) {
+ boolean conflict = false;
+ List<Intent> providedIntents = findAndExpandProfileIntents(sourcePolicySet.getProvidedIntents());
+ checkConflict: for (Intent intent : providedIntents) {
+ for (Intent excluded : intent.getExcludedIntents()) {
+ if (combinedTargetIntents.contains(excluded)) {
+ conflict = true;
+ break checkConflict;
+ }
+ }
+ }
+ if (!conflict)
+ targetPolicySets.add(sourcePolicySet);
+ }
+
+ }
+
+ public static void checkForMutuallyExclusiveIntents(
+ List<Intent> intents,
+ List<PolicySet> policySets,
+ IntentAttachPointType intentAttachPointType,
+ String id) throws PolicyValidationException
+ {
+ // gather all intents (keeping track of where they come from)
+ Map<Intent, PolicySet> combinedIntents = new HashMap<Intent,PolicySet>();
+ for (PolicySet policySet : policySets) {
+ for (Intent providedIntent : findAndExpandProfileIntents(policySet.getProvidedIntents())) {
+ combinedIntents.put(providedIntent, policySet);
+ }
+ }
+ for (Intent intent : intents) {
+ combinedIntents.put(intent, null);
+ }
+
+ // check for conflicts
+ for (Intent intent : combinedIntents.keySet()) {
+ for (Intent excluded : intent.getExcludedIntents()) {
+ if (combinedIntents.keySet().contains(excluded)) {
+ String sIntent1, sIntent2;
+ if (combinedIntents.get(intent) == null)
+ sIntent1 = intent.getName().toString();
+ else
+ sIntent1 = intent.getName().toString() + " in policy set " + combinedIntents.get(intent).getName().toString();
+ if (combinedIntents.get(excluded) == null)
+ sIntent2 = excluded.getName().toString();
+ else
+ sIntent2 = excluded.getName().toString() + " in policy set " + combinedIntents.get(excluded).getName().toString();
+ throw new PolicyValidationException(
+ intentAttachPointType.getName() + " for " + id +
+ " uses mutually-exclusive intents " + sIntent1 + " and " + sIntent2);
+ }
+ }
+ }
+ }
+
+ public static void expandProfileIntents(List<Intent> intents) {
+ List<Intent> expandedIntents = null;
+ if ( intents.size() > 0 ) {
+ expandedIntents = findAndExpandProfileIntents(intents);
+ intents.clear();
+ intents.addAll(expandedIntents);
+ }
+ }
+
+ public static List<Intent> findAndExpandProfileIntents(List<Intent> intents) {
+ List<Intent> expandedIntents = new ArrayList<Intent>();
+ for ( Intent intent : intents ) {
+ if ( intent instanceof ProfileIntent ) {
+ ProfileIntent profileIntent = (ProfileIntent)intent;
+ List<Intent> requiredIntents = profileIntent.getRequiredIntents();
+ expandedIntents.addAll(findAndExpandProfileIntents(requiredIntents));
+ } else {
+ expandedIntents.add(intent);
+ }
+ }
+ return expandedIntents;
}
private static byte[] addApplicablePolicySets(Document doc, Collection<PolicySet> policySets)
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org