Search in sources :

Example 11 with Mapping

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();
    }
}
Also used : InputSource(org.xml.sax.InputSource) ODMContainer(org.akaza.openclinica.bean.submit.crfdata.ODMContainer) InputStream(java.io.InputStream) StringReader(java.io.StringReader) ResourceBundle(java.util.ResourceBundle) Mapping(org.exolab.castor.mapping.Mapping) Unmarshaller(org.exolab.castor.xml.Unmarshaller)

Example 12 with Mapping

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;
}
Also used : XMLContext(org.exolab.castor.xml.XMLContext) Mapping(org.exolab.castor.mapping.Mapping)

Aggregations

Mapping (org.exolab.castor.mapping.Mapping)12 XMLContext (org.exolab.castor.xml.XMLContext)9 IOException (java.io.IOException)6 Marshaller (org.exolab.castor.xml.Marshaller)5 Unmarshaller (org.exolab.castor.xml.Unmarshaller)5 StringWriter (java.io.StringWriter)4 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 ODMContainer (org.akaza.openclinica.bean.submit.crfdata.ODMContainer)3 MappingException (org.exolab.castor.mapping.MappingException)3 MarshalException (org.exolab.castor.xml.MarshalException)3 FileReader (java.io.FileReader)2 StringReader (java.io.StringReader)2 MessageFormat (java.text.MessageFormat)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2