You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Michael Glavassevich <mr...@apache.org> on 2006/12/03 21:02:19 UTC
Re: (POSSIBLE SOLUTION) Serious issue/challenge with Xerces-J the
XSLoader's loadInputList method...
Hi Rick,
If the schema element returned from WSDL4J is a DOM node, you should be
able to pass that directly to the XMLGrammarPreparser using a
DOMInputSource [1] and skip the serialziation step.
Thanks.
[1]
http://xerces.apache.org/xerces2-j/javadocs/xerces2/org/apache/xerces/util/DOMInputSource.html
On Mon, 27 Nov 2006, Bullotta, Rick wrote:
> Hello, all good news!
>
> Via a combination of WSDL4J and Xerces, I think I have something that
> works that I'd like to share (for your benefit, critique, and
> improvements).
>
> The code is based on WSDL4J 1.6 and Xerces 2.9, but should work with
> older versions is well.
>
> 1) First, load the WSDL using a WSDL4J WSDLReader, being certain that
> the javax.wsdl.importDocuments feature is set to true.
>
> 2) Next, create an ArrayList or other structure to hold schema
> "snippets"
>
> 3a) Next, do a recursive walk of the WSDL (diving into imports) looking
> into the getTypes() collection for either:
> - Schema extensibility elements
> - Unknown extensibility elements where getElementType()
> corresponds to a schema QName
>
> 3b) Clone the schema element, and add any namespaces (via attributes) to
> it that exist in the top level Definition (and do not conflict with
> namespaces already assigned to the schema element)
>
> 3c) Serialize the schema element to a string, and create a StringReader
> for it
>
> 3d) Add it to the "schema snippet holder"
>
> 4) Use the XMLGrammarPreparser and an XSGrammarPool to iteratively
> process the schema grammar(s), then create an XSModelImpl passing the
> array of SchemaGrammar(s).
>
> public static XSModel parseMultiple(SchemaCollection coll) {
> try
> {
> XMLGrammarPreparser grammarPreparser = new
> XMLGrammarPreparser();
> XSGrammarPool grammarPool = new XSGrammarPool();
> grammarPreparser.setGrammarPool(grammarPool);
> grammarPreparser.setErrorHandler(new
> XMLErrorReporter().getErrorHandler());
>
> try
> {
> int nItems = coll.getLength();
>
> SchemaGrammar[] grammars = new SchemaGrammar[nItems];
>
> for(int i=0;i<nItems;i++) {
> XMLInputSource is = null;
> is = new
> XMLInputSource(null,null,null,coll.rawItem(i),null);
>
>
> grammarPreparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA,null
> );
> XMLGrammarLoader schemaLoader =
> grammarPreparser.getLoader(XMLGrammarDescription.XML_SCHEMA);
> grammars[i] =
> (SchemaGrammar)grammarPreparser.preparseGrammar(XMLGrammarDescription.XM
> L_SCHEMA,is);
> }
>
> return new XSModelImpl(grammars);
> }
> catch (Exception e)
> {
> //parser will return null pointer exception if the document
> is
> }
> }
> catch (Exception e)
> {
> }
>
> return null;
>
> }
>
> 5) Use the combined XSModel as needed...
>
> This approach seems to work well, but I'm certainly open for
> suggestions/improvements.
>
> Rick Bullotta
> SAP Labs, LLC
>
> http://www.sap.com/manufacturing
>
> -----Original Message-----
> From: Bullotta, Rick [mailto:rick.bullotta@sap.com]
> Sent: Saturday, November 25, 2006 11:50 PM
> To: j-dev@xerces.apache.org; j-users@xerces.apache.org
> Subject: Serious issue/challenge with Xerces-J the XSLoader's
> loadInputList method...
>
> Hello, all.
>
> Here's a quick summary - the WSDL below contains two schema elements. I
> want to create an XSModel that represents this WSDL, and the only way I
> can see to do so is by extracting the schema elements separately,
> turning them into LSInputs, and using the loadInputList method on the
> XSLoader class. Unfortunately, it does not work - there is always an
> error attempting to resolve the n0:YYY type when it attempts to create
> the XSModel.
>
> If I separate the first schema element into its own file, and import it,
> it works fine. However, it should work fine in the same file as well!
> :-(
>
> I suspect it has something to do with the fact that imports within the
> same "file" (in the case of loadInputList, of course, they are separate
> sources), would not have a schemaLocation attribute on the import, but
> only a namespace attribute (as below). I am at a loss to determine how
> to handle this with Xerces.
>
> In this case, I would expect Xerces to simply see if a model or grammar
> has already been loaded for that namespace. I tried as hard as I could
> to trace through the source, but I was completely lost working through
> the intricacies of how these things are resolved.
>
> Help!!!
>
> - Rick Bullotta
> SAP Labs, LLC
>
>
> <?xml version="1.0" encoding="utf-8"?>
> <wsdl:definitions
> targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style"
> xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
> xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
> xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
> xmlns:tns="urn:sap-com:document:sap:soap:functions:mc-style"
> xmlns:n1="urn:sap-com:document:sap:rfc:functions">
> <wsdl:types>
> <xsd:schema attributeFormDefault="qualified"
> targetNamespace="urn:sap-com:document:sap:rfc:functions"
> xmlns:tns="urn:sap-com:document:sap:rfc:functions"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:complexType name="YYY">
> <xsd:sequence>
> <xsd:element name="Param1"
> type="xsd:string"/>
> <xsd:element name="Param2"
> type="xsd:string"/>
> <xsd:element name="Param3"
> type="xsd:string"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:schema>
> <xsd:schema attributeFormDefault="qualified"
> targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style"
> xmlns:tns="urn:sap-com:document:sap:soap:functions:mc-style"
> xmlns:n0="urn:sap-com:document:sap:rfc:functions"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:import
> namespace="urn:sap-com:document:sap:rfc:functions"/>
> <xsd:element name="ZmsWsXmiiTest1">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element
> name="Param" type="n0:YYY"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
> <xsd:element name="ZmsWsXmiiTest1Response">
> <xsd:complexType>
> <xsd:sequence/>
> </xsd:complexType>
> </xsd:element>
> </xsd:schema>
> </wsdl:types>
> <wsdl:message name="ZmsWsXmiiTest1">
> <wsdl:part name="parameters"
> element="tns:ZmsWsXmiiTest1"/>
> </wsdl:message>
> <wsdl:message name="ZmsWsXmiiTest1Response">
> <wsdl:part name="parameters"
> element="tns:ZmsWsXmiiTest1Response"/>
> </wsdl:message>
> <wsdl:portType name="zms_ws_xmii_test1">
> <wsdl:operation name="ZmsWsXmiiTest1">
> <wsdl:input message="tns:ZmsWsXmiiTest1"/>
> <wsdl:output
> message="tns:ZmsWsXmiiTest1Response"/>
> </wsdl:operation>
> </wsdl:portType>
> </wsdl:definitions>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
---------------------------
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org