Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename generated XmlElements method to getContent #158

Closed
baronnoraz opened this issue Sep 18, 2018 · 2 comments
Closed

Rename generated XmlElements method to getContent #158

baronnoraz opened this issue Sep 18, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@baronnoraz
Copy link

It might be better to ask this on Stack Overflow, but I didn't see anything there or here.

I'm using the plugin to create Java Classes from a DTD. Everything is working. However, I have to conform to some "standards" that I can't seem to figure out how to do with the maven-jaxb2-plugin. I think it might be some change from JAXB 1 to 2 or something, but I can't figure out how to configure the plugin correctly to comply.

Given a DTD element like...

<!ELEMENT FOLDER (FOLDERVERSION| CONFIG| SCHEDULER)*>

The previous code would generate a Java class with a generic getContent method.

    @XmlElements({
        @XmlElement(name = "FOLDERVERSION", type = FOLDERVERSION.class),
        @XmlElement(name = "CONFIG", type = CONFIG.class),
        @XmlElement(name = "SCHEDULER", type = SCHEDULER.class)
    })
    protected List<Object> content;

    public List<Object> getContent() {
        if (content == null) {
            content = new ArrayList<Object>();
        }
        return this.content;
    }

However, using version 0.14.0 of the maven-jaxb2-plugin generates the following...

    @XmlElements({
        @XmlElement(name = "FOLDERVERSION", type = FOLDERVERSION.class),
        @XmlElement(name = "CONFIG", type = CONFIG.class),
        @XmlElement(name = "SCHEDULER", type = SCHEDULER.class)
    })
    protected List<Object> folderversionOrCONFIGOrSCHEDULER;

    public List<Object> getFOLDERVERSIONOrCONFIGOrSCHEDULER() {
        if (folderversionOrCONFIGOrSCHEDULER == null) {
            folderversionOrCONFIGOrSCHEDULER = new ArrayList<Object>();
        }
        return this.folderversionOrCONFIGOrSCHEDULER;
    }

How can I rename the generic choice method that's getting created?

@highsource
Copy link
Owner

highsource commented Sep 19, 2018

You should really better ask this on StackOverflow.

This is not directly related to the maven-jaxb2-plugin so I'll close the issue. Backwards incompatibility might have been introduced by the newer version of XJC which maven-jaxb2-plugin now uses.

But here are a few hints.

I haven't touched DTD in ages, but DTD compilaton also support bindings to some extent. Google "xml-java-binding-schema", you will find a bit of documentation.

Unfortunately, seems like generated choice properties cannot be customized this way:

https://stackoverflow.com/questions/18667358/jaxb-binding-schema-of-dtd-file

If I had this problem I would probably think of:

  • converting DTD to XML Schema;
  • if the only problem is the backwards compatibility, I'd add getContent method using code injector plugin;
  • if I were me and had some spare time, I'd write an XJC plugin which could rename properties. This is not straightforward, but possible.

@highsource highsource self-assigned this Sep 19, 2018
@highsource highsource added this to the 0.14.x milestone Sep 19, 2018
@baronnoraz
Copy link
Author

Thanks for the pointers and advice!

laurentschoelens pushed a commit to laurentschoelens/jaxb-tools that referenced this issue May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants