I'm trying to map a
class that has only one, static, element, which is a HashMap from String to
another class.
I have the following
binding file:
<binding name="help" value-style="attribute">
<mapping name="help-services"
class="com.quest.wcf.core.services.HelpServices">
<structure field="help"
marshaller="org.jibx.extras.HashMapperStringToComplex"
unmarshaller="org.jibx.extras.HashMapperStringToComplex"/>
</mapping>
<structure field="help"
marshaller="org.jibx.extras.HashMapperStringToComplex"
unmarshaller="org.jibx.extras.HashMapperStringToComplex"/>
</mapping>
<mapping
name="help-reference"
class="com.quest.wcf.core.services.HelpReference">
<value name="url" field="URL"/>
<value name="map-id" field="mapId"/>
</mapping>
class="com.quest.wcf.core.services.HelpReference">
<value name="url" field="URL"/>
<value name="map-id" field="mapId"/>
</mapping>
</binding>
Here is the core
part of the HelpServices class:
public class
HelpServices {
private static
HashMap help = new HashMap();
}
}
The mapped objects
are HelpReferences, and the keys are Strings. Here is the core part of the
HelpReference class:
public class
HelpReference {
private String URL;
private int mapId;
}
private int mapId;
}
When jibxbind runs,
I'm getting the following error message:
java.lang.IllegalStateException: Internal error: Expected
java.util.HashMap on stack, found
com.quest.wcf.core.services.HelpServices
full stack:
0: com.quest.wcf.core.services.HelpServices
1: com.quest.wcf.core.services.HelpServices
full stack:
0: com.quest.wcf.core.services.HelpServices
1: com.quest.wcf.core.services.HelpServices
Any bright ideas on
what I'm doing wrong? Does it have anything to do with the fact that the HashMap
element is static? It's really only the HashMap element that I want to marshall
/ unmarshall, since the class isn't even intended to have any
instances.
WAIT ... I'm trying
something different. Now my binding is as follows, and jibxbind works
OK:
<binding
name="help" value-style="attribute">
<mapping name="help"
class="java.util.HashMap"
marshaller="org.jibx.extras.HashMapperStringToComplex"
unmarshaller="org.jibx.extras.HashMapperStringToComplex"/>
marshaller="org.jibx.extras.HashMapperStringToComplex"
unmarshaller="org.jibx.extras.HashMapperStringToComplex"/>
<mapping name="help-reference"
class="com.quest.wcf.core.services.HelpReference">
<value name="url" field="URL"/>
<value name="map-id" field="mapId"/>
</mapping>
class="com.quest.wcf.core.services.HelpReference">
<value name="url" field="URL"/>
<value name="map-id" field="mapId"/>
</mapping>
</binding>
But when I run the
following code:
private static
HashMap help = new HashMap();
static
{
try {
IBindingFactory bfact = BindingDirectory.getFactory(HashMap.class);
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.setIndent(4);
mctx.marshalDocument(help, "UTF-8", null,
new FileOutputStream("HelpReferences.xml"));
try {
IBindingFactory bfact = BindingDirectory.getFactory(HashMap.class);
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.setIndent(4);
mctx.marshalDocument(help, "UTF-8", null,
new FileOutputStream("HelpReferences.xml"));
}
catch (JiBXException je) {
System.out.println("JiBXException marshalling HelpReferences: " +
je.getMessage());
}
catch (FileNotFoundException fnfe) {
System.out.println("FileNotFoundException marshalling HelpReferences: " +
fnfe.getMessage());
}
}
catch (JiBXException je) {
System.out.println("JiBXException marshalling HelpReferences: " +
je.getMessage());
}
catch (FileNotFoundException fnfe) {
System.out.println("FileNotFoundException marshalling HelpReferences: " +
fnfe.getMessage());
}
}
what happens is the
JiBXException is thrown, with the message:
Unable to access binding information for class
java.util.HashMap
Make sure the binding has been compiled
Make sure the binding has been compiled
Any bright ideas
about that? Which approach is more correct?
Thanks.
Dan Cooperstock, Senior Software
Developer, Quest Software
[EMAIL PROTECTED]
416-933-5165
