tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svkr...@apache.org
Subject svn commit: r572908 - in /incubator/tuscany/java/sca/modules/policy-xml: ./ src/main/java/org/apache/tuscany/sca/policy/xml/ src/test/java/org/apache/tuscany/sca/policy/xml/ src/test/resources/org/apache/tuscany/sca/policy/xml/
Date Wed, 05 Sep 2007 09:14:02 GMT
Author: svkrish
Date: Wed Sep  5 02:14:01 2007
New Revision: 572908

URL: http://svn.apache.org/viewvc?rev=572908&view=rev
Log:
added code to load ws policy, testing loading of ws policy, removed unused methods in policyset
processor

Modified:
    incubator/tuscany/java/sca/modules/policy-xml/pom.xml
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsBuilderImpl.java
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsDocumentProcessor.java
    incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java
    incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/definitions.xml

Modified: incubator/tuscany/java/sca/modules/policy-xml/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/pom.xml?rev=572908&r1=572907&r2=572908&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/policy-xml/pom.xml Wed Sep  5 02:14:01 2007
@@ -48,6 +48,25 @@
         </dependency>
         
         <dependency>
+            <groupId>org.apache.ws.commons.axiom</groupId>
+            <artifactId>axiom-api</artifactId>
+            <version>1.2.4</version>
+        </dependency>
+        
+         <dependency>
+            <groupId>org.apache.neethi</groupId>
+            <artifactId>neethi</artifactId>
+            <version>2.0.1</version>
+        </dependency>
+
+		<dependency>
+            <groupId>org.apache.ws.commons.axiom</groupId>
+            <artifactId>axiom-impl</artifactId>
+            <version>1.2.4</version>
+            <scope>runtime</scope>
+        </dependency>
+        
+        <dependency>
             <groupId>org.codehaus.woodstox</groupId>
             <artifactId>wstx-asl</artifactId>
             <version>3.2.1</version>

Modified: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java?rev=572908&r1=572907&r2=572908&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java
(original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java
Wed Sep  5 02:14:01 2007
@@ -44,6 +44,9 @@
     String REQUIRES = "requires";
     String DEFAULT = "default";
     
+    String WS_POLICY_NS = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+    String WS_POLICY = "Policy";
+    
     String ALWAYS_PROVIDES = "alwaysProvides";
     String MAY_PROVIDE = "mayProvide";
     String TYPE = "type";
@@ -61,6 +64,7 @@
     QName DESCRIPTION_QNAME = new QName(SCA10_NS, DESCRIPTION);
     QName POLICY_INTENT_MAP_QUALIFIER_QNAME = new QName(SCA10_NS, INTENT_MAP_QUALIFIER);
     QName POLICY_SET_REFERENCE_QNAME = new QName(SCA10_NS, POLICY_SET_REFERENCE);
+    QName WS_POLICY_QNAME = new QName(WS_POLICY_NS, WS_POLICY);
     
     String QUALIFIED_INTENT_CONSTRAINS_ERROR = " - Qualified Intents must not specify 'constrains'
attribute";
     

Modified: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java?rev=572908&r1=572907&r2=572908&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java
Wed Sep  5 02:14:01 2007
@@ -28,10 +28,15 @@
 import java.util.StringTokenizer;
 
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.neethi.PolicyEngine;
 import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
 import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
 import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
@@ -84,6 +89,10 @@
                         PolicySet referredPolicySet = policyFactory.createPolicySet();
                         referredPolicySet.setName(getQName(reader, NAME));
                         policySet.getReferencedPolicySets().add(referredPolicySet);
+                    } else if ( WS_POLICY_QNAME.equals(name) )  {
+                        OMElement policyElement = loadElement(reader);
+                        org.apache.neethi.Policy wsPolicy = PolicyEngine.getPolicy(policyElement);
+                        policySet.getPolicies().add(wsPolicy);
                     } else {
                         Object extension = extensionProcessor.read(reader);
                         if ( extension instanceof Policy ) {
@@ -110,7 +119,7 @@
     
     public void readIntentMap(XMLStreamReader reader, PolicySet policySet, Intent mappedIntent)
throws ContributionReadException {
         QName name = reader.getName();
-        Map<Intent, List<Policy>> mappedPolicies = policySet.getMappedPolicies();
+        Map<Intent, List<Object>> mappedPolicies = policySet.getMappedPolicies();
         if ( POLICY_INTENT_MAP_QNAME.equals(name) ) {
             //Intent mappedIntent = policyFactory.createIntent();
             //mappedIntent.setName(getQName(reader, PROVIDES));
@@ -144,12 +153,27 @@
                                                                     providedIntent + " does
not match parent qualifier " + qualifierName +
                                                                     " in policyset - " +
policySet);
                                 }
+                            } else if ( WS_POLICY_QNAME.equals(name) )  {
+                                OMElement policyElement = loadElement(reader);
+                                org.apache.neethi.Policy wsPolicy = PolicyEngine.getPolicy(policyElement);
+                                policySet.getPolicies().add(wsPolicy);
+                                
+                                List<Object> policyList = mappedPolicies.get(qualifiedIntent);
+                                if ( policyList == null ) {
+                                    policyList = new ArrayList<Object>();
+                                    mappedPolicies.put(qualifiedIntent, policyList);
+                                    
+                                    if (qualifierName.equals(defaultQualifier)) {
+                                        mappedPolicies.put(mappedIntent, policyList);
+                                    }
+                                }
+                                policyList.add((Policy)wsPolicy);
                             } else {
                                 Object extension = extensionProcessor.read(reader);
                                 if ( extension instanceof Policy ) {
-                                    List<Policy> policyList = mappedPolicies.get(qualifiedIntent);
+                                    List<Object> policyList = mappedPolicies.get(qualifiedIntent);
                                     if ( policyList == null ) {
-                                        policyList = new ArrayList<Policy>();
+                                        policyList = new ArrayList<Object>();
                                         mappedPolicies.put(qualifiedIntent, policyList);
                                         
                                         if (qualifierName.equals(defaultQualifier)) {
@@ -168,7 +192,7 @@
                                     Intent defaultQualifiedIntent = policyFactory.createIntent();
                                     defaultQualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(),
                                                                              qualifiedIntentName));
-                                    List<Policy> policyList = mappedPolicies.get(defaultQualifiedIntent);
+                                    List<Object> policyList = mappedPolicies.get(defaultQualifiedIntent);
                                     if ( policyList != null ) {
                                         mappedPolicies.put(mappedIntent, policyList);
                                     } else {
@@ -234,48 +258,6 @@
         }
     }
 
-    //FIXME This method is never used
-//    private void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver) throws
ContributionResolveException {
-//        boolean isUnresolved = false;
-//        if (policySet != null && policySet.isUnresolved()) {
-//            //resolve all provided intents
-//            List<Intent> providedIntents = new ArrayList<Intent>(); 
-//            for (Intent providedIntent : policySet.getProvidedIntents()) {
-//                if ( providedIntent.isUnresolved() ) {
-//                    //policyIntent.getRequiredIntents().remove(requiredIntent);
-//                    providedIntent = resolver.resolveModel(Intent.class, providedIntent);
-//                    providedIntents.add(providedIntent);
-//                    if (providedIntent.isUnresolved()) {
-//                        isUnresolved = true;
-//                    }
-//                }
-//            }
-//            policySet.getProvidedIntents().clear();
-//            policySet.getProvidedIntents().addAll(providedIntents);
-//        }
-//        policySet.setUnresolved(isUnresolved);
-//    }
-
-    //FIXME This method is never used
-//   private void resolveIntentsInMappedPolicies(PolicySet policySet, ModelResolver resolver)
throws ContributionResolveException {
-//       Map<Intent, List<Policy>> mappedPolicies = new Hashtable<Intent,
List<Policy>>();   
-//       boolean isUnresolved = false;
-//       for ( Intent mappedIntent : policySet.getMappedPolicies().keySet() ) {
-//           if ( mappedIntent.isUnresolved() ) {
-//               //policyIntent.getRequiredIntents().remove(requiredIntent);
-//               mappedIntent = resolver.resolveModel(Intent.class, mappedIntent);
-//               mappedPolicies.put(mappedIntent, policySet.getMappedPolicies().get(mappedIntent));
-//               if (mappedIntent.isUnresolved()) {
-//                   isUnresolved = true;
-//               }
-//           }
-//       }
-//       
-//       policySet.getMappedPolicies().clear();
-//       policySet.getMappedPolicies().putAll(mappedPolicies);
-//       policySet.setUnresolved(isUnresolved);
-//   }
-  
    private void resolvePolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException
{
        boolean unresolved = false;
        for ( Object o : policySet.getPolicies() ) {
@@ -304,6 +286,58 @@
     
     public Class<PolicySet> getModelType() {
         return PolicySet.class;
+    }
+    
+    private OMElement loadElement(XMLStreamReader reader) throws XMLStreamException {
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMElement head = fac.createOMElement(reader.getName());
+        OMElement current = head;
+        while (true) {
+            switch (reader.next()) {
+                case XMLStreamConstants.START_ELEMENT:
+                    QName name = reader.getName();
+                    OMElement child = fac.createOMElement(name, current);
+
+                    int count = reader.getNamespaceCount();
+                    for (int i = 0; i < count; i++) {
+                        String prefix = reader.getNamespacePrefix(i);
+                        String ns = reader.getNamespaceURI(i);
+                        child.declareNamespace(ns, prefix);
+                    }
+
+                    if(!"".equals(name.getNamespaceURI())) {
+                        child.declareNamespace(name.getNamespaceURI(), name.getPrefix());
+                    }
+
+                    // add the attributes for this element
+                    count = reader.getAttributeCount();
+                    for (int i = 0; i < count; i++) {
+                        String ns = reader.getAttributeNamespace(i);
+                        String prefix = reader.getAttributePrefix(i);
+                        String qname = reader.getAttributeLocalName(i);
+                        String value = reader.getAttributeValue(i);
+                        
+                        child.addAttribute(qname, value, fac.createOMNamespace(ns, prefix));
+                        if (ns != null) {
+                            child.declareNamespace(ns, prefix);
+                        }
+                    }
+                    current = child;
+                    break;
+                case XMLStreamConstants.CDATA:
+                    fac.createOMText(current, reader.getText());
+                    break;
+                case XMLStreamConstants.CHARACTERS:
+                    fac.createOMText(current, reader.getText());
+                    break;
+                case XMLStreamConstants.END_ELEMENT:
+                    if ( current == head ) {
+                        return head;
+                    } else {
+                        current = (OMElement)current.getParent();
+                    }
+            }
+        }
     }
     
 }

Modified: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsBuilderImpl.java?rev=572908&r1=572907&r2=572908&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsBuilderImpl.java
(original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsBuilderImpl.java
Wed Sep  5 02:14:01 2007
@@ -243,8 +243,8 @@
 
     private void buildIntentsInMappedPolicies(PolicySet policySet, Map<QName, Intent>
definedIntents)
         throws SCADefinitionsBuilderException {
-        Map<Intent, List<Policy>> mappedPolicies = new Hashtable<Intent, List<Policy>>();
-        for (Map.Entry<Intent, List<Policy>> entry : policySet.getMappedPolicies().entrySet())
{
+        Map<Intent, List<Object>> mappedPolicies = new Hashtable<Intent, List<Object>>();
+        for (Map.Entry<Intent, List<Object>> entry : policySet.getMappedPolicies().entrySet())
{
             Intent mappedIntent = entry.getKey();
             if (mappedIntent.isUnresolved()) {
                 Intent resolvedMappedIntent = definedIntents.get(mappedIntent.getName());

Modified: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsDocumentProcessor.java?rev=572908&r1=572907&r2=572908&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsDocumentProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsDocumentProcessor.java
Wed Sep  5 02:14:01 2007
@@ -24,7 +24,6 @@
 import java.net.URI;
 import java.net.URL;
 
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -35,10 +34,10 @@
 import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
 import org.apache.tuscany.sca.contribution.service.ContributionReadException;
 import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory;
 import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
 import org.apache.tuscany.sca.policy.PolicyFactory;
 import org.apache.tuscany.sca.policy.SCADefinitions;
-import org.apache.tuscany.sca.policy.impl.DefaultIntentAttachPointTypeFactoryImpl;
 
 /**
  * A SCA Definitions Document processor.
@@ -65,7 +64,7 @@
         definitionsBuilder = new SCADefinitionsBuilderImpl();
         this.domainModelResolver = new SCADefinitionsResolver();
         
-        IntentAttachPointTypeFactory intentAttachPointFactory = new DefaultIntentAttachPointTypeFactoryImpl();
+        IntentAttachPointTypeFactory intentAttachPointFactory = new DefaultIntentAttachPointTypeFactory();
             
         SCADefinitionsProcessor scaDefnProcessor = new SCADefinitionsProcessor(policyFactory,
extensionProcessor, domainModelResolver);
         

Modified: incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java?rev=572908&r1=572907&r2=572908&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java
(original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java
Wed Sep  5 02:14:01 2007
@@ -30,9 +30,11 @@
 
 import junit.framework.TestCase;
 
+import org.apache.neethi.Policy;
 import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory;
 import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
 import org.apache.tuscany.sca.policy.Intent;
 import org.apache.tuscany.sca.policy.IntentAttachPointType;
@@ -42,7 +44,6 @@
 import org.apache.tuscany.sca.policy.ProfileIntent;
 import org.apache.tuscany.sca.policy.QualifiedIntent;
 import org.apache.tuscany.sca.policy.SCADefinitions;
-import org.apache.tuscany.sca.policy.impl.DefaultIntentAttachPointTypeFactoryImpl;
 
 /**
  * Test reading SCA XML assembly documents.
@@ -60,6 +61,7 @@
     Map<QName, IntentAttachPointType> implTypesTable = new Hashtable<QName, IntentAttachPointType>();
     public static final String namespace = "http://www.osoa.org/xmlns/sca/1.0";
     
+    private static final QName secureWsPolicy = new QName(namespace, "SecureWSPolicy");
     private static final QName confidentiality = new QName(namespace, "confidentiality");
     private static final QName integrity = new QName(namespace, "integrity");
     private static final QName messageProtection = new QName(namespace, "messageProtection");
@@ -77,7 +79,7 @@
     public void setUp() throws Exception {
         XMLInputFactory inputFactory = XMLInputFactory.newInstance();
         PolicyFactory policyFactory = new DefaultPolicyFactory();
-        IntentAttachPointTypeFactory intentAttachPointFactory = new DefaultIntentAttachPointTypeFactoryImpl();
+        IntentAttachPointTypeFactory intentAttachPointFactory = new DefaultIntentAttachPointTypeFactory();
         
         // Create Stax processors
         DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new
DefaultModelFactoryExtensionPoint());
@@ -141,6 +143,7 @@
         
         assertNotNull(policySetTable.get(secureMessagingPolicies));
         assertEquals(policySetTable.get(secureMessagingPolicies).getMappedPolicies().size(),
3);
+        assertTrue(policySetTable.get(secureWsPolicy).getPolicies().get(0) instanceof Policy);
         
         assertEquals(bindingTypesTable.size(), 1);
         assertNotNull(bindingTypesTable.get(wsBinding));

Modified: incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/definitions.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/definitions.xml?rev=572908&r1=572907&r2=572908&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/definitions.xml
(original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/definitions.xml
Wed Sep  5 02:14:01 2007
@@ -136,6 +136,31 @@
     </intentMap>
 </policySet>
 
+<policySet name="SecureWSPolicy"
+ 	provides="confidentiality"
+ 	appliesTo="sca:binding.ws"
+ 	xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ 	xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"
+ 	xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+	<wsp:Policy>
+	    <wsp:ExactlyOne>
+	      <wsp:All>
+	        <sp:SecurityToken>
+	          <sp:TokenType>sp:X509v3</sp:TokenType>
+	        </sp:SecurityToken>
+	        <sp:UsernameToken /> 
+	        <sp:SignedParts />
+	        <sp:EncryptedParts>
+	          <sp:Body />
+	        </sp:EncryptedParts>
+	        <sp:TransportBinding>
+	          <sp:IncludeTimeStamp />
+	        </sp:TransportBinding>
+	      </wsp:All>
+	    </wsp:ExactlyOne>
+  </wsp:Policy>
+ </policySet>
+
 <!-- profile intent -->
  <intent name="reliableMessageProtection" 
  			 constrains="sca:binding"



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


Mime
View raw message