Edit D:\app\Administrator\product\11.2.0\dbhome_1\oc4j\xqs\tools\xds-to-wsdl.xq
declare namespace w = "xdsconfig.to.wsdl"; declare variable $ws-name external; declare variable $global-config external; declare variable $local-config external; declare variable $ws-url external; (: -------------------------------------------- pass-thru to make the fn:normalize() name shorter. $s - the string to normalize -------------------------------------------- :) declare function local:n($s){ fn:normalize-space($s) }; (: -------------------------------------------- Translate a QN (as defined in XQS config schema) into a qualified name. if ns is declared here explicitly, use ns else call local:make-prefix() to construct a prefix with the QN's prefix and (possibly) <use-prefix> bindings. $q - the QN to parse $bp - list of <use-prefix> elements -------------------------------------------- :) declare function local:parse-QN($q, $bp){ if($q/@namespace and $q/@type) then fn:concat(fn:concat($q/@namespace,":"), local:n($q/@type)) else if($q/@namespace) then fn:concat(fn:concat($q/@namespace,":"), local:n($q/text())) else if($q/@type) then fn:concat(local:make-prefix($q/@prefix, $bp), local:n($q/@type)) else fn:concat(local:make-prefix($q/@prefix, $bp), local:n($q/text())) }; (: -------------------------------------------- Creates Namespace prefix. If prefix is null, returns no prefix, otherwise returns trim(prefix) + ":". SPECIAL CASE 1: if prefix is in <use-prefix>, use namespace SPECIAL CASE 2: if prefix points to xs, return no prefix $q - the QN $bp - list of <use-prefix> elements -------------------------------------------- :) declare function local:make-prefix($p, $bp){ let $x := local:n($p) return if($x eq "") then "" else let $pfx := $bp[@prefix eq $x] return if($pfx) then if($pfx eq "http://www.w3.org/2001/XMLSchema") then "" else fn:concat($pfx, ":") else fn:concat($x, ":") }; (: -------------------------------------------- Determine function's namespace if function-name of config element uses @namespace - return it else resolve the prefix to the namespace via <use-prefix> bindings $fn - the <function-name> element $bp - list of <use-prefix> elements -------------------------------------------- :) declare function local:fn-ns($fn, $bp){ if($fn/@namespace ) then local:n($fn/@namespace) else if($fn/@prefix) then local:n($bp[@prefix eq $fn/@prefix]/text()) else "" }; (: -------------------------------------------- Takes a single xqsview-source element, constructs equivalent WSDL types, elements, and operations. $cfg - an <xdsview-source> element $bp - list of <use-prefix> elements -------------------------------------------- :) declare function local:breakout($cfg, $bp) { let $name := local:n($cfg/function-name/text()) let $fnns := local:fn-ns($cfg/function-name, $bp) return <w:breakout> <w:FN-NS>{$fnns}</w:FN-NS> <w:IMPORT> { (: get imported schemas, may be duplicates :) for $s1 in $cfg//schema-type where $s1/@namespace and $s1/@location return <import namespace="{$s1/@namespace}" schemaLocation="{$s1/@location}"/>, for $s2 in $cfg//output-element where $s2/@namespace return <import namespace="{$s2/@namespace}" schemaLocation="{$s2/@location}"/> } </w:IMPORT> <w:TYPES> (: Make complexTypes from input params :) <complexType name="{$name}Type"> <sequence> { for $x in $cfg/input-parameters/part return <element name="{$x/@name}" type="{local:parse-QN($x/schema-type, $bp)}" nillable="true"/> } </sequence> </complexType> (: Make complexTypes from output type :) <complexType name="{$name}ResultType"> <sequence> <element name="return" nillable="true"> <complexType> <sequence> <element name="result" nillable="true"> <complexType> <sequence> {if(($cfg/output-element/@type and $cfg/output-element/@namespace) or ($cfg/output-element/@type and $cfg/output-element/@prefix)) then <element name="{local:n($cfg/output-element/text())}" type="{local:parse-QN($cfg/output-element, $bp)}" minOccurs="0" maxOccurs="unbounded"/> else if($cfg/output-element) then <element ref="{local:parse-QN($cfg/output-element, $bp)}" minOccurs="0" maxOccurs="unbounded"/> else <any/> } </sequence> </complexType> </element> <element name="errors" nillable="true" minOccurs="0"> <complexType> <sequence> <element name="xqserror" type="xqscwsNsPref:XQSErrorType" maxOccurs="unbounded"/> </sequence> </complexType> </element> </sequence> </complexType> </element> </sequence> </complexType> <element name="{$name}" type="tns:{$name}Type"/> <element name="{$name}Result" type="tns:{$name}ResultType"/> </w:TYPES> <w:MESSAGES xmlns="http://schemas.xmlsoap.org/wsdl/"> <message name="{$name}Request"> <part name="parameters" element="{$fnns}:{$name}"/> </message> <message name="{$name}Response"> <part name="return" element="{$fnns}:{$name}Result"/> </message> </w:MESSAGES> <w:OPERATIONS xmlns="http://schemas.xmlsoap.org/wsdl/"> <operation name="{$name}"> <input message="tns:{$name}Request"/> <output message="tns:{$name}Response"/> </operation> </w:OPERATIONS> </w:breakout> }; (: ================================================= MAIN MODULE Proceed in 2 steps. 1) for each WSDL-visible function, parse out its input types, output types and schemas. the function local:breakout() does all the work. 2) construct a single WSDL using parts from the returned by step 1). ================================================= :) let $bindprefixes := doc($local-config)//bind-prefix/use-prefix let $blist := ( for $x in doc($local-config)//xqsview-source[@WSDLvisibility="true"] where count($x/dataSource) = 0 return local:breakout($x, $bindprefixes), if($local-config eq $global-config) then () else for $x in doc($global-config)//xqsview-source[ @WSDLvisibility="true"] return local:breakout($x, $bindprefixes) ) let $dist-fn-nses := fn:distinct-values($blist//w:FN-NS/text()) let $ns-map := for $ns in $dist-fn-nses return <w:ns-map> <w:pf>fnns{fn:index-of($dist-fn-nses, $ns)}</w:pf> <w:ns>{$ns}</w:ns> </w:ns-map> let $schemas := (for $f-ns in $ns-map let $pf := $f-ns//w:pf/text() let $fns := $f-ns//w:ns/text() return <schema dummyTargetNamespace="{$fns}" dummy-xmlns-tns="{$fns}" xmlns:xqscwsNsPref="xqs-client-ws" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" replace="replace-with-xmlns-list" elementFormDefault="qualified"> <import namespace="xqs-client-ws" /> { let $all-nses := for $b in $blist[w:FN-NS/text() eq $fns] where $b/w:IMPORT//@namespace return $b/w:IMPORT//@namespace let $distinctns := fn:distinct-values($all-nses) let $imports := (for $d in $distinctns let $sl := (for $b in $blist[w:FN-NS/text() eq $fns] where $b/w:IMPORT//@namespace eq $d return $b/w:IMPORT//@schemaLocation) return <import namespace="{$d}" schemaLocation="{$sl[1]}" /> ) let $all-types := (for $b in $blist[w:FN-NS/text() eq $fns] return $b/w:TYPES/* ) return ($imports, $all-types) } </schema>) return <definitions name="{$ws-name}" targetNamespace="$$XDS_TARGET_NS$$" xmlns:xqscwsNsPref="xqs-client-ws" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="$$XDS_TARGET_NS$$" replace="replace-with-xmlns-list" > <types> <schema targetNamespace="xqs-client-ws" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <complexType name="XQSErrorType"> <simpleContent> <extension base="string"> <attribute name="functionName" type="string"/> <attribute name="code" type="string"/> <attribute name="type" type="string"/> </extension> </simpleContent> </complexType> </schema> {$schemas} </types> {$blist/w:MESSAGES/*} <portType name="XQSViewWebServices"> {$blist/w:OPERATIONS/*} </portType> <binding name="HttpSoap11Binding" type="tns:XQSViewWebServices"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> {for $o in $blist/w:OPERATIONS/* return <operation name="{$o/@*:name}"> <soap:operation/> <input> <soap:body use="literal" parts="parameters"/> </input> <output> <soap:body use="literal" parts="return"/> </output> </operation> } </binding> <service name="XQSView-WS"> <port name="HttpSoap11" binding="tns:HttpSoap11Binding"> <soap:address location="{$ws-url}"/> </port> </service> </definitions>
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de