Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Generating classes from XSD with restrictions  RSS feed

 
Vadim Tarantin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day everyone.

I have XSD some like this:


I use maven-jaxb22-plugin to generate DTO classes and after generating a I have some like this:




So I have in ABC all fields (and getters/setters) defined in ABCType. I'd like to generate ABC class with field described in restriction scope in XSD only. Is it possible?
 
L Foster
Ranch Hand
Posts: 242
14
Android Angular Framework AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, John:
I don't quite get what you are asking here, sorry.  Do you mean you would like to avoid autogenerating the ABCType class at all?

Also, not sure how important this is, but you have a typo.  A missing quote when you try to name the element "XYZ".  Probably, this is not the actual code, though.  ;-)
 
Vadim Tarantin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Foster. Thank you for your answer. Allow me explain my question.

I have ABCType class after generating:



and I have ABC class also:



I'd like class ABC wasn't be extends ABCType.

In some class I can do:



Why I want to do this - because after setting DTO by field defined in the parent I have a validation error after marshaling.

Can I generate ABC class without extends? Or to do protected fields to private in ABCType And I cannot change XSD.

 
g tsuji
Ranch Hand
Posts: 697
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the schema is itself already incorrect, it would be misleading to speculate on the resultant of code generation by schema compilation. The schema on the element ABC could not be correct. How about you correct the schema first before considering anything else?
 
L Foster
Ranch Hand
Posts: 242
14
Android Angular Framework AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, again, Vadim:

G Tsuji is indeed correct that speculation is futile if the schema is incomplete (perhaps 'G' is referring to the missing double quote?).  However, one thing I would try if I were that worried about class proliferation, is to focus on tag proliferation.  See if you can express the definition for the ABC element without referring to another tag.  Don't have it use a restriction base at all.  You should also try and find a good document on what rules are followed in creating these classes from schema.

This may or may not help.  https://svn.java.net/svn/maven-jaxb2-plugin~svn/tags/0.6.3/www/docs/guide.html

Now, if you deliberately construct your schema so that you are not using restriction bases, you could wind up making a lot of redundant XML (and probably a lot of redundant Java).  There are reasons for the use of base classes, after all.

I hope that helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!