hi,

v.soloist schrieb:
Hello,
i am trying to unmarshall an xml file using castor mapping to my jaxb2 generated sources. the xml is deformed in some way that i cannot use jaxb2 unmarshalling directly. I saw a project proposal about supporting jaxb2 types but i assume it is quite new and could not see any source code about that.

I'm working on the jaxb2 integration project this summer and accidentally on the enum types at the moment. Apart from the jaxb2 annotations, the current castor branch supports the enum type in some ways (maybe you have some special situation that is not covered).

I wrote a small test yesterday and unmarshalling the following works:

   <xsd:element name="root">
     <xsd:complexType>
       <xsd:sequence>
        <xsd:element name="state" type="USState"/>
       </xsd:sequence>
     </xsd:complexType>
   </xsd:element>

   <xsd:simpleType name="USState">
      <xsd:restriction base="xsd:NCName">
      <xsd:enumeration value="AK"/>
      <xsd:enumeration value="AL"/>
    </xsd:restriction>
  </xsd:simpleType>

public class Root {
  private USState state;
  public void setUSState(..)..
  public USState getUSState()
}

public enum USState{
   AK,AL;
}

input file:

<root>
  <state>AL</state>
</root>

output:

Root root = (Root) unmarshaller.unmarshal(inputSource);
System.out.println(root.getState()); -> "AL"

Maybe you can reduce your problem to just the parent class and the enum, in addition with a simple input file and detailed information about your setting (castor version, binding file yes/no, ... ), and attach it to a new jira issue at http://jira.codehaus.org/.

Then I can try to reproduce your problem and give you more competent feedback.

Regards

Matthias

Actually the only problem in my case seems to be the
enumeration types of jaxb2.
i tried using custom handlers for this type but as far as i can understand from the examples,the value from the xml needs to be casted to the original object first and then processed for formatting and such.This is the class that i cannot map to

public enum MyEnum {
@XmlEnumValue("2")
    TWO("2");
    private final String value;
MyEnum(String v) {
        value = v;
    }

    public String value() {
        return value;
    }
public MyEnum setValue(String x) {
        return this.fromValue(x);
    }
public static MyEnum fromValue(String v) {
        for (MyEnum c: MyEnum.values()) {
            if (c.value.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException(v);
    }
}

i tried to create a class with just a string value and casting the xml value to this but i could not convert it back with the custom handler and add it to the parent object that is going to be unmarshalled. Am i missing something here? Any pointers would be helpful,
Thanks is advance,


---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to