I think you could get around this by using a test-method for each of the choices (isPrimitiveType(), isDataType(), isActivityType()) on the containing object, but doing this may be more trouble than it's worth to you. That's the only approach that comes to mind, anyway.

- Dennis

Guillaume Pothier wrote:

This works well for unmarshalling, but for marshalling I get a ClassCastException:
Caused by: java.lang.ClassCastException
at com.redcrea.ina.core.type.Type.JiBX_all_bindings_marshal_1_0(Type.java)
at com.redcrea.ina.core.type.JiBX_all_bindingsType_access.marshal()
at com.redcrea.ina.core.type.Type.marshal(Type.java)
at org.jibx.runtime.impl.MarshallingContext.marshalRoot(MarshallingContext.java:907)
at org.jibx.runtime.impl.MarshallingContext.marshalDocument(MarshallingContext.java:977)
at com.redcrea.ina.tools.jibx.Binder.marshall(Binder.java:72)
at com.redcrea.ina.test.TestTypeBindings.main(TestTypeBindings.java:28)
... 5 more


Which seems logical as JiBX will try to cast my TypeStrategy (which is an interface) into the first concrete class appearing in the binding definition...



Dennis Sosnoski wrote:


For now the best you can do is make them all optional - which means you won't get an error if none or more than one are present in the XML, but at least will handle the case of proper XML input. <xs:choice> does seem worth supporting directly, and I'll enter an enhancement item to add support for this in beta 4. That's not a guarantee it'll be there, but I'll at least look into it.

- Dennis

Guillaume Pothier wrote:



I have an element defined as follows:
<xs:complexType name="TType">
   <xs:choice>
       <xs:element name="primitiveType" type="TPrimitiveType"/>
       <xs:element name="dataType" type="TDataType"/>
       <xs:element name="activityType" type="TActivityType"/>
       (...)
   </xs:choice>
</xs:complexType>

Other binding frameworks (JAXB, and from what I understood a a previous post in this list, Castor as well) usually generate classes with a structure like this:
class Type
{
private PrimitiveType itsPrimitiveType;
private DataType itsDataType;
private ActivityType itsActivityType;
(...)
}


with only one of these fields having a non-null value.

But I have a class like this:
class Type
{
   private TypeStrategy itsStrategy;
}

PrimitiveType, DataType and ActivityType... implementing TypeStrategy.

I did not find a way to define a mapping for this kind of element. Right now, I am solving it with a custom marshaller/unmarshaller. This is not complicated at all, but I would prefer to avoid that.
Did I miss something and is there already a way to define such a binding in xml?
Or is it planned to support that kind of bindings?


Guillaume






------------------------------------------------------- This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek For a limited time only, get FREE Ground shipping on all orders of $35 or more. Hurry up and shop folks, this offer expires April 30th! http://www.thinkgeek.com/freeshipping/?cpg=12297 _______________________________________________ jibx-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to