1 2 Previous Next 18 Replies Latest reply on Oct 12, 2007 5:48 PM by starksm64 Go to original post
      • 15. Re: @XmlElementWrapper/@XmlElements
        starksm64

        Right, I wanted @XmlElementWrapper to unwrap the module element and not have a wrapping Module class.

        • 16. Re: @XmlElementWrapper/@XmlElements
          jason.greene

          Ah Ok. For that We would need a spec (or proprietary) enhancment:
          @XmlElementWrapper(eachElement=true)

          You can do this with an adapter, but keep in mind this representation isn't a complete mapping to application.xml since you lose the alt-dd element.

          
          @XmlAccessorType(XmlAccessType.FIELD)
          @XmlType(name = "application")
          public class Foo2 {
           @XmlElement(required = true)
           @XmlJavaTypeAdapter(Adapter.class)
           public List<Component> module;
          
           @XmlAccessorType(XmlAccessType.FIELD)
           @XmlType(name = "")
           public static class Module {
           @XmlElements({
           @XmlElement(name="connector", type=Connector.class),
           @XmlElement(name="java", type=Java.class)
           })
           public Component component;
          
           @XmlElement(name="alt-dd")
           public String altDD;
           }
           public static interface Component
           {
           }
          
           public static class Connector implements Component
           {
           }
          
           public static class Java implements Component
           {
           }
          
           public static class Adapter extends XmlAdapter<Module, Component>
           {
          
           public Component unmarshal(Module module)
           {
           return module.component;
           }
          
           public Module marshal(Component component)
           {
           return null;
           }
           }
          }
          


          -Jason

          • 17. Re: @XmlElementWrapper/@XmlElements
            jason.greene

             

            "jason.greene@jboss.com" wrote:
            Ah Ok. For that We would need a spec (or proprietary) enhancment:
            @XmlElementWrapper(eachElement=true)

            You can do this with an adapter, but keep in mind this representation isn't a complete mapping to application.xml since you lose the alt-dd element.


            To clarify what I mean, even if XmlElementWrapper supported this, it doesnt conform to the schema because of alt-dd. The following legal xml would cause a failure:

            <module>
             <connector>mq.jar</connector>
             <alt-dd>foo/alt.xml</alt-dd>
            </module>
            


            Using the adapter like above though you could map this property to an attribute on the Connector type.

            -Jason

            • 18. Re: @XmlElementWrapper/@XmlElements
              starksm64

              Yes, and there is also the id attribute on the module. We did end up using a module wrapper with this info in the metadata project.

              1 2 Previous Next