Skip to content
Snippets Groups Projects
Commit 5d1a0a77 authored by kohleman's avatar kohleman
Browse files

[LMS-1634] xml beans and JAXB stuff

SVN: 16981
parent 9bb94762
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.ethz.bsse.cisd.dsu.dss.plugins;
import javax.xml.bind.annotation.XmlElement;
/**
* <pre>
* &lt;ChipResultsSummary&gt;
* &lt;clusterCountPF&gt;98792458&lt;/clusterCountPF&gt;
* &lt;clusterCountRaw&gt;158466917&lt;/clusterCountRaw&gt;
* &lt;yield&gt;3556528488&lt;/yield&gt;
* &lt;/ChipResultsSummary&gt;
* </pre>
*
* @author Manuel Kohler
*/
// @XmlType
public class ChipResultsSummary
{
private String clusterCountPF;
private String clusterCountRaw;
private String yield;
@XmlElement
public String getClusterCountPF()
{
return clusterCountPF;
}
public void setClusterCountPF(String clusterCountPF)
{
this.clusterCountPF = clusterCountPF;
}
@XmlElement
public String getClusterCountRaw()
{
return clusterCountRaw;
}
public void setClusterCountRaw(String clusterCountRaw)
{
this.clusterCountRaw = clusterCountRaw;
}
@XmlElement
public String getYield()
{
return yield;
}
public void setYield(String yield)
{
this.yield = yield;
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.ethz.bsse.cisd.dsu.dss.plugins;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* <pre>
* &lt;Summary&gt;
* &lt;ChipResultsSummary&gt;
* &lt;clusterCountPF&gt;98792458&lt;/clusterCountPF&gt;
* &lt;clusterCountRaw&gt;158466917&lt;/clusterCountRaw&gt;
* &lt;yield&gt;3556528488&lt;/yield&gt;
* &lt;/ChipResultsSummary&gt;
* ...
* &lt;Summary&gt;
* </pre>
*
* @author Manuel Kohler
*/
@XmlRootElement(name = "Summary")
// @XmlType
public class IlluminaSummary
{
private ChipResultsSummary chipResultsSummary;
@XmlElement(name = "ChipResultsSummary")
public ChipResultsSummary getChipResultsSummary()
{
return chipResultsSummary;
}
public void setChipResultsSummary(ChipResultsSummary chipResultsSummary)
{
this.chipResultsSummary = chipResultsSummary;
}
}
/*
* Copyright 2009 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.ethz.bsse.cisd.dsu.dss.plugins;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.UnmarshallerHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
import ch.systemsx.cisd.common.utilities.XMLInfraStructure;
/**
* Loader of Illumina summary XML file.
*
* @author Manuel Kohler
*/
class IlluminaSummaryXMLLoader
{
private final Unmarshaller unmarshaller;
private final XMLInfraStructure xmlInfraStructure;
IlluminaSummaryXMLLoader(boolean validating)
{
try
{
JAXBContext context = JAXBContext.newInstance(IlluminaSummary.class);
unmarshaller = context.createUnmarshaller();
xmlInfraStructure = new XMLInfraStructure(validating);
xmlInfraStructure.setEntityResolver(new EntityResolver()
{
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException
{
String schemaVersion = systemId.substring(systemId.lastIndexOf('/'));
String resource =
"/"
+ IlluminaSummaryXMLLoader.class.getPackage().getName()
.replace('.', '/') + schemaVersion;
InputStream inputStream =
IlluminaSummaryXMLLoader.class.getResourceAsStream(resource);
return inputStream == null ? null : new InputSource(inputStream);
}
});
} catch (Exception ex)
{
throw CheckedExceptionTunnel.wrapIfNecessary(ex);
}
}
IlluminaSummary readSummaryXML(File dataSet)
{
try
{
UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();
xmlInfraStructure.parse(new FileReader(dataSet), unmarshallerHandler);
Object object = unmarshallerHandler.getResult();
if (object instanceof IlluminaSummary == false)
{
throw new IllegalArgumentException("Wrong type: " + object);
}
return (IlluminaSummary) object;
} catch (Exception ex)
{
throw CheckedExceptionTunnel.wrapIfNecessary(ex);
}
}
}
/*
* Copyright 2009 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.ethz.bsse.cisd.dsu.dss.plugins;
import java.io.File;
import org.testng.annotations.Test;
import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase;
import ch.systemsx.cisd.common.filesystem.FileUtilities;
/**
* @author Franz-Josef Elmer
*/
public class IlluminaSummaryXMLLoaderTest extends AbstractFileSystemTestCase
{
@Test
public void test()
{
File file = new File(workingDirectory, "test.xml");
FileUtilities.writeToFile(file, EXAMPLE);
IlluminaSummary summary = new IlluminaSummaryXMLLoader(false).readSummaryXML(file);
ChipResultsSummary chipResultsSummary = summary.getChipResultsSummary();
assertEquals("98792458", chipResultsSummary.getClusterCountPF());
assertEquals("158466917", chipResultsSummary.getClusterCountRaw());
assertEquals("3556528488", chipResultsSummary.getYield());
}
protected static final String EXAMPLE = "<?xml version='1.0' ?>\n "
+ "<?xml-stylesheet type='text/xsl' href='Summary.xsl' ?>\n "
+ "<Summary> "
+ " <ChipResultsSummary> "
+ " <clusterCountPF>98792458</clusterCountPF> "
+ " <clusterCountRaw>158466917</clusterCountRaw> "
+ " <yield>3556528488</yield> "
+ " </ChipResultsSummary> "
+ " <ChipSummary> "
+ " <ChipID>unknown</ChipID> "
+ " <Machine>HWI-EAS264</Machine> "
+ " <RunFolder>090916_42R0CAAXX</RunFolder> "
+ " </ChipSummary> "
+ " <Date>Tue Oct 20 18:15:43 2009</Date> "
+ " <ExpandedLaneSummary/> "
+ " <LaneParameterSummary/> "
+ " <LaneResultsSummary/> "
+ " <TileErrorsByLane/> "
+ "</Summary>";
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment