Package org.apache.muse.ws.metadata.impl

Source Code of org.apache.muse.ws.metadata.impl.SimpleMetadataExchange

/*=============================================================================*
*  Copyright 2006 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.muse.ws.metadata.impl;

import java.lang.reflect.Method;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import org.apache.muse.core.AbstractCapability;
import org.apache.muse.core.Environment;
import org.apache.muse.core.Resource;
import org.apache.muse.core.routing.MessageHandler;
import org.apache.muse.util.ReflectUtils;
import org.apache.muse.util.xml.XmlUtils;
import org.apache.muse.ws.addressing.soap.SoapFault;
import org.apache.muse.ws.metadata.MetadataExchange;
import org.apache.muse.ws.metadata.WsxConstants;
import org.apache.muse.ws.wsdl.WsdlUtils;

/**
*
* SimpleMetadataExchange is Muse's default implementation of the
* WS-MetadataExchange GetMetadata port type. The only supported
* metadata type (dialect) is WSDL.
*
* @author Dan Jemiolo (danj)
*
*/

public class SimpleMetadataExchange
    extends AbstractCapability implements MetadataExchange
{
    private static final Element[] _NOT_FOUND = new Element[0];
   
    protected MessageHandler createGetMetadataHandler()
    {
        MessageHandler handler = new GetMetadataHandler();
       
        try
        {
            Method method = ReflectUtils.getFirstMethod(getClass(), "getMetadata");
            handler.setMethod(method);
        }
       
        catch (Throwable error)
        {
            throw new RuntimeException(error.getMessage(), error);
        }
       
        return handler;
    }
   
    public Element[] getMetadata(String dialect)
    {
        //
        // the resource factory has all its metadata/deployment docs
        //
        Element metadata = null;
       
        //
        // missing dialect has no defined fault in ws-mex
        //
        if (dialect == null)
            return _NOT_FOUND;
       
        //
        // get WSDL - this is fully resolved (very large!)
        //
        else if (dialect.equals(WsxConstants.WSDL_DIALECT))
            metadata = getWSDL();
       
        //
        // dialect provided, but not type matches it
        //
        if (metadata == null)
            return _NOT_FOUND;
       
        return new Element[]{ metadata };
    }
   
    protected Element getWSDL()
    {
        Resource owner = getResource();
       
        Environment env = owner.getEnvironment();
        String path = owner.getWsdlPath();
       
        Document wsdlDoc = WsdlUtils.createWSDL(env, path, true);
        Element wsdl = XmlUtils.getFirstElement(wsdlDoc);
       
        WsdlUtils.removeWsdlReferences(wsdl);
        WsdlUtils.removeSchemaReferences(wsdl);
       
        return wsdl;
    }
   
    public void initialize()
        throws SoapFault
    {
        super.initialize();
        setMessageHandler(createGetMetadataHandler());
    }
}
TOP

Related Classes of org.apache.muse.ws.metadata.impl.SimpleMetadataExchange

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.