XMLContext xmlContext = new XMLContext(contextPath, classLoader);
return new org.eclipse.persistence.jaxb.JAXBContext(xmlContext);
} catch (ValidationException vex) {
if(vex.getErrorCode() != ValidationException.NO_SESSIONS_XML_FOUND) {
//If something went wrong other than not finding a sessions.xml re-throw the exception
throw new JAXBException(vex);
}
} catch (Exception ex) {
throw new JAXBException(ex);
}
ArrayList classes = new ArrayList();
StringTokenizer tokenizer = new StringTokenizer(contextPath, ":");
while (tokenizer.hasMoreElements()) {
String path = tokenizer.nextToken();
try {
Class objectFactory = classLoader.loadClass(path + ".ObjectFactory");
if(isJAXB2ObjectFactory(objectFactory)) {
classes.add(objectFactory);
}
} catch (Exception ex) {
//if there's no object factory, don't worry about it. Check for jaxb.index next
}
try {
//try to load package info just to be safe
classLoader.loadClass(path + ".package-info");
} catch (Exception ex) {
}
//Next check for a jaxb.index file in case there's one available
InputStream jaxbIndex = classLoader.getResourceAsStream(path.replace('.', '/') + "/jaxb.index");
if (jaxbIndex != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(jaxbIndex));
try {
String line = reader.readLine();
while (line != null) {
String className = path + "." + line.trim();
try {
classes.add(classLoader.loadClass(className));
} catch (Exception ex) {
//just ignore for now if the class isn't available.
}
line = reader.readLine();
}
} catch (Exception ex) {
}
}
}
if(classes.size() == 0) {
throw new JAXBException(org.eclipse.persistence.exceptions.JAXBException.noObjectFactoryOrJaxbIndexInPath(contextPath));
}
Class[] classArray = new Class[classes.size()];
for (int i = 0; i < classes.size(); i++) {
classArray[i] = (Class) classes.get(i);
}