Package org.apache.axis.wsdl.wsdl2ws.cpp

Source Code of org.apache.axis.wsdl.wsdl2ws.cpp.WrapHeaderWriter

/*
*   Copyright 2003-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.
*/
/**
* @author Srinath Perera(hemapani@openource.lk)
* @author Susantha Kumara(susantha@opensource.lk, skumara@virtusa.com)
*/


package org.apache.axis.wsdl.wsdl2ws.cpp;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.axis.wsdl.wsdl2ws.WrapperFault;
import org.apache.axis.wsdl.wsdl2ws.WrapperUtils;
import org.apache.axis.wsdl.wsdl2ws.info.MethodInfo;
import org.apache.axis.wsdl.wsdl2ws.info.FaultInfo;
import org.apache.axis.wsdl.wsdl2ws.info.WebServiceContext;
import org.apache.axis.wsdl.wsdl2ws.CUtils;

public class WrapHeaderWriter extends HeaderFileWriter{
  private WebServiceContext wscontext;
  private ArrayList methods; 
  public WrapHeaderWriter(WebServiceContext wscontext)throws WrapperFault{
    super(WrapperUtils.getClassNameFromFullyQualifiedName(wscontext.getSerInfo().getQualifiedServiceName()+CUtils.WRAPPER_NAME_APPENDER));
    this.wscontext = wscontext;
    this.methods = wscontext.getSerInfo().getMethods();
  }
  protected File getFilePath() throws WrapperFault {
    String targetOutputLocation = this.wscontext.getWrapInfo().getTargetOutputLocation();
    if(targetOutputLocation.endsWith("/"))
      targetOutputLocation = targetOutputLocation.substring(0, targetOutputLocation.length() - 1);
    new File(targetOutputLocation).mkdirs();
    String fileName = targetOutputLocation + "/" + classname + ".h";
    return new File(fileName);
  }

  protected File getFilePath(boolean useServiceName) throws WrapperFault {
    String targetOutputLocation = this.wscontext.getWrapInfo().getTargetOutputLocation();
    if(targetOutputLocation.endsWith("/"))
      targetOutputLocation = targetOutputLocation.substring(0, targetOutputLocation.length() - 1);
    new File(targetOutputLocation).mkdirs();

    String fileName = targetOutputLocation + "/" + classname + ".h";
   
    if( useServiceName)
    {
      fileName = targetOutputLocation + "/" + this.wscontext.getSerInfo().getServicename() + "_" + classname + ".h";
    }
   
    return new File(fileName);
  }

  protected String getServiceName() throws WrapperFault {
    return wscontext.getSerInfo().getServicename();
  }

  protected void writeClassComment() throws WrapperFault {
      try{
        writer.write("/*\n")
        writer.write(" * This file was auto-generated by the Axis C++ Web Service Generator (WSDL2Ws)\n");
        writer.write(" * This file contains Web Service Wrapper declarations\n");
        writer.write(" */\n\n");
      }catch(IOException e){
        throw new WrapperFault(e);
      }
  }

  /* (non-Javadoc)
   * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writeConstructors()
   */
  protected void writeConstructors() throws WrapperFault {
    try{
    writer.write("public:\n\t"+classname+"();\n");
    }catch(IOException e){
      throw new WrapperFault(e);
    }
  }

  /* (non-Javadoc)
   * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writeDistructors()
   */
  protected void writeDistructors() throws WrapperFault {
    try{
    writer.write("public:\n\tvirtual ~"+classname+"();\n");
    }catch(IOException e){
      throw new WrapperFault(e);
    }
  }

  /* (non-Javadoc)
   * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writeMethods()
   */
  protected void writeMethods() throws WrapperFault {
    try{
      writer.write("public:/*implementation of WrapperClassHandler interface*/\n");
      writer.write("\tint AXISCALL invoke(void* pMsg);\n");
      writer.write("\tvoid AXISCALL onFault(void* pMsg);\n");
      writer.write("\tint AXISCALL init();\n");
      writer.write("\tint AXISCALL fini();\n");
      writer.write("\tAXIS_BINDING_STYLE AXISCALL getBindingStyle(){return RPC_ENCODED;};\n");
      writer.write("private:/*Methods corresponding to the web service methods*/\n");
      MethodInfo minfo;
      for (int i = 0; i < methods.size(); i++) {
           minfo = (MethodInfo)methods.get(i);
           writer.write("\tint "+minfo.getMethodname()+ "(void* pMsg);");
           writer.write("\n");
         }
    
    }catch(IOException e){
      throw new WrapperFault(e);
    }
  }

  /* (non-Javadoc)
   * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writePreprocssorStatements()
   */
  protected void writePreprocssorStatements() throws WrapperFault {
    try{
      writer.write("#include \""+CUtils.getWebServiceNameFromWrapperName(classname)+".h\"\n");
      writer.write("#include <axis/server/WrapperClassHandler.h>\n");
      writer.write("#include <axis/server/IMessageData.h>\n");
      writer.write("#include <axis/server/GDefine.h>\n");
      writer.write("#include <axis/server/AxisWrapperAPI.h>\n");
      writer.write("#include \"AxisServiceException.h\" \n");
      writer.write("AXIS_CPP_NAMESPACE_USE \n\n");
      //writeFaultHeaders();
     
    }catch(IOException e){
      throw new WrapperFault(e);
    }
  }
  /* (non-Javadoc)
   * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writeMethods()
   */
  protected void writeFaultHeaders() throws WrapperFault {
    try{
     
      MethodInfo minfo;
      for (int i = 0; i < methods.size(); i++) {
        minfo = (MethodInfo)methods.get(i);
        Iterator fault = minfo.getFaultType().iterator();
        String faultInfoName =null;          
        while (fault.hasNext()){
            FaultInfo info = (FaultInfo)fault.next();
            faultInfoName =info.getFaultInfo();      
            writer.write("#include \"Axis"+faultInfoName.toString()+"Exception.h\"\n");
        }
      }     
      writer.write("\n");
    }catch(IOException e){
      throw new WrapperFault(e);
    }
  }
  protected String getExtendsPart(){return " : public WrapperClassHandler";}
  protected void writeAttributes()throws WrapperFault{
    try{
      writer.write("private:/* Actual web service object*/\n\t"+CUtils.getWebServiceNameFromWrapperName(classname)+" *pWs;\n");
    }catch(IOException e){
      throw new WrapperFault(e);
    }     
  }
  protected String getFileType()
  {
    return "ServerWrapper"
  }
}
TOP

Related Classes of org.apache.axis.wsdl.wsdl2ws.cpp.WrapHeaderWriter

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.