use of org.exolab.castor.mapping.Mapping in project OpenClinica by OpenClinica.
the class DataEndpoint method unmarshallToODMContainer.
private ODMContainer unmarshallToODMContainer(Element odmElement) throws Exception {
ResourceBundle respage = ResourceBundleProvider.getPageMessagesBundle();
String xml = node2String(odmElement);
xml = xml.replaceAll("<ODM>", this.ODM_HEADER_NAMESPACE);
if (xml == null)
throw new Exception(respage.getString("unreadable_file"));
Mapping myMap = new Mapping();
// InputStream xsdFile = coreResources.getInputStream("ODM1-3-0.xsd");//new File(propertiesPath + File.separator
// + "ODM1-3-0.xsd");
// InputStream xsdFile2 = coreResources.getInputStream("ODM1-2-1.xsd");//new File(propertiesPath +
// File.separator + "ODM1-2-1.xsd");
InputStream mapInputStream = coreResources.getInputStream("cd_odm_mapping.xml");
myMap.loadMapping(new InputSource(mapInputStream));
Unmarshaller um1 = new Unmarshaller(myMap);
ODMContainer odmContainer = new ODMContainer();
try {
LOG.debug(xml);
// File xsdFileFinal = new File(xsdFile);
// schemaValidator.validateAgainstSchema(xml, xsdFile);
// removing schema validation since we are presented with the chicken v egg error problem
odmContainer = (ODMContainer) um1.unmarshal(new StringReader(xml));
LOG.debug("Found crf data container for study oid: " + odmContainer.getCrfDataPostImportContainer().getStudyOID());
LOG.debug("found length of subject list: " + odmContainer.getCrfDataPostImportContainer().getSubjectData().size());
return odmContainer;
} catch (Exception me1) {
// fail against one, try another
me1.printStackTrace();
LOG.debug("failed in unmarshaling, trying another version = " + me1.getMessage());
// }
throw new Exception();
}
}
use of org.exolab.castor.mapping.Mapping in project camel by apache.
the class AbstractCastorDataFormat method createXMLContext.
protected XMLContext createXMLContext(ClassResolver resolver, ClassLoader contextClassLoader) throws Exception {
XMLContext xmlContext = new XMLContext();
if (ObjectHelper.isNotEmpty(getMappingFile())) {
Mapping xmlMap;
if (contextClassLoader != null) {
xmlMap = new Mapping(contextClassLoader);
} else {
xmlMap = new Mapping();
}
xmlMap.loadMapping(resolver.loadResourceAsURL(getMappingFile()));
xmlContext.addMapping(xmlMap);
}
if (getPackages() != null) {
xmlContext.addPackages(getPackages());
}
if (getClassNames() != null) {
for (String name : getClassNames()) {
Class<?> clazz = resolver.resolveClass(name);
xmlContext.addClass(clazz);
}
}
return xmlContext;
}
Aggregations