You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2007/03/15 16:26:10 UTC

svn commit: r518661 [1/2] - in /webservices/axis2/trunk/java/modules: kernel/src/org/apache/axis2/dataretrieval/ kernel/src/org/apache/axis2/description/ mex/src/org/apache/axis2/mex/ mex/src/org/apache/axis2/mex/OM/ mex/src/org/apache/axis2/mex/util/ ...

Author: dims
Date: Thu Mar 15 08:26:09 2007
New Revision: 518661

URL: http://svn.apache.org/viewvc?view=rev&rev=518661
Log:
Fix for AXIS2-2281 and AXIS2-2267 from GeeChia

Added:
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexDisabledException.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Dialect.java
Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/DataLocatorFactory.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/DataRetrievalUtil.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/ServiceData.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexConstants.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/AnyURIType.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Dialet.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Location.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Metadata.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/MetadataReference.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/MetadataSection.java
    webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/util/MexUtil.java
    webservices/axis2/trunk/java/modules/samples/mex/src/userguide/mex/services/example1/META-INF/ServiceData.xml
    webservices/axis2/trunk/java/modules/samples/mex/src/userguide/mex/services/example1/META-INF/services.xml

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/DataLocatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/DataLocatorFactory.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/DataLocatorFactory.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/DataLocatorFactory.java Thu Mar 15 08:26:09 2007
@@ -29,11 +29,11 @@
     /*
     * Return instance of default Data Locator for the dialect.
     */
-    protected static AxisDataLocator createDataLocator(String dialect) {
+    public static AxisDataLocator createDataLocator(String dialect) {
         return (createDataLocator(dialect, null));
     }
 
-    protected static AxisDataLocator createDataLocator(String dialect,
+    public static AxisDataLocator createDataLocator(String dialect,
                                                        ServiceData[] serviceDataArray) {
         AxisDataLocator dataLocator = null;
         if (dialect.equals(DRConstants.SPEC.DIALECT_TYPE_WSDL)) {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/DataRetrievalUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/DataRetrievalUtil.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/DataRetrievalUtil.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/DataRetrievalUtil.java Thu Mar 15 08:26:09 2007
@@ -18,6 +18,7 @@
 
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.util.StAXUtils;
@@ -44,8 +45,8 @@
      * Loading xml file content and convert to OMElement.
      *
      * @param file - file path relative to the Service Repository
-     * @return OMElement format of the xml file content
-     * @throws DataRetrievalException
+     * @return OMElement format of the xml file content 
+     * @throws DataRetrievalException 
      */
 
     public OMElement buildOM(ClassLoader classLoader, String file)
@@ -56,10 +57,11 @@
             servicexmlStream = getInputStream(classLoader, file);
 
             element = convertToOMElement(servicexmlStream);
-        } catch (XMLStreamException e) {
-            throw new DataRetrievalException(e);
+         } catch (Exception e) {
+            throw new DataRetrievalException("Failed to load from file, " + file, e);
         }
 
+
         return element;
     }
 
@@ -72,7 +74,7 @@
      */
 
     public static OMElement convertToOMElement(InputStream servicexmlStream)
-            throws XMLStreamException {
+            throws XMLStreamException, OMException{
         OMElement element = null;
 
         XMLStreamReader xmlReader = StAXUtils

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/ServiceData.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/ServiceData.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/ServiceData.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dataretrieval/ServiceData.java Thu Mar 15 08:26:09 2007
@@ -42,14 +42,14 @@
      * @param in_data an Data element in the ServiceData.
      */
 
-    protected ServiceData(OMElement in_data) {
+    public ServiceData(OMElement in_data) {
         data = in_data;
         identifier = getAttributeValue(DRConstants.SERVICE_DATA.IDENTIFIER);
         dialect = getAttributeValue(DRConstants.SERVICE_DATA.DIALECT);
         fileName = getAttributeValue(DRConstants.SERVICE_DATA.FILE);
     }
 
-    protected String getAttributeValue(String qName) {
+    public String getAttributeValue(String qName) {
 
         String value = null;
         OMAttribute attribute = data.getAttribute(new QName(qName));
@@ -62,23 +62,23 @@
     }
 
     // return identifier for this Data element
-    protected String getIdentifier() {
+    public String getIdentifier() {
         return identifier;
     }
 
     // return dialect for this Data element
-    protected String getDialect() {
+    public String getDialect() {
         return dialect;
     }
 
     // return the Data ELement
-    protected OMElement getOMData() {
+    public OMElement getOMData() {
         return data;
     }
 
 
     // Get URL from data Element
-    protected String getURL() {
+    public String getURL() {
 
         String urlValue = null;
         OMElement url = data.getFirstChildWithName(new QName(
@@ -91,7 +91,7 @@
     }
 
     // Get ENDPOINT_REFERENCE from Data Element
-    protected OMElement getEndpointReference() {
+    public OMElement getEndpointReference() {
         OMElement epr = data.getFirstChildWithName(new QName(
                 DRConstants.SERVICE_DATA.ENDPOINT_REFERENCE));
         return epr;
@@ -99,7 +99,7 @@
 
     // Load the file content of the file specified in the file attribute
     // in the data element.
-    protected OMElement getFileContent(ClassLoader classloader)
+    public OMElement getFileContent(ClassLoader classloader)
             throws DataRetrievalException {
 
         OMElement metaElement = null;

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java Thu Mar 15 08:26:09 2007
@@ -952,7 +952,7 @@
 
         Data[] result = getData(request, context);
         OMElement wsdlElement;
-        if (result != null && result[0] != null) {
+        if (result != null && result.length > 0) {
             wsdlElement = (OMElement) (result[0].getData());
             try {
                 wsdlElement.serialize(out);

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexConstants.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexConstants.java (original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexConstants.java Thu Mar 15 08:26:09 2007
@@ -1,66 +1,98 @@
-/*
-* Copyright 2007 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.apache.axis2.mex;
-
-/**
- * Contains all the MetadataExchange constants for WS-Mex.
- * 
- */
-
-public interface MexConstants {
-	public interface SPEC_VERSIONS {
-		String v1_0 = "Spec_2004_09";
-	}
-    public interface Spec_2004_09 {
-		
-		String NS_URI = "http://schemas.xmlsoap.org/ws/2004/09/mex";
-
-	    public interface Actions {
-			String GET_METADATA_REQUEST = "http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Request";
-			String GET_METADATA_RESPONSE = "http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Response";
-			
-	    }
-    }
-    
-  
-    public interface SOAPVersion {
-     		int v1_1 = 1;
-
-    		int v1_2 = 2;
-    
-	}
-    
-    
-    public interface SPEC {
-		String NS_PREFIX = "mex";
-		String GET_METADATA = "GetMetadata";
-		String DIALECT = "Dialect";
-		String IDENTIFIER = "Identifier";
-		String METADATA = "Metadata";
-		String METADATA_SECTION = "MetadataSection";
-		String METADATA_REFERENCE = "MetadataReference";
-		String LOCATION = "Location";
-		String TYPE = "type";
-		
-		String DIALECT_TYPE_WSDL = "http://schemas.xmlsoap.org/wsdl/";
-		String DIALECT_TYPE_POLICY = "http://schemas.xmlsoap.org/ws/2004/09/policy";
-		String DIALECT_TYPE_SCHEMA = "http://www.w3.org/2001/XMLSchema";
-		String DIALECT_TYPE_MEX = "http://schemas.xmlsoap.org/ws/2004/09/mex";
-		
-	}
-  
-}
+/*
+* Copyright 2007 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.apache.axis2.mex;
+
+/**
+ * Contains all the MetadataExchange constants for WS-Mex.
+ * 
+ */
+
+public interface MexConstants {
+	public interface SPEC_VERSIONS {
+		public static final String v1_0 = "Spec_2004_09";
+	}
+    public interface Spec_2004_09 {
+		
+    	public static final String NS_URI = "http://schemas.xmlsoap.org/ws/2004/09/mex";
+
+	    public interface Actions {
+	    	public static final String GET_METADATA_REQUEST = "http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Request";
+	    	public static final String GET_METADATA_RESPONSE = "http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Response";
+			
+	    }
+    }
+    
+  
+    public interface SOAPVersion {
+    	public static final int v1_1 = 1;
+
+    	public static final int v1_2 = 2;
+    
+	}
+    
+    
+    public interface SPEC {
+    	public static final String NS_PREFIX = "mex";
+    	public static final String GET_METADATA = "GetMetadata";
+    	public static final String DIALECT = "Dialect";
+    	public static final String IDENTIFIER = "Identifier";
+    	public static final String METADATA = "Metadata";
+    	public static final String METADATA_SECTION = "MetadataSection";
+    	public static final String METADATA_REFERENCE = "MetadataReference";
+    	public static final String LOCATION = "Location";
+    	public static final String TYPE = "type";
+		
+    	public static final String DIALECT_TYPE_WSDL = "http://schemas.xmlsoap.org/wsdl/";
+    	public static final String DIALECT_TYPE_POLICY = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+    	public static final String DIALECT_TYPE_SCHEMA = "http://www.w3.org/2001/XMLSchema";
+    	public static final String DIALECT_TYPE_MEX = "http://schemas.xmlsoap.org/ws/2004/09/mex";
+		
+	}
+    
+
+    /**
+     * MEX Configuration 
+     * 
+     * Sample mex configuration:
+     * <parameter name="metadataexchange" locked="false">
+     *     <outputform dialect="http://schemas.xmlsoap.org/wsdl/" forms="location" />
+     *     <outputform forms="inline,reference,location" />
+     * </parameter> 
+     */
+    public interface MEX_CONFIG{
+    	public static final String MEX_PARM = "metadataExchange";
+    	
+    	// Allow to disable MEX for a Service if MEX is engaged globally. 
+    	public static final String ENABLE_MEX = "enable"; 
+        
+    	// One or more outputform element can be specified in the mex configuration
+    	// outputform element contains an optional "dialect" attribute and an
+    	// required forms attribute. 
+    	public static final String OUTPUT_FORM_PARM = "outputform";
+    	public static final String DIALECT_PARM = "dialect";
+    	public static final String FORMS_PARM = "forms";
+    	
+    	// configurable parameter values
+    	public static final String DELIMITER = ",";
+    	// possible "forms" attribute values
+    	public static final String LOCATION = "location";
+    	public static final String INLINE = "inline";
+    	public static final String REFERENCE = "reference";
+    	
+    }
+  
+}

Added: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexDisabledException.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexDisabledException.java?view=auto&rev=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexDisabledException.java (added)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexDisabledException.java Thu Mar 15 08:26:09 2007
@@ -0,0 +1,10 @@
+package org.apache.axis2.mex;
+
+public class MexDisabledException extends MexException {
+	private static final long serialVersionUID = 1L;
+
+	public MexDisabledException(String message) {
+		super(message);
+	}
+
+  }

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java Thu Mar 15 08:26:09 2007
@@ -1,287 +1,299 @@
-/*
-* Copyright 2007 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.apache.axis2.mex;
-
-import java.util.ArrayList;
-import java.util.List;
-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.context.MessageContext;
-import org.apache.axis2.dataretrieval.Data;
-import org.apache.axis2.dataretrieval.DataRetrievalException;
-import org.apache.axis2.dataretrieval.DataRetrievalRequest;
-import org.apache.axis2.dataretrieval.OutputForm;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver;
-import org.apache.axis2.mex.OM.Location;
-import org.apache.axis2.mex.OM.Metadata;
-import org.apache.axis2.mex.OM.MetadataReference;
-import org.apache.axis2.mex.OM.MetadataSection;
-import org.apache.axis2.mex.OM.MexOMException;
-import org.apache.axis2.mex.util.MexUtil;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.xml.namespace.QName;
-
-/**
- * Message Receiver for processing WS-MEX GetMetadata request. 
- *
- */
-public class MexMessageReceiver extends AbstractInOutSyncMessageReceiver {
-	private static final Log log = LogFactory.getLog(MexMessageReceiver.class);
-
-	String mexNamespaceValue = null;
-
-	/**
-	 * 
-     */
-	public void invokeBusinessLogic(MessageContext msgContext,
-			MessageContext newmsgContext) throws AxisFault {
-	
-		try {
-			Metadata metadata = handleRequest(msgContext);
-			AxisService theService = msgContext.getAxisService();
-
-			theService.setEndpointURL(msgContext.getTo().getAddress());
-
-			if (metadata != null) {
-				SOAPEnvelope envelope = newmsgContext.getEnvelope();
-				if (envelope == null) {
-					SOAPFactory fac = getSOAPFactory(msgContext);
-					envelope = fac.getDefaultEnvelope();
-				}
-           
-				OMElement result = metadata.toOM();
-				if (result != null) {
-					AxisService service = msgContext.getAxisService();
-					result.declareNamespace(service.getTargetNamespace(),
-							service.getTargetNamespacePrefix());
-					envelope.getBody().addChild(result);
-				}
-
-				newmsgContext.setEnvelope(envelope);
-			}
-			// AxisService service = msgContext.getAxisService();
-
-		} catch (Exception e) {
-			log.info(e);
-			if (e instanceof MexException) {
-				throw (MexException) e;
-			}
-			throw new MexException(e);
-		}
-
-	}
-
-
-	/*
-	 * Handle GetMetadata Request 
-	 * Interprete GetMetadata request and process request.
-	 * @returns Metadata object
-	 */
-	private Metadata handleRequest(MessageContext msgContext) throws AxisFault {
-		Metadata metadata = null;
-		SOAPEnvelope envelope = msgContext.getEnvelope();
-
-		SOAPBody body = envelope.getBody();
-		OMElement aReq = body.getFirstChildWithName(new QName(
-				MexConstants.SPEC.GET_METADATA));
-		List metadata_request_list;
-		if (aReq != null) {
-			metadata_request_list = determineMetadataTypes(aReq);
-
-		} else {
-			throw new MexException("Invalid Metadata request");
-		}
-
-		metadata = processRequest(metadata_request_list, msgContext, aReq);
-
-		return metadata;
-	}
-
-	/*
-	 * Process the requests
-	 * 
-	 * @param metadata_request_list list of mex Dialect for requesting data
-	 * @msgContext MessageContext
-	 * @aReq GetMetadata request 
-     */
-	
-	public Metadata processRequest(List metadata_request_list,
-			MessageContext msgContext, OMElement aReq) throws MexException {
-			
-		String identifier_value = null;
-		
-		DataRetrievalRequest requestOptions = new DataRetrievalRequest();
-		// Check if Identifier element included in request
-		OMElement identifier = aReq.getFirstChildWithName(new QName(
-				MexConstants.SPEC.IDENTIFIER));
-		if (identifier != null) {
-			identifier_value = identifier.getText();
-			if (identifier_value != null && identifier_value.length() > 0) {
-				requestOptions.putIdentifier(identifier_value);
-			}
-		}
-
-		// Instantiate Metadata instance to build the WS-Mex Metadata element
-		SOAPEnvelope envelope = msgContext.getEnvelope();
-		String soapNamespaceURI = envelope.getNamespace().getNamespaceURI();
-		SOAPFactory factory = MexUtil.getSOAPFactory(soapNamespaceURI);
-		mexNamespaceValue = MexConstants.Spec_2004_09.NS_URI;
-		Metadata metadata = new Metadata(factory, mexNamespaceValue);
-
-		// Process the request and append MetadataSection to Metadata
-		// Loop through the metadata_request_list for Dialect(s)), and setup requestOptions.
-		// Basically, one requestOptions is setup for each supported outputForm for the Dialect
-		// and Identifier specified in the GetMetadata request.
-		int len = metadata_request_list.size();
-		OutputForm[] outputforms;
-		
-		for (int i = 0; i < len; i++) { // metadata request
-			String dialect = "";
-			try {
-				dialect = (String) metadata_request_list.get(i);
-
-				requestOptions.putDialect(dialect);
-
-				outputforms = MexUtil.allSupportedOutputForms();
-				// Loop to call AxisService::getData API to retrieve data
-				// for the Dialect and Identifier(if specified) in the request
-				// for each
-				// supported output form.
-				
-				for (int j = 0; j < outputforms.length; j++) { // output form
-					requestOptions.putOutputForm(outputforms[j]);
-
-					Data[] result =  msgContext.getAxisService().getData(requestOptions,
-							msgContext);
-
-					ArrayList sections = processData(result, outputforms[j], dialect,
-							   identifier_value, factory);
-					metadata.addMetadatSections(sections);
-				}
-
-			} catch (DataRetrievalException e) {
-				log.error("Data Retrieval exception detected for dialect, " + dialect, e);
-				
-				throw new MexException(e);
-			} catch (Throwable e) {
-				
-				log.error("Throwable detected for dialect, " + dialect , e);
-
-				throw new MexException(e);
-			}
-
-		}
-		return metadata;
-	}
-
-	/*
-	 * Create MetadataSection for each Data element, and add the
-	 * MetadataSections to Metadata.
-	 */
-	private ArrayList processData(Data[] data, OutputForm outputForm,
-			String dialect, String identifier_value, SOAPFactory factory) throws MexException {
-		MetadataSection section=null;
-		ArrayList sections = new ArrayList();
-		if (data == null || data.length == 0) {
-			if (log.isDebugEnabled())
-				log
-						.debug("No result was returned from getData request for dialect,"
-								+ dialect
-								+ " Form: "
-								+ outputForm.getType()
-								+ ". No MetadataSection will be added!");
-
-		} else {
-			for (int k = 0; k < data.length; k++) {
-
-				section = createMetadataSection(outputForm, data[k].getData(),
-						factory, mexNamespaceValue);
-
-				section.setDialet(dialect);
-				identifier_value = data[k].getIdentifier();
-
-				if (identifier_value != null) {
-					section.setIdentifier(identifier_value);
-				}
-				sections.add(section);
-
-			}
-		}
-		return sections;
-	}
-
-	private MetadataSection createMetadataSection(OutputForm outputForm,
-			Object result, SOAPFactory factory, String mexNamespaceValue)
-			throws MexOMException {
-		MetadataSection section = new MetadataSection(factory,
-				mexNamespaceValue);
-
-		if (outputForm == OutputForm.INLINE_FORM)
-			section.setinlineData(result);
-		else if (outputForm == OutputForm.LOCATION_FORM)
-			section.setLocation(new Location(factory, mexNamespaceValue,
-					(String) result));
-		else if (outputForm == OutputForm.REFERENCE_FORM) {
-			MetadataReference ref = new MetadataReference(factory,
-					mexNamespaceValue);
-			ref.setEPRElement((OMElement) result);
-			section.setMetadataReference(ref);
-		} else {
-
-			section.setinlineData((OMElement) result);
-		}
-
-		return section;
-	}
-
-	/*
-	 * Traverse and interprete the GetMetadata OMElement for Dialect element
-	 * that specified in the request. @returns a List with Dialect(s) of
-	 * metadata requested.
-	 * 
-	 */
-	private List determineMetadataTypes(OMElement aReq) {
-		List metadata_request_list = new ArrayList();
-
-		boolean allTypes = false;
-
-		OMElement dialect = aReq.getFirstChildWithName(new QName(
-				MexConstants.SPEC.DIALECT));
-		if (dialect != null) {
-			String dialectText = dialect.getText();
-			if (dialectText != null && dialectText.length() > 0) {
-				metadata_request_list.add(dialectText.trim());
-			} else
-				allTypes = true;
-		} else
-			allTypes = true;
-
-		if (allTypes) { // retrieve all metadata
-			metadata_request_list.add(MexConstants.SPEC.DIALECT_TYPE_POLICY);
-			metadata_request_list.add(MexConstants.SPEC.DIALECT_TYPE_SCHEMA);
-			metadata_request_list.add(MexConstants.SPEC.DIALECT_TYPE_WSDL);
-		}
-		return metadata_request_list;
-	}
-
-}
\ No newline at end of file
+/*
+* Copyright 2007 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.apache.axis2.mex;
+
+import java.util.ArrayList;
+import java.util.List;
+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.context.MessageContext;
+import org.apache.axis2.dataretrieval.Data;
+import org.apache.axis2.dataretrieval.DataRetrievalException;
+import org.apache.axis2.dataretrieval.DataRetrievalRequest;
+import org.apache.axis2.dataretrieval.OutputForm;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver;
+import org.apache.axis2.mex.OM.Location;
+import org.apache.axis2.mex.OM.Metadata;
+import org.apache.axis2.mex.OM.MetadataReference;
+import org.apache.axis2.mex.OM.MetadataSection;
+import org.apache.axis2.mex.OM.MexOMException;
+import org.apache.axis2.mex.util.MexUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Message Receiver for processing WS-MEX GetMetadata request. 
+ *
+ */
+public class MexMessageReceiver extends AbstractInOutSyncMessageReceiver {
+	private static final Log log = LogFactory.getLog(MexMessageReceiver.class);
+	Parameter axisConfigMEXParm = null;
+    Parameter serviceConfigMEXParm = null;
+	String mexNamespaceValue = null;
+
+	/**
+	 * Process GetMetadata request
+        */
+	public void invokeBusinessLogic(MessageContext msgContext,
+			MessageContext newmsgContext) throws AxisFault {
+		AxisService theService = msgContext.getAxisService();       
+		axisConfigMEXParm = msgContext.getConfigurationContext().getAxisConfiguration().getParameter(MexConstants.MEX_CONFIG.MEX_PARM);
+		serviceConfigMEXParm = theService.getParameter(MexConstants.MEX_CONFIG.MEX_PARM);
+		
+		check_MEX_disabled(serviceConfigMEXParm);
+		
+		try {
+			Metadata metadata = handleRequest(msgContext);
+		        theService.setEndpointURL(msgContext.getTo().getAddress());
+
+			if (metadata != null) {
+				SOAPEnvelope envelope = newmsgContext.getEnvelope();
+				if (envelope == null) {
+					SOAPFactory fac = getSOAPFactory(msgContext);
+					envelope = fac.getDefaultEnvelope();
+				}
+           
+				OMElement result = metadata.toOM();
+				if (result != null) {
+					AxisService service = msgContext.getAxisService();
+					result.declareNamespace(service.getTargetNamespace(),
+							service.getTargetNamespacePrefix());
+					envelope.getBody().addChild(result);
+				}
+
+				newmsgContext.setEnvelope(envelope);
+			}
+			// AxisService service = msgContext.getAxisService();
+
+		} catch (Exception e) {
+			log.info(e);
+			if (e instanceof MexException) {
+				throw (MexException) e;
+			}
+			throw new MexException(e);
+		}
+
+	}
+
+
+	/*
+	 * Handle GetMetadata Request 
+	 * Interprete GetMetadata request and process request.
+	 * @returns Metadata object
+	 */
+	private Metadata handleRequest(MessageContext msgContext) throws AxisFault {
+		Metadata metadata = null;
+		SOAPEnvelope envelope = msgContext.getEnvelope();
+
+		SOAPBody body = envelope.getBody();
+		OMElement aReq = body.getFirstChildWithName(new QName(
+				MexConstants.SPEC.GET_METADATA));
+		List metadata_request_list;
+		if (aReq != null) {
+			metadata_request_list = determineMetadataTypes(aReq);
+
+		} else {
+			throw new MexException("Invalid Metadata request");
+		}
+
+		metadata = processRequest(metadata_request_list, msgContext, aReq);
+
+		return metadata;
+	}
+
+	/*
+	 * Process the requests
+	 * 
+	 * @param metadata_request_list list of mex Dialect for requesting data
+	 * @msgContext MessageContext
+	 * @aReq GetMetadata request 
+     */
+	
+	public Metadata processRequest(List metadata_request_list,
+			MessageContext msgContext, OMElement aReq) throws MexException {
+			
+		String identifier_value = null;
+		
+		DataRetrievalRequest requestOptions = new DataRetrievalRequest();
+		// Check if Identifier element included in request
+		OMElement identifier = aReq.getFirstChildWithName(new QName(
+				MexConstants.SPEC.IDENTIFIER));
+		if (identifier != null) {
+			identifier_value = identifier.getText();
+			if (identifier_value != null && identifier_value.length() > 0) {
+				requestOptions.putIdentifier(identifier_value);
+			}
+		}
+
+		// Instantiate Metadata instance to build the WS-Mex Metadata element
+		SOAPEnvelope envelope = msgContext.getEnvelope();
+		String soapNamespaceURI = envelope.getNamespace().getNamespaceURI();
+		SOAPFactory factory = MexUtil.getSOAPFactory(soapNamespaceURI);
+		mexNamespaceValue = MexConstants.Spec_2004_09.NS_URI;
+		Metadata metadata = new Metadata(factory, mexNamespaceValue);
+
+		// Process the request and append MetadataSection to Metadata
+		// Loop through the metadata_request_list for Dialect(s)), and setup requestOptions.
+		// Basically, one requestOptions is setup for each supported outputForm for the Dialect
+		// and Identifier specified in the GetMetadata request.
+		int len = metadata_request_list.size();
+		OutputForm[] outputforms;
+		
+		for (int i = 0; i < len; i++) { // metadata request
+			String dialect = "";
+			try {
+				dialect = (String) metadata_request_list.get(i);
+
+				requestOptions.putDialect(dialect);
+
+				outputforms = MexUtil.determineOutputForm(dialect, axisConfigMEXParm, serviceConfigMEXParm);
+				// Loop to call AxisService::getData API to retrieve data
+				// for the Dialect and Identifier(if specified) in the request
+				// for each
+				// supported output form.
+				
+				for (int j = 0; j < outputforms.length; j++) { // output form
+					requestOptions.putOutputForm(outputforms[j]);
+
+					Data[] result =  msgContext.getAxisService().getData(requestOptions,
+							msgContext);
+
+					ArrayList sections = processData(result, outputforms[j], dialect,
+							   identifier_value, factory);
+					metadata.addMetadatSections(sections);
+				}
+
+			} catch (DataRetrievalException e) {
+				log.error("Data Retrieval exception detected for dialect, " + dialect, e);
+				
+				throw new MexException(e);
+			} catch (Throwable e) {
+				
+				log.error("Throwable detected for dialect, " + dialect , e);
+
+				throw new MexException(e);
+			}
+
+		}
+		return metadata;
+	}
+
+	/*
+	 * Create MetadataSection for each Data element, and add the
+	 * MetadataSections to Metadata.
+	 */
+	private ArrayList processData(Data[] data, OutputForm outputForm,
+			String dialect, String identifier_value, SOAPFactory factory) throws MexException {
+		MetadataSection section=null;
+		ArrayList sections = new ArrayList();
+		if (data == null || data.length == 0) {
+			if (log.isDebugEnabled())
+				log
+						.debug("No result was returned from getData request for dialect,"
+								+ dialect
+								+ " Form: "
+								+ outputForm.getType()
+								+ ". No MetadataSection will be added!");
+
+		} else {
+			for (int k = 0; k < data.length; k++) {
+
+				section = createMetadataSection(outputForm, data[k].getData(),
+						factory, mexNamespaceValue);
+
+				section.setDialect(dialect);
+				identifier_value = data[k].getIdentifier();
+
+				if (identifier_value != null) {
+					section.setIdentifier(identifier_value);
+				}
+				sections.add(section);
+
+			}
+		}
+		return sections;
+	}
+
+	private MetadataSection createMetadataSection(OutputForm outputForm,
+			Object result, SOAPFactory factory, String mexNamespaceValue)
+			throws MexOMException {
+		MetadataSection section = new MetadataSection(factory,
+				mexNamespaceValue);
+
+		if (outputForm == OutputForm.INLINE_FORM)
+			section.setinlineData(result);
+		else if (outputForm == OutputForm.LOCATION_FORM)
+			section.setLocation(new Location(factory, mexNamespaceValue,
+					(String) result));
+		else if (outputForm == OutputForm.REFERENCE_FORM) {
+			MetadataReference ref = new MetadataReference(factory,
+					mexNamespaceValue);
+			
+			ref.setEPR((OMElement) result);
+			section.setMetadataReference(ref);
+		} else {
+
+			section.setinlineData((OMElement) result);
+		}
+
+		return section;
+	}
+
+	/*
+	 * Traverse and interprete the GetMetadata OMElement for Dialect element
+	 * that specified in the request. @returns a List with Dialect(s) of
+	 * metadata requested.
+	 * 
+	 */
+	private List determineMetadataTypes(OMElement aReq) {
+		List metadata_request_list = new ArrayList();
+
+		boolean allTypes = false;
+
+		OMElement dialect = aReq.getFirstChildWithName(new QName(
+				MexConstants.SPEC.DIALECT));
+		if (dialect != null) {
+			String dialectText = dialect.getText();
+			if (dialectText != null && dialectText.length() > 0) {
+				metadata_request_list.add(dialectText.trim());
+			} else
+				allTypes = true;
+		} else
+			allTypes = true;
+
+		if (allTypes) { // retrieve all metadata
+			metadata_request_list.add(MexConstants.SPEC.DIALECT_TYPE_POLICY);
+			metadata_request_list.add(MexConstants.SPEC.DIALECT_TYPE_SCHEMA);
+			metadata_request_list.add(MexConstants.SPEC.DIALECT_TYPE_WSDL);
+		}
+		return metadata_request_list;
+	}
+
+
+    private void check_MEX_disabled (Parameter mexConfig) throws MexDisabledException{
+        if (MexUtil.isMexDisabled(mexConfig)){
+            throw new MexDisabledException("'metadataexchange' parameter configured to disable MEX for the service.");
+        }
+    }
+}
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/AnyURIType.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/AnyURIType.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/AnyURIType.java (original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/AnyURIType.java Thu Mar 15 08:26:09 2007
@@ -1,67 +1,74 @@
-/*
-* Copyright 2007 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.apache.axis2.mex.OM;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axis2.mex.MexConstants;
-
-/**
- * Base Class implemented for element(s) that of type='xs:anyURI' defined in 
- * the WS-MEX spec.
- *
- */
-
-public abstract class AnyURIType extends MexOM implements IMexOM {
-    private String uri = null;
-	private OMFactory defaultFactory;
-	
-	private String namespaceValue = null;
-	
-	public AnyURIType(OMFactory defaultFactory, String namespaceValue, String uri) throws MexOMException {
-		if (!isNamespaceSupported(namespaceValue))
-			throw new MexOMException ("Unsupported namespace");
-		
-		this.defaultFactory = defaultFactory;
-		this.namespaceValue = namespaceValue;
-		this.uri = uri;
-	}
-	
-
-	/**
-	 * Convert object content to the OMElement representation.
-	 * @return OMElement representation of sub-class of AnyURIType.
-	 * @throws MexOMException
-	 */
-	
-	public OMElement toOM() throws MexOMException {
-		if (uri == null || uri == "") {
-			throw new MexOMException("Expected URI type is not set .. ");
-		}
-			
-		OMNamespace mexNamespace = defaultFactory.createOMNamespace(namespaceValue,MexConstants.SPEC.NS_PREFIX);
-		OMElement  element = defaultFactory.createOMElement(getElementName(), mexNamespace);	
-		element.setText(uri);
-		return element;
-	}
-	
-	/*
-	 * Child class must implement to answer the element name.
-	 */
-  protected abstract String getElementName();
-}
+/*
+* Copyright 2007 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.apache.axis2.mex.OM;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axis2.mex.MexConstants;
+
+/**
+ * Base Class implemented for element(s) that of type='xs:anyURI' defined in 
+ * the WS-MEX spec.
+ *
+ */
+
+public abstract class AnyURIType extends MexOM implements IMexOM {
+    private String uri = null;
+	private OMFactory defaultFactory;
+	
+	private String namespaceValue = null;
+	
+	public AnyURIType(OMFactory defaultFactory, String namespaceValue, String uri) throws MexOMException {
+		if (!isNamespaceSupported(namespaceValue))
+			throw new MexOMException ("Unsupported namespace");
+		
+		this.defaultFactory = defaultFactory;
+		this.namespaceValue = namespaceValue;
+		this.uri = uri;
+	}
+	
+
+	/**
+	 * Convert object content to the OMElement representation.
+	 * @return OMElement representation of sub-class of AnyURIType.
+	 * @throws MexOMException
+	 */
+	
+	public OMElement toOM() throws MexOMException {
+		if (uri == null || uri == "") {
+			throw new MexOMException("Expected URI type is not set .. ");
+		}
+			
+		OMNamespace mexNamespace = defaultFactory.createOMNamespace(namespaceValue,MexConstants.SPEC.NS_PREFIX);
+		OMElement  element = defaultFactory.createOMElement(getElementName(), mexNamespace);	
+		element.setText(uri);
+		return element;
+	}
+	
+    protected void setURI(String uri){
+	     this.uri = uri;	
+	}
+    
+    public String getURI(){
+	   return uri;	
+	}
+	/*
+	 * Child class must implement to answer the element name.
+	 */
+  protected abstract String getElementName();
+}

Added: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Dialect.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Dialect.java?view=auto&rev=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Dialect.java (added)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Dialect.java Thu Mar 15 08:26:09 2007
@@ -0,0 +1,59 @@
+/*
+* Copyright 2007 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.apache.axis2.mex.OM;
+
+import org.apache.axiom.om.OMFactory;
+import org.apache.axis2.mex.MexConstants;
+
+/**
+ * Class implemented for Dialect element defined in 
+ * the WS-MEX spec.
+ *
+ */
+
+public class Dialect extends AnyURIType {
+
+	/**
+	 * Constructor
+	 * @param defaultFactory
+	 * @param namespaceValue namespace info
+	 * @param dialect Dialect in URI representation
+	 * @throws MexOMException
+	 */
+	public Dialect(OMFactory defaultFactory, String namespaceValue, String dialect) throws MexOMException {
+		super(defaultFactory, namespaceValue, dialect);
+	}
+	
+	/**
+	 * Constructor with default namespace
+	 * @param defaultFactory
+	 * @param dialect  Dialect in URI representation
+	 * @throws MexOMException
+	 */
+	public Dialect(OMFactory defaultFactory, String dialect) throws MexOMException {
+		super(defaultFactory, MexConstants.Spec_2004_09.NS_URI, dialect );
+	}
+
+	/*
+	 * Return name of this element
+	 * (non-Javadoc)
+	 * @see org.apache.axis2.Mex.OM.AnyURIType#getElementName()
+	 */
+	protected String getElementName(){
+		return MexConstants.SPEC.DIALECT;
+	}
+}

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Dialet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Dialet.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Dialet.java (original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Dialet.java Thu Mar 15 08:26:09 2007
@@ -1,59 +0,0 @@
-/*
-* Copyright 2007 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.apache.axis2.mex.OM;
-
-import org.apache.axiom.om.OMFactory;
-import org.apache.axis2.mex.MexConstants;
-
-/**
- * Class implemented for Dialect element defined in 
- * the WS-MEX spec.
- *
- */
-
-public class Dialet extends AnyURIType {
-
-	/**
-	 * Constructor
-	 * @param defaultFactory
-	 * @param namespaceValue namespace info
-	 * @param dialect Dialect in URI representation
-	 * @throws MexOMException
-	 */
-	public Dialet(OMFactory defaultFactory, String namespaceValue, String dialect) throws MexOMException {
-		super(defaultFactory, namespaceValue, dialect);
-	}
-	
-	/**
-	 * Constructor with default namespace
-	 * @param defaultFactory
-	 * @param dialect  Dialect in URI representation
-	 * @throws MexOMException
-	 */
-	public Dialet(OMFactory defaultFactory, String dialect) throws MexOMException {
-		super(defaultFactory, MexConstants.Spec_2004_09.NS_URI, dialect );
-	}
-
-	/*
-	 * Return name of this element
-	 * (non-Javadoc)
-	 * @see org.apache.axis2.Mex.OM.AnyURIType#getElementName()
-	 */
-	protected String getElementName(){
-		return MexConstants.SPEC.DIALECT;
-	}
-}

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Location.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Location.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Location.java (original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Location.java Thu Mar 15 08:26:09 2007
@@ -1,45 +1,72 @@
-/*
-* Copyright 2007 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.apache.axis2.mex.OM;
-
-import org.apache.axiom.om.OMFactory;
-import org.apache.axis2.mex.MexConstants;
-
-/**
- * Class implemented for Location element defined in 
- * the WS-MEX spec.
- *
- */
-
-public class Location extends AnyURIType {
-
-	public Location(OMFactory defaultFactory, String namespaceValue, String uri) throws MexOMException {
-		super(defaultFactory, namespaceValue, uri);
-	}
-	public Location(OMFactory defaultFactory, String uri) throws MexOMException {
-		super(defaultFactory, MexConstants.Spec_2004_09.NS_URI, uri );
-	}
-	
-	/*
-	 * Return name of this element
-	 * (non-Javadoc)
-	 * @see org.apache.axis2.Mex.OM.AnyURIType#getElementName()
-	 */
-	protected String getElementName(){
-		return MexConstants.SPEC.LOCATION;
-	}
-}
+/*
+* Copyright 2007 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.apache.axis2.mex.OM;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axis2.mex.MexConstants;
+import org.apache.axis2.mex.MexException;
+import org.apache.axis2.mex.util.MexUtil;
+
+/**
+ * Class implemented for Location element defined in 
+ * the WS-MEX spec.
+ *
+ */
+
+public class Location extends AnyURIType {
+
+	
+	/**
+	 * @param uri  valid URL to retrieve the metadata using HTTP Get
+	 * @throws MexException 
+         *
+	 */
+	public Location(String uri) throws MexException {
+		super(MexUtil.getSOAPFactory(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI), MexConstants.Spec_2004_09.NS_URI, uri);
+	}
+	
+	public Location(OMFactory defaultFactory, String namespaceValue, String uri) throws MexOMException {
+		super(defaultFactory, namespaceValue, uri);
+	}
+
+	public Location(OMFactory defaultFactory, String uri) throws MexOMException {
+		super(defaultFactory, MexConstants.Spec_2004_09.NS_URI, uri );
+	}
+	
+	public Location fromOM(OMElement element) throws MexOMException{
+		if (element == null) {
+			throw new MexOMException("Null element passed.");
+		}
+		if (!element.getLocalName().equals(MexConstants.SPEC.LOCATION)) {
+			throw new MexOMException("Invalid element passed.");
+		}
+		super.setURI(element.getText());
+			
+		return this;
+	}
+	
+	/*
+	 * Return name of this element
+	 * (non-Javadoc)
+	 * @see org.apache.axis2.Mex.OM.AnyURIType#getElementName()
+	 */
+	protected String getElementName(){
+		return MexConstants.SPEC.LOCATION;
+	}
+}

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Metadata.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Metadata.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Metadata.java (original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/Metadata.java Thu Mar 15 08:26:09 2007
@@ -1,93 +1,240 @@
-/*
-* Copyright 2007 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.apache.axis2.mex.OM;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axis2.mex.MexConstants;
-
-/**
- * 
- * Class implementing  mex:Metadata element 
- *
- */
-
-public class Metadata extends MexOM implements IMexOM {
-	private String namespaceValue = null;
-	private OMFactory factory;
-	private List  metadataSections = new ArrayList(); 
-	private OMAttribute attribute = null;
-	
-	/**
-	 * 
-	 * @param defaultFactory
-	 * @param namespaceValue
-	 * @throws MexOMException
-	 */
-
-	public Metadata(OMFactory defaultFactory, String namespaceValue) throws MexOMException  {
-		this.factory = defaultFactory;
-		this.namespaceValue = namespaceValue;
-	}
-
-	
-	public OMElement toOM() throws MexOMException
-	{
-		OMNamespace mexNamespace = factory.createOMNamespace(namespaceValue,MexConstants.SPEC.NS_PREFIX);
-		OMElement metadata = factory.createOMElement(MexConstants.SPEC.METADATA, mexNamespace);
-
-		Iterator sections = metadataSections.iterator();
-		while (sections.hasNext()) {
-			MetadataSection aSection = (MetadataSection) sections.next();
-			metadata.addChild(aSection.toOM());
-		}
-		if (attribute != null){
-			metadata.addAttribute(attribute); //???
-		}
-		return metadata;
-	}
-	
-	public void setMetadatSections(List in_metadataSections) {
-		metadataSections = in_metadataSections;
-	}
-	
-	public void addMetadatSections(List in_metadataSections) {
-		Iterator sections = in_metadataSections.iterator();
-		while (sections.hasNext()) {
-			addMetadatSection((MetadataSection) sections.next());
-		}
-	}
-
-	public void addMetadatSection(MetadataSection section) {
-		metadataSections.add(section);
-	}
-	
-	public MetadataSection[] getMetadatSections() {
-		return (MetadataSection[])metadataSections.toArray(new MetadataSection[0]);
-	}
-	
-	public void setAttribute(OMAttribute in_attribute) {
-		attribute = in_attribute;
-	}
-
-}
+/*
+* Copyright 2007 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.apache.axis2.mex.OM;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import javax.xml.namespace.QName;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axis2.AxisFault;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.EndpointReferenceHelper;
+import org.apache.axis2.dataretrieval.OutputForm;
+import org.apache.axis2.mex.MexException;
+import org.apache.axis2.mex.util.MexUtil;
+import org.apache.axis2.mex.MexConstants;
+
+/**
+ * 
+ * Class implementing  mex:Metadata element 
+ *
+ */
+
+public class Metadata extends MexOM implements IMexOM {
+	private String namespaceValue = null;
+	private OMFactory factory;
+	private List  metadataSections = new ArrayList(); 
+	private OMAttribute attribute = null;
+	
+        /**
+	 * Constructor
+	 * @throws MexException 
+	 */
+
+	public Metadata() throws MexException  {
+		
+		this.factory = MexUtil.getSOAPFactory(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);;
+		this.namespaceValue = MexConstants.Spec_2004_09.NS_URI;
+	}
+
+	/**
+	 * 
+	 * @param defaultFactory
+	 * @param namespaceValue
+	 * @throws MexOMException
+	 */
+
+	public Metadata(OMFactory defaultFactory, String namespaceValue) throws MexOMException  {
+		this.factory = defaultFactory;
+		this.namespaceValue = namespaceValue;
+	}
+
+        /**
+         * 
+         * @return Array of MetadataSection of metadata units
+         */
+        public MetadataSection[] getMetadatSections() {
+		return (MetadataSection[])metadataSections.toArray(new MetadataSection[0]);
+	}
+
+         /**
+     * 
+     * @param dialect
+     * @param identifier
+     * @return Array of MetadataSection for the specified dialect metadata type and identifier  
+     */
+    public MetadataSection[] getMetadataSection(String dialect, String identifier){
+    	MetadataSection[] sections = getMetadataSection(dialect, identifier, null);
+    	return sections;
+    }
+    
+    /**
+     * 
+     * Answers the Metadata Sections that met the criteria specified in the dialect, identifier, and form.
+     * Note: Null value parameter will be treated as wild card.
+     * @param dialect
+     * @param identifier
+     * @param form specify the form of metadata: inline or by reference
+     *        See <code>OutputForm</code> for valid output forms.
+     * @return Array of MetadataSection for the specified dialect metadata type and identifier of
+     *         the form specified.
+     *
+     */
+    public MetadataSection[] getMetadataSection(String dialect, String identifier, OutputForm form ){
+        
+    	Iterator sections = metadataSections.iterator();
+    	List foundSections = new ArrayList();
+    	while (sections.hasNext()){
+    		MetadataSection aSection = (MetadataSection) sections.next();
+    		if ((dialect == null || dialect.equals(aSection.getDialect())) &&
+    			(identifier == null || dialect.equals(aSection.getIdentifier())) &&
+    			matchOutputForm(aSection, form)){
+    			foundSections.add(aSection);
+    		}	
+    		
+    	}
+    	return (MetadataSection[])foundSections.toArray(new MetadataSection[0]);
+    }
+    
+    /**
+	 * Populates an Metadata object based on the <code>OMElement</code> passed. 
+	 * @param inElement mex:Metadata element or element contains mex:Metadata element
+	 * @return Metadata 
+	 * @throws MexOMException
+	 */
+	public Metadata fromOM(OMElement inElement) throws MexOMException {
+			
+		OMElement mexElement = null;
+        if (inElement == null ){
+        	throw new MexOMException("Null element passed.");
+        }
+        
+        if (inElement.getLocalName().equals(MexConstants.SPEC.METADATA)){
+        	mexElement = inElement;
+        }
+        if (inElement.getLocalName().equals("EndpointReference")){
+            try {
+	    	  EndpointReference epr = EndpointReferenceHelper.fromOM(inElement);
+				
+		  ArrayList metadata = epr.getMetaData();
+		  if (metadata != null)
+		      mexElement = (OMElement)metadata.get(0);
+		  else {
+		      ArrayList refParm = epr.getExtensibleElements();
+		      for (int i=0; i<refParm.size(); i++){
+		          OMElement elem = (OMElement)refParm.get(i);
+			  if (elem.getLocalName().equals(MexConstants.SPEC.METADATA)){
+			      mexElement = elem;
+			      break;
+			   }
+			}
+			}
+		} catch (AxisFault e) {
+		   throw new MexOMException(e);
+		}
+        	
+	        if (mexElement == null) {
+		    throw new MexOMException("Missing expected Metadata element in element passed.");
+		}
+	   }
+          else mexElement = inElement;
+        
+	  OMFactory aFactory = mexElement.getOMFactory();
+	  if (aFactory == null) {
+	     aFactory = factory;
+	   }
+	   Iterator mexSections = mexElement.getChildrenWithName(new QName(MexConstants.SPEC.METADATA_SECTION));
+        
+           if (mexSections == null){
+         	throw new MexOMException("Metadata element does not contain MetadataSection element.");
+         }
+        while (mexSections.hasNext()){
+        	OMElement aSection = (OMElement) mexSections.next();
+            MetadataSection metadataSection = new MetadataSection(aFactory, namespaceValue);
+            addMetadatSection(metadataSection.fromOM(aSection)); 
+        }
+        
+		return this;
+	}
+	
+	
+       /**
+        * 
+        * @return Array of MetadataSection of metadata units
+        */
+        public OMElement toOM() throws MexOMException
+	{
+		OMNamespace mexNamespace = factory.createOMNamespace(namespaceValue,MexConstants.SPEC.NS_PREFIX);
+		OMElement metadata = factory.createOMElement(MexConstants.SPEC.METADATA, mexNamespace);
+
+		Iterator sections = metadataSections.iterator();
+		while (sections.hasNext()) {
+			MetadataSection aSection = (MetadataSection) sections.next();
+			metadata.addChild(aSection.toOM());
+		}
+		if (attribute != null){
+			metadata.addAttribute(attribute); //???
+		}
+		return metadata;
+	}
+	
+	public void setMetadatSections(List in_metadataSections) {
+		metadataSections = in_metadataSections;
+	}
+	
+	public void addMetadatSections(List in_metadataSections) {
+		Iterator sections = in_metadataSections.iterator();
+		while (sections.hasNext()) {
+			addMetadatSection((MetadataSection) sections.next());
+		}
+	}
+
+	public void addMetadatSection(MetadataSection section) {
+		metadataSections.add(section);
+	}
+	
+       	
+	public void setAttribute(OMAttribute in_attribute) {
+		attribute = in_attribute;
+	}
+
+  
+    // check if section contains data matching the output form requested
+    private boolean matchOutputForm(MetadataSection section,
+			OutputForm outputForm) {
+		boolean match = (outputForm == null);  // no matching needed in null outputForm is passed
+
+		if (!match) {
+			if (outputForm == OutputForm.LOCATION_FORM) {
+				match = (section.getLocation() != null);
+			} else if (outputForm == OutputForm.REFERENCE_FORM) {
+				match = (section.getMetadataReference() != null);
+			} else if (outputForm == OutputForm.INLINE_FORM) {
+				match = (section.getInlineData() != null);
+			}
+		}
+
+		return match;
+	}
+	
+
+}

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/MetadataReference.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/MetadataReference.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/MetadataReference.java (original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/MetadataReference.java Thu Mar 15 08:26:09 2007
@@ -1,95 +1,154 @@
-/*
-* Copyright 2007 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.apache.axis2.mex.OM;
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axis2.AxisFault;
-//import org.apache.axis2.addressing.EndpointReference;
-//import org.apache.axis2.addressing.EndpointReferenceHelper;
-import org.apache.axis2.mex.MexConstants;
-
-/**
- * Class implemented for MetadataReference element defined in 
- * the WS-MetadataExchange spec.
- *
- */
-
-public class MetadataReference extends MexOM implements IMexOM {
-
-	private OMFactory factory;
-	private OMElement eprElement = null; 
-
-	private String namespaceValue = null;
-
-	/**
-	 * Constructor
-	 * @param defaultFactory
-	 * @param namespaceValue
-	 * @throws MexOMException
-	 */
-
-	public MetadataReference(OMFactory defaultFactory, String namespaceValue)
-	 throws MexOMException {
-		if (!isNamespaceSupported(namespaceValue))
-			throw new MexOMException("Unsupported namespace");
-
-		this.factory = defaultFactory;
-		this.namespaceValue = namespaceValue;
-		}
-
-	/**
-	 * Convert MetadatReference object content to the OMElement representation.
-	 * @return OMElement representation of MetadatReference.
-	 * @throws MexOMException
-	 */
-	public OMElement toOM() throws MexOMException {
-		if (eprElement == null) {
-			throw new MexOMException(
-					"Must have EndpointReference element in MetadataReference");
-		}
-
-		OMElement metadataRef = null;
-		/*if (eprElement.getLocalName() == "EndpointReference") {
-			EndpointReference epr;
-			try {
-				epr = EndpointReferenceHelper.fromOM(eprElement);
-				metadataRef = EndpointReferenceHelper.toOM(factory, epr,
-						new QName(namespaceValue,
-								MexConstants.SPEC.METADATA_REFERENCE,
-								MexConstants.SPEC.NS_PREFIX), eprElement
-								.getNamespace().getNamespaceURI());
-
-			} catch (AxisFault e) {
-				throw new MexOMException(e);
-			}
-		} */
-
-		return metadataRef;
-	}
-	
-	/**
-	 * Set EPR element
-	 * 
-	 * @param element
-	 */
-	public void setEPRElement(OMElement element) {
-		eprElement = element;
-	}
-	
-}
+/*
+* Copyright 2007 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.apache.axis2.mex.OM;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.EndpointReferenceHelper;
+import org.apache.axis2.mex.MexConstants;
+import org.apache.axis2.mex.MexException;
+import org.apache.axis2.mex.util.MexUtil;
+
+/**
+ * Class implemented for MetadataReference element defined in 
+ * the WS-MetadataExchange spec.
+ *
+ */
+
+public class MetadataReference extends MexOM implements IMexOM {
+
+	private OMFactory factory;
+	private OMElement eprElement = null; 
+        private EndpointReference epr = null;
+ 	private String namespaceValue = null;
+
+	 /**
+	 * Constructor
+	 * @throws MexException 
+	 */
+
+	public MetadataReference() throws MexException  {
+		
+		this.factory = MexUtil.getSOAPFactory(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+		this.namespaceValue = MexConstants.Spec_2004_09.NS_URI;
+	}
+	
+	/**
+	 * Constructor
+	 * @param defaultFactory
+	 * @param namespaceValue
+	 * @throws MexOMException
+	 */
+
+	public MetadataReference(OMFactory defaultFactory, String namespaceValue)
+	 throws MexOMException {
+		if (!isNamespaceSupported(namespaceValue))
+			throw new MexOMException("Unsupported namespace");
+
+		this.factory = defaultFactory;
+		this.namespaceValue = namespaceValue;
+		}
+
+	 public OMElement getEPRElement() {
+			return eprElement;
+		}
+	  
+	public EndpointReference getEPR() {
+			return epr;
+	}
+
+
+	/**
+	 * Populates an MetadataReference object based on the endpoint reference type <code>OMElement</code> passed. 
+	 * @param inElement MetadataReference element
+	 * @return MetadataReference 
+	 * @throws MexOMException
+	 */
+	
+	public MetadataReference fromOM(OMElement element) throws MexOMException{
+		
+		if (element == null) {
+			throw new MexOMException("Null element passed.");
+		}
+		if (!element.getLocalName().equals(MexConstants.SPEC.METADATA_REFERENCE)) {
+			throw new MexOMException("Invalid element passed.");
+		}
+		eprElement = element;
+		try {
+			epr = EndpointReferenceHelper.fromOM(element);
+		} catch (AxisFault e) {
+			throw new MexOMException (e);
+		}
+		
+		return this;
+	}
+	/**
+	 * Convert MetadatReference object content to the OMElement representation.
+	 * @return OMElement representation of MetadatReference.
+	 * @throws MexOMException
+	 */
+	public OMElement toOM() throws MexOMException {
+		if (eprElement == null) {
+			throw new MexOMException(
+					"Must have EndpointReference element in MetadataReference");
+		}
+
+		OMElement metadataRef = null;
+		try {
+			metadataRef = EndpointReferenceHelper.toOM(factory, epr, new QName(
+					namespaceValue, MexConstants.SPEC.METADATA_REFERENCE,
+					MexConstants.SPEC.NS_PREFIX), eprElement.getNamespace()
+					.getNamespaceURI());
+	
+		} catch (AxisFault e) {
+			throw new MexOMException(e);
+		}
+		
+
+		return metadataRef;
+	}
+	
+	/**
+	 * Set EPR 
+	 * 
+	 * @param element Endpoint Reference Type element
+	 */
+	public void setEPR(OMElement element) throws MexOMException {
+		eprElement = element;
+		try {
+			epr = EndpointReferenceHelper.fromOM(eprElement);
+		} catch (AxisFault e) {
+			throw new MexOMException (e);
+		}
+		
+	}
+	
+	/**
+	 * Set EPR 
+	 * 
+	 * @param element Endpoint Reference Type elem
+	 */
+	public void setEPR(EndpointReference endRef) throws MexOMException {
+		epr = endRef;
+		
+	}
+	
+}

Modified: webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/MetadataSection.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/MetadataSection.java?view=diff&rev=518661&r1=518660&r2=518661
==============================================================================
--- webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/MetadataSection.java (original)
+++ webservices/axis2/trunk/java/modules/mex/src/org/apache/axis2/mex/OM/MetadataSection.java Thu Mar 15 08:26:09 2007
@@ -1,151 +1,236 @@
-/*
-* Copyright 2007 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.apache.axis2.mex.OM;
-
-
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMNode;
-import org.apache.axis2.mex.MexConstants;
-
-
-/**
- * Class implemented for MetadataSection element defined in 
- * the WS-MEX spec.
- *
- */
-public  class MetadataSection extends MexOM implements IMexOM {
-	private String namespaceValue = null;
-	private OMFactory factory;
-	// Choices of content: inline metadata, MetadataReference, Location
-	private String anyAttribute = null;
-	private OMNode inlineData = null;
-	//private String inlineData = null;
-	private Location location = null;
-	private MetadataReference ref = null;
-	
-    // Attributes
-    private String dialet;
-    private String identifier;
-    
-    /**
-     * Constructor
-     * @param defaultFactory
-     * @param namespaceValue
-     * @throws MexOMException
-     */
-	public MetadataSection(OMFactory defaultFactory, String namespaceValue) throws MexOMException  {
-		this.factory = defaultFactory;
-		this.namespaceValue = namespaceValue;
-	}
-	
-		
-	/**
-	 * Convert MetadatSection content to the OMElement representation.
-	 * @return OMElement representation of MetadataSection.
-	 * @throws MexOMException
-	 */
-	public OMElement toOM() throws MexOMException {
-		OMNamespace mexNamespace = factory.createOMNamespace(namespaceValue,
-				MexConstants.SPEC.NS_PREFIX);
-		OMElement metadataSection = factory.createOMElement(
-				MexConstants.SPEC.METADATA_SECTION, mexNamespace);
-
-		// dialet is required
-		if (dialet == null) {
-			throw new MexOMException("Dialet was not set. Dialet must be set.");
-		}
-		OMAttribute dialetAttrib = factory.createOMAttribute(
-				MexConstants.SPEC.DIALECT, null, dialet);
-
-		metadataSection.addAttribute(dialetAttrib);
-
-		if (identifier != null && identifier.trim().length() > 0) {
-			OMAttribute identifierAttrib = factory.createOMAttribute(
-					MexConstants.SPEC.IDENTIFIER, null, identifier);
-
-			metadataSection.addAttribute(identifierAttrib);
-		}
-		if (anyAttribute != null) {
-			OMAttribute anyAttrib = factory.createOMAttribute("AnyAttribute",
-					null, anyAttribute);
-
-			metadataSection.addAttribute(anyAttrib);
-		}
-
-		if (inlineData != null) {
-			metadataSection.addChild(inlineData);
-			
-		}
-
-		if (location != null) {
-			metadataSection.addChild(location.toOM());
-		}
-
-		if (ref != null) {
-			metadataSection.addChild(ref.toOM());
-		}
-		return metadataSection;
-
-	}
-	
-	public String getDialet() {
-		return dialet;
-	}
-	
-	public String getIdentifier() {
-		return identifier;
-	}
-	
-	public String getanyAttribute() {
-		return anyAttribute;
-	}
-	public Location getLocation() {
-		return location;
-	}
-	
-	public OMNode getInlineData() {
-		return inlineData;
-	}
-	
-	public MetadataReference getMetadataReference() {
-		return ref;
-	}
-	
-	public void setIdentifier(String in_identifier) {
-		identifier =in_identifier;
-	}
-	
-	public void setDialet(String in_dialet) {
-		dialet = in_dialet;
-	}
-	
-	
-	public void setLocation(Location in_location) {
-		location = in_location;
-	}
-	
-	public void setinlineData(Object in_inlineData) {
-		inlineData = (OMNode)in_inlineData;
-	}
-	
-	public void setMetadataReference(MetadataReference in_ref) {
-		ref = in_ref;
-	}
-}
+/*
+* Copyright 2007 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.apache.axis2.mex.OM;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axis2.mex.MexConstants;
+import org.apache.axis2.mex.MexException;
+import org.apache.axis2.mex.util.MexUtil;
+
+
+/**
+ * Class implemented for MetadataSection element defined in 
+ * the WS-MEX spec. A unit of metdata i.e. a MetadataSection may be included in-line data, 
+ * or may be by reference as an endpoint reference (MetadataReference) or a URL (Location).
+ * An instance of MetadataSection can have one form of data: inline, location, or reference.
+ *
+ */
+
+public  class MetadataSection extends MexOM implements IMexOM {
+	private String namespaceValue = null;
+	private OMFactory factory;
+	// Choices of content: inline metadata, MetadataReference, Location
+	private String anyAttribute = null;
+	private OMNode inlineData = null;
+	//private String inlineData = null;
+	private Location location = null;
+	private MetadataReference ref = null;
+	
+    // Attributes
+    private String dialect;
+    private String identifier;
+    
+    
+    /**
+	 * Constructor
+	 * @throws MexException 
+	 */
+
+	public MetadataSection() throws MexException  {
+		
+		this.factory = MexUtil.getSOAPFactory(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);;
+		this.namespaceValue = MexConstants.Spec_2004_09.NS_URI;
+	}
+	
+    /**
+     * Constructor
+     * @param defaultFactory
+     * @param namespaceValue
+     * @throws MexOMException
+     */
+	public MetadataSection(OMFactory defaultFactory, String namespaceValue) throws MexOMException  {
+		this.factory = defaultFactory;
+		this.namespaceValue = namespaceValue;
+	}
+	
+	
+	/**
+	 * Populates an MetadataSection object based on the <code>OMElement</code> passed. 
+	 * @param inElement mex:MetadataSection element
+	 * @return MetadataSection 
+	 * @throws MexOMException
+	 */
+	
+	public MetadataSection fromOM(OMElement element) throws MexOMException {
+		if (element == null) {
+			throw new MexOMException("Null element passed.");
+		}
+		if (!element.getLocalName().equals(MexConstants.SPEC.METADATA_SECTION)) {
+			throw new MexOMException("Invalid element passed.");
+		}
+		OMAttribute dialectAttr  = element.getAttribute(new QName(MexConstants.SPEC.DIALECT));
+		if (dialectAttr == null){
+			throw new MexOMException("Missing Dialect Attribute in MetadataSection.");
+		}
+		setDialect(dialectAttr.getAttributeValue());
+		OMAttribute identifierAttr  = element.getAttribute(new QName(MexConstants.SPEC.IDENTIFIER));
+		if (identifierAttr != null){
+			setIdentifier(identifierAttr.getAttributeValue());		
+		}
+		// validate one of the following element must exist: Location, MetadataReference, inline data
+		OMElement locationElem = element.getFirstChildWithName(new QName(MexConstants.SPEC.LOCATION));
+		Location location = null;
+		MetadataReference ref = null;
+		
+		if (locationElem != null){
+			location = new Location(factory, namespaceValue);
+		    setLocation(location.fromOM(locationElem));	
+		}
+		else { // check for MetadataReference
+			OMElement refElem = element.getFirstChildWithName(new QName(MexConstants.SPEC.METADATA_REFERENCE));
+			if (refElem != null ){
+				ref = new MetadataReference(factory, namespaceValue);
+				setMetadataReference(ref.fromOM(refElem));
+			}
+		}
+		if (location == null && ref == null) { // check for inline content
+			OMNode inline = element.getFirstOMChild();
+		    if (inline != null)
+		    	setinlineData(inline);
+		    else {
+		    	throw new MexOMException("Invalid empty MetadataSection.");
+		    }
+		    
+		}
+
+		return this;
+	}
+	
+	/**
+	 * Convert MetadatSection content to the OMElement representation.
+	 * 
+	 * @return OMElement representation of MetadataSection.
+	 * @throws MexOMException
+	 */
+	public OMElement toOM() throws MexOMException {
+		OMNamespace mexNamespace = factory.createOMNamespace(namespaceValue,
+				MexConstants.SPEC.NS_PREFIX);
+		OMElement metadataSection = factory.createOMElement(
+				MexConstants.SPEC.METADATA_SECTION, mexNamespace);
+
+		// dialet is required
+		if (dialect == null) {
+			throw new MexOMException("Dialet was not set. Dialet must be set.");
+		}
+		OMAttribute dialetAttrib = factory.createOMAttribute(
+				MexConstants.SPEC.DIALECT, null, dialect);
+
+		metadataSection.addAttribute(dialetAttrib);
+
+		if (identifier != null && identifier.trim().length() > 0) {
+			OMAttribute identifierAttrib = factory.createOMAttribute(
+					MexConstants.SPEC.IDENTIFIER, null, identifier);
+
+			metadataSection.addAttribute(identifierAttrib);
+		}
+		if (anyAttribute != null) {
+			OMAttribute anyAttrib = factory.createOMAttribute("AnyAttribute",
+					null, anyAttribute);
+
+			metadataSection.addAttribute(anyAttrib);
+		}
+
+		if (inlineData != null) {
+			metadataSection.addChild(inlineData);
+			
+		}
+
+		if (location != null) {
+			metadataSection.addChild(location.toOM());
+		}
+
+		if (ref != null) {
+			metadataSection.addChild(ref.toOM());
+		}
+		return metadataSection;
+
+	}
+	
+	public String getDialect() {
+		return dialect;
+	}
+	
+	public String getIdentifier() {
+		return identifier;
+	}
+	
+	public String getanyAttribute() {
+		return anyAttribute;
+	}
+	
+	/**
+	 * Return metadata unit in URL form i.e. mex:Location
+	 * 
+	 * @return
+	 */
+	public Location getLocation() {
+		return location;
+	}
+	
+	/**
+	 * Return metadata unit in inline form such as WSDL definitions, XML schema document, etc.
+	 * @return
+	 */
+	public OMNode getInlineData() {
+		return inlineData;
+	}
+	
+	/**
+	 * Return metadata unit in endpoint reference form i.e. mex:MetadataReference.
+	 * @return
+	 */
+	public MetadataReference getMetadataReference() {
+		return ref;
+	}
+	
+	public void setIdentifier(String in_identifier) {
+		identifier =in_identifier;
+	}
+	
+	public void setDialect(String in_dialect) {
+		dialect = in_dialect;
+	}
+	
+	
+	public void setLocation(Location in_location) {
+		location = in_location;
+	}
+	
+	public void setinlineData(Object in_inlineData) {
+		inlineData = (OMNode)in_inlineData;
+	}
+	
+	public void setMetadataReference(MetadataReference in_ref) {
+		ref = in_ref;
+	}
+}



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