6 Replies Latest reply on Apr 18, 2008 2:29 PM by jyrinx

    Customizing XJC invocation?

      We have an XJC plugin we very much need to use, but I don't see any way of changing the XJC command line used by wsconsume. Is it possible to use XJC plugins with JBoss WS?

      (I saw a post from a year ago asking this question, but evidently the answer has changed, as wsconsume no longer appears to be a thin wrapper around wsimport.)

        • 1. Re: Customizing XJC invocation?
          ropalka

           

          "jyrinx" wrote:
          Is it possible to use XJC plugins with JBoss WS?
          No :(

          • 2. Re: Customizing XJC invocation?

             

            "richard.opalka@jboss.com" wrote:
            "jyrinx" wrote:
            Is it possible to use XJC plugins with JBoss WS?
            No :(


            Hrm ... that's saddening. Can anyone think of a good hack here?

            Well, let me explain the problem: We have a Web service that returns objects of an abstract class. So long as we put @XmlSeeAlso on the superclass, the WSDL comes out fine, and the XML elements have xsi:type attributes, and all is well on the server side. (We're using JBoss WS on both the client and server.)

            But then we try out our test client, and we keep getting InstantiationExceptions when JAXB fails to resolve the entities to their concrete subclass and tries to instantiate the abstract superclass. We realized that if we modified the generated code to include @XmlSeeAlso annotations mirroring those on the server side, everything worked. So the question is one of getting those annotations into the client code.

            (We could put dummy methods with the concrete subclasses as argument types into the Web service just to force all the subclasses into the JAXBContext, but we'd rather not ...)

            So this is all quite solvable with an XJC plugin: It has all the information it needs to write the annotations, and the ideal interface to add them to the generated classes. (The plugin class is about 30 LOC.) If there's some way to get that to work, that would be best. Otherwise, we're going to have to resort to much cruder means of post-processing (or the aforementioned dummy methods).

            (There's also this <xjc:substitutable/> thing, but honestly I'm not sure how we'd make use of it: it has to go in the generated schema somehow?)

            And besides, there are other very useful XJC plugins - the one that adds toString() methods, for instance, would be very convenient.

            • 3. Re: Customizing XJC invocation?
              ropalka

              Please read the following doc:

              http://wiki.jboss.org/wiki/JAXBIntroductions

              It allows you to do some JAXB customizations and it's config driven. Maybe you will be able to solve your usecase. JBossWS support jaxbintros feature. There are also some tests available in JBossWS source distribution so you can take a look there.

              If you will be able to find the solution that solves your usecase we would be very pleased if you would document it in our Wiki ;)

              • 4. Re: Customizing XJC invocation?
                heiko.braun

                No, JAXBIntrods is something different. I guess what you are asking for is
                http://weblogs.java.net/blog/kohsuke/archive/2005/06/writing_a_plugi.html, right?

                • 5. Re: Customizing XJC invocation?

                   

                  "richard.opalka@jboss.com" wrote:
                  Please read the following doc:

                  http://wiki.jboss.org/wiki/JAXBIntroductions

                  It allows you to do some JAXB customizations and it's config driven. Maybe you will be able to solve your usecase. JBossWS support jaxbintros feature. There are also some tests available in JBossWS source distribution so you can take a look there.


                  Hrm ... if one could sneak an <xjc:substitutable/> element into the schema that way, that'd be great. I'm guessing from the wiki, though, that Introductions only hooks into schemagen as an alternate annotation reader; can it then do anything an annotation can't? (Otherwise, I don't think Introductions applies here (slick tool nonetheless), since we control all the relevant classes on the server side and can annotate them the old-fashioned way.)

                  • 6. Re: Customizing XJC invocation?

                     

                    "heiko.braun@jboss.com" wrote:
                    No, JAXBIntrods is something different. I guess what you are asking for is
                    http://weblogs.java.net/blog/kohsuke/archive/2005/06/writing_a_plugi.html, right?


                    Yes yes, that. The problem is I can't add the option ("-Xinject-code" in his example) to the XJC command line, thereby activating the plugin. (Come to think of it, XJC should just let plugins be activated by a registered customization element ... this is Java, land of XML everything :-) )