ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r356290 - /webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java
Date Mon, 12 Dec 2005 17:21:53 GMT
Author: sanka
Date: Mon Dec 12 09:21:45 2005
New Revision: 356290

URL: http://svn.apache.org/viewcvs?rev=356290&view=rev
Log:
Fixed: child <wsp:Policy> ..</wsp:Policy> elements are serialized as <wsp:All>
.. </wsp:All>

Modified:
    webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java?rev=356290&r1=356289&r2=356290&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java Mon
Dec 12 09:21:45 2005
@@ -60,11 +60,23 @@
 
     private void writePolicy(Policy policy, XMLStreamWriter writer)
             throws XMLStreamException {
-        writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
-                PolicyConstants.WS_POLICY,
-                PolicyConstants.WS_POLICY_NAMESPACE_URI);
-        writer.writeNamespace(PolicyConstants.WS_POLICY_PREFIX,
-                PolicyConstants.WS_POLICY_NAMESPACE_URI);
+        String writerPerfix = writer
+                .getPrefix(PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+        if (writerPerfix != null) {
+            writer.writeStartElement(PolicyConstants.WS_POLICY_NAMESPACE_URI,
+                    PolicyConstants.WS_POLICY);
+
+        } else {
+            writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
+                    PolicyConstants.WS_POLICY,
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI);
+            writer.writeNamespace(PolicyConstants.WS_POLICY_PREFIX,
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI);
+            writer.setPrefix(PolicyConstants.WS_POLICY_PREFIX,
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+        }
 
         if (policy.getId() != null) {
             writer.writeAttribute("wsu", PolicyConstants.WSU_NAMESPACE_URI,
@@ -85,10 +97,6 @@
         if (assertion instanceof PrimitiveAssertion) {
             writePrimitiveAssertion((PrimitiveAssertion) assertion, writer);
 
-        } else if (assertion instanceof AndCompositeAssertion) {
-            writeAndCompositeAssertion((AndCompositeAssertion) assertion,
-                    writer);
-
         } else if (assertion instanceof XorCompositeAssertion) {
             writeXorCompositeAssertion((XorCompositeAssertion) assertion,
                     writer);
@@ -98,6 +106,10 @@
 
         } else if (assertion instanceof Policy) {
             writePolicy((Policy) assertion, writer);
+        } else if (assertion instanceof AndCompositeAssertion) {
+            writeAndCompositeAssertion((AndCompositeAssertion) assertion,
+                    writer);
+
         } else {
             throw new RuntimeException("unknown element type");
         }
@@ -105,9 +117,23 @@
 
     private void writeAndCompositeAssertion(AndCompositeAssertion assertion,
             XMLStreamWriter writer) throws XMLStreamException {
-        writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
-                PolicyConstants.AND_COMPOSITE_ASSERTION,
-                PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+        String writerPrefix = writer
+                .getPrefix(PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+        if (writerPrefix == null) {
+            writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
+                    PolicyConstants.AND_COMPOSITE_ASSERTION,
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI);
+            writer.writeNamespace(PolicyConstants.WS_POLICY_PREFIX,
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI);
+            writer.setPrefix(PolicyConstants.WS_POLICY_PREFIX,
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+        } else {
+            writer.writeStartElement(PolicyConstants.WS_POLICY_NAMESPACE_URI,
+                    PolicyConstants.AND_COMPOSITE_ASSERTION);
+        }
 
         List terms = assertion.getTerms();
         writeTerms(terms, writer);
@@ -117,9 +143,22 @@
 
     private void writeXorCompositeAssertion(XorCompositeAssertion assertion,
             XMLStreamWriter writer) throws XMLStreamException {
-        writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
-                PolicyConstants.XOR_COMPOSITE_ASSERTION,
-                PolicyConstants.WS_POLICY_NAMESPACE_URI);
+        String writerPrefix = writer
+                .getPrefix(PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+        if (writerPrefix == null) {
+            writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
+                    PolicyConstants.XOR_COMPOSITE_ASSERTION,
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI);
+            writer.writeNamespace(PolicyConstants.WS_POLICY_PREFIX,
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI);
+            writer.setPrefix(PolicyConstants.WS_POLICY_PREFIX,
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+        } else {
+            writer.writeStartElement(PolicyConstants.WS_POLICY_NAMESPACE_URI,
+                    PolicyConstants.XOR_COMPOSITE_ASSERTION);
+        }
 
         List terms = assertion.getTerms();
         writeTerms(terms, writer);
@@ -131,16 +170,18 @@
             XMLStreamWriter writer) throws XMLStreamException {
         QName qname = assertion.getName();
 
-        String prefix = qname.getPrefix();
-        if (prefix != null) {
-            writer.writeStartElement(qname.getPrefix(), qname.getLocalPart(),
-                    qname.getNamespaceURI());
-            writer.writeNamespace(qname.getPrefix(), qname.getNamespaceURI());
-
+        String writerPrefix = writer.getPrefix(qname.getNamespaceURI());
+        if (writerPrefix != null) {
+            writer.writeStartElement(qname.getNamespaceURI(), qname
+                    .getLocalPart());
         } else {
-            writer.writeStartElement(qname.getLocalPart(), qname
+            String prefix = (qname.getPrefix() != null) ? qname.getPrefix()
+                    : generateNamespace();
+            writer.writeStartElement(prefix, qname.getLocalPart(), qname
                     .getNamespaceURI());
-            writer.writeNamespace(generateNamespace(), qname.getNamespaceURI());
+            writer.writeNamespace(prefix, qname.getNamespaceURI());
+            writer.setPrefix(prefix, qname.getNamespaceURI());
+
         }
 
         Hashtable attributes = assertion.getAttributes();
@@ -159,6 +200,7 @@
 
     private void writePolicyReference(PolicyReference assertion,
             XMLStreamWriter writer) throws XMLStreamException {
+        throw new UnsupportedOperationException();
     }
 
     private void writeTerms(List terms, XMLStreamWriter writer)



Mime
View raw message