removed obsolete functionality

upgraded to java 1.7 and set project encoding to UTF-8
This commit is contained in:
2013-10-02 13:30:50 +02:00
parent 0b9ee77f76
commit 70cb7a8939
5 changed files with 13 additions and 121 deletions

View File

@@ -28,7 +28,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>

View File

@@ -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

View File

@@ -73,8 +73,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- Generate Javadoc Jar -->

View File

@@ -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);
}

View File

@@ -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<String, String> 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
// <xsl:value-of select="$var.regions" disable-output-escaping="yes" />
// If it is not done this way the < and > of the tags will be replaced by &lt; and &gt;
// 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<Configuration>(qname, Configuration.class, model ), file);
}
}