ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r355072 - in /webservices/commons/trunk/policy/src/org/apache/ws/policy/util: PolicyAttachmentUtil.java PolicyReader.java PolicyWriter.java
Date Thu, 08 Dec 2005 11:25:51 GMT
Author: sanka
Date: Thu Dec  8 03:25:42 2005
New Revision: 355072

URL: http://svn.apache.org/viewcvs?rev=355072&view=rev
Log:
some refactring and few add-ons to several utility classes

Modified:
    webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyAttachmentUtil.java
    webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyReader.java
    webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyWriter.java

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyAttachmentUtil.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyAttachmentUtil.java?rev=355072&r1=355071&r2=355072&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyAttachmentUtil.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyAttachmentUtil.java Thu Dec  8 03:25:42 2005
@@ -45,7 +45,9 @@
 import org.apache.wsdl.WSDLInterface;
 import org.apache.wsdl.WSDLOperation;
 import org.apache.wsdl.WSDLService;
+import org.apache.wsdl.WSDLTypes;
 import org.apache.wsdl.extensions.DefaultExtensibilityElement;
+import org.apache.wsdl.extensions.Schema;
 import org.w3c.dom.Element;
 
 import com.ibm.wsdl.util.xml.DOM2Writer;
@@ -55,56 +57,66 @@
  * 2004).
  * 
  * @author Sanka Samaranayake <ssanka@gmail.com>
- *
+ *  
  */
 public class PolicyAttachmentUtil {
-    
+
     private WSDLDescription wsdlDescription = null;
+
     //private HashMap loadedPolicies = new HashMap();
     private PolicyRegistry reg = new PolicyRegistry();
-    
+
+    private SchemaRegistry schemaRegistry = new SchemaRegistry();
+
     public PolicyAttachmentUtil() {
     }
 
     public PolicyAttachmentUtil(WSDLDescription wsdlDescription) {
         this.wsdlDescription = wsdlDescription;
+
         populatePolicyRegistry();
+        populateSchemaRegistry();
+
     }
-    
+
     public PolicyAttachmentUtil(InputStream wsdlInputStream) {
         try {
-            WSDLVersionWrapper build = WOMBuilderFactory.
-                getBuilder(WSDLConstants.WSDL_1_1).build(wsdlInputStream);
+            WSDLVersionWrapper build = WOMBuilderFactory.getBuilder(
+                    WSDLConstants.WSDL_1_1).build(wsdlInputStream);
             wsdlDescription = build.getDescription();
-            populatePolicyRegistry();
             
+            populatePolicyRegistry();
+            populateSchemaRegistry();
+
         } catch (WSDLException e) {
-            throw new IllegalArgumentException("error : "+ e.getMessage());
+            throw new IllegalArgumentException("error : " + e.getMessage());
         }
     }
-    
+
     public void setWSDLDescription(WSDLDescription wsdlDescription) {
         this.wsdlDescription = wsdlDescription;
         reg = new PolicyRegistry();
+        
         populatePolicyRegistry();
+        populateSchemaRegistry();
     }
-    
+
     public WSDLDescription getWSDLDescription() {
         try {
             return getDescription();
-            
+
         } catch (IllegalStateException ex) {
             return null;
         }
     }
-    
+
     private WSDLDescription getDescription() {
         if (wsdlDescription != null) {
             return wsdlDescription;
         }
         throw new IllegalStateException("ERROR: A WSDLDescription is not set");
     }
-    
+
     /**
      * Retruns the Effective policy for a service.
      * 
@@ -114,7 +126,7 @@
     public Policy getPolicyForService(QName serviceName) {
         return getServicePolicy(serviceName);
     }
-    
+
     /**
      * Returns the Effective policy for an Endpoint.
      * 
@@ -124,9 +136,9 @@
     public Policy getPolicyForEndPoint(QName epName) {
         Policy servicePolicy = null;
         Policy endPointPolicy = null;
-        
+
         Iterator iterator = wsdlDescription.getServices().values().iterator();
-        
+
         while (iterator.hasNext()) {
             WSDLService service = (WSDLService) iterator.next();
             if (service.getEndpoints().containsKey(epName)) {
@@ -134,17 +146,16 @@
                 break;
             }
         }
-        
+
         endPointPolicy = getEndPointPolicy(epName);
-        
-        return (servicePolicy != null) 
-                ? (Policy) servicePolicy.merge(endPointPolicy)
-                : endPointPolicy;       
+
+        return (servicePolicy != null) ? (Policy) servicePolicy
+                .merge(endPointPolicy) : endPointPolicy;
     }
-    
+
     /**
      * Returns the Effective policy for an Operation.
-     *  
+     * 
      * @param endPoint
      * @param operation
      * @return
@@ -152,41 +163,41 @@
     public Policy getPolicyForOperation(QName endPoint, QName operation) {
         Policy endPointPolicy = getPolicyForEndPoint(endPoint);
         Policy operationPolicy = getOperationPolicy(endPoint, operation);
-        
+
         //
         if (operationPolicy == null) {
             return endPointPolicy;
-            
+
         } else if (endPointPolicy == null) {
             return operationPolicy;
-            
+
         } else {
             return (Policy) endPointPolicy.merge(operationPolicy);
         }
     }
-    
+
     /**
      * Returns the effective policy of an Input Message.
      * 
      * @param endPoint
      * @param operation
      * @return
-     */ 
+     */
     public Policy getPolicyForInputMessage(QName endPoint, QName operation) {
         Policy operationPolicy = getPolicyForOperation(endPoint, operation);
-        Policy inputMsgPolicy  = getInputMeassagePolicy(endPoint, operation);
-        
+        Policy inputMsgPolicy = getInputMeassagePolicy(endPoint, operation);
+
         if (operationPolicy == null) {
             return inputMsgPolicy;
-            
+
         } else if (inputMsgPolicy == null) {
             return operationPolicy;
-            
+
         } else {
-            return (Policy) operationPolicy.merge(inputMsgPolicy);   
+            return (Policy) operationPolicy.merge(inputMsgPolicy);
         }
     }
-    
+
     /**
      * Returns the effective policy of an Output Message.
      * 
@@ -196,14 +207,14 @@
      */
     public Policy getPolicyForOutputMessage(QName endPoint, QName operation) {
         Policy operationPolicy = getPolicyForOperation(endPoint, operation);
-        Policy outputMsgPolicy  = getOutputMeassagePolicy(endPoint, operation);
-        
+        Policy outputMsgPolicy = getOutputMeassagePolicy(endPoint, operation);
+
         if (operationPolicy == null) {
             return outputMsgPolicy;
-            
+
         } else if (outputMsgPolicy == null) {
             return operationPolicy;
-            
+
         } else {
             return (Policy) operationPolicy.merge(outputMsgPolicy);
         }
@@ -214,144 +225,149 @@
      * @param qname
      * @return
      */
-    public Policy getServicePolicy(QName qname) 
-        throws IllegalArgumentException {
-        
+    public Policy getServicePolicy(QName qname) throws IllegalArgumentException {
+
         WSDLService service = getDescription().getService(qname);
-        
+
         if (service == null) {
-            throw new IllegalArgumentException("no such service:" + qname );
+            throw new IllegalArgumentException("no such service:" + qname);
         }
-        
+
         Policy policy = getPolicyFromComponent(service);
         return (policy == null) ? null : (Policy) policy.normalize();
     }
-    
+
     public Policy getEndPointPolicy(QName qname) {
         WSDLEndpoint endpoint = getEndpoint(qname);
         if (endpoint == null) {
             throw new IllegalArgumentException("no such portType:" + qname);
         }
-        
+
         ArrayList policies = new ArrayList();
-        
+
         // wsdl:port
         Assertion epPolicy = getPolicyFromComponent(endpoint);
         if (epPolicy != null) {
-            policies.add(getPolicyFromComponent(endpoint));         
-        }        
+            policies.add(getPolicyFromComponent(endpoint));
+        }
 
         //wsdl:binding
         WSDLBinding wsdlBinding = endpoint.getBinding();
         Assertion wsdlBindingPolicy = getPolicyFromComponent(wsdlBinding);
         if (wsdlBindingPolicy != null) {
-            policies.add(getPolicyFromComponent(wsdlBinding));          
+            policies.add(getPolicyFromComponent(wsdlBinding));
         }
-        
+
         //wsdl:portType
         WSDLInterface wsdlInterface = wsdlBinding.getBoundInterface();
         Assertion portTypePolicy = getPolicyFromComponent(wsdlInterface);
         if (portTypePolicy != null) {
             policies.add(getPolicyFromComponent(wsdlInterface));
         }
-        
-        return getSinglePolicy(policies);       
+
+        return getSinglePolicy(policies);
     }
 
     public Policy getOperationPolicy(QName eqame, QName oqname) {
-        WSDLEndpoint endPoint = getEndpoint(eqame);             
+        WSDLEndpoint endPoint = getEndpoint(eqame);
         ArrayList list = new ArrayList();
-        
+
         //wsdl:binding/wsdl:operation
         WSDLBinding binding = endPoint.getBinding();
-        WSDLBindingOperation bindingOperation 
-            = (WSDLBindingOperation) binding.getBindingOperations().get(oqname);
-        
+        WSDLBindingOperation bindingOperation = (WSDLBindingOperation) binding
+                .getBindingOperations().get(oqname);
+
         Assertion bindingPolicy = getPolicyFromComponent(bindingOperation);
         if (bindingPolicy != null) {
             list.add(bindingPolicy);
         }
-        
+
         // wsdl:portType/wsdl:operation
         WSDLOperation wsdlOperation = bindingOperation.getOperation();
         Assertion interfacePolicy = getPolicyFromComponent(wsdlOperation);
-        
+
         if (interfacePolicy != null) {
             list.add(interfacePolicy);
-            
+
         }
         return getSinglePolicy(list);
     }
-    
+
     public Policy getInputMeassagePolicy(QName eqname, QName oqname) {
         List policies = new ArrayList();
         WSDLEndpoint endPoint = getEndpoint(eqname);
-        
-        // wsdl:binding/wsdl:operation/wsdl:input       
-        WSDLBindingOperation wsdlBindingOperation 
-            = endPoint.getBinding().getBindingOperation(oqname);
-        WSDLBindingMessageReference bindingInput 
-            = wsdlBindingOperation.getInput();
-        
-        //List extensibilityAttributes = bindingInput.getExtensibilityAttributes();
-        Policy bindingInputPolicy
-            = getSinglePolicy(getPoliciesAsExtensibleElements(bindingInput));
+
+        // wsdl:binding/wsdl:operation/wsdl:input
+        WSDLBindingOperation wsdlBindingOperation = endPoint.getBinding()
+                .getBindingOperation(oqname);
+        WSDLBindingMessageReference bindingInput = wsdlBindingOperation
+                .getInput();
+
+        //List extensibilityAttributes =
+        // bindingInput.getExtensibilityAttributes();
+        Policy bindingInputPolicy = getSinglePolicy(getPoliciesAsExtensibleElements(bindingInput));
         if (bindingInputPolicy != null) {
-            policies.add(bindingInputPolicy);       
-        }        
-        
-        // wsdl:portType/wsdl:operation/wsdl:input              
+            policies.add(bindingInputPolicy);
+        }
+
+        // wsdl:portType/wsdl:operation/wsdl:input
         WSDLOperation wsdlOperation = wsdlBindingOperation.getOperation();
         MessageReference operationInput = wsdlOperation.getInputMessage();
-        Policy operationInputPolicy 
-            = getSinglePolicy(getPoliciesAsExtensibilityAttribute(operationInput));
+        Policy operationInputPolicy = getSinglePolicy(getPoliciesAsExtensibilityAttribute(operationInput));
         if (operationInputPolicy != null) {
             policies.add(operationInputPolicy);
         }
-        
+
         // wsdl:Message
         // TODO
-        
+
         return getSinglePolicy(policies);
     }
 
     public Policy getOutputMeassagePolicy(QName endPointName, QName opName) {
         List policies = new ArrayList();
         WSDLEndpoint endPoint = getEndpoint(endPointName);
-        
+
         // wsdl:binding/wsdl:operation/wsdl:output
-        WSDLBindingOperation wsdlBindingOperation 
-            = endPoint.getBinding().getBindingOperation(opName);
-        WSDLBindingMessageReference bindingOutput 
-            = wsdlBindingOperation.getOutput();
-        Policy bindingOutputPolicy 
-            = getSinglePolicy(getPoliciesAsExtensibleElements(bindingOutput));
+        WSDLBindingOperation wsdlBindingOperation = endPoint.getBinding()
+                .getBindingOperation(opName);
+        WSDLBindingMessageReference bindingOutput = wsdlBindingOperation
+                .getOutput();
+        Policy bindingOutputPolicy = getSinglePolicy(getPoliciesAsExtensibleElements(bindingOutput));
         if (bindingOutputPolicy != null) {
-            policies.add(getPolicyFromComponent(bindingOutput));        
+            policies.add(getPolicyFromComponent(bindingOutput));
         }
-        
+
         // wsdl:portType/wsdl:operation/wsdl:output
         WSDLOperation wsdlOperation = wsdlBindingOperation.getOperation();
         MessageReference operationOutput = wsdlOperation.getOutputMessage();
-        Policy operationOutputPolicy 
-            = getSinglePolicy(getPoliciesAsExtensibilityAttribute(operationOutput));
+        Policy operationOutputPolicy = getSinglePolicy(getPoliciesAsExtensibilityAttribute(operationOutput));
         if (operationOutputPolicy != null) {
             policies.add(operationOutputPolicy);
         }
-        
+
         // wsdl:Message
         // TODO
-        
+
         return getSinglePolicy(policies);
     }
 
-    public Policy getFaultMeassagePolicy(QName endPointName, QName opName, QName fault) {
-        throw new UnsupportedOperationException();      
+    public Policy getFaultMeassagePolicy(QName endPointName, QName opName,
+            QName fault) {
+        throw new UnsupportedOperationException();
+    }
+    
+    public PolicyRegistry getPolicyRegistry() {
+        return reg;
+    }
+    
+    public Element getSchemaElement(String uri) {
+        return schemaRegistry.lookup(uri);
     }
 
     private Policy getSinglePolicy(List policies) {
         Policy result = null;
-        
+
         if (!policies.isEmpty()) {
             Iterator iter = policies.iterator();
             result = (Policy) iter.next();
@@ -362,7 +378,7 @@
         }
         return result;
     }
-    
+
     private WSDLEndpoint getEndpoint(QName epName) {
         Iterator iterator = wsdlDescription.getServices().values().iterator();
         while (iterator.hasNext()) {
@@ -373,85 +389,91 @@
         }
         return null;
     }
-    
+
     private Policy getPolicyFromComponent(Component component) {
-        List list   = new ArrayList();
-        List policiesAsAttributes = getPoliciesAsExtensibilityAttribute(component),
-             policiesAsElements  = getPoliciesAsExtensibleElements(component);
-        
+        List list = new ArrayList();
+        List policiesAsAttributes = getPoliciesAsExtensibilityAttribute(component), policiesAsElements = getPoliciesAsExtensibleElements(component);
+
         list.addAll(policiesAsAttributes);
         list.addAll(policiesAsElements);
-        
-        return getSinglePolicy(list);   
+
+        return getSinglePolicy(list);
     }
 
     private List getPoliciesAsExtensibilityAttribute(Component component) {
         Iterator iterator;
         List policyURIStrings = new ArrayList();
-        List policies   = new ArrayList();
+        List policies = new ArrayList();
         iterator = component.getExtensibilityAttributes().iterator();
-    
+
         while (iterator.hasNext()) {
-            WSDLExtensibilityAttribute exAttribute 
-                = (WSDLExtensibilityAttribute) iterator.next();
+            WSDLExtensibilityAttribute exAttribute = (WSDLExtensibilityAttribute) iterator
+                    .next();
             QName qname = exAttribute.getKey();
-            
-            if (qname.getNamespaceURI().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI) &&
-                    qname.getLocalPart().equals("PolicyURIs")) {
+
+            if (qname.getNamespaceURI().equals(
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI)
+                    && qname.getLocalPart().equals("PolicyURIs")) {
                 String value = exAttribute.getValue().toString();
                 String[] uriStrings = value.split(" ");
-            
+
                 for (int i = 0; i < uriStrings.length; i++) {
                     policyURIStrings.add(uriStrings[i].trim());
-                }               
+                }
             }
         }
-        
+
         if (!policyURIStrings.isEmpty()) {
             iterator = policyURIStrings.iterator();
-            
+
             do {
                 String policyURIString = (String) iterator.next();
                 Policy policy = getPolicyFromURI(policyURIString);
-                policies.add(policy);               
+                policies.add(policy);
             } while (iterator.hasNext());
-        }       
+        }
         return policies;
     }
-    
+
     private List getPoliciesAsExtensibleElements(Component component) {
         ArrayList policies = new ArrayList();
         Iterator iterator = component.getExtensibilityElements().iterator();
-        
+
         while (iterator.hasNext()) {
             Object extensibilityElement = iterator.next();
             if (extensibilityElement instanceof DefaultExtensibilityElement) {
-                DefaultExtensibilityElement defaultExtensibilityElement 
-                    = (DefaultExtensibilityElement) extensibilityElement;
+                DefaultExtensibilityElement defaultExtensibilityElement = (DefaultExtensibilityElement) extensibilityElement;
                 Element element = defaultExtensibilityElement.getElement();
-                
-                if (element.getNamespaceURI().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI) 
+
+                if (element.getNamespaceURI().equals(
+                        PolicyConstants.WS_POLICY_NAMESPACE_URI)
                         && element.getLocalName().equals("PolicyReference")) {
                     policies.add(getPolicyFromPolicyRef(element));
-                    
-                } else if (element.getNamespaceURI().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI) 
+
+                } else if (element.getNamespaceURI().equals(
+                        PolicyConstants.WS_POLICY_NAMESPACE_URI)
                         && element.getLocalName().equals("Policy")) {
                     policies.add(getPolicyFromElement(element));
                 }
             }
-//          WSDLExtensibilityElement exElement = (WSDLExtensibilityElement) iterator.next();
-//          Element element = (Element) exElement.getElement();
-//          if (element.getNamespaceURI().equals(WSPConstants.WS_POLICY_NAMESPACE_URI) && element.getLocalName().equals("PolicyReference")) {
-//              policyList.add(getPolicyAsPolicyRef(element));
-//              
-//          } else if (element.getNamespaceURI().equals(WSPConstants.WS_POLICY_NAMESPACE_URI) && element.getLocalName().equals("Policy")) {
-//              policyList.add(getPolicyAsElement(element));
-//          }
-            
+            //          WSDLExtensibilityElement exElement = (WSDLExtensibilityElement)
+            // iterator.next();
+            //          Element element = (Element) exElement.getElement();
+            //          if
+            // (element.getNamespaceURI().equals(WSPConstants.WS_POLICY_NAMESPACE_URI)
+            // && element.getLocalName().equals("PolicyReference")) {
+            //              policyList.add(getPolicyAsPolicyRef(element));
+            //              
+            //          } else if
+            // (element.getNamespaceURI().equals(WSPConstants.WS_POLICY_NAMESPACE_URI)
+            // && element.getLocalName().equals("Policy")) {
+            //              policyList.add(getPolicyAsElement(element));
+            //          }
+
         }
         return policies;
     }
-    
+
     private Policy getPolicyFromPolicyRef(Element element) {
         String policyURIString = element.getAttribute("URI");
         if (policyURIString != null && policyURIString.length() != 0) {
@@ -459,52 +481,67 @@
         }
         return null;
     }
-    
+
     private Policy getPolicyFromElement(Element element) {
         InputStream policyInputStream = createInputStream(element);
         PolicyReader reader = PolicyFactory.getInstance().getPolicyReader();
         return reader.readPolicy(policyInputStream);
     }
-    
+
     private InputStream createInputStream(Element element) {
-        // some improvements ..??? 
+        // some improvements ..???
         StringWriter sw = new StringWriter();
         DOM2Writer.serializeAsXML(element, sw);
         return new ByteArrayInputStream(sw.toString().getBytes());
     }
-    
+
     private Policy getPolicyFromURI(String policyURIString) {
         return reg.lookup(policyURIString);
     }
-    
+
     public String getTargetURI() {
         return getDescription().getTargetNameSpace();
     }
 
+    private void populateSchemaRegistry() {
+        WSDLDescription des = getDescription();
+        WSDLTypes types = des.getTypes();
+
+        Iterator iterator = types.getExtensibilityElements().iterator();
+        while (iterator.hasNext()) {
+            Object extElement = iterator.next();
+            if (extElement instanceof Schema) {
+                Element schemaElement = ((Schema) extElement).getElement();
+                schemaRegistry.register(schemaElement
+                        .getAttribute("targetNamespace"), schemaElement);
+            }
+        }
+    }
+
     private void populatePolicyRegistry() {
         Iterator iterator;
         WSDLDescription des = getDescription();
         List extElements = des.getExtensibilityElements();
         registerPoliciesAsElements(extElements);
-        
+
         iterator = des.getWsdlInterfaces().values().iterator();
         while (iterator.hasNext()) {
             WSDLInterface interfaze = (WSDLInterface) iterator.next();
             registerPoliciesInWSDLInterface(interfaze);
         }
-        
+
         iterator = des.getBindings().values().iterator();
         while (iterator.hasNext()) {
             WSDLBinding wsdlBinding = (WSDLBinding) iterator.next();
             registerPoliciesInWSDLBinding(wsdlBinding);
         }
-        
+
         iterator = des.getServices().values().iterator();
         while (iterator.hasNext()) {
-            WSDLService service = (WSDLService) iterator.next();    
+            WSDLService service = (WSDLService) iterator.next();
             registerPoliciesInService(service);
         }
-        
+
         iterator = reg.keys();
         while (iterator.hasNext()) {
             String uriString = (String) iterator.next();
@@ -513,10 +550,12 @@
                 try {
                     URI policyURI = new URI(uriString);
                     URL policyURL = policyURI.toURL();
-                    PolicyReader reader = PolicyFactory.getInstance().getPolicyReader();
-                    Policy newPolicy = reader.readPolicy(policyURL.openStream());
+                    PolicyReader reader = PolicyFactory.getInstance()
+                            .getPolicyReader();
+                    Policy newPolicy = reader
+                            .readPolicy(policyURL.openStream());
                     reg.register(uriString, newPolicy);
-                    
+
                 } catch (Exception e) {
                     e.printStackTrace();
                     reg.unregister(uriString);
@@ -529,40 +568,46 @@
     private void registerPoliciesInService(WSDLService service) {
         List extensibilityElements = service.getExtensibilityElements();
         registerPoliciesAsElements(extensibilityElements);
-        
+
         Iterator iterator = service.getEndpoints().values().iterator();
         while (iterator.hasNext()) {
             WSDLEndpoint wsdlEndpoint = (WSDLEndpoint) iterator.next();
             extensibilityElements = wsdlEndpoint.getExtensibilityElements();
-            registerPoliciesAsElements(extensibilityElements);          
-        }       
+            registerPoliciesAsElements(extensibilityElements);
+        }
     }
-    
+
     private void registerPoliciesInWSDLBinding(WSDLBinding wsdlBinding) {
         List extensibilityElements = wsdlBinding.getExtensibilityElements();
         registerPoliciesAsElements(extensibilityElements);
-        
-        Iterator iterator = wsdlBinding.getBindingOperations().values().iterator();
+
+        Iterator iterator = wsdlBinding.getBindingOperations().values()
+                .iterator();
         while (iterator.hasNext()) {
-            WSDLBindingOperation wsdlBindingOperation = (WSDLBindingOperation) iterator.next();
+            WSDLBindingOperation wsdlBindingOperation = (WSDLBindingOperation) iterator
+                    .next();
             registerPoliciesInBindOperation(wsdlBindingOperation);
-        }       
+        }
     }
-    
-    private void registerPoliciesInBindOperation(WSDLBindingOperation wsdlBindingOperation) {
-        List extensibilityElements = wsdlBindingOperation.getExtensibilityElements();
+
+    private void registerPoliciesInBindOperation(
+            WSDLBindingOperation wsdlBindingOperation) {
+        List extensibilityElements = wsdlBindingOperation
+                .getExtensibilityElements();
         registerPoliciesAsElements(extensibilityElements);
-        
+
         if (wsdlBindingOperation.getInput() != null) {
-            extensibilityElements = wsdlBindingOperation.getInput().getExtensibilityElements();
+            extensibilityElements = wsdlBindingOperation.getInput()
+                    .getExtensibilityElements();
             registerPoliciesAsElements(extensibilityElements);
         }
         if (wsdlBindingOperation.getOutput() != null) {
-            extensibilityElements = wsdlBindingOperation.getOutput().getExtensibilityElements();
+            extensibilityElements = wsdlBindingOperation.getOutput()
+                    .getExtensibilityElements();
             registerPoliciesAsElements(extensibilityElements);
         }
     }
-    
+
     private void registerPoliciesInWSDLInterface(WSDLInterface wsdlInterface) {
         registerPoliciesInElement(wsdlInterface);
         Iterator iterator = wsdlInterface.getOperations().values().iterator();
@@ -571,63 +616,64 @@
             registerPoliciesInWSDLOperation(wsdlOperation);
         }
     }
-    
-    private void registerPoliciesInWSDLOperation(WSDLOperation wsdlOperation){
+
+    private void registerPoliciesInWSDLOperation(WSDLOperation wsdlOperation) {
         List extensibilityElements = wsdlOperation.getExtensibilityElements();
         registerPoliciesAsElements(extensibilityElements);
-        
+
         if (wsdlOperation.getInputMessage() != null) {
             registerPoliciesInElement(wsdlOperation.getInputMessage());
         }
         if (wsdlOperation.getOutputMessage() != null) {
-            registerPoliciesInElement(wsdlOperation.getOutputMessage());        
+            registerPoliciesInElement(wsdlOperation.getOutputMessage());
         }
     }
-    
+
     private void registerPoliciesInElement(Component component) {
         registerPoliciesAsAttribute(component.getExtensibilityAttributes());
         registerPoliciesAsElements(component.getExtensibilityElements());
     }
-    
+
     private void registerPoliciesAsElements(List elements) {
         Iterator iterator = elements.iterator();
         while (iterator.hasNext()) {
             Object extensibilityElement = iterator.next();
-            
+
             if (extensibilityElement instanceof DefaultExtensibilityElement) {
-                DefaultExtensibilityElement defaultExtensibilityElement 
-                    = (DefaultExtensibilityElement) extensibilityElement;
+                DefaultExtensibilityElement defaultExtensibilityElement = (DefaultExtensibilityElement) extensibilityElement;
                 Element element = defaultExtensibilityElement.getElement();
-                
-                if (element.getNamespaceURI().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI) 
+
+                if (element.getNamespaceURI().equals(
+                        PolicyConstants.WS_POLICY_NAMESPACE_URI)
                         && element.getLocalName().equals("PolicyReference")) {
                     String uriString = element.getAttribute("URI");
-                    
+
                     if (reg.lookup(uriString) == null) {
-                        reg.register(uriString, null);                      
+                        reg.register(uriString, null);
                     }
-                } 
-                
-                String policyID 
-                    = element.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI, "Id");
-    
+                }
+
+                String policyID = element.getAttributeNS(
+                        PolicyConstants.WSU_NAMESPACE_URI, "Id");
+
                 if (policyID.length() != 0) {
                     registerPolicyElement(element);
                 }
             }
-        }       
+        }
     }
-    
+
     private void registerPoliciesAsAttribute(List elements) {
         Iterator iterator = elements.iterator();
-        
+
         while (iterator.hasNext()) {
-            WSDLExtensibilityAttribute wsdlExtensibilityAttribute 
-                = (WSDLExtensibilityAttribute) iterator.next();
+            WSDLExtensibilityAttribute wsdlExtensibilityAttribute = (WSDLExtensibilityAttribute) iterator
+                    .next();
             QName qname = wsdlExtensibilityAttribute.getKey();
-            
-            if (qname.getNamespaceURI().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI) &&
-                    qname.getLocalPart().equals("PolicyURIs")) {
+
+            if (qname.getNamespaceURI().equals(
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI)
+                    && qname.getLocalPart().equals("PolicyURIs")) {
                 String value = wsdlExtensibilityAttribute.getValue().toString();
                 String[] policyURIs = value.split(" ");
                 for (int i = 0; i < policyURIs.length; i++) {
@@ -636,11 +682,11 @@
                     if (reg.lookup(policyURI) == null) {
                         reg.register(policyURI, null);
                     }
-                }               
+                }
             }
         }
     }
-    
+
     private void registerPolicyElement(Element element) {
         InputStream elementInputStream = createInputStream(element);
         PolicyReader reader = PolicyFactory.getInstance().getPolicyReader();

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyReader.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyReader.java?rev=355072&r1=355071&r2=355072&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyReader.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyReader.java Thu Dec  8 03:25:42 2005
@@ -16,7 +16,6 @@
 
 package org.apache.ws.policy.util;
 
-
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Hashtable;
@@ -44,129 +43,150 @@
  * @author Sanka Samaranayake (sanka@apache.org)
  */
 public class PolicyReader {
-	PolicyReader() {
-	}
+    PolicyReader() {
+    }
+
+    public Policy readPolicy(InputStream in) {
+        try {
+            XMLStreamReader reader = XMLInputFactory.newInstance()
+                    .createXMLStreamReader(in);
+            OMXMLParserWrapper builder = OMXMLBuilderFactory
+                    .createStAXOMBuilder(OMAbstractFactory.getOMFactory(),
+                            reader);
+
+            OMElement element = builder.getDocumentElement();
+            return readPolicy(element);
+
+        } catch (XMLStreamException ex) {
+            throw new RuntimeException("error : " + ex.getMessage());
+        }
+    }
+
+    private Assertion readAssertion(OMElement element) {
+        String namespace = element.getNamespace().getName();
+        String localName = element.getLocalName();
+
+        if (!(namespace.equals(PolicyConstants.WS_POLICY_NAMESPACE_URI))) {
+            return readPrimitiveAssertion(element);
+        }
+
+        if (localName.equals(PolicyConstants.WS_POLICY)) {
+            return readPolicy(element);
+
+        } else if (localName.equals(PolicyConstants.AND_COMPOSITE_ASSERTION)) {
+            return readAndComposite(element);
+
+        } else if (localName.equals(PolicyConstants.XOR_COMPOSITE_ASSERTION)) {
+            return readXorComposite(element);
+
+        } else if (localName.equals(PolicyConstants.WS_POLICY_REFERENCE)) {
+            return readPolicyReference(element);
+
+        } else {
+            throw new RuntimeException("unknown element ..");
+        }
+    }
+
+    private Policy readPolicy(OMElement element) {
+        Policy policy = new Policy();
+
+        OMAttribute attri;
+        attri = element.getAttribute(new QName(
+                PolicyConstants.WSU_NAMESPACE_URI, "Id"));
+        if (attri != null) {
+            policy.setId(attri.getAttributeValue());
+        }
+
+        attri = element.getAttribute(new QName("base", "", "xml"));
+        if (attri != null) {
+            policy.setBase(attri.getAttributeValue());
+        }
+
+        policy.addTerms(readTerms(element));
+        return policy;
+    }
+
+    private AndCompositeAssertion readAndComposite(OMElement element) {
+        AndCompositeAssertion andCompositeAssertion = new AndCompositeAssertion();
+        andCompositeAssertion.addTerms(readTerms(element));
+        return andCompositeAssertion;
+    }
+
+    private XorCompositeAssertion readXorComposite(OMElement element) {
+        XorCompositeAssertion xorCompositeAssertion = new XorCompositeAssertion();
+        xorCompositeAssertion.addTerms(readTerms(element));
+        return xorCompositeAssertion;
+    }
 
-	public Policy readPolicy(InputStream in) {
-		try {
-			XMLStreamReader reader = XMLInputFactory.newInstance()
-					.createXMLStreamReader(in);
-			OMXMLParserWrapper builder = OMXMLBuilderFactory
-					.createStAXOMBuilder(OMAbstractFactory.getOMFactory(),
-							reader);
-
-			OMElement element = builder.getDocumentElement();
-			return readPolicy(element);
-
-		} catch (XMLStreamException ex) {
-			throw new RuntimeException("error : " + ex.getMessage());
-		}
-	}
-	
-	private Assertion readAssertion(OMElement element) {
-		String namespace = element.getNamespace().getName();
-		String localName = element.getLocalName();
-		
-		if (!(namespace.equals(PolicyConstants.WS_POLICY_NAMESPACE_URI))) {
-			return readPrimitiveAssertion(element);
-		}
-		
-		if (localName.equals(PolicyConstants.WS_POLICY)) {
-			return readPolicy(element);
-			
-		} else if (localName.equals(PolicyConstants.AND_COMPOSITE_ASSERTION)) {
-			return readAndComposite(element);
-			
-		} else if (localName.equals(PolicyConstants.XOR_COMPOSITE_ASSERTION)) {
-			return readXorComposite(element);
-			
-		} else if (localName.equals(PolicyConstants.WS_POLICY_REFERENCE)) {
-			return readPolicyReference(element);
-			
-		} else {
-			throw new RuntimeException("unknown element ..");
-		}		
-	}
-	
-	private Policy readPolicy(OMElement element) {
-		Policy policy = new Policy();
-		policy.addTerms(readTerms(element));
-		return policy;
-	}
-	
-	private AndCompositeAssertion readAndComposite(OMElement element) {
-		AndCompositeAssertion andCompositeAssertion = new AndCompositeAssertion();
-		andCompositeAssertion.addTerms(readTerms(element));
-		return andCompositeAssertion;
-	}	
-	
-	private XorCompositeAssertion readXorComposite(OMElement element) {
-		XorCompositeAssertion xorCompositeAssertion = new XorCompositeAssertion();
-		xorCompositeAssertion.addTerms(readTerms(element));
-		return xorCompositeAssertion;
-	}
-	
-	private PolicyReference readPolicyReference(OMElement element) {
-		OMAttribute attribute = element.getAttribute(new QName("URI"));
-		return new PolicyReference(attribute.getAttributeValue());
-	}
-	
-	private PrimitiveAssertion readPrimitiveAssertion(OMElement element) {
+    private PolicyReference readPolicyReference(OMElement element) {
+        OMAttribute attribute = element.getAttribute(new QName("URI"));
+        return new PolicyReference(attribute.getAttributeValue());
+    }
+
+    private PrimitiveAssertion readPrimitiveAssertion(OMElement element) {
         QName qname = element.getQName();
         PrimitiveAssertion result = new PrimitiveAssertion(qname);
-        
+
         result.setAttributes(getAttributes(element));
-        
+
+        String isOptional = result.getAttribute(new QName(
+                PolicyConstants.WS_POLICY_NAMESPACE_URI, "Optional"));
+        if (isOptional != null && Boolean.getBoolean(isOptional)) {
+            result.setOptional(true);
+        }
+
         // setting the text value ..
         String strValue = element.getText();
-     
+
         if (strValue != null && strValue.length() != 0) {
-            result.setStrValue(strValue);            
+            result.setStrValue(strValue);
         }
-        
+
         //CHECK ME
         Iterator childElements = element.getChildElements();
-        
+
         while (childElements.hasNext()) {
             OMElement childElement = (OMElement) childElements.next();
-            
-            if (childElement.getNamespace().getName().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI)
-                    && childElement.getLocalName().equals(PolicyConstants.WS_POLICY)) {
+
+            if (childElement.getNamespace().getName().equals(
+                    PolicyConstants.WS_POLICY_NAMESPACE_URI)
+                    && childElement.getLocalName().equals(
+                            PolicyConstants.WS_POLICY)) {
                 Policy policy = readPolicy(childElement);
                 result.addTerm(policy);
-        
+
             } else {
                 PrimitiveAssertion pa = readPrimitiveAssertion(childElement);
-                result.addTerm(pa);                
+                result.addTerm(pa);
+            }
+        }
+        return result;
+    }
+
+    private ArrayList readTerms(OMElement element) {
+        ArrayList terms = new ArrayList();
+        Iterator childElements = element.getChildren();
+
+        while (childElements.hasNext()) {
+            Object obj = childElements.next();
+
+            if (obj instanceof OMElement) {
+                OMElement e = (OMElement) obj;
+                terms.add(readAssertion(e));
             }
-        }        
-        return result;       
+        }
+        return terms;
     }
-	
-	private ArrayList readTerms(OMElement element) {
-		ArrayList terms = new ArrayList();
-		Iterator childElements = element.getChildren();
-		
-		while (childElements.hasNext()) {
-			Object obj = childElements.next();
-			
-			if (obj instanceof OMElement) {
-				OMElement e = (OMElement) obj;
-				terms.add(readAssertion(e));				
-			}
-		}
-		return terms;		
-	}
-	
-	private Hashtable getAttributes(OMElement element) {
-		Hashtable attributes = new Hashtable();
-		Iterator iterator = element.getAllAttributes();
-
-		while (iterator.hasNext()) {
-			OMAttribute attribute = (OMAttribute) iterator.next();
-			attributes.put(attribute.getQName(), attribute.getAttributeValue());
-		}
 
-		return attributes;
-	}
+    private Hashtable getAttributes(OMElement element) {
+        Hashtable attributes = new Hashtable();
+        Iterator iterator = element.getAllAttributes();
+
+        while (iterator.hasNext()) {
+            OMAttribute attribute = (OMAttribute) iterator.next();
+            attributes.put(attribute.getQName(), attribute.getAttributeValue());
+        }
+
+        return attributes;
+    }
 }

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyWriter.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyWriter.java?rev=355072&r1=355071&r2=355072&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyWriter.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyWriter.java Thu Dec  8 03:25:42 2005
@@ -16,7 +16,6 @@
 
 package org.apache.ws.policy.util;
 
-
 import java.io.OutputStream;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -39,138 +38,157 @@
  * @author Sanka Samaranayake (sanka@apache.org)
  */
 public class PolicyWriter {
-	
-	PolicyWriter() {
-	}
-	
-	public void writePolicy(Policy policy, OutputStream output) {
-		XMLStreamWriter writer = null;
-		try {
-			writer =
-				XMLOutputFactory.newInstance().createXMLStreamWriter(output);
-			writePolicy(policy, writer);
-			
-			writer.flush();
-			
-		} catch (XMLStreamException ex) {
-			throw new RuntimeException(ex);
-		}
-	}
-	
-	private void writePolicy(Policy policy, XMLStreamWriter writer) throws XMLStreamException {
-		writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX, PolicyConstants.WS_POLICY, 
-				PolicyConstants.WSU_NAMESPACE_URI);
-		
-		Iterator iterator = policy.getTerms().iterator();
-		while (iterator.hasNext()) {
-			Assertion term = (Assertion) iterator.next();
-			writeAssertion(term, writer);
-		}
-		
-		writer.writeEndElement();
-	}
-	
-	private void writeAssertion(Assertion assertion,
-			XMLStreamWriter writer) throws XMLStreamException {
-		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);
-			
-		} else if (assertion instanceof PolicyReference) {
-			writePolicyReference((PolicyReference) assertion, writer);
-			
-		} else if (assertion instanceof Policy) {
-			writePolicy((Policy) assertion, writer);
-		} else {
-			throw new RuntimeException("unknown element type");
-		}
-	}
-	
-	private void writeAndCompositeAssertion(AndCompositeAssertion assertion, 
-			XMLStreamWriter writer) throws XMLStreamException {
-		writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX, 
-				PolicyConstants.AND_COMPOSITE_ASSERTION, PolicyConstants.WS_POLICY_NAMESPACE_URI);
-		
-		List terms = assertion.getTerms();
-		writeTerms(terms, writer);
-		
-		writer.writeEndElement();		
-	}
-	
-	private void writeXorCompositeAssertion(XorCompositeAssertion assertion,
-			XMLStreamWriter writer) throws XMLStreamException {
-		writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX, 
-				PolicyConstants.XOR_COMPOSITE_ASSERTION, PolicyConstants.WS_POLICY_NAMESPACE_URI);
-		
-		List terms = assertion.getTerms();
-		writeTerms(terms, writer);
-		
-		writer.writeEndElement();		
-	}
-	
-	private void writePrimitiveAssertion(PrimitiveAssertion assertion,
-			XMLStreamWriter writer) throws XMLStreamException {	
-		QName qname = assertion.getName();
-		
-		String prefix = qname.getPrefix();
-		if (prefix != null) {
-			writer.writeStartElement(qname.getPrefix(), qname.getLocalPart(),
-					qname.getNamespaceURI());
-			
-		} else {
-			writer.writeStartElement(qname.getLocalPart(), 
-					qname.getNamespaceURI());
-		}
-		
-		Hashtable attributes = assertion.getAttributes();
-		writeAttributes(attributes, writer);		
-		
-		String text = (String) assertion.getStrValue();
-		if (text != null) {
-			writer.writeCharacters(text);
-		}
-		
-		List terms = assertion.getTerms();
-		writeTerms(terms, writer);
-		
-		writer.writeEndElement();
-	}
-	
-	private void writePolicyReference(PolicyReference assertion, 
-			XMLStreamWriter writer) throws XMLStreamException {
-	}
-	
-	private void writeTerms(List terms, 
-			XMLStreamWriter writer) throws XMLStreamException {
-		
-		Iterator iterator = terms.iterator();
-		while (iterator.hasNext()) {
-			Assertion assertion = (Assertion) iterator.next();
-			writeAssertion(assertion, writer);
-		}
-	}	
-	
-	private void writeAttributes(Hashtable attributes, XMLStreamWriter writer) 
-			throws XMLStreamException {
-		
-		Iterator iterator = attributes.keySet().iterator();
-		while (iterator.hasNext()) {
-			QName qname = (QName) iterator.next();
-			String value = (String) attributes.get(qname);
-			
-			String prefix = qname.getPrefix();
-			if (prefix != null) {
-				writer.writeAttribute(prefix, qname.getNamespaceURI(),
-						qname.getLocalPart(), value);
-			} else {
-				writer.writeAttribute(qname.getNamespaceURI(), 
-						qname.getLocalPart(), value);
-			}
-		}
-	}
+
+    private int num = 1;
+
+    PolicyWriter() {
+    }
+
+    public void writePolicy(Policy policy, OutputStream output) {
+        XMLStreamWriter writer = null;
+        try {
+            writer = XMLOutputFactory.newInstance().createXMLStreamWriter(
+                    output);
+            writePolicy(policy, writer);
+
+            writer.flush();
+
+        } catch (XMLStreamException ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    private void writePolicy(Policy policy, XMLStreamWriter writer)
+            throws XMLStreamException {
+        writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
+                PolicyConstants.WS_POLICY);
+        writer.writeNamespace(PolicyConstants.WS_POLICY_PREFIX,
+                PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+        if (policy.getId() != null) {
+            writer.writeAttribute("wsu", PolicyConstants.WSU_NAMESPACE_URI,
+                    "Id", policy.getId());
+        }
+
+        Iterator iterator = policy.getTerms().iterator();
+        while (iterator.hasNext()) {
+            Assertion term = (Assertion) iterator.next();
+            writeAssertion(term, writer);
+        }
+
+        writer.writeEndElement();
+    }
+
+    private void writeAssertion(Assertion assertion, XMLStreamWriter writer)
+            throws XMLStreamException {
+        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);
+
+        } else if (assertion instanceof PolicyReference) {
+            writePolicyReference((PolicyReference) assertion, writer);
+
+        } else if (assertion instanceof Policy) {
+            writePolicy((Policy) assertion, writer);
+        } else {
+            throw new RuntimeException("unknown element type");
+        }
+    }
+
+    private void writeAndCompositeAssertion(AndCompositeAssertion assertion,
+            XMLStreamWriter writer) throws XMLStreamException {
+        writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
+                PolicyConstants.AND_COMPOSITE_ASSERTION,
+                PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+        List terms = assertion.getTerms();
+        writeTerms(terms, writer);
+
+        writer.writeEndElement();
+    }
+
+    private void writeXorCompositeAssertion(XorCompositeAssertion assertion,
+            XMLStreamWriter writer) throws XMLStreamException {
+        writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
+                PolicyConstants.XOR_COMPOSITE_ASSERTION,
+                PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+        List terms = assertion.getTerms();
+        writeTerms(terms, writer);
+
+        writer.writeEndElement();
+    }
+
+    private void writePrimitiveAssertion(PrimitiveAssertion assertion,
+            XMLStreamWriter writer) throws XMLStreamException {
+        QName qname = assertion.getName();
+
+        String prefix = qname.getPrefix();
+        if (prefix != null) {
+            writer.writeStartElement(qname.getPrefix(), qname.getLocalPart());
+            writer.writeNamespace(qname.getPrefix(), qname.getNamespaceURI());
+
+        } else {
+            writer.writeStartElement(qname.getLocalPart(), qname
+                    .getNamespaceURI());
+            writer.writeNamespace(generateNamespace(), qname.getNamespaceURI());
+        }
+
+        Hashtable attributes = assertion.getAttributes();
+        writeAttributes(attributes, writer);
+
+        String text = (String) assertion.getStrValue();
+        if (text != null) {
+            writer.writeCharacters(text);
+        }
+
+        List terms = assertion.getTerms();
+        writeTerms(terms, writer);
+
+        writer.writeEndElement();
+    }
+
+    private void writePolicyReference(PolicyReference assertion,
+            XMLStreamWriter writer) throws XMLStreamException {
+    }
+
+    private void writeTerms(List terms, XMLStreamWriter writer)
+            throws XMLStreamException {
+
+        Iterator iterator = terms.iterator();
+        while (iterator.hasNext()) {
+            Assertion assertion = (Assertion) iterator.next();
+            writeAssertion(assertion, writer);
+        }
+    }
+
+    private void writeAttributes(Hashtable attributes, XMLStreamWriter writer)
+            throws XMLStreamException {
+
+        Iterator iterator = attributes.keySet().iterator();
+        while (iterator.hasNext()) {
+            QName qname = (QName) iterator.next();
+            String value = (String) attributes.get(qname);
+
+            String prefix = qname.getPrefix();
+            if (prefix != null) {
+                writer.writeAttribute(prefix, qname.getNamespaceURI(), qname
+                        .getLocalPart(), value);
+            } else {
+                writer.writeAttribute(qname.getNamespaceURI(), qname
+                        .getLocalPart(), value);
+            }
+        }
+    }
+
+    private String generateNamespace() {
+        return "ns" + num++;
+    }
 }



Mime
View raw message