jaxb bindings add variables to generated classes - jaxb

I have a set of schemas that I generate JAXB classes from and I would like JAXB to add a new property to one of the classes for an element that doesn't exist in the schema. How can I do this?

Related

ObjectFactory Class from Java Beans

Can anyone please tell how to generate the ObjectFactory class from some Java beans ? Remember , I dont have the xsd and hence I cannot use JAXB for the same.
The only class generation that JAXB (JSR-222) implementations do is from XML schema. When starting from Java classes you just need to create a class and annotate it #XmlRegistry. You will need to include this class in the array of classes used to bootstrap the JAXBContext. The main reason for doing this is to leverage the #XmlElementDecl annotation to associated multiple root elements with a class. Is this what you are trying to do?

Finding JAXB generated class for root element

I am new to using JAXB. I need to generate an xml file from its schema, where the schema and element values are input from the user.
My problem is, if I don't know the name of the elements beforehand, how can I use the JAXB generated classes? Is there a generic function, like getRoot() or getChildren() which I can use to traverse through the classes?

Can xsd.exe's generated classes identify required attributes

Is it possible to have xsd.exe add "IsNullable=false" to XmlAttributes for fields/properties that are defined in the schema as being required?
Xjc adds it to the Java annotation, but I haven't found a way to get Xsd.exe to do something similar.
I'm trying to use reflection to do a merge of our configuration files that isn't configuration file type dependent. I want to use the required attributes of an element to determine if that element exists in both files or just one.

How do I make more complex XSDs using JAXB?

Using JAXB I can create an XSD using code like:
JAXBContext ctx = JAXBContext.newInstance(classes);
ctx.generateSchema(new MySchemaOutputResolver());
That makes a goods XSD describing the structure of all the JAXB objects in the list of classes I pass in, however, I can't figure out how to add other types of XSD restrictions like minOccurs, maxOccurs, pattern, etc.
Is it possible to add annotations which indicate that additional information so that the XSD will include it?
You can use the #XmlElement(required = true) annotation to make an item required. Similar annotations exist for repetition, etc.
See here for annotation classes, the Javadoc has details.

Element Defaulting using JAXB

I am trying to use JAXB 1.0 provided by JDeveloper 10g version. I have created a Schema definition with elements having default values.
I have following questions:
Whenever I create the Java Content tree using the JAXB generated classes, the java objects should have been created with the default values mentioned in the XML schema. But it doesn't happen. How to make JAXB create the Java objects of an XML document with default values of the elements?
I am trying to add the schemalocation to the marshalled XML document using Marshaller.setProperty( Marshaller.JAXB_SCHEMA_LOCATION, "http://mylocation"); But its not getting reflected in the marshalled XML content.
Have a look at JAXB default value plugin. Some nice additional plugins are mentioned here.

Resources