Home » Language IDEs » ServerTools (WTP) » Creating an XML Document (and more) from an InputStream?
Creating an XML Document (and more) from an InputStream? [message #186534] |
Thu, 18 January 2007 23:50  |
Eclipse User |
|
|
|
Originally posted by: fakeaddress.brainkandy.org
Hello,
I am trying to write a test whereby I pass an IDOMDocument to one of my
classes. The problem is I don't know how to build an IDOMDocument from
an XMLString.
I've tried this:
InputStream is = new ByteArrayInputString(xmlText.getBytes());
XMLDocumentLoader loader = new XMLDocumentLoader();
IEncodedDocument doc = loader.createNewStructuredDocument(null, is);
This is as far as I was able to get, but I get an exception:
java.lang.ExceptionInInitializerError
at org.eclipse.core.runtime.FileLocator.find(FileLocator.java:8 6)
at org.eclipse.core.runtime.Platform.find(Platform.java:885)
....
and now I'm stuck.
Truth be told, I need more than that, I need an IDOMDocument, and also
need the affiliated IDOMModel and IStructuredDocument (though I believe
I can successfully mock out IDOMModel and IStructuredDocument)
Any suggestions?
Thanks, Robert
|
|
|
Re: Creating an XML Document (and more) from an InputStream? [message #186691 is a reply to message #186534] |
Mon, 22 January 2007 08:53   |
|
Robert Konigsberg wrote:
> Hello,
>
> I am trying to write a test whereby I pass an IDOMDocument to one of my
> classes. The problem is I don't know how to build an IDOMDocument from
> an XMLString.
>
> I've tried this:
>
> InputStream is = new ByteArrayInputString(xmlText.getBytes());
> XMLDocumentLoader loader = new XMLDocumentLoader();
> IEncodedDocument doc = loader.createNewStructuredDocument(null, is);
>
> This is as far as I was able to get, but I get an exception:
>
> java.lang.ExceptionInInitializerError
> at org.eclipse.core.runtime.FileLocator.find(FileLocator.java:8 6)
> at org.eclipse.core.runtime.Platform.find(Platform.java:885)
> ...
>
>
> and now I'm stuck.
>
> Truth be told, I need more than that, I need an IDOMDocument, and also
> need the affiliated IDOMModel and IStructuredDocument (though I believe
> I can successfully mock out IDOMModel and IStructuredDocument)
>
> Any suggestions?
>
> Thanks, Robert
The best way to go is to start with the IStructuredModel using the
org.eclipse.wst.sse.core.internal.provisional.IModelManager. getModelForRead(String
id, InputStream inStream) (ore getModelForEdit) method. You can
obtain an IModelManager instance from
org.eclipse.wst.sse.core.StructuredModelManager. The "id" value
must be unique, should probably end with ".xml" just to give an
extra hint of the content type, and you absolutely must call the
corresponding IStructuredModel.releaseFromRead() (or
releaseFromEdit) method when you're done with it. IDOMModel is a
subinterface of IStructuredModel, and you can retrieve the
IDOMDocument and IStructuredDocument from there.
--
Nitin Dahyabhai
Structured Source Editor
_
Nitin Dahyabhai
Eclipse Web Tools Platform
|
|
|
Re: Creating an XML Document (and more) from an InputStream? [message #186750 is a reply to message #186691] |
Mon, 22 January 2007 19:05   |
Eclipse User |
|
|
|
Originally posted by: fakeaddress.brainkandy.org
Thank you Nitin. I will give this a try before too long.
Nitin Dahyabhai wrote:
> Robert Konigsberg wrote:
>> Hello,
>>
>> I am trying to write a test whereby I pass an IDOMDocument to one of
>> my classes. The problem is I don't know how to build an IDOMDocument
>> from an XMLString.
>>
>> I've tried this:
>>
>> InputStream is = new ByteArrayInputString(xmlText.getBytes());
>> XMLDocumentLoader loader = new XMLDocumentLoader();
>> IEncodedDocument doc = loader.createNewStructuredDocument(null, is);
>>
>> This is as far as I was able to get, but I get an exception:
>>
>> java.lang.ExceptionInInitializerError
>> at org.eclipse.core.runtime.FileLocator.find(FileLocator.java:8 6)
>> at org.eclipse.core.runtime.Platform.find(Platform.java:885)
>> ...
>>
>>
>> and now I'm stuck.
>>
>> Truth be told, I need more than that, I need an IDOMDocument, and also
>> need the affiliated IDOMModel and IStructuredDocument (though I
>> believe I can successfully mock out IDOMModel and IStructuredDocument)
>>
>> Any suggestions?
>>
>> Thanks, Robert
>
>
> The best way to go is to start with the IStructuredModel using the
> org.eclipse.wst.sse.core.internal.provisional.IModelManager. getModelForRead(String
> id, InputStream inStream) (ore getModelForEdit) method. You can obtain
> an IModelManager instance from
> org.eclipse.wst.sse.core.StructuredModelManager. The "id" value must be
> unique, should probably end with ".xml" just to give an extra hint of
> the content type, and you absolutely must call the corresponding
> IStructuredModel.releaseFromRead() (or releaseFromEdit) method when
> you're done with it. IDOMModel is a subinterface of IStructuredModel,
> and you can retrieve the IDOMDocument and IStructuredDocument from there.
>
> --
> Nitin Dahyabhai
> Structured Source Editor
|
|
|
Re: Creating an XML Document (and more) from an InputStream? [message #186943 is a reply to message #186750] |
Thu, 25 January 2007 03:49   |
Eclipse User |
|
|
|
Originally posted by: fakeaddress.brainkandy.org
Nitin,
I am stuck once more. Unfortunately, if I start my first test with:
IModelManager mgr = StructuredModelManager.getModelManager()
but this results in a NullPointerException in getModelManager:
"int state = localBundle.getState()";
localBundle is not initialized (comes from
Platform.getBundle(SSECorePlugin.ID))
Now I have looked at some of the sample unit tests in the CVS
respository, and tried to initialize my project in a similar way, but
only resulting in yet more exceptions.
Thoughts?
Thanks, Robert
Robert Konigsberg wrote:
> Thank you Nitin. I will give this a try before too long.
>
> Nitin Dahyabhai wrote:
>> Robert Konigsberg wrote:
>>> Hello,
>>>
>>> I am trying to write a test whereby I pass an IDOMDocument to one of
>>> my classes. The problem is I don't know how to build an IDOMDocument
>>> from an XMLString.
>>>
>>> I've tried this:
>>>
>>> InputStream is = new ByteArrayInputString(xmlText.getBytes());
>>> XMLDocumentLoader loader = new XMLDocumentLoader();
>>> IEncodedDocument doc = loader.createNewStructuredDocument(null, is);
>>>
>>> This is as far as I was able to get, but I get an exception:
>>>
>>> java.lang.ExceptionInInitializerError
>>> at org.eclipse.core.runtime.FileLocator.find(FileLocator.java:8 6)
>>> at org.eclipse.core.runtime.Platform.find(Platform.java:885)
>>> ...
>>>
>>>
>>> and now I'm stuck.
>>>
>>> Truth be told, I need more than that, I need an IDOMDocument, and
>>> also need the affiliated IDOMModel and IStructuredDocument (though I
>>> believe I can successfully mock out IDOMModel and IStructuredDocument)
>>>
>>> Any suggestions?
>>>
>>> Thanks, Robert
>>
>>
>> The best way to go is to start with the IStructuredModel using the
>> org.eclipse.wst.sse.core.internal.provisional.IModelManager. getModelForRead(String
>> id, InputStream inStream) (ore getModelForEdit) method. You can
>> obtain an IModelManager instance from
>> org.eclipse.wst.sse.core.StructuredModelManager. The "id" value must
>> be unique, should probably end with ".xml" just to give an extra hint
>> of the content type, and you absolutely must call the corresponding
>> IStructuredModel.releaseFromRead() (or releaseFromEdit) method when
>> you're done with it. IDOMModel is a subinterface of IStructuredModel,
>> and you can retrieve the IDOMDocument and IStructuredDocument from there.
>>
>> --
>> Nitin Dahyabhai
>> Structured Source Editor
|
|
|
Re: Creating an XML Document (and more) from an InputStream? [message #187069 is a reply to message #186943] |
Fri, 26 January 2007 12:56   |
|
Robert Konigsberg wrote:
> Nitin,
>
> I am stuck once more. Unfortunately, if I start my first test with:
>
> IModelManager mgr = StructuredModelManager.getModelManager()
>
> but this results in a NullPointerException in getModelManager:
>
> "int state = localBundle.getState()";
>
> localBundle is not initialized (comes from
> Platform.getBundle(SSECorePlugin.ID))
>
> Now I have looked at some of the sample unit tests in the CVS
> respository, and tried to initialize my project in a similar way, but
> only resulting in yet more exceptions.
>
> Thoughts?
The most likely reason is that you've added org.eclipse.wst.sse.core
to the Java Build Path, but not added it to your list of plug-in
dependencies.
--
Nitin Dahyabhai
Structured Source Editor
_
Nitin Dahyabhai
Eclipse Web Tools Platform
|
|
|
Re: Creating an XML Document (and more) from an InputStream? [message #187149 is a reply to message #187069] |
Fri, 26 January 2007 19:18   |
Eclipse User |
|
|
|
Originally posted by: fakeaddress.brainkandy.org
Unfortunately, it was already in my list of plug-in dependencies. My
Java build path is pretty clean, actually. No required projects, no
additional source, and my libraries are limited to the JRE (1.5.0_06,
incidentally), JUnit 3.8.1 and Plug-in dependencies. Hmm...
Nitin Dahyabhai wrote:
> Robert Konigsberg wrote:
>> Nitin,
>>
>> I am stuck once more. Unfortunately, if I start my first test with:
>>
>> IModelManager mgr = StructuredModelManager.getModelManager()
>>
>> but this results in a NullPointerException in getModelManager:
>>
>> "int state = localBundle.getState()";
>>
>> localBundle is not initialized (comes from
>> Platform.getBundle(SSECorePlugin.ID))
>>
>> Now I have looked at some of the sample unit tests in the CVS
>> respository, and tried to initialize my project in a similar way, but
>> only resulting in yet more exceptions.
>>
>> Thoughts?
>
> The most likely reason is that you've added org.eclipse.wst.sse.core to
> the Java Build Path, but not added it to your list of plug-in dependencies.
>
> --
> Nitin Dahyabhai
> Structured Source Editor
|
|
|
Re: Creating an XML Document (and more) from an InputStream? [message #187349 is a reply to message #187149] |
Tue, 30 January 2007 18:31   |
Eclipse User |
|
|
|
Originally posted by: fakeaddress.brainkandy.org
Robert Konigsberg wrote:
> Unfortunately, it was already in my list of plug-in dependencies. My
> Java build path is pretty clean, actually. No required projects, no
> additional source, and my libraries are limited to the JRE (1.5.0_06,
> incidentally), JUnit 3.8.1 and Plug-in dependencies. Hmm...
>
> Nitin Dahyabhai wrote:
>> Robert Konigsberg wrote:
>>> Nitin,
>>>
>>> I am stuck once more. Unfortunately, if I start my first test with:
>>>
>>> IModelManager mgr = StructuredModelManager.getModelManager()
>>>
>>> but this results in a NullPointerException in getModelManager:
>>>
>>> "int state = localBundle.getState()";
>>>
>>> localBundle is not initialized (comes from
>>> Platform.getBundle(SSECorePlugin.ID))
>>>
>>> Now I have looked at some of the sample unit tests in the CVS
>>> respository, and tried to initialize my project in a similar way, but
>>> only resulting in yet more exceptions.
>>>
>>> Thoughts?
>>
>> The most likely reason is that you've added org.eclipse.wst.sse.core
>> to the Java Build Path, but not added it to your list of plug-in
>> dependencies.
>>
>> --
>> Nitin Dahyabhai
>> Structured Source Editor
Is there, by chance, someone who has a simple demo that creates an XML
document starting with the model manager? As I've mentioned, I've had
some strange trouble with this problem.
Thanks, Robert
|
|
|
Re: Creating an XML Document (and more) from an InputStream? [message #187541 is a reply to message #187149] |
Mon, 05 February 2007 17:20   |
Eclipse User |
|
|
|
Originally posted by: fakeaddress.brainkandy.org
Nitin, the other most likely reason is that I was running the test as a
junit JUnit Test and not a JUnit Plug-in Test. :)
Lesson learned. Thanks for your help; I am finally moving forward with
tests.
Robert
Robert Konigsberg wrote:
> Unfortunately, it was already in my list of plug-in dependencies. My
> Java build path is pretty clean, actually. No required projects, no
> additional source, and my libraries are limited to the JRE (1.5.0_06,
> incidentally), JUnit 3.8.1 and Plug-in dependencies. Hmm...
>
> Nitin Dahyabhai wrote:
>> Robert Konigsberg wrote:
>>> Nitin,
>>>
>>> I am stuck once more. Unfortunately, if I start my first test with:
>>>
>>> IModelManager mgr = StructuredModelManager.getModelManager()
>>>
>>> but this results in a NullPointerException in getModelManager:
>>>
>>> "int state = localBundle.getState()";
>>>
>>> localBundle is not initialized (comes from
>>> Platform.getBundle(SSECorePlugin.ID))
>>>
>>> Now I have looked at some of the sample unit tests in the CVS
>>> respository, and tried to initialize my project in a similar way, but
>>> only resulting in yet more exceptions.
>>>
>>> Thoughts?
>>
>> The most likely reason is that you've added org.eclipse.wst.sse.core
>> to the Java Build Path, but not added it to your list of plug-in
>> dependencies.
>>
>> --
>> Nitin Dahyabhai
>> Structured Source Editor
|
|
| |
Goto Forum:
Current Time: Fri Feb 07 09:14:08 GMT 2025
Powered by FUDForum. Page generated in 0.04036 seconds
|