[wsf-c-dev] svn commit r385 - wsf/php/src/scripts

svn at wso2.com svn at wso2.com
Wed Jan 10 02:27:19 PST 2007


Author: buddhika
Date: Wed Jan 10 02:26:26 2007
New Revision: 385

Added:
   wsf/php/src/scripts/WS_WsdlInterface.php
Modified:
   wsf/php/src/scripts/WS_WsdlBinding.php
   wsf/php/src/scripts/WS_WsdlConsts.php
   wsf/php/src/scripts/WS_WsdlCreater.php
   wsf/php/src/scripts/WS_WsdlScript.php
   wsf/php/src/scripts/WS_WsdlService.php
   wsf/php/src/scripts/WS_WsdlType.php
Log:
 Wsdl Generation - for wsdl2.0


Modified: wsf/php/src/scripts/WS_WsdlBinding.php
==============================================================================
--- wsf/php/src/scripts/WS_WsdlBinding.php	(original)
+++ wsf/php/src/scripts/WS_WsdlBinding.php	Wed Jan 10 02:26:26 2007
@@ -21,9 +21,16 @@
        const WS_WSDL_BINDING_ENCOD_STYLE_TAG = 'encodingStyle';
        const WS_WSDL_BINDING_SOAP_ACTION_TAG = 'soapAction';
 
+       const WS_WSDL2_BINDING_PROTOCAL_ATTR_NAME = "protocol";
+       const WS_WSDL2_BINDING_INTERFACE_ATTR_NAME = "interface";
+       const WS_WSDL2_BINDING_VERSION_ATTR_NAME = "version";
+       const WS_WSDL2_BINDING_VERSION_ATTR_VAL = "1.2";
+       const WS_WSDL2_BINDING_SOAP_ATTR_NAME = "soap";
+
        private $svr_name;
        public  $operations;
-       function __construct($service_name, $operations)
+       //function __construct($service_name, $operations)
+       function __construct($service_name, $operations = false)
        {
 	   $this->svr_name = $service_name;
 	   $this->operations = $operations;
@@ -110,6 +117,30 @@
 	   }
 	   $binding_root->appendChild($binding_ele);
        }
+
+
+       public function createWsdl2Binding(DomDocument $binding_doc, DomElement $binding_root)
+      {
+          $binding_ele = $binding_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+				      self::WS_WSDL_BINDING_BINDING_TAG);
+	  $binding_ele->setAttribute(self::WS_WSDL_BINDING_NAME_TAG, 
+				     $this->svr_name.strtoupper(self::WS_WSDL2_BINDING_SOAP_ATTR_NAME).
+				     ucfirst(self::WS_WSDL_BINDING_BINDING_TAG));
+	  $binding_ele->setAttribute(self::WS_WSDL_BINDING_TYPE_TAG, 
+				     WS_WsdlConst:: WS_WSDL2_WSOAP_ATTR_VAL);
+	  
+	  $binding_ele->setAttribute(self::WS_WSDL2_BINDING_INTERFACE_ATTR_NAME,
+				    $this->svr_name.ucfirst(self::WS_WSDL2_BINDING_INTERFACE_ATTR_NAME));
+	  $binding_ele->setAttribute(self::WS_WSDL2_BINDING_VERSION_ATTR_NAME,
+				     self::WS_WSDL2_BINDING_VERSION_ATTR_VAL);
+	  $binding_ele->setAttribute(self::WS_WSDL2_BINDING_PROTOCAL_ATTR_NAME,
+				     WS_WsdlConst:: WS_WSDL2_BINDING_ATTR_VAL);
+
+	  $binding_root->appendChild($binding_ele);
+      }
+
+
+
        
 }
 

Modified: wsf/php/src/scripts/WS_WsdlConsts.php
==============================================================================
--- wsf/php/src/scripts/WS_WsdlConsts.php	(original)
+++ wsf/php/src/scripts/WS_WsdlConsts.php	Wed Jan 10 02:26:26 2007
@@ -13,6 +13,20 @@
     const WS_WSDL_DEF_SOAP_ENC_QN = 'xmlns:soapenc';
     const WS_WSDL_DEF_TARGET_NS = 'targetNamespace';
 
+    const WS_WSDL2_DESCRIPTION = "description";
+    const WS_WSDL2_WSOAP_ATTR_NAME = "xmlns:wsoap";
+    const WS_WSDL2_WSDLX_ATTR_NAME = "xmlns:wsdlx";
+    const WS_WSDL2_WHTTP_ATTR_NAME = "xmlns:whttp";
+    const WS_WSDL2_DOCUMENTATION = "documentation";
+
+    
+    const WS_WSDL2_NAMESPACE = "http://www.w3.org/2006/01/wsdl";
+    const WS_WSDL2_WSOAP_ATTR_VAL = "http://www.w3.org/2006/01/wsdl/soap";
+    const WS_WSDL2_WSDLX_ATTR_VAL = "http://www.w3.org/2006/01/wsdl-extension";
+    const WS_WSDL2_WHTTP_ATTR_VAL = "http://www.w3.org/2006/01/wsdl/http";
+    const WS_WSDL2_SOAP_ATTR_VAL = "http://www.w3.org/2003/05/soap-envelope";
+    const WS_WSDL2_BINDING_ATTR_VAL = "http://www.w3.org/2003/05/soap/bindings/HTTP";
+    const WS_WSDL2_PATTERN_ATTR_VAL ="http://www.w3.org/2006/01/wsdl/in-out";
 
     const WS_SOAP_XML_SCHEMA_NAMESPACE = 'http://www.w3.org/2001/XMLSchema';
     const WS_SOAP_SCHEMA_INSTANCE_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance';

Modified: wsf/php/src/scripts/WS_WsdlCreater.php
==============================================================================
--- wsf/php/src/scripts/WS_WsdlCreater.php	(original)
+++ wsf/php/src/scripts/WS_WsdlCreater.php	Wed Jan 10 02:26:26 2007
@@ -7,6 +7,7 @@
 include 'WS_WsdlPort.php';
 include 'WS_WsdlBinding.php';
 include 'WS_WsdlService.php';
+include 'WS_WsdlInterface.php';
 
      class WS_WsdlCreater
      {
@@ -15,9 +16,10 @@
 	 private $f_name;
 	 private $service_name;
 	 private $Binding_style;
+	 private $wsdl_version;
 
 	 function __construct($obj_name, $service, $endpoints, 
-			      $binding_style,  $ns = false, $obj_type = false)
+			      $binding_style,  $ns , $wsdl_ver)
 	 {
 	     if(!$ns)
 	     {
@@ -30,6 +32,10 @@
 	     $this->f_name = $obj_name;
 	     $this->service_name = $service;
 	     $this->Binding_style = $binding_style;
+	     if($wsdl_ver == "wsdl1.1")
+		 $this->wsdl_version = "wsdl1";
+	     if($wsdl_ver == "wsdl2.0")
+		 $this->wsdl_version = "wsdl2";
 	 }
 	 
 	 private function buildWsdlDom()
@@ -69,9 +75,7 @@
 	      $operationsArry = $oper_obj->operations;
 	      $xsdArry = $oper_obj->xsdTypes;
 		  
-	      // testing
-//	      print_r($xsdArry);
-		  
+	        
 	      if($this->Binding_style == "doc-lit")
 	      {
 		  $type_obj = new WS_WsdlType($this->namespace, $createdTypeArry, $xsdArry);
@@ -125,9 +129,78 @@
 	      return $wsdl_dom->saveXML();
 	      
 	 }
+
+	 private function buildWsdl2Dom()
+	 {
+	     $wsdl_dom = new DomDocument(WS_WsdlConst::WS_DOM_DOCUMENT_VERSION_NO,
+					 WS_WsdlConst::WS_DOM_DOCUMENT_ENCODING);
+	     
+	     $wsdl_root_ele = $wsdl_dom->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+							 WS_WsdlConst::WS_WSDL2_DESCRIPTION);
+	     
+	    
+
+	     $wsdl_root_ele->setAttributeNS(WS_WsdlConst::WS_WSDL_DEF_SCHEMA_URI, 
+					    WS_WsdlConst::WS_WSDL2_WSDLX_ATTR_NAME,
+					    WS_WsdlConst::WS_WSDL2_WSDLX_ATTR_VAL);
+	     
+	     $wsdl_root_ele->setAttributeNS(WS_WsdlConst::WS_WSDL_DEF_SCHEMA_URI,
+					    WS_WsdlConst::WS_WSDL_DEF_TNS_QN, 
+					    $this->namespace);
+	     
+	     $wsdl_root_ele->setAttributeNS(WS_WsdlConst::WS_WSDL_DEF_SCHEMA_URI, 
+					    WS_WsdlConst::WS_WSDL2_WSOAP_ATTR_NAME,
+					    WS_WsdlConst::WS_WSDL2_WSOAP_ATTR_VAL);
+	     
+	     $wsdl_root_ele->setAttributeNS(WS_WsdlConst::WS_WSDL_DEF_SCHEMA_URI,
+					    WS_WsdlConst::WS_WSDL2_WHTTP_ATTR_NAME,
+					    WS_WsdlConst::WS_WSDL2_WHTTP_ATTR_VAL);
+	     
+	     $wsdl_root_ele->setAttributeNS(WS_WsdlConst::WS_WSDL_DEF_SCHEMA_URI,
+					    WS_WsdlConst::WS_WSDL_DEF_SOAP_ENC_QN,
+					    WS_WsdlConst::WS_WSDL2_SOAP_ATTR_VAL);
+	     
+	      $wsdl_root_ele->setAttribute(WS_WsdlConst::WS_WSDL_DEF_TARGET_NS,
+					   $this->namespace);
+	      
+
+	      $wsdl_doc_ele = $wsdl_dom->createElement(WS_WsdlConst::WS_WSDL2_DOCUMENTATION);
+	      $doc_txt = new DomText("A simple ".$this->service_name." service");
+	      $wsdl_doc_ele->appendChild($doc_txt);
+	      $wsdl_root_ele->appendChild($wsdl_doc_ele);
+
+
+	      $oper_obj = new WS_WsdlOperations($this->f_name);
+	      $createdTypeArry = $oper_obj->createdTypes;
+	      $operationsArry = $oper_obj->operations;
+	      $xsdArry = $oper_obj->xsdTypes;
+
+	      
+	      $type_obj = new WS_WsdlType($this->namespace, $createdTypeArry, $xsdArry);
+	      $type_obj->createWsdl2Type($wsdl_dom, $wsdl_root_ele);
+
+	      $interface_obj = new WS_WsdlInterface($this->service_name, $operationsArry);
+	      $interface_obj->createInterface($wsdl_dom, $wsdl_root_ele);
+		      
+	      $bind_obj = new WS_WsdlBinding($this->service_name);
+	      $bind_obj->createWsdl2Binding($wsdl_dom, $wsdl_root_ele);
+
+	      $svr_obj = new WS_WsdlService($this->service_name, $this->endpoint);
+	      $svr_obj->createWsdl2Service($wsdl_dom, $wsdl_root_ele);
+	      
+	      
+	      $wsdl_dom->appendChild($wsdl_root_ele);
+	      $wsdl_dom->save("/tmp/wsdl2.wsdl");
+	      return $wsdl_dom->saveXML();
+	      
+	 }
+
 	 public function WS_WsdlOut()
 	     {
-		 $tmp = $this->buildWsdlDom();
+		 if ($this->wsdl_version == "wsdl1")
+		     $tmp = $this->buildWsdlDom();
+		 else
+		     $tmp = $this->buildWsdl2Dom();
 		 return $tmp;
 	     }
 	 

Added: wsf/php/src/scripts/WS_WsdlInterface.php
==============================================================================
--- (empty file)
+++ wsf/php/src/scripts/WS_WsdlInterface.php	Wed Jan 10 02:26:26 2007
@@ -0,0 +1,67 @@
+<?php
+
+  class WS_WsdlInterface
+   {
+
+       const WS_WSDL_INTERFACE_NAME_ATTR_NAME = 'name';
+       const WS_WSDL_INTERFACE_TYPE_ATTR_NAME = 'type';
+       const WS_WSDL_INTERFACE_OPERATION_ATTR_NAME = 'operation'; 
+       const WS_WSDL_INTERFACE_STYLE_ATTR_NAME = 'style';
+       const WS_WSDL_INTERFACE_INPUT_ATTR_NAME = 'input';
+       const WS_WSDL_INTERFACE_OUTPUT_ATTR_NAME = 'output';
+
+       const WS_WSDL2_INTERFACE_PROTOCAL_ATTR_NAME = "protocol";
+       const WS_WSDL2_INTERFACE_INTERFACE_ATTR_NAME = "interface";
+       const WS_WSDL2_INTERFACE_VERSION_ATTR_NAME = "version";
+       const WS_WSDL2_INTERFACE_VERSION_ATTR_VAL = "1.2";
+       const WS_WSDL2_INTERFACE_SOAP_ATTR_NAME = "soap";
+       const WS_WSDL2_INTERFACE_PATTERN_ATTR_NAME = "pattern";
+       const WS_WSDL2_INTERFACE_ELEMENT_ATTR_NAME = "element";
+
+       private $svr_name;
+       public  $operations;
+
+       function __construct($service_name, $operations)
+       {
+	   $this->svr_name = $service_name;
+	   $this->operations = $operations;
+       }
+
+
+      public function createInterface(DomDocument $interface_doc, DomElement $interface_root)
+      {
+          $interface_ele = $interface_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+				      self::WS_WSDL2_INTERFACE_INTERFACE_ATTR_NAME);
+	  $interface_ele->setAttribute(self::WS_WSDL_INTERFACE_NAME_ATTR_NAME,
+				       $this->svr_name.ucfirst(self::WS_WSDL2_INTERFACE_INTERFACE_ATTR_NAME));
+	  
+	  foreach($this->operations as $name => $params) 
+	  {
+	      $op = $interface_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+					  self::WS_WSDL_INTERFACE_OPERATION_ATTR_NAME  );
+	      $op->setAttribute(self::WS_WSDL_INTERFACE_NAME_ATTR_NAME  , $name);
+	      $op->setAttribute(self::WS_WSDL2_INTERFACE_PATTERN_ATTR_NAME, 
+				WS_WsdlConst::WS_WSDL2_PATTERN_ATTR_VAL);
+	      
+
+	      foreach(array(self::WS_WSDL_INTERFACE_INPUT_ATTR_NAME  ,
+			    self::WS_WSDL_INTERFACE_OUTPUT_ATTR_NAME  ) as $type) 
+	      {
+		  $operation_ele = $interface_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE, $type);
+		  if($type == self::WS_WSDL_INTERFACE_INPUT_ATTR_NAME)
+		      $operation_ele->setAttribute(self::WS_WSDL2_INTERFACE_PATTERN_ATTR_NAME,
+						   $name);
+		  else
+		      $operation_ele->setAttribute(self::WS_WSDL2_INTERFACE_PATTERN_ATTR_NAME,
+						   $name."Response");
+		  $op->appendChild($operation_ele);
+	      }
+ 	      $interface_ele->appendChild($op);
+ 	  }
+	  $interface_root->appendChild($interface_ele);
+      }
+
+       
+}
+
+?>
\ No newline at end of file

Modified: wsf/php/src/scripts/WS_WsdlScript.php
==============================================================================
--- wsf/php/src/scripts/WS_WsdlScript.php	(original)
+++ wsf/php/src/scripts/WS_WsdlScript.php	Wed Jan 10 02:26:26 2007
@@ -1,6 +1,6 @@
 <?php
 
-function ws_generate_wsdl($include_location, $service_name, $fn_arry, $binding_style)
+function ws_generate_wsdl($include_location, $service_name, $fn_arry, $binding_style, $wsdl_version)
 {
     include $include_location;
     
@@ -22,10 +22,9 @@
     }
 
     
-    $wsdl = new WS_WsdlCreater($fn_arry ,$service_name, 'http://localhost/Wso2/Wsdl_gen.php', $Binding_style, 'http://www.wso2.org/php/');
+    $wsdl = new WS_WsdlCreater($fn_arry ,$service_name, 'http://localhost/Wso2/Wsdl_gen.php', $Binding_style, 'http://www.wso2.org/php/', $wsdl_version);
     $wsdl_out = $wsdl->WS_WsdlOut();
 
-    echo $wsdl_out;
 
    return $wsdl_out; 
    

Modified: wsf/php/src/scripts/WS_WsdlService.php
==============================================================================
--- wsf/php/src/scripts/WS_WsdlService.php	(original)
+++ wsf/php/src/scripts/WS_WsdlService.php	Wed Jan 10 02:26:26 2007
@@ -12,6 +12,10 @@
     const WS_WSDL_SERVICE_LOCATION_TAG = 'location';
     const WS_WSDL_SERVICE_ADDRESS_TAG = 'address';
 
+    const WS_WSDL2_SERVICE_INTERFACE_ATTR_NAME = "interface";
+    const WS_WSDL2_SERVICE_ENDPOINT_ATTR_NAME = "endpoint";
+    
+
     private $S_name;
     private $endpoint;
     
@@ -31,18 +35,40 @@
 	    $svr_ele = $svr_dom->createElementNS(WS_WsdlConst::WS_SCHEMA_WSDL_NAMESPACE,
 						 self::WS_WSDL_SERVICE_TAG);
 	    $svr_ele->setAttribute(self::WS_WSDL_SERVICE_NAME_TAG, $this->S_name);
-	    
+
 	    $svr_port = $svr_dom->createElementNS(WS_Wsdlconst::WS_SCHEMA_WSDL_NAMESPACE,
 						  self::WS_WSDL_SERVICE_PORT_TAG);
 	    $svr_port->setAttribute(self::WS_WSDL_SERVICE_NAME_TAG, $this->S_name);
 	    $svr_port->setAttribute(self::WS_WSDL_SERVICE_BINDING_TAG,
 				    self::WS_WSDL_SERVICE_TNS_TAG.$this->S_name);
 	    
-	    $svr_addr = $svr_dom->createElementNS(WS_WsdlConst::WS_SCHEMA_SOAP_NAMESPACE,
+	    $svr_addr = $svr_dom->createElementNS(WS_WsdlConst::WS_SCHEMA_WSDL_NAMESPACE,
 						  self::WS_WSDL_SERVICE_ADDRESS_TAG);
 	    $svr_addr->setAttribute(self::WS_WSDL_SERVICE_LOCATION_TAG, $this->endpoint);
 	    
-	    $svr_port->appendChild($svr_addr);
+	    $svr_ele->appendChild($svr_port);
+	    $svr_root->appendChild($svr_ele);
+	    
+	}
+
+
+    public function createWsdl2Service(DomDocument $svr_dom,DomElement $svr_root)
+	{
+	    $svr_ele = $svr_dom->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+						 self::WS_WSDL_SERVICE_TAG);
+	    $svr_ele->setAttribute(self::WS_WSDL_SERVICE_NAME_TAG, $this->S_name);
+	    $svr_ele->setAttribute(self::WS_WSDL2_SERVICE_INTERFACE_ATTR_NAME,
+				   $this->S_name.ucfirst(self::WS_WSDL2_SERVICE_INTERFACE_ATTR_NAME));
+
+
+	    $svr_port = $svr_dom->createElementNS(WS_Wsdlconst::WS_WSDL2_NAMESPACE,
+						  self::WS_WSDL2_SERVICE_ENDPOINT_ATTR_NAME);
+	    $svr_port->setAttribute(self::WS_WSDL_SERVICE_NAME_TAG, $this->S_name);
+	    $svr_port->setAttribute(self::WS_WSDL_SERVICE_BINDING_TAG,
+				    self::WS_WSDL_SERVICE_TNS_TAG.$this->S_name);
+	    
+	    $svr_port->setAttribute(self::WS_WSDL_SERVICE_ADDRESS_TAG, $this->endpoint);
+	    
 	    $svr_ele->appendChild($svr_port);
 	    $svr_root->appendChild($svr_ele);
 	    

Modified: wsf/php/src/scripts/WS_WsdlType.php
==============================================================================
--- wsf/php/src/scripts/WS_WsdlType.php	(original)
+++ wsf/php/src/scripts/WS_WsdlType.php	Wed Jan 10 02:26:26 2007
@@ -228,6 +228,83 @@
 
 		 
 	 }
+
+
+
+	 public function createWsdl2Type(DomDocument $type_doc, DomElement $type_root)
+	 {
+	         $types = $type_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+						     self::WS_WSDL_TYPE_TYPES_TAG);
+		 $type_root->appendChild($types);
+		 $el = $type_doc->createElementNS(WS_WsdlConst::WS_SOAP_XML_SCHEMA_NAMESPACE, 
+						  self::WS_WSDL_TYPE_SCHEMA_TAG);
+
+		 $el->setAttribute(self::WS_WSDL_TYPE_ELEMENTFROM_TAG,
+				   self::WS_WSDL_TYPE_QULIFIED_TAG);
+		 $types->appendChild($el);
+		 
+
+		 foreach ($this->schemaTypes as $function_name => $params)
+		 {
+		     foreach ($params as $requestType => $params2)
+		     {
+			 $ct = $type_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+							  self::WS_WSDL_TYPE_ELEMENT_TAG);
+			 if ($requestType == self::WS_WSDL_TYPE_IN_TAG)
+			 {
+			     $ct->setAttribute(self::WS_WSDL_TYPE_NAME_TAG, $function_name);
+			     $el->appendChild($ct);
+			     $comtype = $type_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+								   self::WS_WSDL_TYPE_COMPLXTYPE_TAG);
+			     $ct->appendChild($comtype);
+			     $seq = $type_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+							       self::WS_WSDL_TYPE_SEQUECE_TAG);
+			     
+			     $comtype->appendChild($seq);
+			     foreach ($params2 as $paramName => $xsType)
+			     {
+				 $ele = $type_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+							       self::WS_WSDL_TYPE_ELEMENT_TAG);
+				 $ele->setAttribute(self::WS_WSDL_TYPE_NAME_TAG, $paramName);
+				 $ele->setAttribute(self::WS_WSDL_TYPE_TYPE_TAG, self::WS_WSDL_TYPE_XSD_TAG.$xsType);
+				 $seq->appendChild($ele);
+			     }
+			 }
+			 if ($requestType == self::WS_WSDL_TYPE_OUT_TAG)
+			 {
+			     $ct->setAttribute(self::WS_WSDL_TYPE_NAME_TAG, $function_name.self::WS_WSDL_TYPE_RESPONSE_TAG);
+                             $el->appendChild($ct);
+                             $comtype = $type_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+                                                                   self::WS_WSDL_TYPE_COMPLXTYPE_TAG);
+                             $ct->appendChild($comtype);
+                             $seq = $type_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+                                                               self::WS_WSDL_TYPE_SEQUECE_TAG);
+
+                             $comtype->appendChild($seq);
+                        
+			     foreach ($params2 as $paramName => $xsType)
+			     {
+				 $ele = $type_doc->createElementNS(WS_WsdlConst::WS_WSDL2_NAMESPACE,
+							       self::WS_WSDL_TYPE_ELEMENT_TAG);
+				 $ele->setAttribute(self::WS_WSDL_TYPE_NAME_TAG, $paramName);
+				 $ele->setAttribute(self::WS_WSDL_TYPE_TYPE_TAG, self::WS_WSDL_TYPE_XSD_TAG.$xsType);
+				 $seq->appendChild($ele);
+			     }
+			
+			
+			 }
+		     }
+
+		 }
+		 
+	 }
+
+
+
+
+
+
+
       }
      
 




More information about the Wsf-c-dev mailing list