From 755737f1cef0f827f6c87c3d55560adebdb776f0 Mon Sep 17 00:00:00 2001 From: lresende Date: Tue, 8 Jul 2008 23:04:16 +0000 Subject: TUSCANY-2354 - Applying a slightly modified version of Ram's patch to get a sucessful build git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@675018 13f79535-47bb-0310-9956-ffa450edef68 --- .../ws/axis2/itests/policy/mixed/definitions.xml | 9 ----- .../wspolicy/WSSecurityAuthentication.composite | 4 +- .../axis2/itests/policy/wspolicy/definitions.xml | 12 +----- .../definitions/xml/SCADefinitionsProcessor.java | 43 +++++++++++++++----- .../tuscany/sca/definitions/test_definitions.xml | 5 +-- .../sca/policy/xml/PolicyIntentProcessor.java | 46 ++++++++++++++++++---- .../tuscany/sca/policy/xml/PolicySetProcessor.java | 15 +++---- .../policy-xml-validation-messages.properties | 3 +- .../sca/policy/xml/ReadDocumentTestCase.java | 46 +++++++++++++++++++--- .../tuscany/sca/policy/xml/test_definitions.xml | 5 +-- 10 files changed, 131 insertions(+), 57 deletions(-) (limited to 'java/sca/modules') diff --git a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/definitions.xml b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/definitions.xml index 75d0dc717c..871e889835 100644 --- a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/definitions.xml +++ b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/mixed/definitions.xml @@ -22,15 +22,6 @@ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"> - - - - - Communitcation thro this binding required Authentication. - - - - + @@ -41,7 +41,7 @@ - + diff --git a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/definitions.xml b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/definitions.xml index 200400f0b5..8f7135e767 100644 --- a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/definitions.xml +++ b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/wspolicy/definitions.xml @@ -21,20 +21,12 @@ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0" xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"> - - - - Communitcation thro this binding required Authentication. - - - + appliesTo="sca:binding.ws"> diff --git a/java/sca/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java b/java/sca/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java index 6958501922..7709a9577e 100644 --- a/java/sca/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java +++ b/java/sca/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java @@ -22,6 +22,9 @@ package org.apache.tuscany.sca.definitions.xml; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; +import java.util.List; +import java.util.ArrayList; + import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; @@ -40,6 +43,7 @@ import org.apache.tuscany.sca.definitions.impl.SCADefinitionsImpl; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentAttachPointType; import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.ProfileIntent; import org.apache.tuscany.sca.policy.QualifiedIntent; import org.apache.tuscany.sca.monitor.Monitor; @@ -173,12 +177,28 @@ public class SCADefinitionsProcessor extends BaseStAXArtifactProcessor implement // start by adding all of the top level artifacts into the resolver as there // are many cross artifact references in a definitions file and we don't want // to be dependent on the order things appear + + List simpleIntents = new ArrayList(); + List profileIntents = new ArrayList(); + List qualifiedIntents = new ArrayList(); + List simplePolicySets = new ArrayList(); + List referredPolicySets = new ArrayList(); for (Intent policyIntent : scaDefns.getPolicyIntents()) { - resolver.addModel(policyIntent); - } + if (policyIntent instanceof ProfileIntent) + profileIntents.add((ProfileIntent)policyIntent); + else if (policyIntent instanceof QualifiedIntent) + qualifiedIntents.add((QualifiedIntent)policyIntent); + else simpleIntents.add(policyIntent); + + resolver.addModel(policyIntent); + } for (PolicySet policySet : scaDefns.getPolicySets()) { + if (policySet.getReferencedPolicySets().isEmpty()) + simplePolicySets.add(policySet); + else referredPolicySets.add(policySet); + resolver.addModel(policySet); } @@ -193,15 +213,20 @@ public class SCADefinitionsProcessor extends BaseStAXArtifactProcessor implement // now resolve everything to ensure that any references between // artifacts are satisfied - for (int count = 0, size = scaDefns.getPolicyIntents().size(); count < size; count++) { - Intent intent = scaDefns.getPolicyIntents().get(count); - extensionProcessor.resolve(intent, resolver); - } + for (Intent policyIntent : simpleIntents) + extensionProcessor.resolve(policyIntent, resolver); - for (int count = 0, size = scaDefns.getPolicySets().size(); count < size; count++) { - PolicySet policySet = scaDefns.getPolicySets().get(count); + for (ProfileIntent policyIntent : profileIntents) + extensionProcessor.resolve(policyIntent, resolver); + + for (QualifiedIntent policyIntent : qualifiedIntents) + extensionProcessor.resolve(policyIntent, resolver); + + for (PolicySet policySet : simplePolicySets) extensionProcessor.resolve(policySet, resolver); - } + + for (PolicySet policySet : referredPolicySets) + extensionProcessor.resolve(policySet, resolver); for (int count = 0, size = scaDefns.getBindingTypes().size(); count < size; count++) { IntentAttachPointType bindingType = scaDefns.getBindingTypes().get(count); diff --git a/java/sca/modules/definitions-xml/src/test/resources/org/apache/tuscany/sca/definitions/test_definitions.xml b/java/sca/modules/definitions-xml/src/test/resources/org/apache/tuscany/sca/definitions/test_definitions.xml index e01a29863a..6750944697 100644 --- a/java/sca/modules/definitions-xml/src/test/resources/org/apache/tuscany/sca/definitions/test_definitions.xml +++ b/java/sca/modules/definitions-xml/src/test/resources/org/apache/tuscany/sca/definitions/test_definitions.xml @@ -30,8 +30,7 @@ + constrains="sca:binding"> Test Intent @@ -39,7 +38,7 @@ + requires="test:TestIntentOne"> Protect messages from unauthorized reading or modification diff --git a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java index 109090ccab..33e88663ee 100644 --- a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java +++ b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java @@ -247,10 +247,24 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP for (Intent requiredIntent : policyIntent.getRequiredIntents()) { if (requiredIntent.isUnresolved()) { Intent resolvedRequiredIntent = resolver.resolveModel(Intent.class, requiredIntent); - if (resolvedRequiredIntent != null) { + // At this point, when the required intent is not resolved, it does not mean + // its undeclared, chances are that their dependency are not resolved yet. + // Lets try to resolve them first. + if (resolvedRequiredIntent.isUnresolved()) { + if (resolvedRequiredIntent instanceof ProfileIntent) { + if ((((ProfileIntent)resolvedRequiredIntent).getRequiredIntents()).contains(policyIntent)) { + error("CyclicReferenceFound", resolver, requiredIntent, policyIntent); + return; + } + resolveDependent(resolvedRequiredIntent, resolver); + } + } + + if (!resolvedRequiredIntent.isUnresolved()) { requiredIntents.add(resolvedRequiredIntent); } else { error("RequiredIntentNotFound", resolver, requiredIntent, policyIntent); + return; //throw new ContributionResolveException("Required Intent - " + requiredIntent //+ " not found for ProfileIntent " + policyIntent); } @@ -270,19 +284,36 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP Intent qualifiableIntent = policyIntent.getQualifiableIntent(); if (qualifiableIntent.isUnresolved()) { Intent resolvedQualifiableIntent = resolver.resolveModel(Intent.class, qualifiableIntent); - - if (resolvedQualifiableIntent != null) { + // At this point, when the qualifiable intent is not resolved, it does not mean + // its undeclared, chances are that their dependency are not resolved yet. + // Lets try to resolve them first. + if (resolvedQualifiableIntent.isUnresolved()) { + if (resolvedQualifiableIntent instanceof QualifiedIntent) { + resolveDependent(resolvedQualifiableIntent, resolver); + } + } + + if (!resolvedQualifiableIntent.isUnresolved()) { policyIntent.setQualifiableIntent(resolvedQualifiableIntent); } else { error("QualifiableIntentNotFound", resolver, qualifiableIntent, policyIntent); //throw new ContributionResolveException("Qualifiable Intent - " + qualifiableIntent //+ " not found for QualifiedIntent " + policyIntent); - } - + } } } } + public void resolveDependent(Intent policyIntent, ModelResolver resolver) throws ContributionResolveException { + if (policyIntent instanceof ProfileIntent) + resolveProfileIntent((ProfileIntent)policyIntent, resolver); + + if (policyIntent instanceof QualifiedIntent) + resolveQualifiedIntent((QualifiedIntent)policyIntent, resolver); + + resolveContrainedArtifacts(policyIntent, resolver); + } + public void resolve(T policyIntent, ModelResolver resolver) throws ContributionResolveException { if (policyIntent instanceof ProfileIntent) { resolveProfileIntent((ProfileIntent)policyIntent, resolver); @@ -360,11 +391,12 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP List excludedIntents = new ArrayList(); for (Intent excludedIntent : policyIntent.getExcludedIntents()) { if (excludedIntent.isUnresolved()) { - Intent resolvedExcludedIntent = resolver.resolveModel(Intent.class, excludedIntent); - if (resolvedExcludedIntent != null) { + Intent resolvedExcludedIntent = resolver.resolveModel(Intent.class, excludedIntent); + if (!resolvedExcludedIntent.isUnresolved()) { excludedIntents.add(resolvedExcludedIntent); } else { error("ExcludedIntentNotFound", resolver, excludedIntent, policyIntent); + return; //throw new ContributionResolveException("Excluded Intent " + excludedIntent //+ " not found for intent " + policyIntent); } diff --git a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java index b6f33aa677..e19099a2f3 100644 --- a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java +++ b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java @@ -371,13 +371,13 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA for (Intent providedIntent : policySet.getProvidedIntents()) { if (providedIntent.isUnresolved()) { Intent resolvedProvidedIntent = resolver.resolveModel(Intent.class, providedIntent); - if (resolvedProvidedIntent != null) { + if (!resolvedProvidedIntent.isUnresolved()) { providedIntents.add(resolvedProvidedIntent); } else { error("ProvidedIntentNotFound", policySet, providedIntent, policySet); + return; //throw new ContributionResolveException("Provided Intent - " + providedIntent //+ " not found for PolicySet " + policySet); - } } else { providedIntents.add(providedIntent); @@ -394,11 +394,11 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA Intent mappedIntent = entry.getKey(); if (mappedIntent.isUnresolved()) { Intent resolvedMappedIntent = resolver.resolveModel(Intent.class, mappedIntent); - - if (resolvedMappedIntent != null) { + if (!resolvedMappedIntent.isUnresolved()) { mappedPolicies.put(resolvedMappedIntent, entry.getValue()); } else { error("MappedIntentNotFound", policySet, mappedIntent, policySet); + return; //throw new ContributionResolveException("Mapped Intent - " + mappedIntent //+ " not found for PolicySet " + policySet); } @@ -417,10 +417,11 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { if (referredPolicySet.isUnresolved()) { PolicySet resolvedReferredPolicySet = resolver.resolveModel(PolicySet.class, referredPolicySet); - if (resolvedReferredPolicySet != null) { + if (!resolvedReferredPolicySet.isUnresolved()) { referredPolicySets.add(resolvedReferredPolicySet); } else { error("ReferredPolicySetNotFound", policySet, referredPolicySet, policySet); + return; //throw new ContributionResolveException("Referred PolicySet - " + referredPolicySet //+ "not found for PolicySet - " + policySet); } @@ -453,9 +454,9 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA //resolve the policy attachments resolvePolicies(policySet, resolver); - if ( !policySet.isUnresolved() ) { + /*if ( !policySet.isUnresolved() ) { resolver.addModel(policySet); - } + }*/ } } } diff --git a/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties b/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties index d8eb214c15..60c73d5354 100644 --- a/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties +++ b/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties @@ -33,4 +33,5 @@ UnrecognizedIntentAttachPointType = Unrecognized IntentAttachPointType - {0} RequiredAttributeMissing = Required attribute {0} missing from BindingType Definition AlwaysProvidedIntentNotFound = Always Provided Intent - {0} not found for ExtensionType {1} MayProvideIntentNotFound = May Provide Intent - {0} not found for ExtensionType {1} -ContributionReadException = ContributionReadException occured due to: {0} \ No newline at end of file +ContributionReadException = ContributionReadException occured due to: {0} +CyclicReferenceFound = Cyclic reference detected in required attributes of ProfileIntents {0} and {1} \ No newline at end of file diff --git a/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java b/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java index b2e16f97e7..60de55a0d9 100644 --- a/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java +++ b/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java @@ -23,7 +23,9 @@ import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import java.io.InputStream; import java.net.URL; +import java.util.ArrayList; import java.util.Hashtable; +import java.util.List; import java.util.Map; import javax.xml.namespace.QName; @@ -38,6 +40,10 @@ import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtens import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentAttachPointType; import org.apache.tuscany.sca.policy.PolicySet; @@ -55,7 +61,7 @@ public class ReadDocumentTestCase extends TestCase { private ModelResolver resolver; private StAXArtifactProcessor staxProcessor; - + private Monitor monitor; private Map intentTable = new Hashtable(); private Map policySetTable = new Hashtable(); @@ -82,8 +88,15 @@ public class ReadDocumentTestCase extends TestCase { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); resolver = new DefaultModelResolver(); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); staxProcessors.addArtifactProcessor(new TestPolicyProcessor()); URL url = getClass().getResource("test_definitions.xml"); @@ -187,12 +200,35 @@ public class ReadDocumentTestCase extends TestCase { assertNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription()); assertNull(javaImplType.getMayProvideIntents().get(0).getDescription()); - for ( Intent intent : intentTable.values() ) { + List simpleIntents = new ArrayList(); + List profileIntents = new ArrayList(); + List qualifiedIntents = new ArrayList(); + + for (Intent intent : intentTable.values()) { + if (intent instanceof ProfileIntent) + profileIntents.add((ProfileIntent)intent); + else if (intent instanceof QualifiedIntent) + qualifiedIntents.add((QualifiedIntent)intent); + else simpleIntents.add(intent); + } + + for (Intent intent : simpleIntents) + staxProcessor.resolve(intent, resolver); + + for (ProfileIntent intent : profileIntents) staxProcessor.resolve(intent, resolver); + + for (QualifiedIntent intent : qualifiedIntents) + staxProcessor.resolve(intent, resolver); + + for ( PolicySet policySet : policySetTable.values() ) { + if (policySet.getReferencedPolicySets().isEmpty()) + staxProcessor.resolve(policySet, resolver); } for ( PolicySet policySet : policySetTable.values() ) { - staxProcessor.resolve(policySet, resolver); + if (!policySet.getReferencedPolicySets().isEmpty()) + staxProcessor.resolve(policySet, resolver); } for ( IntentAttachPointType bindingType : bindingTypesTable.values() ) { @@ -203,8 +239,6 @@ public class ReadDocumentTestCase extends TestCase { staxProcessor.resolve(implType, resolver); } - - //testing if policy intents have been linked have property been linked up assertNotNull(profileIntent.getRequiredIntents().get(0).getDescription()); assertNotNull(qualifiedIntent.getQualifiableIntent().getDescription()); diff --git a/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml b/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml index e01a29863a..6750944697 100644 --- a/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml +++ b/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml @@ -30,8 +30,7 @@ + constrains="sca:binding"> Test Intent @@ -39,7 +38,7 @@ + requires="test:TestIntentOne"> Protect messages from unauthorized reading or modification -- cgit v1.2.3