Package org.apache.ws.util

Source Code of org.apache.ws.util.OperationInfo

/*=============================================================================*
*  Copyright 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.apache.ws.util;

import org.apache.commons.lang.StringUtils;
import org.apache.ws.resource.tool.GenerationUtils;

import javax.wsdl.Input;
import javax.wsdl.Operation;
import javax.wsdl.Output;
import javax.wsdl.Part;
import javax.wsdl.Fault;
import javax.xml.namespace.QName;
import java.util.Map;
import java.util.Iterator;

/**
* The Java method signature info for a WSDL operation.
*
* @author Ian Springer (ian DOT springer AT hp DOT com)
*/
public class OperationInfo
{

    private String m_methodName;
    private String m_methodSig;
    private QName m_requestElemName;
    private Map m_faults;
    private String m_fullyQualifiedResponseClassName;
    private String m_fullyQualifiedRequestClassName;

    public OperationInfo(Operation op, String targetNamespace)
    {
        m_methodName = StringUtils.capitalize( op.getName() );
        Input input = op.getInput();
        if ( input != null )
        {
            Map inputParts = input.getMessage().getParts();
            if ( inputParts.size() != 1 )
            {
                throw new RuntimeException( "WSDL input element should have exactly one part." );
            }
            Part inputPart = (Part) inputParts.values().iterator().next();
            m_requestElemName = inputPart.getElementName();
            m_fullyQualifiedRequestClassName = XmlBeanNameUtils.getDocumentElementXmlBeanClassName( m_requestElemName );
        }
        else
        {
            m_fullyQualifiedRequestClassName = "";
        }
        Output output = op.getOutput();
        if ( output != null )
        {
            Map outputParts = output.getMessage().getParts();
            if ( outputParts.size() > 1 )
            {
                throw new RuntimeException( "WSDL output element should have at most one part." );
            }
            if ( outputParts.size() == 1)
            {
                Part outputPart = (Part) outputParts.values().iterator().next();
                m_fullyQualifiedResponseClassName = XmlBeanNameUtils.getDocumentElementXmlBeanClassName( outputPart.getElementName() );
            }
            else  // no output parts
            {
                m_fullyQualifiedResponseClassName = "void";
            }
        }
        else  // no output
        {
            m_fullyQualifiedResponseClassName = "void";
        }
        m_methodSig = m_fullyQualifiedResponseClassName + " " + m_methodName + "( " + m_fullyQualifiedRequestClassName + " requestDoc )";

        //add faults to signature....
        m_faults = op.getFaults();
        if(!m_faults.isEmpty())
        {
            m_methodSig += " throws ";
            Iterator iterator = m_faults.keySet().iterator();
            while (iterator.hasNext())
            {
                String faultName = (String) iterator.next();
                Fault fault = (Fault) m_faults.get(faultName);
                Part part = (Part) fault.getMessage().getParts().values().iterator().next();
                String javaPackageName = GenerationUtils.getJavaPackageName( targetNamespace );
                if(part.getElementName() == null)
                {
                    //its a type..get the name of the type
                    faultName = part.getTypeName().getLocalPart();
                }
                faultName = javaPackageName + "." + faultName + "Exception";
                m_methodSig += faultName;
                if(iterator.hasNext())
                {
                    m_methodSig += ", ";
                }
            }
        }

    }

    public String getJavaMethodName()
    {
        return m_methodName;
    }

    public String getJavaMethodSignature()
    {
        return m_methodSig;
    }

    public QName getRequestElementName()
    {
        return m_requestElemName;
    }

    public Map getFaults()
    {
        return m_faults;
    }

    public String getFullyQualifiedResponseClassName()
    {
        return m_fullyQualifiedResponseClassName;
    }

    public String getFullyQualifiedRequestClassName()
    {
        return m_fullyQualifiedRequestClassName;
    }

    /**
     * Returns the class name without the package
     *
     * @return Class name without the package
     */
    public String getUnqualifiedResponseClassName()
    {
        return m_fullyQualifiedResponseClassName.substring(m_fullyQualifiedResponseClassName.lastIndexOf(".") + 1);
    }

    /**
     * Returns the class name without the package
     *
     * @return  class name without the package
     */
    public String getUnqualifiedRequestClassName()
    {
        return m_fullyQualifiedRequestClassName.substring(m_fullyQualifiedRequestClassName.lastIndexOf(".") + 1);
    }

    public String getUnqualifiedResponseTypeName()
    {
        return  getUnqualifiedResponseClassName().substring(0, getUnqualifiedResponseClassName().lastIndexOf("Document"));
    }

    public String getUnqualifiedRequestTypeName()
    {
       return getUnqualifiedRequestClassName().substring(0, getUnqualifiedRequestClassName().lastIndexOf("Document"));
    }
}
TOP

Related Classes of org.apache.ws.util.OperationInfo

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.