Skip to main content

@Generated - preserving user code - is it supported?

7 replies [Last post]
mspitzer
Offline
Joined: 2006-10-09

I found the excerpt below, in italics, from the JAXB 2.0 Final Revision specification. It seems to state that there should be a way to generate JAXB classes from a schema and have the properties and methods tagged if the correct argument is supplied to the compiler. I didn't see any support for this in xjc. Is it there? Will it be there?

I didn't want to have to modify the generated source but I'm finding that I need to add some interfaces implementations to a couple of classes that get generated and I don't want to risk the code getting overwritten.

A schema compiler must have an option to generate the Common Annotation,
@javax.annotation.Generated annotation, specified in [CA], on every
generated class, method and field. If a developer does modify an @Generated
annotated method or field, they must denote this modification by deleting the
@Generated annotation. If a developer adds a new method or field, it will not
have an @Generated annotation on it. Based on these conventions, a JAXB
implementation in conjunction with an IDE or other external tool, would be able
to support regeneration of schema-derived code while preserving developer
additions/modifications to methods and fields in a schema-derived class.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mspitzer
Offline
Joined: 2006-10-09

2 things.

1) I've downloaded the simple generator and plan to make a pass at using it soon.
2) That being said, I also want to generate code with the @Generated tag so I leverage what's in the spec. Not sure how I missed that option from xjc before but I see it now. When I use it I get compilation errors because there is no supporting annotation class. Shouldn't there be one in one of the jaxb libraries (jars)?

mspitzer
Offline
Joined: 2006-10-09

Okay, I just answered my own question. It's available in Java EE 5, which I'm unfortunately not able to use yet. I'm stuck using JAXB2 with the old JAX-RPC in Java EE 4. I also see that it'll be in Java SE 6, but that's even farther away for us since we use WebSphere.

kohsuke
Offline
Joined: 2003-06-09

I think you can download common annotations jar from JCP website separately, outside EE5.

mspitzer
Offline
Joined: 2006-10-09

Cool! I'll look into it. Is this something that xjc will honor in addition to the simple-preserve option that you provide today via a plug-in?

Message was edited by: mspitzer

kohsuke
Offline
Joined: 2003-06-09

There has been some discussion about having XJC natively recognize @Generated in some ways. But it doesn't do that today, and there's no plan to do something like this in near future.

kohsuke
Offline
Joined: 2003-06-09

The only support for @Generated in XJC today is to generate code with @Generated.

Sounds like you might be interested in this: https://jaxb2-commons.dev.java.net/simple-regenerator/

mspitzer
Offline
Joined: 2006-10-09

You're the man! Thanks I'll check it out first thing in the morning. That might save me a ton of time.