XmlCursor cursor = xmlObject.newCursor();
XmlCursor moveable = xmlObject.newCursor();
try {
cursor.toFirstChild();
if ("http://java.sun.com/xml/ns/j2ee".equals(cursor.getName().getNamespaceURI())) {
XmlObject result = xmlObject.changeType(EjbJarDocument.type);
validateDD(result);
return (EjbJarDocument) result;
}
XmlDocumentProperties xmlDocumentProperties = cursor.documentProperties();
String publicId = xmlDocumentProperties.getDoctypePublicId();
String cmpVersion;
if ("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN".equals(publicId)) {
cmpVersion = "1.x";
} else if ("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN".equals(publicId)) {
cmpVersion = null;//2.x is the default "2.x";
} else {
throw new XmlException("Unrecognized document type: " + publicId);
}
String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
String version = "2.1";
convertToSchema(cursor, J2EE_NAMESPACE, schemaLocationURL, version);
//play with message-driven
cursor.toStartDoc();
convertBeans(cursor, moveable, cmpVersion);
} finally {
cursor.dispose();
moveable.dispose();
}
XmlObject result = xmlObject.changeType(EjbJarDocument.type);
if (result != null) {
validateDD(result);
return (EjbJarDocument) result;
}
validateDD(xmlObject);