[wsas-java-dev] [wsas commit] r21 - in wsas/java/trunk: . modules/wsf-common-core modules/wsf-common-core/src/org/wso2/wsf/common/mex modules/wsf-common-core/src/org/wso2/wsf/common/mex/model modules/wsf-common-core/src/org/wso2/wsf/common/mex/module modules/wsf-common-core/src/org/wso2/wsf/common/mex/module/META-INF modules/wsf-common-core/src/org/wso2/wsf/common/mex/util

svn at wso2.com svn at wso2.com
Thu Nov 30 04:37:14 PST 2006


Author: sanka
Date: Thu Nov 30 04:37:13 2006
New Revision: 21

Added:
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/MetadataConstants.java
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/MetadataExchangeMessageReceiver.java
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/GetMetadata.java
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/Metadata.java
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/MetadataLocation.java
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/MetadataReference.java
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/MetadataSection.java
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/module/
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/module/META-INF/
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/module/META-INF/module.xml
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/module/MetadataExchangeModule.java
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/util/
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/util/MetadataExchangeClient.java
   wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/util/MetadataUtil.java
Modified:
   wsas/java/trunk/maven.xml
   wsas/java/trunk/modules/wsf-common-core/maven.xml
Log:
Added the mex module codebase.



Modified: wsas/java/trunk/maven.xml
==============================================================================
--- wsas/java/trunk/maven.xml	(original)
+++ wsas/java/trunk/maven.xml	Thu Nov 30 04:37:13 2006
@@ -948,6 +948,9 @@
         <ant:copy
                 tofile="${dist.temp.dir}/repository/modules/throttle-${wso2wsas.version}.mar"
                 file="modules/wsf-common-core/target/throttle-${wso2wsas.version}.mar"/>
+	<ant:copy
+                tofile="${dist.temp.dir}/repository/modules/mex-${wso2wsas.version}.mar"
+                file="modules/wsf-common-core/target/mex-${wso2wsas.version}.mar"/>
 
         <ant:move toDir="${dist.temp.dir}/repository/modules">
             <ant:fileset dir="${dist.temp.dir}/lib">

Modified: wsas/java/trunk/modules/wsf-common-core/maven.xml
==============================================================================
--- wsas/java/trunk/modules/wsf-common-core/maven.xml	(original)
+++ wsas/java/trunk/modules/wsf-common-core/maven.xml	Thu Nov 30 04:37:13 2006
@@ -56,6 +56,19 @@
         </jar>
         <copy file="target/tracer-${wso2wsas.version}.mar"
               tofile="${maven.repo.local}/org.wso2.wsf/mars/tracer-${wso2wsas.version}.mar"/>
+	      
+	      
+	<!-- MEX module -->
+	<property name="mex.module.dir" value="target/mex/module"/>
+        <mkdir dir="${mex.module.dir}/META-INF"/>
+        <copy tofile="${mex.module.dir}/META-INF/module.xml"
+              file="src/org/wso2/wsf/common/mex/module/META-INF/module.xml"/>
+        <jar jarfile="target/mex-${wso2wsas.version}.mar"
+             basedir="${mex.module.dir}">
+            <include name="**"/>
+        </jar>
+        <copy file="target/mex-${wso2wsas.version}.mar"
+              tofile="${maven.repo.local}/org.wso2.wsf/mars/mex-${wso2wsas.version}.mar"/>
 
     </postGoal>
 

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/MetadataConstants.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/MetadataConstants.java	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsf.common.mex;
+
+import javax.xml.namespace.QName;
+
+public class MetadataConstants {
+    
+    public static final String URI_MEX_NS = "http://schemas.xmlsoap.org/ws/2004/09/mex/";
+    
+    public static final String URI_WSA_NS = "http://www.w3.org/2005/08/addressing"; 
+    
+    public static final String URI_MEX_TRANSFER_ACTION = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get";
+    
+    public static final String URI_MEX_TRANSFER_RESPONSE_ACTION = "http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse/";
+    
+    public static final String URI_MEX_GET_ACTION = "http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Request";
+    
+    public static final String URI_MEX_GET_RESPONSE_ACTION = "http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Response";
+    
+    public static final String ATTR_MEX = "mex";
+    
+    public static final String ELEM_METADATA = "Metadata";
+    
+    public static final String ATTR_WSA = "wsa";
+    
+    public static final String ELEM_METADATA_SECTION = "MetadataSection";
+    
+    public static final String ATTR_DIALECT = "Dialect";
+    
+    public static final String ATTR_IDENTIFIER = "Identifier";
+    
+    public static final String ELEM_METADATA_REFERENCE = "MetadataReference";
+    
+    public static final String ELEM_GET_METADATA = "GetMetadata";
+    
+    public static final String ELEM_LOCATION = "Location";
+    
+    public static final String ELEM_ADDRESS = "Address";
+    
+    public static final String ELEM_IDENTIFIER = "Identifier";
+    
+    public static final String ELEM_DIALECT = "Dialect";
+    
+    public static final QName Q_ATTR_DIALECT = new QName("", ATTR_DIALECT);
+    
+    public static final QName Q_ELEM_DIALECT = new QName(URI_MEX_NS,ELEM_DIALECT, ATTR_MEX);
+    
+    public static final QName Q_ELEM_IDENTIFIER = new QName(URI_MEX_NS, ELEM_IDENTIFIER, ATTR_MEX);
+    
+    public static final QName Q_ELEM_GET_METADATA = new QName(URI_MEX_NS, ELEM_GET_METADATA, ATTR_MEX);
+    
+    public static final QName Q_ELEM_METADATA_SECTION = new QName(URI_MEX_NS, ELEM_METADATA_SECTION, ATTR_MEX);
+    
+    public static final QName Q_ELEM_METADATA_REFERENCE =  new QName(URI_MEX_NS, ELEM_METADATA_REFERENCE, ATTR_MEX);
+    
+    public static final String DIALECT_WSDL = "http://schemas.xmlsoap.org/wsdl/";
+    
+    public static final String DIALECT_SCHEMA = "http://www.w3.org/2001/XMLSchema";
+    
+    public static final String DIALECT_POLICY = "http://schemas.xmlsoap.org/ws/2004/09/policy/";
+}

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/MetadataExchangeMessageReceiver.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/MetadataExchangeMessageReceiver.java	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,183 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsf.common.mex;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver;
+import org.wso2.wsf.common.mex.model.GetMetadata;
+import org.wso2.wsf.common.mex.model.Metadata;
+import org.wso2.wsf.common.mex.model.MetadataSection;
+import org.wso2.wsf.common.mex.util.MetadataUtil;
+
+public class MetadataExchangeMessageReceiver extends
+        AbstractInOutSyncMessageReceiver {
+
+    public void invokeBusinessLogic(MessageContext inMsgCtx,
+            MessageContext outMsgCtx) throws AxisFault {
+
+        String wsaAction = inMsgCtx.getWSAAction();
+        wsaAction = wsaAction.trim();
+
+        if (MetadataConstants.URI_MEX_TRANSFER_ACTION.equals(wsaAction)) {
+            EndpointReference epr = inMsgCtx.getTo();
+
+            if (epr.getAddress().endsWith("metadata")) {
+                handleWSTransferMetadataRequest(inMsgCtx, outMsgCtx);
+
+            } else if (epr.getAddress().indexOf("/policy") > -1) {
+                handleWSTransferPolicyRequest(inMsgCtx, outMsgCtx);
+            }
+
+        } else {
+            handleGetMetadataRequest(inMsgCtx, outMsgCtx);
+        }
+    }
+
+    private void handleWSTransferMetadataRequest(MessageContext inMsgCtx,
+            MessageContext outMsgCtx) throws AxisFault {
+        String address = inMsgCtx.getTo().getAddress();
+        SOAPEnvelope inMsgEnvelope = inMsgCtx.getEnvelope();
+        SOAPFactory factory = (SOAPFactory) inMsgEnvelope.getOMFactory();
+
+        SOAPEnvelope outMsgEnvelope = factory.getDefaultEnvelope();
+        SOAPBody outMsgBody = outMsgEnvelope.getBody();
+
+        // create the default reponse ..
+        Metadata metadata = new Metadata();
+
+        addServiceMetadata(metadata, inMsgCtx, factory, address);
+        metadata.toOM(outMsgBody);
+
+        outMsgCtx
+                .setWSAAction(MetadataConstants.URI_MEX_TRANSFER_RESPONSE_ACTION);
+        outMsgCtx
+                .setSoapAction(MetadataConstants.URI_MEX_TRANSFER_RESPONSE_ACTION);
+
+        outMsgCtx.setEnvelope(outMsgEnvelope);
+    }
+
+    private void handleWSTransferPolicyRequest(MessageContext inMsgCtx,
+            MessageContext outMsgCtx) throws AxisFault {
+        SOAPEnvelope inMsgEnvelope = inMsgCtx.getEnvelope();
+        SOAPFactory factory = (SOAPFactory) inMsgEnvelope.getOMFactory();
+
+        SOAPEnvelope outMsgEnvelope = factory.getDefaultEnvelope();
+        SOAPBody outMsgBody = outMsgEnvelope.getBody();
+
+        String address = inMsgCtx.getTo().getAddress();
+        String identifier = address.substring(address.lastIndexOf("/policy/")
+                + "/policy/".length());
+
+        // create the default reponse ..
+        Metadata metadata = new Metadata();
+
+        MetadataSection metadataSection = MetadataUtil.getMetadataSection(
+                MetadataConstants.DIALECT_POLICY, identifier, inMsgCtx,
+                factory);
+
+        if (metadataSection != null) {
+            metadata.addMetadataSection(metadataSection);
+        }
+
+        metadata.toOM(outMsgBody);
+
+        outMsgCtx
+                .setWSAAction(MetadataConstants.URI_MEX_TRANSFER_RESPONSE_ACTION);
+        outMsgCtx
+                .setSoapAction(MetadataConstants.URI_MEX_TRANSFER_RESPONSE_ACTION);
+
+        outMsgCtx.setEnvelope(outMsgEnvelope);
+
+    }
+
+    private void handleGetMetadataRequest(MessageContext inMsgCtx,
+            MessageContext outMsgCtx) throws AxisFault {
+
+        String address = inMsgCtx.getTo().getAddress();
+        SOAPEnvelope inMsgEnvelope = inMsgCtx.getEnvelope();
+        SOAPBody inMsgBody = inMsgEnvelope.getBody();
+
+        OMElement getMetadataElement = inMsgBody.getFirstElement();
+
+        if (getMetadataElement == null
+                || (!MetadataConstants.Q_ELEM_GET_METADATA
+                        .equals(getMetadataElement.getQName()))) {
+            throw new AxisFault("<mex:GetMetadata> element is expected");
+        }
+
+        GetMetadata getMetadata = new GetMetadata(inMsgBody.getFirstElement());
+
+        SOAPFactory factory = (SOAPFactory) inMsgEnvelope.getOMFactory();
+
+        SOAPEnvelope outMsgEnvelope = factory.getDefaultEnvelope();
+        SOAPBody outMsgBody = outMsgEnvelope.getBody();
+
+        Metadata metadata = new Metadata();
+
+        String dialect = getMetadata.getDialect();
+        String identifier = getMetadata.getIdentifier();
+
+        if (dialect != null) {
+
+            MetadataSection metadataSection = null;
+
+            if (MetadataConstants.DIALECT_SCHEMA.equals(dialect)) {
+                metadataSection = MetadataUtil.getMetadataSection(dialect,
+                        identifier, inMsgCtx, factory);
+
+            } else if (MetadataConstants.DIALECT_WSDL.equals(dialect)) {
+                metadataSection = MetadataUtil.getMetadataSection(dialect,
+                        identifier, inMsgCtx, factory);
+
+            } else if (MetadataConstants.DIALECT_POLICY.equals(dialect)) {
+                metadataSection = MetadataUtil.getMetadataSection(dialect,
+                        identifier, inMsgCtx, factory);
+            }
+
+            if (metadataSection != null) {
+                metadata.addMetadataSection(metadataSection);
+            }
+
+        } else {
+            addServiceMetadata(metadata, inMsgCtx, factory, address);
+        }
+
+        metadata.toOM(outMsgBody);
+
+        outMsgCtx.setWSAAction(MetadataConstants.URI_MEX_GET_RESPONSE_ACTION);
+        outMsgCtx.setSoapAction(MetadataConstants.URI_MEX_GET_RESPONSE_ACTION);
+
+        outMsgCtx.setEnvelope(outMsgEnvelope);
+    }
+
+    private void addServiceMetadata(Metadata metadata, MessageContext msgCtx,
+            OMFactory factory, String address) throws AxisFault {
+        metadata.addMetadataSection(MetadataUtil.getMetadataSection(
+                MetadataConstants.DIALECT_SCHEMA, null, msgCtx, factory));
+        metadata.addMetadataSection(MetadataUtil.getMetadataSection(
+                MetadataConstants.DIALECT_WSDL, null, msgCtx, factory));
+        metadata.addMetadataSections(MetadataUtil.getPolicyMetadataSections(
+                msgCtx, factory, address));
+
+    }
+}

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/GetMetadata.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/GetMetadata.java	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsf.common.mex.model;
+
+import org.apache.axiom.om.OMElement;
+import org.wso2.wsf.common.mex.MetadataConstants;
+
+public class GetMetadata {
+
+    private String dialect;
+
+    private String identifier;
+
+    public GetMetadata(OMElement getMetadataElement) {
+
+        OMElement dialectElement = getMetadataElement
+                .getFirstChildWithName(MetadataConstants.Q_ELEM_DIALECT);
+        
+        if (dialectElement == null) {
+            return;
+       }
+        
+       String dialectText = dialectElement.getText();
+       
+       if (dialectText != null && (dialectText = dialectText.trim()).length() != 0) {
+           setDialect(dialectText);
+           
+       } else {
+           throw new IllegalArgumentException("TODO : meaningful exceptions");
+       }
+       
+       OMElement identifierElement = getMetadataElement.getFirstChildWithName(MetadataConstants.Q_ELEM_IDENTIFIER);
+       
+       if (identifierElement != null) {
+           String  identifierText = identifierElement.getText();
+           
+           if (identifierText != null && (identifierText = identifierText.trim()).length() != 0) {
+               setIdentifier(identifierText);  
+           } 
+       }
+    }
+
+    public String getDialect() {
+        return dialect;
+    }
+
+    public void setDialect(String dialect) {
+        this.dialect = dialect;
+    }
+
+    public String getIdentifier() {
+        return identifier;
+    }
+
+    public void setIdentifier(String identifier) {
+        this.identifier = identifier;
+    }
+}

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/Metadata.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/Metadata.java	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsf.common.mex.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axis2.AxisFault;
+import org.wso2.wsf.common.mex.MetadataConstants;
+
+public class Metadata {
+
+    private ArrayList metadataSections = new ArrayList();
+
+    public void addMetadataSection(MetadataSection metadataSection) {
+        this.metadataSections.add(metadataSection);
+    }
+
+    public void addMetadataSections(List metadataSections) {
+        this.metadataSections.addAll(metadataSections);
+    }
+
+    public void toOM(OMElement soapBody) throws AxisFault {
+
+        OMFactory factory = soapBody.getOMFactory();
+        OMElement metadataElement = factory.createOMElement(
+                MetadataConstants.ELEM_METADATA, MetadataConstants.URI_MEX_NS,
+                MetadataConstants.ATTR_MEX);
+
+        MetadataSection metadataSection;
+        for (Iterator iterator = metadataSections.iterator(); iterator
+                .hasNext();) {
+            metadataSection = (MetadataSection) iterator.next();
+            metadataSection.toOM(metadataElement);
+        }
+
+        soapBody.addChild(metadataElement);
+    }
+
+}

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/MetadataLocation.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/MetadataLocation.java	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsf.common.mex.model;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.wso2.wsf.common.mex.MetadataConstants;
+
+public class MetadataLocation {
+    String location;
+
+    public void setLocation(String location) {
+        this.location = location;
+    }
+
+    public String getLocation() {
+        return location;
+    }
+
+    public void toOM(OMElement metadataSecElement) {
+        OMFactory factory = metadataSecElement.getOMFactory();
+        OMElement locationElement = factory.createOMElement(
+                MetadataConstants.ELEM_LOCATION, MetadataConstants.URI_MEX_NS,
+                MetadataConstants.ATTR_MEX);
+        
+        locationElement.setText(location);
+        metadataSecElement.addChild(locationElement);
+    }
+}

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/MetadataReference.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/MetadataReference.java	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsf.common.mex.model;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.wso2.wsf.common.mex.MetadataConstants;
+
+public class MetadataReference {
+    String address;
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void toOM(OMElement metadataSecElement) {
+        OMFactory factory = metadataSecElement.getOMFactory();
+        
+        OMElement metadataReferenceElement = factory.createOMElement(MetadataConstants.ELEM_METADATA_REFERENCE, MetadataConstants.URI_MEX_NS, MetadataConstants.ATTR_MEX);
+        OMElement addressElement = factory.createOMElement(
+                MetadataConstants.ELEM_ADDRESS, MetadataConstants.URI_WSA_NS,
+                MetadataConstants.ATTR_WSA);
+        
+        addressElement.setText(getAddress());
+        
+        metadataReferenceElement.addChild(addressElement);
+        metadataSecElement.addChild(metadataReferenceElement);
+    }
+}

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/MetadataSection.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/model/MetadataSection.java	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsf.common.mex.model;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axis2.AxisFault;
+import org.wso2.wsf.common.mex.MetadataConstants;
+
+public class MetadataSection {
+
+    public static final short WSDL_ELEMENT = 1;
+
+    public static final short SCHEMA_ELEMENT = 2;
+
+    public static final short POLICY_ELEMENT = 3;
+    
+    private String dialect;
+
+    private String identifier;
+
+    private MetadataReference metadataReference;
+
+    private MetadataLocation location;
+    
+    private OMElement element;
+
+    public String getDialect() {
+        return dialect;
+    }
+
+    public void setDialect(String dialect) {
+        this.dialect = dialect;
+    }
+
+    public void setIdentifier(String identifier) {
+        this.identifier = identifier;
+    }
+    
+    public String getIdentifier() {
+        return identifier;
+    }
+
+    public void setLocation(MetadataLocation location) {
+        this.location = location;
+    }
+
+    public MetadataReference getMetadataReference() {
+        return metadataReference;
+    }
+
+    public void setMetadataReference(MetadataReference metadataReference) {
+        this.metadataReference = metadataReference;
+    }
+    
+    public void setDialectSpecificType(OMElement element) {
+        this.element = element;
+    }
+    
+    public OMElement getDialectSpecificType() {
+        return element;
+    }
+
+    public void toOM(OMElement metadataElement) throws AxisFault {
+        
+        OMFactory factory = metadataElement.getOMFactory();
+
+        OMElement metadataSecElement = factory.createOMElement(
+                MetadataConstants.ELEM_METADATA_SECTION,
+                MetadataConstants.URI_MEX_NS, MetadataConstants.ATTR_MEX);
+
+        OMAttribute dialectAttr = factory.createOMAttribute(
+                MetadataConstants.ATTR_DIALECT, null, getDialect());
+        metadataSecElement.addAttribute(dialectAttr);
+                
+        if (getIdentifier() != null) {
+            OMAttribute identifierAttr = factory.createOMAttribute(
+                    MetadataConstants.ATTR_IDENTIFIER, null, getIdentifier());
+            metadataSecElement.addAttribute(identifierAttr);
+        }
+
+        if (metadataReference != null) {
+            metadataReference.toOM(metadataSecElement);
+
+        } else if (location != null) {
+            location.toOM(metadataSecElement);
+
+        } else if (element != null) {
+            metadataSecElement.addChild(element);
+            
+        } else {
+            throw new RuntimeException("Dialect specific type is not set");
+        }
+        
+        metadataElement.addChild(metadataSecElement);
+    }
+}

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/module/META-INF/module.xml
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/module/META-INF/module.xml	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,8 @@
+<module name="mex" class="org.wso2.wsf.common.mex.module.MetadataExchangeModule">
+	<description>This module provides MetadataExchange services for any services that the module is Engaged</description>
+	<operation name="GetMetadata" mep="http://www.w3.org/2004/08/wsdl/in-out">
+		<messageReceiver class="org.wso2.wsf.common.mex.MetadataExchangeMessageReceiver" />
+		<actionMapping>http://schemas.xmlsoap.org/ws/2004/09/transfer/Get</actionMapping>
+		<actionMapping>http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Request</actionMapping>
+	</operation>
+</module>
\ No newline at end of file

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/module/MetadataExchangeModule.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/module/MetadataExchangeModule.java	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsf.common.mex.module;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisDescription;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.modules.Module;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+
+public class MetadataExchangeModule implements Module {
+
+    public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault {
+    }
+
+    public boolean canSupportAssertion(Assertion assertion) {
+        return true;
+    }
+
+    public void engageNotify(AxisDescription axisDescription) throws AxisFault {
+    }
+
+    public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault {
+    }
+
+    public void shutdown(ConfigurationContext configurationContext) throws AxisFault {
+    }
+}

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/util/MetadataExchangeClient.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/util/MetadataExchangeClient.java	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,278 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsf.common.mex.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Iterator;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.OperationClient;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyEngine;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.w3c.dom.Document;
+import org.wso2.wsf.common.mex.MetadataConstants;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import com.ibm.wsdl.Constants;
+
+public class MetadataExchangeClient {
+
+    private static final QName Q_ELEM_ADDRESSING_MODULE = new QName("",
+            "addressing-1.1");
+
+    private static final QName Q_ELEM_ADDRESS = new QName(
+            "http://www.w3.org/2005/08/addressing", "Address");
+
+    private static final QName Q_ELEM_DEFINITION = new QName(
+            "http://schemas.xmlsoap.org/wsdl/", "definitions");
+
+    private static final QName Q_ELEM_SCHEMA = new QName(
+            "http://www.w3.org/2001/XMLSchema", "schema");
+
+    private static final QName Q_ELEM_POLICY = new QName(
+            "http://schemas.xmlsoap.org/ws/2004/09/policy", "Policy");
+
+    public static Definition getWSDLFromClient(String endpointURL)
+            throws AxisFault {
+
+        try {
+            String wsaToEPRString = endpointURL
+                    + ((endpointURL.endsWith("/")) ? "" : "/") + "metadata";
+            EndpointReference wsaToEPR = new EndpointReference(wsaToEPRString);
+
+            return (Definition) fetchMetadataUsingWSTransfer(wsaToEPR,
+                    MetadataConstants.DIALECT_WSDL);
+
+        } catch (Exception ex) {
+            throw new AxisFault(ex);
+        }
+    }
+
+    public static XmlSchema getSchemaFromClient(String endpointURL)
+            throws AxisFault {
+        try {
+            String wsaToEPRString = endpointURL
+                    + ((endpointURL.endsWith("/")) ? "" : "/") + "metadata";
+            EndpointReference wsaToEPR = new EndpointReference(wsaToEPRString);
+
+            return (XmlSchema) fetchMetadataUsingWSTransfer(wsaToEPR,
+                    MetadataConstants.DIALECT_SCHEMA);
+
+        } catch (Exception ex) {
+            throw new AxisFault(ex);
+        }
+    }
+
+    public static Policy getPolicyFromClient(String endpointURL)
+            throws AxisFault {
+        try {
+            String wsaToEPRString = endpointURL
+             + ((endpointURL.endsWith("/")) ? "" : "/") + "metadata";
+            EndpointReference wsaToEPR = new EndpointReference(wsaToEPRString);
+
+            return (Policy) fetchMetadataUsingWSTransfer(wsaToEPR,
+                    MetadataConstants.DIALECT_POLICY);
+
+        } catch (Exception ex) {
+            throw new AxisFault(ex);
+        }
+    }
+
+    // public static XMLs
+
+    private static Object fetchMetadataUsingWSTransfer(
+            EndpointReference wsaToEPR, String dialect) throws WSDLException,
+            SAXException, IOException, ParserConfigurationException {
+        SOAPEnvelope envelope = sendWSTransferRequest(wsaToEPR);
+        SOAPBody body = envelope.getBody();
+
+        OMElement metaData = body.getFirstElement();
+        OMElement metadataSection = getMetadataSection(metaData, dialect);
+
+        if (metadataSection == null) {
+            return null;
+        }
+
+        OMElement childElement = metadataSection.getFirstElement();
+
+        if (MetadataConstants.Q_ELEM_METADATA_REFERENCE.equals(childElement
+                .getQName())) {
+            OMElement wsaAddressElement = childElement
+                    .getFirstChildWithName(Q_ELEM_ADDRESS);
+            // TODO Check for null ??
+            String address = wsaAddressElement.getText();
+            // TODO Check for null??
+            EndpointReference wsaToEPR2 = new EndpointReference(address.trim());
+            return fetchMetadataUsingWSTransfer(wsaToEPR2, dialect);
+
+        } else {
+
+            QName dataElementName = getDataElementName(dialect);
+            OMElement dataElement = metadataSection
+                    .getFirstChildWithName(dataElementName);
+
+            if (MetadataConstants.DIALECT_SCHEMA.equals(dialect)) {
+                return getSchemaFromOM(dataElement);
+
+            } else if (MetadataConstants.DIALECT_WSDL.equals(dialect)) {
+                return getWSDLFromOM(dataElement);
+
+            } else if (MetadataConstants.DIALECT_POLICY.equals(dialect)) {
+                return getPolicyFromOM(dataElement);
+            }
+        }
+
+        return null;
+    }
+
+    private static QName getDataElementName(String dialect) {
+        if (MetadataConstants.DIALECT_SCHEMA.equals(dialect)) {
+            return Q_ELEM_SCHEMA;
+        } else if (MetadataConstants.DIALECT_WSDL.equals(dialect)) {
+            return Q_ELEM_DEFINITION;
+        } else if (MetadataConstants.DIALECT_POLICY.equals(dialect)) {
+            return Q_ELEM_POLICY;
+        } else {
+            return null;
+        }
+    }
+
+    private static SOAPEnvelope sendWSTransferRequest(EndpointReference wsaToEPR)
+            throws AxisFault {
+        try {
+            ServiceClient serviceClient = new ServiceClient();
+            OperationClient operationClient = serviceClient
+                    .createClient(ServiceClient.ANON_OUT_IN_OP);
+
+            Options options = operationClient.getOptions();
+            options.setAction(MetadataConstants.URI_MEX_TRANSFER_ACTION);
+            
+            options.setTo(wsaToEPR);
+
+            serviceClient
+                    .engageModule(MetadataExchangeClient.Q_ELEM_ADDRESSING_MODULE);
+            //          
+
+            MessageContext outMessageCtx = new MessageContext();
+            SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+            SOAPEnvelope outEnvelope = factory.getDefaultEnvelope();
+
+            outMessageCtx.setEnvelope(outEnvelope);
+            operationClient.addMessageContext(outMessageCtx);
+
+            operationClient.execute(true);
+
+            MessageContext msgCtx = operationClient
+                    .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+
+            return msgCtx.getEnvelope();
+
+        } catch (Exception e) {
+            throw new AxisFault(e);
+        }
+    }
+
+    private static Definition getWSDLFromOM(OMElement definitionElement)
+            throws WSDLException, SAXException, IOException,
+            ParserConfigurationException {
+
+        WSDLFactory factory = WSDLFactory.newInstance();
+        WSDLReader reader = factory.newWSDLReader();
+
+        reader.setFeature(Constants.FEATURE_VERBOSE, false);
+        reader.setFeature(Constants.FEATURE_IMPORT_DOCUMENTS, true);
+
+        String wsdlDocumentString = definitionElement.toString();
+
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+
+        Document d = dbf.newDocumentBuilder().parse(
+                new InputSource(new StringReader(wsdlDocumentString)));
+
+        Definition de = reader.readWSDL(null, d);
+        return de;
+    }
+
+    private static XmlSchema getSchemaFromOM(OMElement schemaElement) {
+        String schemaString = schemaElement.toString();
+        StringReader reader = new StringReader(schemaString);
+
+        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
+        return schemaCollection.read(reader, null);
+    }
+
+    private static Policy getPolicyFromOM(OMElement policyElement) {
+        if (policyElement == null) {
+            return null;
+        }
+        
+        String policyString = policyElement.toString();
+        ByteArrayInputStream bais = new ByteArrayInputStream(policyString
+                .getBytes());
+        return PolicyEngine.getPolicy(bais);
+    }
+
+    private static OMElement getMetadataSection(OMElement metadata,
+            String targetDialect) throws AxisFault {
+
+        OMElement metadataSection = null;
+        String dialect = null;
+
+        for (Iterator iterator = metadata
+                .getChildrenWithName(MetadataConstants.Q_ELEM_METADATA_SECTION); iterator
+                .hasNext();) {
+
+            metadataSection = (OMElement) iterator.next();
+            dialect = metadataSection
+                    .getAttributeValue(MetadataConstants.Q_ATTR_DIALECT);
+
+            if (dialect == null) {
+                throw new AxisFault(
+                        "<mex:MetadataSection> element without dialect attribute");
+            }
+
+            if (targetDialect.equals(dialect.trim())) {
+                break;
+            }
+        }
+
+        return metadataSection;
+    }
+}

Added: wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/util/MetadataUtil.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/wsf-common-core/src/org/wso2/wsf/common/mex/util/MetadataUtil.java	Thu Nov 30 04:37:13 2006
@@ -0,0 +1,239 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsf.common.mex.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisDescription;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.PolicyInclude;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyReference;
+import org.apache.neethi.PolicyRegistry;
+import org.wso2.wsf.common.mex.MetadataConstants;
+import org.wso2.wsf.common.mex.model.MetadataReference;
+import org.wso2.wsf.common.mex.model.MetadataSection;
+import org.wso2.wsf.common.util.NetworkUtils;
+
+public class MetadataUtil {
+
+    public static MetadataSection getMetadataSection(String dialect,
+            String identifier, MessageContext msgCtx, OMFactory factory)
+            throws AxisFault {
+
+        AxisService axisService = msgCtx.getAxisService();
+
+        OMElement dialectSpecificType;
+        MetadataSection metadataSection = new MetadataSection();
+
+        if (MetadataConstants.DIALECT_SCHEMA.equals(dialect)) {
+
+            if (identifier != null
+                    && identifier.equals(axisService.getTargetNamespace())) {
+                return null;
+            }
+
+            try {
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                axisService.printSchema(baos);
+
+                ByteArrayInputStream bais = new ByteArrayInputStream(baos
+                        .toByteArray());
+
+                XMLStreamReader streamReader = XMLInputFactory.newInstance()
+                        .createXMLStreamReader(bais);
+                StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(factory,
+                        streamReader);
+                dialectSpecificType = stAXOMBuilder.getDocumentElement();
+
+            } catch (Exception ex) {
+                throw new AxisFault(ex);
+            }
+
+            metadataSection.setDialect(dialect);
+            metadataSection.setIdentifier(axisService.getTargetNamespace());
+            metadataSection.setDialectSpecificType(dialectSpecificType);
+
+        } else if (MetadataConstants.DIALECT_WSDL.equals(dialect)) {
+
+            try {
+
+                ConfigurationContext configCtx = msgCtx
+                        .getConfigurationContext();
+                
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+                axisService.printWSDL(baos, NetworkUtils.getLocalHostname(),
+                        configCtx.getServicePath());
+
+                ByteArrayInputStream bais = new ByteArrayInputStream(baos
+                        .toByteArray());
+                XMLStreamReader streamReader = XMLInputFactory.newInstance()
+                        .createXMLStreamReader(bais);
+                StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(factory,
+                        streamReader);
+                dialectSpecificType = stAXOMBuilder.getDocumentElement();
+
+            } catch (Exception ex) {
+                throw new AxisFault(ex);
+            }
+
+            String targetName = dialectSpecificType
+                    .getAttributeValue(new QName("", "targetNamespace"));
+
+            if (identifier != null && !targetName.equals(identifier)) {
+                return null;
+            }
+
+            metadataSection.setDialect(dialect);
+            metadataSection.setIdentifier(targetName);
+            metadataSection.setDialectSpecificType(dialectSpecificType);
+
+        } else if (MetadataConstants.DIALECT_POLICY.equals(dialect)) {
+
+            Policy policy = null;
+
+            PolicyInclude policyInclude = axisService.getPolicyInclude();
+
+            if (identifier != null) {
+                PolicyRegistry registry = policyInclude.getPolicyRegistry();
+                policy = registry.lookup(identifier);
+
+            } else {
+                policy = policyInclude.getEffectivePolicy();
+            }
+
+            try {
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+                XMLStreamWriter writer = XMLOutputFactory.newInstance()
+                        .createXMLStreamWriter(baos);
+
+                policy.serialize(writer);
+                writer.flush();
+
+                ByteArrayInputStream bais = new ByteArrayInputStream(baos
+                        .toByteArray());
+
+                XMLStreamReader streamReader = XMLInputFactory.newInstance()
+                        .createXMLStreamReader(bais);
+                StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(factory,
+                        streamReader);
+                dialectSpecificType = stAXOMBuilder.getDocumentElement();
+
+            } catch (Exception ex) {
+                throw new AxisFault(ex);
+            }
+
+            metadataSection.setDialect(dialect);
+            metadataSection.setIdentifier(policy.getName());
+            metadataSection.setDialectSpecificType(dialectSpecificType);
+
+        } else {
+            return null;
+        }
+
+        return metadataSection;
+    }
+
+    public static List getPolicyMetadataSections(MessageContext msgCtx,
+            OMFactory factory, String address) {
+        
+        AxisService axisService = msgCtx.getAxisService();
+
+        ArrayList metadataSectionList = new ArrayList();
+        address = address.substring(0, address.indexOf("metadata") - 1)
+                + "/policy/";
+
+        MetadataSection metadataSection;
+        MetadataReference metadataReference;
+        String identifier;
+
+        for (Iterator iterator = getPolicyURIs(axisService).iterator(); iterator
+                .hasNext();) {
+
+            metadataSection = new MetadataSection();
+
+            identifier = (String) iterator.next();
+            metadataSection.setDialect(MetadataConstants.DIALECT_POLICY);
+            metadataSection.setIdentifier(identifier);
+
+            metadataReference = new MetadataReference();
+            metadataReference.setAddress(address + identifier);
+
+            metadataSection.setMetadataReference(metadataReference);
+            metadataSectionList.add(metadataSection);
+        }
+        return metadataSectionList;
+    }
+
+    private static List getPolicyURIs(AxisDescription axisDescription) {
+
+        ArrayList policyURIs = new ArrayList();
+
+        PolicyInclude policyInclude = axisDescription.getPolicyInclude();
+        ArrayList policyElements = policyInclude.getPolicyElements();
+
+        Object policyElement;
+
+        for (Iterator iterator = policyElements.iterator(); iterator.hasNext();) {
+            policyElement = iterator.next();
+
+            String value;
+
+            if (policyElement instanceof PolicyReference) {
+                value = ((PolicyReference) policyElement).getURI();
+
+                if (!value.startsWith("#")) {
+                    policyURIs.add(value);
+                }
+
+            } else {
+                value = ((Policy) policyElement).getName();
+
+                if (value != null) {
+                    policyURIs.add(value);
+                }
+            }
+        }
+
+        AxisDescription child;
+
+        for (Iterator iterator = axisDescription.getChildren(); iterator
+                .hasNext();) {
+            child = (AxisDescription) iterator.next();
+            policyURIs.addAll(getPolicyURIs(child));
+        }
+
+        return policyURIs;
+    }
+}




More information about the Wsas-java-dev mailing list