private JAXBContextHelper() {
}
public static JAXBContext createJAXBContext(TransformationContext tContext, boolean source) throws JAXBException {
if (tContext == null)
throw new TransformationException("JAXB context is not set for the transformation.");
// FIXME: We should check the context path or classes
// FIXME: What should we do if JAXB is an intermediate node?
DataType<?> bindingContext = source ? tContext.getSourceDataType() : tContext.getTargetDataType();
String contextPath = (String) bindingContext.getMetadata(JAXB_CONTEXT_PATH);
JAXBContext context = null;
if (contextPath != null)
context = JAXBContext.newInstance(contextPath);
else {
Class[] classes = (Class[]) bindingContext.getMetadata(JAXB_CLASSES);
context = JAXBContext.newInstance(classes);
}
if (context == null)
throw new TransformationException("JAXB context is not set for the transformation.");
return context;
}