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 da...@apache.org on 2004/06/07 13:22:42 UTC

cvs commit: ws-axis/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/cpp CPPExceptionClassWriter.java ExceptionHeaderWriter.java ExceptionWriter.java AllExceptionWriter.java

damitha     2004/06/07 04:22:42

  Added:       c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/cpp
                        CPPExceptionClassWriter.java
                        ExceptionHeaderWriter.java ExceptionWriter.java
                        AllExceptionWriter.java
  Log:
  
  
  Revision  Changes    Path
  1.1                  ws-axis/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/cpp/CPPExceptionClassWriter.java
  
  Index: CPPExceptionClassWriter.java
  ===================================================================
  /*
   * Created on Jun 3, 2004
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.axis.wsdl.wsdl2ws.cpp;
  import java.io.BufferedWriter;
  import java.io.FileWriter;
  import java.io.IOException;
  
  import org.apache.axis.wsdl.wsdl2ws.WrapperFault;
  import org.apache.axis.wsdl.wsdl2ws.BasicFileWriter;
  
  /**
   * @author nithya
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  
  public abstract class CPPExceptionClassWriter extends BasicFileWriter{
  	
  	public CPPExceptionClassWriter(String classname) throws WrapperFault{
  			super(classname);
  		}
  	public void writeSource()throws WrapperFault{
  		   try{
  		  this.writer = new BufferedWriter(new FileWriter(getFilePath(), false));
  		   writeClassComment();
  		   writePreprocssorStatements();
  		   writeGlobalCodes();
  		   writeAttributes();
  		   writeConstructors();
  		   writeDistructors();
  		   writeMethods();
  		   writer.flush();
  		   writer.close();
  		   System.out.println(getFilePath().getAbsolutePath() + " created.....");
  		   } catch (IOException e) {
  				e.printStackTrace();
  				throw new WrapperFault(e);
  			}
  		}
  		
        protected void writeGlobalCodes()throws WrapperFault{}
  }
  
  
  
  1.1                  ws-axis/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/cpp/ExceptionHeaderWriter.java
  
  Index: ExceptionHeaderWriter.java
  ===================================================================
  /*
   *   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.
   */
  package org.apache.axis.wsdl.wsdl2ws.cpp;
  import java.io.File;
  import java.io.IOException;
  import java.util.ArrayList;
  import org.apache.axis.wsdl.wsdl2ws.WrapperFault;
  import org.apache.axis.wsdl.wsdl2ws.WrapperUtils;
  import org.apache.axis.wsdl.wsdl2ws.info.WebServiceContext;
  /**
   * @author nithya
   *
   */
  public class ExceptionHeaderWriter extends HeaderFileWriter{
  	
  	private WebServiceContext wscontext;
  	private ArrayList methods;		
  
  	String faultInfoName;
  	String langName;
  	String faultType;
  	   
  	public ExceptionHeaderWriter(WebServiceContext wscontext,String faultInfoName,String langName,String faultType)throws WrapperFault{
  	    //super(WrapperUtils.getClassNameFromFullyQualifiedName(wscontext.getSerInfo().getQualifiedServiceName()));
  	    super("Axis"+faultInfoName+"Exception");//damitha
              System.out.println("faultInfoName is:"+faultInfoName);
  	    this.wscontext = wscontext;
  	    this.methods = wscontext.getSerInfo().getMethods();
  	    this.faultInfoName ="Axis"+faultInfoName+"Exception";
  		this.langName =langName;
  		this.faultType =faultType;
      }
  
       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 + "/" + faultInfoName + ".h";
  	    return new File(fileName);
      }
  
  	/* (non-Javadoc)
  		 * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writePreprocssorStatements()
  		 */
  		protected void writePreprocssorStatements() throws WrapperFault {
  			try{
  				//writer.write("#include \""+faultInfoName+".h\"\n\n");//damitha
  				//writer.write("#include <axis/server/AxisException.h>\n\n");//damitha
  				writer.write("#include <string>\n");
  				writer.write("#include <exception>\n");
  				writer.write("#include <axis/server/AxisException.h>\n");
  				writer.write("#include \""+langName+".h\"\n\n");
  				writer.write("using namespace std;\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{
  				writer.write("/*\n");
  				writer.write(" * This is the Client Stub Class genarated by the tool WSDL2Ws\n");
  				writer.write(" * "+faultInfoName+".h: interface for the "+faultInfoName+"class.\n");
  				writer.write(" *\n");
  				writer.write(" */\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"+faultInfoName+"();\n");
  			writer.write("\t"+faultInfoName+"("+faultType+" pFault);\n");
  			writer.write("\t"+faultInfoName+"(int iExceptionCode);\n");
  			writer.write("\t"+faultInfoName+"(exception* e);\n");
  			writer.write("\t"+faultInfoName+"(exception* e, int iExceptionCode);\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("\tvirtual ~"+faultInfoName+"() 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{
  				writer.write("\t const char* what() throw();\n");
  				writer.write("\t const int getExceptionCode();\n");
  				writer.write("\t const string getMessage(exception* e);\n");
  				writer.write("\t const string getMessage(int iExceptionCode);\n");
  				writer.write("private:\n\t void processException(exception* e);\n");
  				writer.write("\t void processException("+faultType+" pFault);\n");
  				writer.write("\t void processException(exception* e, int iExceptionCode);\n");
  				writer.write("\t void processException(int iExceptionCode);\n");//damitha
  				writer.write("\t string m_sMessage;\n");
				writer.write("\t int m_iExceptionCode;\n\n");								
  			}catch (Exception e) {
  			  e.printStackTrace();
  			  throw new WrapperFault(e);
  	    	}
  		}
  		
  	protected String getFileType()
  		{
  			return "Exception";	// must change accordingly
  		}
          protected String getExtendsPart(){return ": public AxisException";}//damitha
  
  }//end of main
   
   
  //class AxisDivByZeroException : public AxisException
  //{
  
  
  
  
  1.1                  ws-axis/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/cpp/ExceptionWriter.java
  
  Index: ExceptionWriter.java
  ===================================================================
  /*
   * Created on Jun 3, 2004
   *
   * To change the template for this generated file go to
   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
   */
  package org.apache.axis.wsdl.wsdl2ws.cpp;
  import java.io.File;
  import java.io.IOException;
  import java.util.ArrayList;
  //import java.util.Collection;
  //import java.util.HashSet;
  //import java.util.Iterator;
  //
  //import javax.xml.namespace.QName;
  //
  //import org.apache.axis.wsdl.wsdl2ws.WrapperConstants;
  import org.apache.axis.wsdl.wsdl2ws.WrapperFault;
  import org.apache.axis.wsdl.wsdl2ws.WrapperUtils;
  //import org.apache.axis.wsdl.wsdl2ws.CUtils;
  //import org.apache.axis.wsdl.wsdl2ws.info.MethodInfo;
  //import org.apache.axis.wsdl.wsdl2ws.info.ParameterInfo;
  //import org.apache.axis.wsdl.wsdl2ws.info.Type;
  //import org.apache.axis.wsdl.wsdl2ws.info.FaultInfo; 
  import org.apache.axis.wsdl.wsdl2ws.info.WebServiceContext;
  /**
   * @author nithya
   *
   * To change the template for this generated type comment go to
   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
   */
  public class ExceptionWriter extends CPPExceptionClassWriter{
  	   private WebServiceContext wscontext;
  	   private ArrayList methods;		
  	  // String  classname = "AxisDivByZeroException";	
  	   String faultInfoName;
  	   String langName;
  	   String faultType;
  	   
  		public ExceptionWriter(WebServiceContext wscontext,String faultInfoName,String langName,String faultType)throws WrapperFault{
  			super(WrapperUtils.getClassNameFromFullyQualifiedName(wscontext.getSerInfo().getQualifiedServiceName()));
  			this.wscontext = wscontext;
  			this.methods = wscontext.getSerInfo().getMethods();
  			this.faultInfoName ="Axis"+faultInfoName+"Exception";
  			this.langName =langName;
  			this.faultType =faultType;
  	
  			
  		}
  	
  	    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 + "/" + faultInfoName + ".cpp";
  			return new File(fileName);
  		}	
  		
  
  	/* (non-Javadoc)
  	 * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writePreprocssorStatements()
  	 */
  	protected void writePreprocssorStatements() throws WrapperFault {
  		try{
  			writer.write("#include \""+faultInfoName+".h\"\n\n");
  			writer.write("#include <axis/server/AxisWrapperAPI.h>\n\n");
  		}catch(IOException e){
  			throw new WrapperFault(e);
  		}
  	}
  		
  	    protected void writeClassComment() throws WrapperFault {
  				try{
  					writer.write("/*\n");	
  					writer.write(" * This is the  implementation file genarated by WSDL2Ws tool.\n");
  					writer.write(" * "+faultInfoName+".cpp: implemtation for the "+faultInfoName+".\n");
  					writer.write(" *\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(faultInfoName+"::"+faultInfoName+"()\n{\n");
  		writer.write("/* This only serves the pupose of indicating that the \n");
  		writer.write(" * service has thrown an excpetion \n");
  		writer.write(" */ \n");
  		writer.write("\tm_iExceptionCode = AXISC_SERVICE_THROWN_EXCEPTION; \n");
  		writer.write("\tprocessException(m_iExceptionCode); \n");
  		writer.write("}\n\n");
  		
  		writer.write(faultInfoName+"::"+faultInfoName+"("+faultType +"pFault)\n");
  		writer.write("{\n");
  		writer.write("\tm_iExceptionCode = AXISC_SERVICE_THROWN_EXCEPTION;\n");//damitha
  		writer.write("\tprocessException(pFault);");//damitha
  		writer.write("}\n\n");
  		
  		writer.write(faultInfoName+"::"+faultInfoName+"(int iExceptionCode)\n");
  		writer.write("{\n\n");
  		writer.write("\tm_iExceptionCode = iExceptionCode;\n");//damitha
  		writer.write("\tprocessException (iExceptionCode);\n");//damitha
  		writer.write("}\n\n");
  		
  		writer.write(faultInfoName+"::"+faultInfoName+"(exception* e)\n");
  		writer.write("{\n");
  		writer.write("\tprocessException (e);\n");//damitha
  		writer.write("}\n\n");
  		
  		writer.write(faultInfoName+"::"+faultInfoName+"(exception* e,int iExceptionCode)\n");
  		writer.write("{\n\n");
  		writer.write("\tprocessException (e, iExceptionCode);\n");//damitha
  		writer.write("}\n\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(faultInfoName+"::~"+faultInfoName+"() throw () \n{\n\tm_sMessage =\"\";\n}\n\n");
  			}catch(IOException e){
  				throw new WrapperFault(e);
  			}
  		}
  		
  	   protected void writeMethods() throws WrapperFault {
  	
  	   try{	
  	       writer.write("void "+faultInfoName+":: processException(exception* e, int iExceptionCode)\n");
  	       writer.write("{\n");
  	       writer.write("\tm_sMessage = getMessage (e) + getMessage (iExceptionCode);\n");//damitha
  	       writer.write("}\n\n");
  
  	       writer.write("void "+faultInfoName+"::processException ("+faultType+" pFault)\n");
  		   writer.write("{\n");
                     writer.write("\t/*User can do something like deserializing the struct into a string*/");//damitha
  		   writer.write("}\n\n");
  
  		   writer.write("void "+faultInfoName+"::processException(exception* e)\n");
  		   writer.write("{\n");
  		   writer.write("\tm_sMessage = getMessage (e);\n");//damitha
  		   writer.write("}\n\n");
  
  		    writer.write("void "+faultInfoName+"::processException(int iExceptionCode)\n");//damitha
  		    writer.write("{\n");
  		    writer.write("\tm_sMessage = getMessage (iExceptionCode);\n");//damitha
  		    writer.write("}\n\n");
  		
  	       writer.write("const string "+faultInfoName+"::getMessage (exception* objException)\n");
  	       writer.write("{\n");
  	       writer.write("\tstring sMessage = objException->what();\n");//damitha
  	       writer.write("\treturn sMessage;\n");//damitha
  	       writer.write("}\n\n");
  
  		   writer.write("const string "+faultInfoName+"::getMessage (int iExceptionCode)\n");
  		   writer.write("{\n");
  		   writer.write("\tstring sMessage;\n");
  		   writer.write("\tswitch(iExceptionCode)\n");
  		   writer.write("\t{\n");
  		   writer.write("\t\tcase AXISC_SERVICE_THROWN_EXCEPTION:\n");
  		   writer.write("\t\tsMessage = \"A service has thrown an exception. see detail\";\n");
  		   writer.write("\t\tbreak;\n");
  		   writer.write("\t\tdefault:\n");
  		   writer.write("\t\tsMessage = \"Unknown Exception has occured\";\n");
  		   writer.write("\t}\n");
  		   writer.write("return sMessage;\n");
  	       writer.write("}\n\n");
  
  		   writer.write("const char* "+faultInfoName+"::what() throw ()\n");
  	       writer.write("{\n");
  		   writer.write("\treturn m_sMessage.c_str ();\n");
  		   writer.write("}\n\n");
  		   
        	   writer.write("const int "+faultInfoName+"::getExceptionCode()");//damitha
  	  	   writer.write("{\n");
  		   writer.write("\treturn m_iExceptionCode;\n");
  		   writer.write("}\n\n");
  			  	     
  	 }catch(IOException e){
  					 throw new WrapperFault(e);
  				 }
  	   }	
  }
  
  
  
  1.1                  ws-axis/c/src/wsdl/org/apache/axis/wsdl/wsdl2ws/cpp/AllExceptionWriter.java
  
  Index: AllExceptionWriter.java
  ===================================================================
  /*
   * Created on Jun 4, 2004
   *
   * To change the template for this generated file go to
   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
   */
  package org.apache.axis.wsdl.wsdl2ws.cpp;
  import java.util.Iterator;
  import java.util.ArrayList; 
  import org.apache.axis.wsdl.wsdl2ws.SourceWriter;
  import org.apache.axis.wsdl.wsdl2ws.WrapperUtils;
  import org.apache.axis.wsdl.wsdl2ws.WrapperFault;
  //import org.apache.axis.wsdl.wsdl2ws.info.Type;
  import org.apache.axis.wsdl.wsdl2ws.info.ParameterInfo;
  import org.apache.axis.wsdl.wsdl2ws.info.WebServiceContext;
  
  import org.apache.axis.wsdl.wsdl2ws.info.MethodInfo;
  
  //import org.apache.axis.wsdl.wsdl2ws.info.Type;
  import org.apache.axis.wsdl.wsdl2ws.info.FaultInfo; 
  
  /**
   * @author nithya
   *
   * To change the template for this generated type comment go to
   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
   */
  public class AllExceptionWriter implements SourceWriter{
  private WebServiceContext wscontext;
  	
  public AllExceptionWriter(WebServiceContext wscontext){
  	this.wscontext =wscontext;
  }
      /**
  	 * genarate all the Exceptions.
  	 * @see org.apache.axis.wsdl.wsdl2ws.SourceWriter#writeSource()
  	 */
  	public void writeSource() throws WrapperFault {		
      ArrayList methods;
  	methods = wscontext.getSerInfo().getMethods();
  	MethodInfo minfo;
  	FaultInfo faultinfo;
  	try{
  				for (int i = 0; i < methods.size(); i++) {
  					minfo = (MethodInfo)methods.get(i);
  					Iterator paramsFault = minfo.getFaultType().iterator();
  							String faultInfoName =null;
  							String faultType =null;	 
  							String langName =null;
  							String paramName =null;
  							if (paramsFault.hasNext()){
  								FaultInfo info = (FaultInfo)paramsFault.next();
  								faultInfoName =info.getFaultInfo();
  								ArrayList paramInfo =info.getParams();
  								for (int j= 0; j < paramInfo.size(); j++) {
  									ParameterInfo par =(ParameterInfo)paramInfo.get(j);                                                                                                                                                           
  									paramName  = par.getParamName();
  									langName =par.getLangName();
  									faultType = WrapperUtils.getClassNameFromParamInfoConsideringArrays(par,wscontext);
  														(new ExceptionHeaderWriter(wscontext,faultInfoName,langName,faultType)).writeSource();
  														(new ExceptionWriter(wscontext,faultInfoName,langName,faultType)).writeSource();	
  									}
  								}
  				}
  			
  			}catch(Exception e){
  				System.out.println("Error occured yet we continue to genarate other classes ... you should check the error");
  				e.printStackTrace();
  			}	
  	}
  }