diff --git a/ch.psi.fda/.classpath b/ch.psi.fda/.classpath index 2da5706..a37deec 100644 --- a/ch.psi.fda/.classpath +++ b/ch.psi.fda/.classpath @@ -28,7 +28,7 @@ - + diff --git a/ch.psi.fda/.settings/org.eclipse.jdt.core.prefs b/ch.psi.fda/.settings/org.eclipse.jdt.core.prefs index 60105c1..ec4300d 100644 --- a/ch.psi.fda/.settings/org.eclipse.jdt.core.prefs +++ b/ch.psi.fda/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/ch.psi.fda/pom.xml b/ch.psi.fda/pom.xml index 6630f3d..f392a4f 100644 --- a/ch.psi.fda/pom.xml +++ b/ch.psi.fda/pom.xml @@ -73,8 +73,9 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 + UTF-8 + 1.7 + 1.7 diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionMain.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionMain.java index 5feeb73..cf5f2ad 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionMain.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/AcquisitionMain.java @@ -216,13 +216,7 @@ public class AcquisitionMain { Configuration c; try { - if(file.getName().endsWith(".xsl")){ - c = ModelManager.unmarshall(file, variables); - } - else{ - c = ModelManager.unmarshall(file); - } - + c = ModelManager.unmarshall(file); } catch (Exception e) { throw new RuntimeException("Unable to deserialize configuration: "+e.getMessage(), e); } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java b/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java index 1cd559f..e2e831f 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java @@ -19,11 +19,7 @@ package ch.psi.fda.model; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.IOException; -import java.util.HashMap; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; @@ -32,13 +28,7 @@ import javax.xml.bind.Marshaller; import javax.xml.bind.UnmarshalException; import javax.xml.bind.Unmarshaller; import javax.xml.namespace.QName; -import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; @@ -47,95 +37,18 @@ import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import ch.psi.fda.model.v1.Configuration; -//import ch.psi.fda.model.v1.Data; /** - * Manage the serialization and deserialization of the model + * Manage the serialization and deserialization of the FDA data model * @author ebner * */ public class ModelManager { /** - * Deserialize an instance of a data model of the type Configuration - * Before creating the object model variables will be replaced + * De-serialize an instance of the FDA data model * - * @param file Scan file - * @param variables Scan variables - * @throws JAXBException Something went wrong while unmarshalling - * @throws SAXException Cannot read model schema file - * @throws ParserConfigurationException - * @throws IOException - * @throws TransformerFactoryConfigurationError - * @throws TransformerException - */ - public static Configuration unmarshall(File file, HashMap variables) throws JAXBException, SAXException, IOException, - ParserConfigurationException, TransformerFactoryConfigurationError, TransformerException { - - // Load template file - Transformer xformer = TransformerFactory.newInstance().newTransformer(new StreamSource(file)); - // Overwrite parameters - for(String key: variables.keySet()){ - xformer.setParameter(key, variables.get(key)); - } - - - // Workaround for complex parameters (parameter including xml fragments) - // How the workaround works: - // Because we want to set complex parameters we first have to apply the xslt transformation to the input - // stream and create an other output stream. In the template file the complex parameter must be referenced as follows - // - // If it is not done this way the < and > of the tags will be replaced by < and > - // Also if we directly transform to a DOMResult the dom tree would not include the - // nodes added by the parameter but just a text object. Therefor we do the workaround via the StreamResult ... - ByteArrayOutputStream bstream = new ByteArrayOutputStream(); - StreamResult sresult = new StreamResult(bstream); - - - // Perform transformation (using template file also as input source) - xformer.transform(new StreamSource(file), sresult ); - - - // Workaround for complex parameters - ByteArrayInputStream bistream = new ByteArrayInputStream(bstream.toByteArray()); - StreamSource bsource = new StreamSource(bistream); - - - JAXBContext context = JAXBContext.newInstance(Configuration.class); - Unmarshaller u = context.createUnmarshaller(); - - // Validation - SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); - Source s = new StreamSource(Configuration.class.getResourceAsStream("/model-v1.xsd")); - Schema schema = sf.newSchema(new Source[]{s}); // Use schema reference provided in XML - u.setSchema(schema); - - try{ - Configuration model = (Configuration) u.unmarshal(bsource, Configuration.class).getValue(); - -// // Ensure that the filename inside the xml file is always the file name -// Data d = model.getData(); -// if(d==null){ -// d = new Data(); -// model.setData(d); -// } -// d.setFileName(file.getName().replaceAll("\\.xml$", "")); - - return (model); - } - catch(UnmarshalException e){ - // Check - if(e.getLinkedException() instanceof SAXParseException){ - throw new RuntimeException("Configuration file does not comply to required model specification\nCause: "+e.getLinkedException().getMessage(), e); - } - throw e; - } - } - - - /** - * Deserialize an instance of a data model of the type Configuration - * @param file + * @param file File to deserialize * @throws JAXBException Something went wrong while unmarshalling * @throws SAXException Cannot read model schema file */ @@ -152,15 +65,6 @@ public class ModelManager { try{ Configuration model = (Configuration) u.unmarshal(new StreamSource(file), Configuration.class).getValue(); - -// // Ensure that the filename inside the xml file is always the file name -// Data d = model.getData(); -// if(d==null){ -// d = new Data(); -// model.setData(d); -// } -// d.setFileName(file.getName().replaceAll("\\.xml$", "")); - return (model); } catch(UnmarshalException e){ @@ -173,7 +77,8 @@ public class ModelManager { } /** - * Serialize an instance of a data model of the type Configuration + * Serialize an instance of the FDA data model + * * @param model Model datastructure * @param file File to write the model data into * @throws JAXBException Something went wrong while marshalling model @@ -192,14 +97,6 @@ public class ModelManager { Schema schema = sf.newSchema(new Source[]{s}); // Use schema reference provided in XML m.setSchema(schema); -// // Set scan name equal to file name -// Data d = model.getData(); -// if(d==null){ -// d = new Data(); -// model.setData(d); -// } -// d.setFileName(file.getName().replaceAll("\\.xml$", "")); - m.marshal( new JAXBElement(qname, Configuration.class, model ), file); } }