Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » Loading schemas from WSDL documents
Loading schemas from WSDL documents [message #6949] Tue, 10 December 2002 16:50 Go to next message
Eclipse UserFriend
Originally posted by: carman.itc.it

G'day!

I have been attempting to use the excellent xsd project to access schema
type definitions within WSDL (Web Service Description Language) documents.

But have thus far been unable to load them. Is there an easy way to do
this?

At first I tried to load the documents as if they were straight xsd
documents by adding "wsdl" to the Extension-to-Factory-Mapping:


Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "wsdl",
new XSDResourceFactoryImpl());

That didn't work, (and probably it wasn't supposed to?), so I decided to
use a DOM parser on the original document, find the <xsd:schema> element
and pass that to xsd using the XSDSchema.setElement(org.w3c.dom.Element)
method. That should work, right?

Using the EMF/XSD build from 20021023, the code (attached to the end of
this message), runs without raising an exception, but doesn't seem to load
the schema properly, (I can't access the type definitions that should be
in it).

Using the build from 20021127, the code returns an exception:
java.lang.NullPointerException
at org.eclipse.emf.common.EMFPlugin.getBaseURL(EMFPlugin.java:1 02)
....
when executing the setElement() command.

I am using xsd/emf in stand-alone mode (from outside of eclipse). Have I
forgotten to do something, or is there a bug here?

Please forgive me if I have missed something obvious!
Thanks a lot for your help,

Mark Carman
PhD Student
ITC-irst


********** The Code **************************************

import org.w3c.dom.*;
import org.eclipse.xsd.*;

public class Test {

public static void main(String args[]) {

// required proxy settings to access internet
java.util.Properties props = System.getProperties();
props.put("http.proxyHost","wwwproxy");
props.put("http.proxyPort","80");

try {

// load WSDL document into DOM
String wsdlURL =
"http://live.capescience.com/wsdl/GlobalWeather.wsdl";
Document doc =
javax.xml.parsers.DocumentBuilderFactory.newInstance().newDo cumentBuilder().parse(wsdlURL);

// get <schema> element from inside <types> declaration
Element schemaElement = (Element) ((Element)
doc.getDocumentElement().getElementsByTagName("types").item(0)).getElementsByTagName( "xsd:schema").item(0);

// create new schema object and use the setElement method to load
the DOM description into it
XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
schema.setElement(schemaElement);

// print out the schema
System.out.println(schema.toString());

}
catch (Exception e) {
e.printStackTrace();
}

}

}

********* The Error Message ****************************
java.lang.NullPointerException
at org.eclipse.emf.common.EMFPlugin.getBaseURL(EMFPlugin.java:1 02)
at
org.eclipse.xsd.impl.XSDSchemaImpl.getSchemaInstance(XSDSche maImpl.java:704)
at
org.eclipse.xsd.impl.XSDSchemaImpl.resolveSchema(XSDSchemaIm pl.java:1935)
at
org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1444)
at
org.eclipse.xsd.impl.XSDSchemaImpl.traverseToRootForPatching (XSDSchemaImpl.java:1436)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.changeAttribut e(XSDConcreteComponentImpl.java:1211)
at
org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2147)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1182)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElementGen( XSDConcreteComponentImpl.java:2768)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElement(XSD ConcreteComponentImpl.java:2800)
at
org.eclipse.xsd.impl.XSDSchemaImpl.setElement(XSDSchemaImpl. java:2274)
at Test.main(Test.java:23)
java.lang.NullPointerException
at
org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1447)
at
org.eclipse.xsd.impl.XSDSchemaImpl.traverseToRootForPatching (XSDSchemaImpl.java:1436)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.changeAttribut e(XSDConcreteComponentImpl.java:1211)
at
org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2147)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1182)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElementGen( XSDConcreteComponentImpl.java:2768)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElement(XSD ConcreteComponentImpl.java:2800)
at
org.eclipse.xsd.impl.XSDSchemaImpl.setElement(XSDSchemaImpl. java:2274)
at Test.main(Test.java:23)
Re: Loading schemas from WSDL documents [message #6974 is a reply to message #6949] Tue, 10 December 2002 22:20 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

--------------DFEB9C385DA33E9CCBCA91B4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Mark,

Thanks for the kind words.

You would need to implement a WSDLResourceImpl, much like the XSDResourceImpl if you wanted full support
including save; XSDResourceImpl only works for a document with a root schema. However, creating the DOM and
using XSDSchema.setElement is the right approach to make something work quickly for navigation/analysis
purposes. In order for imports/includes/redefines to resolve, you must also call XSDSchema.setSchemaLocation
with the URI of the document that contains the schema, i.e., your .wsdl's URI. This is normally done
automatically by the XSDResourceImpl when the schema is added:

public void attached(EObject eObject)
{
super.attached(eObject);

if (eObject instanceof XSDSchema)
{
((XSDSchema)eObject).setSchemaLocation(getURI().toString());
}
}

Your stack trace looks to be caused by xsd.resources.jar not being on the CLASSPATH. Please have a look at the
org.eclipse.xsd.test for setup details of a working standalone example.


Mark Carman wrote:

> G'day!
>
> I have been attempting to use the excellent xsd project to access schema
> type definitions within WSDL (Web Service Description Language) documents.
>
> But have thus far been unable to load them. Is there an easy way to do
> this?
>
> At first I tried to load the documents as if they were straight xsd
> documents by adding "wsdl" to the Extension-to-Factory-Mapping:
>
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "wsdl",
> new XSDResourceFactoryImpl());
>
> That didn't work, (and probably it wasn't supposed to?), so I decided to
> use a DOM parser on the original document, find the <xsd:schema> element
> and pass that to xsd using the XSDSchema.setElement(org.w3c.dom.Element)
> method. That should work, right?
>
> Using the EMF/XSD build from 20021023, the code (attached to the end of
> this message), runs without raising an exception, but doesn't seem to load
> the schema properly, (I can't access the type definitions that should be
> in it).
>
> Using the build from 20021127, the code returns an exception:
> java.lang.NullPointerException
> at org.eclipse.emf.common.EMFPlugin.getBaseURL(EMFPlugin.java:1 02)
> ....
> when executing the setElement() command.
>
> I am using xsd/emf in stand-alone mode (from outside of eclipse). Have I
> forgotten to do something, or is there a bug here?
>
> Please forgive me if I have missed something obvious!
> Thanks a lot for your help,
>
> Mark Carman
> PhD Student
> ITC-irst
>
> ********** The Code **************************************
>
> import org.w3c.dom.*;
> import org.eclipse.xsd.*;
>
> public class Test {
>
> public static void main(String args[]) {
>
> // required proxy settings to access internet
> java.util.Properties props = System.getProperties();
> props.put("http.proxyHost","wwwproxy");
> props.put("http.proxyPort","80");
>
> try {
>
> // load WSDL document into DOM
> String wsdlURL =
> "http://live.capescience.com/wsdl/GlobalWeather.wsdl";
> Document doc =
> javax.xml.parsers.DocumentBuilderFactory.newInstance().newDo cumentBuilder().parse(wsdlURL);
>
> // get <schema> element from inside <types> declaration
> Element schemaElement = (Element) ((Element)
> doc.getDocumentElement().getElementsByTagName("types").item(0)).getElementsByTagName( "xsd:schema").item(0);
>
> // create new schema object and use the setElement method to load
> the DOM description into it
> XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
> schema.setElement(schemaElement);
>
> // print out the schema
> System.out.println(schema.toString());
>
> }
> catch (Exception e) {
> e.printStackTrace();
> }
>
> }
>
> }
>
> ********* The Error Message ****************************
> java.lang.NullPointerException
> at org.eclipse.emf.common.EMFPlugin.getBaseURL(EMFPlugin.java:1 02)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.getSchemaInstance(XSDSche maImpl.java:704)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.resolveSchema(XSDSchemaIm pl.java:1935)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1444)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.traverseToRootForPatching (XSDSchemaImpl.java:1436)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.changeAttribut e(XSDConcreteComponentImpl.java:1211)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2147)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1182)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElementGen( XSDConcreteComponentImpl.java:2768)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElement(XSD ConcreteComponentImpl.java:2800)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.setElement(XSDSchemaImpl. java:2274)
> at Test.main(Test.java:23)
> java.lang.NullPointerException
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1447)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.traverseToRootForPatching (XSDSchemaImpl.java:1436)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.changeAttribut e(XSDConcreteComponentImpl.java:1211)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2147)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1182)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElementGen( XSDConcreteComponentImpl.java:2768)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElement(XSD ConcreteComponentImpl.java:2800)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.setElement(XSDSchemaImpl. java:2274)
> at Test.main(Test.java:23)

--
Ed Merks


--------------DFEB9C385DA33E9CCBCA91B4
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Mark,
<p>Thanks for the kind words.
<p>You would need to implement a WSDLResourceImpl, much like the XSDResourceImpl
if you wanted full support including save; XSDResourceImpl only works for
a document with a root schema. However, creating the DOM and using XSDSchema.setElement
is the right approach to make something work quickly for navigation/analysis
purposes.&nbsp; In order for imports/includes/redefines to resolve, you
must also call XSDSchema.setSchemaLocation with the URI of the document
that contains the schema, i.e., your .wsdl's URI.&nbsp; This is normally
done automatically by the XSDResourceImpl when the schema is added:
<blockquote>&nbsp; public void attached(EObject eObject)
<br>&nbsp; {
<br>&nbsp;&nbsp;&nbsp; super.attached(eObject);
<p>&nbsp;&nbsp;&nbsp; if (eObject instanceof XSDSchema)
<br>&nbsp;&nbsp;&nbsp; {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((XSDSchema)eObject).<b>setSchemaLocation</b>(getURI().toString());
<br>&nbsp;&nbsp;&nbsp; }
<br>&nbsp; }</blockquote>
Your stack trace looks to be caused by xsd.resources.jar not being on the
CLASSPATH.&nbsp; Please have a look at the org.eclipse.xsd.test for setup
details of a working standalone example.
<br>&nbsp;
<p>Mark Carman wrote:
<blockquote TYPE=CITE>G'day!
<p>I have been attempting to use the excellent xsd project to access schema
<br>type definitions within WSDL (Web Service Description Language) documents.
<p>But have thus far been unable to load them. Is there an easy way to
do
<br>this?
<p>At first I tried to load the documents as if they were straight xsd
<br>documents by adding "wsdl" to the Extension-to-Factory-Mapping:
<br>&nbsp;
<p> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "wsdl",
<br>new XSDResourceFactoryImpl());
<p>That didn't work, (and probably it wasn't supposed to?), so I decided
to
<br>use a DOM parser on the original document, find the &lt;xsd:schema>
element
<br>and pass that to xsd using the XSDSchema.setElement(org.w3c.dom.Element)
<br>method. That should work, right?
<p>Using the EMF/XSD build from 20021023, the code (attached to the end
of
<br>this message), runs without raising an exception, but doesn't seem
to load
<br>the schema properly, (I can't access the type definitions that should
be
<br>in it).
<p>Using the build from 20021127, the code returns an exception:
<br>java.lang.NullPointerException
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at org.eclipse.emf.common.EMFPlugin.getBaseURL(EMFPlugin.java:1 02)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ....
<br>when executing the setElement() command.
<p>I am using xsd/emf in stand-alone mode (from outside of eclipse). Have
I
<br>forgotten to do something, or is there a bug here?
<p>Please forgive me if I have missed something obvious!
<br>Thanks a lot for your help,
<p>Mark Carman
<br>PhD Student
<br>ITC-irst
<p>********** The Code **************************************
<p>import org.w3c.dom.*;
<br>import org.eclipse.xsd.*;
<p>public class Test {
<p>&nbsp; public static void main(String args[]) {
<p>&nbsp;&nbsp;&nbsp; // required proxy settings to access internet
<br>&nbsp;&nbsp;&nbsp; java.util.Properties props = System.getProperties();
<br>&nbsp;&nbsp;&nbsp; props.put("http.proxyHost","wwwproxy");
<br>&nbsp;&nbsp;&nbsp; props.put("http.proxyPort","80");
<p>&nbsp;&nbsp;&nbsp; try {
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // load WSDL document into DOM
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String wsdlURL =
<br>"<a href="http://live.capescience.com/wsdl/GlobalWeather.wsdl">http://live.capescience.com/wsdl/GlobalWeather.wsdl</a>";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Document doc =
<br> javax.xml.parsers.DocumentBuilderFactory.newInstance().newDo cumentBuilder().parse(wsdlURL);
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // get &lt;schema> element from inside
&lt;types> declaration
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Element schemaElement = (Element) ((Element)
<br>doc.getDocumentElement().getElementsByTagName("types").item(0)).getElementsByTagName( "xsd:schema").item(0);
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // create new schema object and use the
setElement method to load
<br>the DOM description into it
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; schema.setElement(schemaElement);
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // print out the schema
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(schema.toString());
<p>&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp; catch (Exception e) {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();
<br>&nbsp;&nbsp;&nbsp; }
<p>&nbsp; }
<p>}
<p>********* The Error Message ****************************
<br>java.lang.NullPointerException
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at org.eclipse.emf.common.EMFPlugin.getBaseURL(EMFPlugin.java:1 02)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.getSchemaInstance(XSDSche maImpl.java:704)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.resolveSchema(XSDSchemaIm pl.java:1935)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1444)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.traverseToRootForPatching (XSDSchemaImpl.java:1436)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.changeAttribut e(XSDConcreteComponentImpl.java:1211)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2147)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1182)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElementGen( XSDConcreteComponentImpl.java:2768)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElement(XSD ConcreteComponentImpl.java:2800)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.setElement(XSDSchemaImpl. java:2274)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at Test.main(Test.java:23)
<br>java.lang.NullPointerException
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1447)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.traverseToRootForPatching (XSDSchemaImpl.java:1436)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.changeAttribut e(XSDConcreteComponentImpl.java:1211)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2147)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1182)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElementGen( XSDConcreteComponentImpl.java:2768)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElement(XSD ConcreteComponentImpl.java:2800)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.setElement(XSDSchemaImpl. java:2274)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at Test.main(Test.java:23)</blockquote>

<p>--
<br>Ed Merks
<br>&nbsp;</html>

--------------DFEB9C385DA33E9CCBCA91B4--
Re: Loading schemas from WSDL documents [message #563995 is a reply to message #6949] Tue, 10 December 2002 22:20 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
--------------DFEB9C385DA33E9CCBCA91B4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Mark,

Thanks for the kind words.

You would need to implement a WSDLResourceImpl, much like the XSDResourceImpl if you wanted full support
including save; XSDResourceImpl only works for a document with a root schema. However, creating the DOM and
using XSDSchema.setElement is the right approach to make something work quickly for navigation/analysis
purposes. In order for imports/includes/redefines to resolve, you must also call XSDSchema.setSchemaLocation
with the URI of the document that contains the schema, i.e., your .wsdl's URI. This is normally done
automatically by the XSDResourceImpl when the schema is added:

public void attached(EObject eObject)
{
super.attached(eObject);

if (eObject instanceof XSDSchema)
{
((XSDSchema)eObject).setSchemaLocation(getURI().toString());
}
}

Your stack trace looks to be caused by xsd.resources.jar not being on the CLASSPATH. Please have a look at the
org.eclipse.xsd.test for setup details of a working standalone example.


Mark Carman wrote:

> G'day!
>
> I have been attempting to use the excellent xsd project to access schema
> type definitions within WSDL (Web Service Description Language) documents.
>
> But have thus far been unable to load them. Is there an easy way to do
> this?
>
> At first I tried to load the documents as if they were straight xsd
> documents by adding "wsdl" to the Extension-to-Factory-Mapping:
>
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "wsdl",
> new XSDResourceFactoryImpl());
>
> That didn't work, (and probably it wasn't supposed to?), so I decided to
> use a DOM parser on the original document, find the <xsd:schema> element
> and pass that to xsd using the XSDSchema.setElement(org.w3c.dom.Element)
> method. That should work, right?
>
> Using the EMF/XSD build from 20021023, the code (attached to the end of
> this message), runs without raising an exception, but doesn't seem to load
> the schema properly, (I can't access the type definitions that should be
> in it).
>
> Using the build from 20021127, the code returns an exception:
> java.lang.NullPointerException
> at org.eclipse.emf.common.EMFPlugin.getBaseURL(EMFPlugin.java:1 02)
> ....
> when executing the setElement() command.
>
> I am using xsd/emf in stand-alone mode (from outside of eclipse). Have I
> forgotten to do something, or is there a bug here?
>
> Please forgive me if I have missed something obvious!
> Thanks a lot for your help,
>
> Mark Carman
> PhD Student
> ITC-irst
>
> ********** The Code **************************************
>
> import org.w3c.dom.*;
> import org.eclipse.xsd.*;
>
> public class Test {
>
> public static void main(String args[]) {
>
> // required proxy settings to access internet
> java.util.Properties props = System.getProperties();
> props.put("http.proxyHost","wwwproxy");
> props.put("http.proxyPort","80");
>
> try {
>
> // load WSDL document into DOM
> String wsdlURL =
> "http://live.capescience.com/wsdl/GlobalWeather.wsdl";
> Document doc =
> javax.xml.parsers.DocumentBuilderFactory.newInstance().newDo cumentBuilder().parse(wsdlURL);
>
> // get <schema> element from inside <types> declaration
> Element schemaElement = (Element) ((Element)
> doc.getDocumentElement().getElementsByTagName("types").item(0)).getElementsByTagName( "xsd:schema").item(0);
>
> // create new schema object and use the setElement method to load
> the DOM description into it
> XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
> schema.setElement(schemaElement);
>
> // print out the schema
> System.out.println(schema.toString());
>
> }
> catch (Exception e) {
> e.printStackTrace();
> }
>
> }
>
> }
>
> ********* The Error Message ****************************
> java.lang.NullPointerException
> at org.eclipse.emf.common.EMFPlugin.getBaseURL(EMFPlugin.java:1 02)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.getSchemaInstance(XSDSche maImpl.java:704)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.resolveSchema(XSDSchemaIm pl.java:1935)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1444)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.traverseToRootForPatching (XSDSchemaImpl.java:1436)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.changeAttribut e(XSDConcreteComponentImpl.java:1211)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2147)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1182)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElementGen( XSDConcreteComponentImpl.java:2768)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElement(XSD ConcreteComponentImpl.java:2800)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.setElement(XSDSchemaImpl. java:2274)
> at Test.main(Test.java:23)
> java.lang.NullPointerException
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1447)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.traverseToRootForPatching (XSDSchemaImpl.java:1436)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.changeAttribut e(XSDConcreteComponentImpl.java:1211)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2147)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1182)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElementGen( XSDConcreteComponentImpl.java:2768)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElement(XSD ConcreteComponentImpl.java:2800)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.setElement(XSDSchemaImpl. java:2274)
> at Test.main(Test.java:23)

--
Ed Merks


--------------DFEB9C385DA33E9CCBCA91B4
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Mark,
<p>Thanks for the kind words.
<p>You would need to implement a WSDLResourceImpl, much like the XSDResourceImpl
if you wanted full support including save; XSDResourceImpl only works for
a document with a root schema. However, creating the DOM and using XSDSchema.setElement
is the right approach to make something work quickly for navigation/analysis
purposes.&nbsp; In order for imports/includes/redefines to resolve, you
must also call XSDSchema.setSchemaLocation with the URI of the document
that contains the schema, i.e., your .wsdl's URI.&nbsp; This is normally
done automatically by the XSDResourceImpl when the schema is added:
<blockquote>&nbsp; public void attached(EObject eObject)
<br>&nbsp; {
<br>&nbsp;&nbsp;&nbsp; super.attached(eObject);
<p>&nbsp;&nbsp;&nbsp; if (eObject instanceof XSDSchema)
<br>&nbsp;&nbsp;&nbsp; {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((XSDSchema)eObject).<b>setSchemaLocation</b>(getURI().toString());
<br>&nbsp;&nbsp;&nbsp; }
<br>&nbsp; }</blockquote>
Your stack trace looks to be caused by xsd.resources.jar not being on the
CLASSPATH.&nbsp; Please have a look at the org.eclipse.xsd.test for setup
details of a working standalone example.
<br>&nbsp;
<p>Mark Carman wrote:
<blockquote TYPE=CITE>G'day!
<p>I have been attempting to use the excellent xsd project to access schema
<br>type definitions within WSDL (Web Service Description Language) documents.
<p>But have thus far been unable to load them. Is there an easy way to
do
<br>this?
<p>At first I tried to load the documents as if they were straight xsd
<br>documents by adding "wsdl" to the Extension-to-Factory-Mapping:
<br>&nbsp;
<p> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "wsdl",
<br>new XSDResourceFactoryImpl());
<p>That didn't work, (and probably it wasn't supposed to?), so I decided
to
<br>use a DOM parser on the original document, find the &lt;xsd:schema>
element
<br>and pass that to xsd using the XSDSchema.setElement(org.w3c.dom.Element)
<br>method. That should work, right?
<p>Using the EMF/XSD build from 20021023, the code (attached to the end
of
<br>this message), runs without raising an exception, but doesn't seem
to load
<br>the schema properly, (I can't access the type definitions that should
be
<br>in it).
<p>Using the build from 20021127, the code returns an exception:
<br>java.lang.NullPointerException
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at org.eclipse.emf.common.EMFPlugin.getBaseURL(EMFPlugin.java:1 02)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ....
<br>when executing the setElement() command.
<p>I am using xsd/emf in stand-alone mode (from outside of eclipse). Have
I
<br>forgotten to do something, or is there a bug here?
<p>Please forgive me if I have missed something obvious!
<br>Thanks a lot for your help,
<p>Mark Carman
<br>PhD Student
<br>ITC-irst
<p>********** The Code **************************************
<p>import org.w3c.dom.*;
<br>import org.eclipse.xsd.*;
<p>public class Test {
<p>&nbsp; public static void main(String args[]) {
<p>&nbsp;&nbsp;&nbsp; // required proxy settings to access internet
<br>&nbsp;&nbsp;&nbsp; java.util.Properties props = System.getProperties();
<br>&nbsp;&nbsp;&nbsp; props.put("http.proxyHost","wwwproxy");
<br>&nbsp;&nbsp;&nbsp; props.put("http.proxyPort","80");
<p>&nbsp;&nbsp;&nbsp; try {
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // load WSDL document into DOM
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String wsdlURL =
<br>"<a href="http://live.capescience.com/wsdl/GlobalWeather.wsdl">http://live.capescience.com/wsdl/GlobalWeather.wsdl</a>";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Document doc =
<br> javax.xml.parsers.DocumentBuilderFactory.newInstance().newDo cumentBuilder().parse(wsdlURL);
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // get &lt;schema> element from inside
&lt;types> declaration
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Element schemaElement = (Element) ((Element)
<br>doc.getDocumentElement().getElementsByTagName("types").item(0)).getElementsByTagName( "xsd:schema").item(0);
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // create new schema object and use the
setElement method to load
<br>the DOM description into it
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; schema.setElement(schemaElement);
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // print out the schema
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(schema.toString());
<p>&nbsp;&nbsp;&nbsp; }
<br>&nbsp;&nbsp;&nbsp; catch (Exception e) {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();
<br>&nbsp;&nbsp;&nbsp; }
<p>&nbsp; }
<p>}
<p>********* The Error Message ****************************
<br>java.lang.NullPointerException
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at org.eclipse.emf.common.EMFPlugin.getBaseURL(EMFPlugin.java:1 02)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.getSchemaInstance(XSDSche maImpl.java:704)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.resolveSchema(XSDSchemaIm pl.java:1935)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1444)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.traverseToRootForPatching (XSDSchemaImpl.java:1436)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.changeAttribut e(XSDConcreteComponentImpl.java:1211)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2147)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1182)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElementGen( XSDConcreteComponentImpl.java:2768)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElement(XSD ConcreteComponentImpl.java:2800)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.setElement(XSDSchemaImpl. java:2274)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at Test.main(Test.java:23)
<br>java.lang.NullPointerException
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1447)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.traverseToRootForPatching (XSDSchemaImpl.java:1436)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.changeAttribut e(XSDConcreteComponentImpl.java:1211)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2147)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1182)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElementGen( XSDConcreteComponentImpl.java:2768)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDConcreteComponentImpl.setElement(XSD ConcreteComponentImpl.java:2800)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at
<br> org.eclipse.xsd.impl.XSDSchemaImpl.setElement(XSDSchemaImpl. java:2274)
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; at Test.main(Test.java:23)</blockquote>

<p>--
<br>Ed Merks
<br>&nbsp;</html>

--------------DFEB9C385DA33E9CCBCA91B4--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Loading schemas from WSDL documents
Next Topic:xs:import problem
Goto Forum:
  


Current Time: Thu Apr 25 04:12:31 GMT 2024

Powered by FUDForum. Page generated in 0.08171 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top