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)

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 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

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

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.

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

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.

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?