Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (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 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 2341
Registered: July 2009
Senior Member
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 WTP, IBM
Re: Creating an XML Document (and more) from an InputStream? [message #186750 is a reply to message #186691] Mon, 22 January 2007 19:05 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 2341
Registered: July 2009
Senior Member
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 WTP, IBM
Re: Creating an XML Document (and more) from an InputStream? [message #187149 is a reply to message #187069] Fri, 26 January 2007 19:18 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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
Service Startup [message #188308 is a reply to message #187149] Tue, 20 February 2007 13:16 Go to previous message
Mirza Hadzic is currently offline Mirza HadzicFriend
Messages: 19
Registered: July 2009
Junior Member
Hello,

Is there any "standard" way of implementing startup functions for
WTP/Tomcat? I need to do some stuff on startup *before* service becomes
available. I am using bottom-um generated services and would prefere
solution where startup code is not overwritten each time I re-generate
services. Any toughts?

Thx
Previous Topic:out of sync using a vfat filesystem?
Next Topic:Announcing WTP 1.5.3
Goto Forum:
  


Current Time: Thu Dec 18 23:11:02 GMT 2014

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

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