how do I convert a java class to a xsd String using java
I have a java class AsOfDate.java, which I am trying to convert it to XSD
String and display the contents. The problem is with the returning it as a
String. Please suggest easier mechanisms which take a class name as a
input and returns a XSD in String format.
Please find below the class details and the code I used for conversion of
the class to XSD. JAXB SchemaOutputResolver seems to convert it but it
converts it to StreamResult. I am not able to convert it to String and
return it as a String type.
public class AsOfDate extends HrdhDatedEntry {
/**
*/
private static final long serialVersionUID = -193670018802945645L;
@NotEmpty
@Size(max = ValidationConstants.MAX_LENGTH_10)
private String asOfD;
@NotEmpty
@Size(max = ValidationConstants.MAX_LENGTH_10)
private String status;
/**
* Get the as of d.
*
* @return as of d
*/
public String getAsOfD() {
return asOfD;
}
/**
* Set the as of d.
*
* @param asOfD The as of d
*/
public void setAsOfD(String asOfD) {
this.asOfD = asOfD;
}
/**
* Get the status.
*
* @return status
*/
public String getStatus() {
return status;
}
/**
* Set the status.
*
* @param status The status
*/
public void setStatus(String status) {
this.status = status;
}
}
Can someone tell me a simple java program which passes the class name as a
parameter and it spits out an XSD as a String.
I do have a program which does convert
public static void returnXsd(Class clazz, String namespaceUri, String
suggestedFileName) throws JAXBException, IOException {
//StreamResult result = null;
JAXBContext jc = JAXBContext.newInstance(clazz);
jc.generateSchema(new SchemaOutputResolver() {
@Override
public Result createOutput(String namespaceUri, String
suggestedFileName)
throws IOException {
StreamResult result = new StreamResult(System.out);
result.setSystemId(suggestedFileName);
return result;
}
});
}
but this stores the result in Result object. And I am trying to modify
this to return a String output. Any good suggestions.
No comments:
Post a Comment