blob: b8e402626eabbf43adfb2ec06b44ae804c90073e [file] [log] [blame]
/*
* Copyright 2003-2004 The Apache Software Foundation.
// (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved
*
* 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.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.CUtils;
import org.apache.axis.wsdl.wsdl2ws.WSDL2Ws;
import org.apache.axis.wsdl.wsdl2ws.WrapperFault;
import org.apache.axis.wsdl.wsdl2ws.info.FaultInfo;
import org.apache.axis.wsdl.wsdl2ws.info.MethodInfo;
import org.apache.axis.wsdl.wsdl2ws.info.ParameterInfo;
import org.apache.axis.wsdl.wsdl2ws.info.WebServiceContext;
/**
* @author nithya
* @author Samisa Abeysinghe (sabeysinghe@virtusa.com)
*/
public class ExceptionHeaderWriter extends HeaderFileWriter
{
String faultInfoName;
public ExceptionHeaderWriter(
WebServiceContext wscontext,
String faultInfoName)
throws WrapperFault
{
//super(WrapperUtils.getClassNameFromFullyQualifiedName(wscontext.getSerInfo().getQualifiedServiceName()));
super("Axis" + faultInfoName + "Exception"); //damitha
if (WSDL2Ws.c_veryVerbose)
System.out.println("faultInfoName is:" + faultInfoName);
this.wscontext = wscontext;
this.faultInfoName = "Axis" + faultInfoName + "Exception";
}
protected File getFilePath(boolean useServiceName) throws WrapperFault
{
String targetOutputLocation = wscontext.getWrapperInfo().getTargetOutputLocation();
new File(targetOutputLocation).mkdirs();
String serviceName = "";
if (useServiceName)
serviceName = wscontext.getServiceInfo().getServicename() + "_";
String fileName = targetOutputLocation + "/" + serviceName + faultInfoName + c_fileExtension;
wscontext.addGeneratedFile(fileName);
return new File(fileName);
}
/* (non-Javadoc)
* @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writePreprocssorStatements()
*/
protected void writePreprocessorStatements() throws WrapperFault
{
try
{
c_writer.write("#include <string>\n");
c_writer.write("#include <exception>\n");
c_writer.write("#include <axis/AxisException.hpp>\n");
c_writer.write("#include <axis/ISoapFault.hpp>\n");
getLangName();
c_writer.write("using namespace std;\n");
c_writer.write("AXIS_CPP_NAMESPACE_USE \n\n");
}
catch (IOException e)
{
throw new WrapperFault(e);
}
}
/* (non-Javadoc)
* @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writeClassComment()
*/
protected void writeClassComment() throws WrapperFault
{
try
{
c_writer.write("/*\n");
c_writer.write(
" * This file was auto-generated by the Axis C++ Web Service "
+ "Generator (WSDL2Ws)\n");
c_writer.write(
" * This file contains an Exception class of the web service.\n");
c_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
{
String faultName = faultInfoName;
if ("AxisClientException".equals(faultInfoName))
{
faultName = getServiceName() + "_" + faultInfoName;
}
c_writer.write("public:\n");
c_writer.write("\tSTORAGE_CLASS_INFO " + faultName + "(ISoapFault* pFault);\n");
c_writer.write("\tSTORAGE_CLASS_INFO " + faultName + "(const int iExceptionCode, const char* pcMessage = NULL );\n");
c_writer.write("\tSTORAGE_CLASS_INFO " + faultName + "(const " + faultName + "& e);\n");
}
catch (IOException e)
{
throw new WrapperFault(e);
}
}
/* (non-Javadoc)
* @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writeDistructors()
*/
protected void writeDestructors() throws WrapperFault
{
try
{
String faultName = faultInfoName;
if ("AxisClientException".equals(faultInfoName))
{
faultName = getServiceName() + "_" + faultInfoName;
}
c_writer.write("\tSTORAGE_CLASS_INFO virtual ~" + faultName + "() throw();\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
{
c_writer.write("\tSTORAGE_CLASS_INFO const ISoapFault* getFault();\n\n");
c_writer.write("private:\n");
c_writer.write("\tSTORAGE_CLASS_INFO string getMessageForExceptionCode(int iExceptionCode);\n");
c_writer.write("\t ISoapFault* m_pISoapFault;\n");
c_writer.write("\t string m_sMessageForExceptionCode;\n\n");
}
catch (Exception e)
{
throw new WrapperFault(e);
}
}
protected String getFileType()
{
return "Exception"; // must change accordingly
}
protected String getExtendsPart()
{
return ": public AxisException";
}
public void getLangName() throws WrapperFault
{
ArrayList methods;
methods = wscontext.getServiceInfo().getMethods();
MethodInfo minfo;
try
{
for (int i = 0; i < methods.size(); i++)
{
minfo = (MethodInfo) methods.get(i);
Iterator paramsFault = minfo.getFaultType().iterator();
String langName = null;
while (paramsFault.hasNext())
{
FaultInfo info = (FaultInfo) paramsFault.next();
ArrayList paramInfo = info.getParams();
for (int j = 0; j < paramInfo.size(); j++)
{
ParameterInfo par = (ParameterInfo) paramInfo.get(j);
langName = par.getLangName();
c_writer.write(
"#include \""
+ langName
+ CUtils.getHeaderFileExtension()
+ "\"\n\n");
}
}
}
}
catch (Exception e)
{
System.out.println(
"Error occurred yet we continue to generate other classes ... you should check the error");
e.printStackTrace();
}
}
}