You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by su...@apache.org on 2003/08/04 07:03:50 UTC

cvs commit: xml-axis/c/src/wcg WSClass.h WSClass.cpp Variable.h Variable.cpp TranslationUnit.h TranslationUnit.cpp Method.h Method.cpp

susantha    2003/08/03 22:03:50

  Modified:    c/src/wcg WSClass.h WSClass.cpp Variable.h Variable.cpp
                        TranslationUnit.h TranslationUnit.cpp Method.h
                        Method.cpp
  Log:
  improved WCG so that it now generates wsdl
  
  Revision  Changes    Path
  1.4       +3 -0      xml-axis/c/src/wcg/WSClass.h
  
  Index: WSClass.h
  ===================================================================
  RCS file: /home/cvs/xml-axis/c/src/wcg/WSClass.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WSClass.h	18 Jul 2003 13:31:44 -0000	1.3
  +++ WSClass.h	4 Aug 2003 05:03:49 -0000	1.4
  @@ -81,6 +81,9 @@
   class WSClass  
   {
   public:
  +	int GenerateOperationsInBinding(File& file, string& sServiceName, int nBinding, int nStyle, string& sURI);
  +	int GenerateWSDLPortTypes(File& file, string& sServiceName);
  +	int GenerateWSDLMessages(File& file);
   	int GenerateClassImpl(File& file);
   	int GenerateClassDef(File& file);
   	const string& GetName();
  
  
  
  1.5       +30 -1     xml-axis/c/src/wcg/WSClass.cpp
  
  Index: WSClass.cpp
  ===================================================================
  RCS file: /home/cvs/xml-axis/c/src/wcg/WSClass.cpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WSClass.cpp	24 Jul 2003 03:51:31 -0000	1.4
  +++ WSClass.cpp	4 Aug 2003 05:03:49 -0000	1.5
  @@ -233,4 +233,33 @@
   		return 1;
   	}
   	return 0; //success}
  -}
  \ No newline at end of file
  +}
  +
  +int WSClass::GenerateWSDLMessages(File &file)
  +{
  +	for (list<Method*>::iterator it = m_Methods.begin(); it != m_Methods.end(); it++)
  +	{
  +		if ((*it)->GenerateWSDLMessages(file)) return 1; //error occured;
  +	}
  +	return 0; //success;
  +}
  +
  +int WSClass::GenerateWSDLPortTypes(File &file, string& sServiceName)
  +{
  +	file << "<portType name=\"" << sServiceName << "PortType\">" << endl;
  +	for (list<Method*>::iterator it = m_Methods.begin(); it != m_Methods.end(); it++)
  +	{
  +		if ((*it)->GenerateWSDLOperationInPortType(file)) return 1; //error occured;
  +	}
  +	file << "</portType>" << endl;
  +	return 0; //success;
  +}
  +
  +
  +int WSClass::GenerateOperationsInBinding(File &file, string &sServiceName, int nBinding, int nStyle, string &sURI)
  +{
  +	for (list<Method*>::iterator it = m_Methods.begin(); it != m_Methods.end(); it++)
  +	{
  +		if ((*it)->GenerateOperationInBinding(file, sServiceName, nBinding, nStyle, sURI)) return 1; //error occured;
  +	}
  +}
  
  
  
  1.6       +5 -0      xml-axis/c/src/wcg/Variable.h
  
  Index: Variable.h
  ===================================================================
  RCS file: /home/cvs/xml-axis/c/src/wcg/Variable.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Variable.h	24 Jul 2003 04:13:40 -0000	1.5
  +++ Variable.h	4 Aug 2003 05:03:49 -0000	1.6
  @@ -84,6 +84,9 @@
   enum VARTYPE { VAR_UNKNOWN=0, VAR_INT=1, VAR_FLOAT, VAR_STRING, VAR_LONG, VAR_SHORT, \
   			   VAR_CHAR, VAR_DOUBLE, VAR_BOOL, VAR_UNSIGNEDLONG, VAR_UNSIGNEDINT,\
   			   VAR_UNSIGNEDSHORT, VAR_UNSIGNED_CHAR, VAR_USER};
  +enum WSDL_BINDINGS { SOAP_BINDING=1, HTTP_BINDING };
  +enum BINDING_STYLES { SOAP_RPC=1, SOAP_DOCUMENT, HTTP_GET, HTTP_POST};
  +enum WSDL_TRANSPORT { HTTP_TRANSPORT=1 };
   
   //Qualifiers
   const unsigned char Q_PRIVATE = 0x01;
  @@ -98,6 +101,8 @@
   class Variable  
   {
   public:	
  +	int GenerateWSDLPartInMessage(File& file, bool bInput);
  +	int GenerateWSDLSchema(File &file);
   	static string& GetParamGetMethod(int nType);
   	int GenerateDeserializerImpl(File& file);
   	int GenerateSerializerImpl(File& file);
  
  
  
  1.6       +26 -1     xml-axis/c/src/wcg/Variable.cpp
  
  Index: Variable.cpp
  ===================================================================
  RCS file: /home/cvs/xml-axis/c/src/wcg/Variable.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Variable.cpp	24 Jul 2003 04:13:40 -0000	1.5
  +++ Variable.cpp	4 Aug 2003 05:03:49 -0000	1.6
  @@ -278,4 +278,29 @@
   		case VAR_UNSIGNED_CHAR: m_sAuxStr = "GetUnsignedChar"; break;
   	}
   	return m_sAuxStr;
  -}
  \ No newline at end of file
  +}
  +
  +int Variable::GenerateWSDLSchema(File &file)
  +{
  +	if (m_Type == VAR_UNKNOWN) return 1; //error
  +	file << "<element name=\"" << m_VarName << "\" type=\"";
  +	if (m_Type != VAR_USER) file << "xsd:" << m_TypeName << "\" />" << endl;
  +	else file << "xsdl:" << m_TypeName << "\" />" << endl;
  +}
  +
  +int Variable::GenerateWSDLPartInMessage(File &file, bool bInput)
  +{
  +	if (m_Type == VAR_UNKNOWN) return 1; //error
  +	file << "<part name=\"";
  +	if (bInput) 
  +	{
  +		file << "input" << m_TypeName << m_VarName;
  +	}
  +	else
  +	{
  +		file << "return";
  +	}
  +	file << "\" type=\"";
  +	if (m_Type != VAR_USER) file << "xsd:" << m_TypeName << "\" />" << endl;
  +	else file << "xsdl:" << m_TypeName << "\" />" << endl;
  +}
  
  
  
  1.4       +2 -1      xml-axis/c/src/wcg/TranslationUnit.h
  
  Index: TranslationUnit.h
  ===================================================================
  RCS file: /home/cvs/xml-axis/c/src/wcg/TranslationUnit.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TranslationUnit.h	25 Jul 2003 13:49:37 -0000	1.3
  +++ TranslationUnit.h	4 Aug 2003 05:03:49 -0000	1.4
  @@ -82,6 +82,7 @@
   class TranslationUnit  
   {
   public:
  +	int GenerateWSDLBinding(File& file, string& sServiceName, int nBinding, int nStyle, int nTransport, string& sURI);
   	int GenerateServiceFile(string& sServiceFile);
   	void SetWsFileName(const char* sFileName);
   	void AddBeanClass(BeanClass* pClass);
  @@ -90,7 +91,7 @@
   	void AddInclude(string& sInclude);
   	int GenerateWrapperClassImpl();
   	int GenerateWrapperClassDef();
  -	int GenerateWSDL();
  +	int GenerateWSDL(string& sServiceFile, string& sURI);
   	TranslationUnit();
   	virtual ~TranslationUnit();
   private:
  
  
  
  1.4       +79 -5     xml-axis/c/src/wcg/TranslationUnit.cpp
  
  Index: TranslationUnit.cpp
  ===================================================================
  RCS file: /home/cvs/xml-axis/c/src/wcg/TranslationUnit.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TranslationUnit.cpp	25 Jul 2003 13:49:37 -0000	1.3
  +++ TranslationUnit.cpp	4 Aug 2003 05:03:49 -0000	1.4
  @@ -90,11 +90,44 @@
   	}
   }
   
  -int TranslationUnit::GenerateWSDL()
  +int TranslationUnit::GenerateWSDL(string& sServiceFile, string& sURI)
   {
   	try {
  -
  -	
  +		if (!m_pWSClass) {
  +			cout << "No web service class found" << endl;	
  +			return 1;
  +		}
  +		string fname = sServiceFile + ".wsdl"; 
  +		File file(fname);
  +		file << "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"<< endl;
  +		file << "<definitions targetNamespace=\"http://" << sURI.c_str() << "/Axis/" << sServiceFile.c_str() << "\""<< endl;
  +		file << "xmlns=\"http://schemas.xmlsoap.org/wsdl/\""<< endl;
  +		file << "xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\""<< endl;
  +		file << "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""<< endl;
  +		file << "xmlns:xsdl=\""<< sServiceFile.c_str() << "-xsd\""<< endl; //xsd local
  +		file << "xmlns:impl=\"http://" << sURI.c_str() << "/Axis/" << sServiceFile.c_str() << "\""<< endl; //implimentation
  +		file << "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">" << endl;
  +		//types section
  +		if (!m_Beans.empty())
  +		{
  +			file << "<types>" << endl;
  +			file << "<schema targetNamespace=\"" << sServiceFile.c_str() << "-xsd\" "<< "xmlns=\"http://www.w3.org/2001/XMLSchema\" " << "xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\">" << endl;
  +			//generate schema for types
  +			for (list<BeanClass*>::iterator it = m_Beans.begin(); it != m_Beans.end(); it++)
  +			{
  +				(*it)->GenerateWSDLSchema(file);
  +			}
  +			file << "</schema>" << endl;
  +			file << "</types>" << endl;
  +		}
  +		//messages section
  +		m_pWSClass->GenerateWSDLMessages(file);
  +		//porttypes section
  +		m_pWSClass->GenerateWSDLPortTypes(file, sServiceFile);
  +		//bindings section
  +		//create only soap - rpc - http binding for now
  +		GenerateWSDLBinding(file, sServiceFile, SOAP_BINDING, SOAP_RPC, HTTP_TRANSPORT, sURI);
  +		file << "</definitions>" << endl;
   	}
   	catch(...) //any exception
   	{
  @@ -239,7 +272,7 @@
   		file << "{" << endl;
   		file << "\tif (inst) " << endl;
   		file << "\t{" << endl;
  -		file << "\t\tWrapperClassHandler* pWCH = dynamic_cast<WrapperClassHandler*>(inst);" << endl;
  +		file << "\t\tWrapperClassHandler* pWCH = reinterpret_cast<WrapperClassHandler*>(inst);" << endl;
   		file << "\t\tpWCH->Fini();" << endl;
   		file << "\t\tdelete pWCH;" << endl;
   		file << "\t\treturn SUCCESS;" << endl;
  @@ -254,4 +287,45 @@
   		return 1;
   	}
   	return 0; //success
  -}
  \ No newline at end of file
  +}
  +
  +int TranslationUnit::GenerateWSDLBinding(File &file, string& sServiceName, int nBinding, int nStyle, int nTransport, string& sURI)
  +{
  +	file << "<binding name=\"" << sServiceName;
  +	switch (nBinding)
  +	{
  +	case SOAP_BINDING: file << "Soap"; break;
  +	case HTTP_BINDING: file << "Http"; break;
  +	default: return 1; //error
  +	}
  +	file << "Binding\" type=\"impl:" << sServiceName << "PortType\">" << endl;
  +	switch (nBinding)
  +	{
  +	case SOAP_BINDING: 
  +		{
  +			file << "<soap:binding style=\"";
  +			switch (nStyle)
  +			{
  +			case SOAP_RPC: file << "rpc"; break;
  +			case SOAP_DOCUMENT: file << "document"; break;
  +			default: return 1; //error
  +			}
  +			file << "\" transport=\"";
  +			switch (nTransport)
  +			{
  +			case HTTP_TRANSPORT: file << "http://schemas.xmlsoap.org/soap/http"; break;
  +			default: return 1; //error
  +			}
  +			file << "\" />" << endl;
  +		}
  +		break;
  +	case HTTP_BINDING: 
  +		{
  +			
  +		}
  +		break;
  +	default: return 1; //error
  +	}
  +	m_pWSClass->GenerateOperationsInBinding(file, sServiceName, nBinding, nStyle, sURI); 
  +	file << "</binding>" << endl;
  +}
  
  
  
  1.5       +3 -0      xml-axis/c/src/wcg/Method.h
  
  Index: Method.h
  ===================================================================
  RCS file: /home/cvs/xml-axis/c/src/wcg/Method.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Method.h	24 Jul 2003 04:13:40 -0000	1.4
  +++ Method.h	4 Aug 2003 05:03:49 -0000	1.5
  @@ -82,6 +82,9 @@
   class Method  
   {
   public:
  +	int GenerateOperationInBinding(File &file, string &sServiceName, int nBinding, int nStyle, string &sURI);
  +	int GenerateWSDLOperationInPortType(File& file);
  +	int GenerateWSDLMessages(File &file);
   	int GenerateMethodImpl(string& sClassName, File& file);
   	string& GetName();
   	int GenerateMethodDef(File &file);
  
  
  
  1.6       +73 -0     xml-axis/c/src/wcg/Method.cpp
  
  Index: Method.cpp
  ===================================================================
  RCS file: /home/cvs/xml-axis/c/src/wcg/Method.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Method.cpp	24 Jul 2003 04:13:40 -0000	1.5
  +++ Method.cpp	4 Aug 2003 05:03:49 -0000	1.6
  @@ -191,3 +191,76 @@
   	return 0;
   }
   
  +int Method::GenerateWSDLMessages(File &file)
  +{
  +	file << "<message name=\"" << m_Name << "Request\">" << endl;
  +	for (list<Variable*>::iterator it = m_Params.begin(); it != m_Params.end(); it++)
  +	{
  +		(*it)->GenerateWSDLPartInMessage(file, true);
  +	}
  +	file << "</message>" << endl;
  +	if (m_pReturnType)
  +	{
  +		file << "<message name=\"" << m_Name << "Response\">" << endl;
  +		m_pReturnType->GenerateWSDLPartInMessage(file, false);
  +		file << "</message>" << endl;
  +	}
  +	return 0; //success
  +}
  +
  +int Method::GenerateWSDLOperationInPortType(File &file)
  +{
  +	file << "<operation name=\"" << m_Name << "\">" << endl;
  +	file << "<input message=\"impl:" << m_Name << "Request\" />" << endl; 
  +	file << "<output message=\"impl:" << m_Name << "Response\" />" << endl; 
  +	file << "</operation>" << endl;
  +	return 0;
  +}
  +
  +int Method::GenerateOperationInBinding(File &file, string &sServiceName, int nBinding, int nStyle, string &sURI)
  +{
  +	file << "<operation name=\"" << m_Name << "\">" << endl;
  +	switch (nBinding)
  +	{
  +	case SOAP_BINDING: 
  +		{
  +			file << "<soap:operation soapAction=\"" << sServiceName << "\" style=\""; //service name should be in soapAction
  +			switch (nStyle)
  +			{
  +			case SOAP_RPC: 
  +				{	
  +					file << "rpc\" />" << endl;
  +					file << "<input>" << endl;
  +					file << "<soap:body use=\"encoded\" namespace=\"http://" << sURI << "/\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />" << endl; 
  +					file << "</input>" << endl;
  +					file << "<output>" << endl;
  +					file << "<soap:body use=\"encoded\" namespace=\"http://" << sURI << "/\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />" << endl; 
  +					file << "</output>" << endl;
  +				}
  +				break;
  +			case SOAP_DOCUMENT: 
  +				{
  +					file << "document\" />" << endl; 
  +					file << "<input>" << endl;
  +					file << "<soap:body use=\"literal\" />" << endl; 
  +					file << "</input>" << endl;
  +					file << "<output>" << endl;
  +					file << "<soap:body use=\"literal\" />" << endl; 
  +					file << "</output>" << endl;
  +
  +				}
  +				break;
  +			default: return 1; //error
  +			}
  +		}
  +		break;
  +	case HTTP_BINDING: 
  +		{
  +			
  +		}
  +		break;
  +	default: return 1; //error
  +	}
  +	file << "</operation>" << endl;
  +	return 0;
  +}