I just copied an XSD file from somewhere:
FileName: unknowntest.xsd (some problem with blogger, not able to take xml code :D, so pasting the image)
Usage: xjc [-options ...]
parsing a schema...
compiling a schema...
generated\Country.java
generated\ObjectFactory.java
Ah I got 2 Java files yeppp - Country.java and ObjectFactory.java
Look at these 2 files ( I am removing the documentation part of it, to make it small)
package generated;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"name",
"pop"
})
@XmlRootElement(name = "country")
public class Country {
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected BigDecimal pop;
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the pop property.
*
* @return
* possible object is
* {@link BigDecimal }
*
*/
public BigDecimal getPop() {
return pop;
}
/**
* Sets the value of the pop property.
*
* @param value
* allowed object is
* {@link BigDecimal }
*
*/
public void setPop(BigDecimal value) {
this.pop = value;
}
}
and objectFactory don't have too much in it. Just creating a Country class instance. Oh so it is something cool, its making all the getter and setter method for me, what else I need :).
Remember, such type of methods are too much in demand when you are writing any jsp page. So, if you are clear with the data type, just make an xsd file and xjc will convert in into java code.
I still doubt what xjc refers for ... may be xml to java converter :)
7 comments:
this has made me laugh,
we needed exactly this for our project, and we did it through XML beans, good u explored, next time i'll use this.
Ha ha ha !
Ya I guess this is one of the most common demands, really surprised that I am not getting any document for it.
check out Jikes, it is a java compiler with a difference.
Check my post on it.
What do IDEs use for generating the getter and setter methods? XML Beans? and I think it should be pretty basic because this feature has been present in most of the IDEs since quite long. Even my dear Dr.Java :)
I guess Mustang is no more official name of JDK6
Is it official?
Why in the hell, BTW?
yes no idea.. but they have remove mutang from official name and declared it to be jdk6 only.
Yes Abhishek, it should be present in jdk older versions also
Post a Comment