Commit 2919bda1 authored by Vincent van Beveren's avatar Vincent van Beveren

Changed XML, added XSD validation

parent 113618b5
......@@ -46,7 +46,7 @@ public class DDMIContext
if (element instanceof DDMIValue) {
DDMIValue value = DDMIValue.class.cast(element);
switch (value.getType()) {
case INTEGER_TYPE:
case INT_TYPE:
case BITMAP_TYPE:
return LuaValue.valueOf(DDMIUtils.readInt(value, DDMIContext.this));
case TEXT_TYPE:
......
......@@ -8,6 +8,8 @@ import java.util.List;
import javax.xml.stream.XMLStreamException;
import org.xml.sax.SAXException;
import nl.nikhef.tools.Conversion;
import nl.nikhef.tools.Converter;
import nl.nikhef.tools.xml.FXML;
......@@ -20,6 +22,8 @@ import nl.nikhef.tools.xml.XOLProxyFactory;
public class DDMILoader {
private static final String SFPDD_XML = "desc/sfpdd.xml";
private static final String SFPDD_XSD = "desc/sfpdd.xsd";
private XOL _xol = new XOL();
private FXML _fxml;
......@@ -357,23 +361,24 @@ public class DDMILoader {
public DDMILoader() throws IOException, XMLStreamException {
this(DDMILoader.class.getResource("desc/sfpdd.xml"));
public DDMILoader() throws IOException, XMLStreamException, SAXException {
this(DDMILoader.class.getResource(SFPDD_XML),
DDMILoader.class.getResource(SFPDD_XSD));
}
public DDMILoader(URL base) throws IOException, XMLStreamException
public DDMILoader(URL base, URL xsd) throws IOException, XMLStreamException, SAXException
{
_xol.setMapping("source", new SimpleProxyFactory<DataSource>(SourceProxy.class));
_xol.setMapping("checksum", new SimpleProxyFactory<Void>(ChecksumProxy.class));
_xol.setMapping("cache", new SimpleProxyFactory<Void>(CacheProxy.class));
_xol.setMapping("group", DDMIGroup.class);
_xol.setMapping("ddmi", DDMI.class);
_xol.setMapping("int", new DDMIValueFactory(DDMIValue.DDMIType.INTEGER_TYPE));
_xol.setMapping("int", new DDMIValueFactory(DDMIValue.DDMIType.INT_TYPE));
_xol.setMapping("bitmap", new DDMIValueFactory(DDMIValue.DDMIType.BITMAP_TYPE));
_xol.setMapping("text", new DDMIValueFactory(DDMIValue.DDMIType.TEXT_TYPE));
_xol.setMapping("float", new DDMIValueFactory(DDMIValue.DDMIType.DECIMAL_TYPE_FLOAT));
_xol.setMapping("signed", new DDMIValueFactory(DDMIValue.DDMIType.DECIMAL_TYPE_SIGNED));
_xol.setMapping("unsigned", new DDMIValueFactory(DDMIValue.DDMIType.DECIMAL_TYPE_UNSIGNED));
_xol.setMapping("sfix", new DDMIValueFactory(DDMIValue.DDMIType.DECIMAL_TYPE_SFIXED));
_xol.setMapping("ufix", new DDMIValueFactory(DDMIValue.DDMIType.DECIMAL_TYPE_UFIXED));
Converter.add(new Conversion(String.class, ViewLevel.class) {
......@@ -390,15 +395,20 @@ public class DDMILoader {
_xol.setMapping("bool", new DDMIMapMetaFactory(DDMIMeta.BITFIELD));
_xol.setMapping("convert", new DDMIMapMetaFactory(DDMIMeta.CONV));
_fxml = new FXML(base);
_fxml = new FXML(base, xsd);
}
public void loadOverlays(URL ... overlays) throws XMLStreamException, IOException
public void loadOverlays(URL ... overlays) throws IOException
{
for (URL overlay : overlays) {
_fxml.loadOverlay(overlay);
try {
_fxml.loadOverlay(overlay, DDMILoader.class.getResource(SFPDD_XSD));
} catch (Exception e)
{
throw new IOException("Failed to load overlay " + overlay, e);
}
}
_ddmi = null;
}
......@@ -414,3 +424,4 @@ public class DDMILoader {
}
......@@ -45,12 +45,12 @@ public class DDMIMeta<T extends Object> {
}
public static final class Conversion {
public static final class Scale {
private float _scale = 1;
private float _offset = 0;
public Conversion() {
public Scale() {
// System.out.println("Conversion created, no args");
}
......@@ -60,7 +60,7 @@ public class DDMIMeta<T extends Object> {
_offset = offset;
}
public Conversion(float scale, float offset)
public Scale(float scale, float offset)
{
this._scale = scale;
this._offset = offset;
......@@ -152,7 +152,7 @@ public class DDMIMeta<T extends Object> {
public static final DDMIMeta<String> UNIT = new DDMIMeta<String>(String.class);
public static final DDMIMeta<Conversion> CONV = new DDMIMeta<Conversion>(Conversion.class);
public static final DDMIMeta<Scale> CONV = new DDMIMeta<Scale>(Scale.class);
public static final DDMIMeta<Integer> DEC_PLACES = new DDMIMeta<Integer>(Integer.class);
......
......@@ -19,8 +19,8 @@ public final class DDMIUtils {
if (d == null) return 0;
boolean signed;
if (val.getType() == DDMIType.INTEGER_TYPE ||
val.getType() == DDMIType.DECIMAL_TYPE_SIGNED ||
if (val.getType() == DDMIType.INT_TYPE ||
val.getType() == DDMIType.DECIMAL_TYPE_SFIXED ||
val.getType() == DDMIType.DECIMAL_TYPE_FLOAT) {
signed =true;
} else {
......@@ -46,9 +46,10 @@ public final class DDMIUtils {
case DECIMAL_TYPE_FLOAT:
baseValue = Float.intBitsToFloat(intValue);
break;
case DECIMAL_TYPE_UNSIGNED:
case DECIMAL_TYPE_SIGNED:
case DECIMAL_TYPE_UFIXED:
case DECIMAL_TYPE_SFIXED:
baseValue = intValue;
baseValue /= val.getDivider();
break;
default:
break;
......@@ -81,8 +82,9 @@ public final class DDMIUtils {
case DECIMAL_TYPE_FLOAT:
intValue = Float.floatToIntBits(value);
break;
case DECIMAL_TYPE_UNSIGNED:
case DECIMAL_TYPE_SIGNED:
case DECIMAL_TYPE_UFIXED:
case DECIMAL_TYPE_SFIXED:
value *= val.getDivider();
intValue = Math.round(value);
break;
default:
......@@ -144,7 +146,7 @@ public final class DDMIUtils {
public static final String getValueAsSting(DDMIValue val, DDMIContext ctx) {
switch (val.getType()) {
case INTEGER_TYPE:
case INT_TYPE:
int v = readInt(val, ctx);
if (DDMIMeta.LOOKUP.partOf(val)) {
DDMIMeta.LookupTable lut = DDMIMeta.LOOKUP.of(val);
......@@ -156,8 +158,8 @@ public final class DDMIUtils {
case TEXT_TYPE:
return readString(val, ctx);
case DECIMAL_TYPE_FLOAT:
case DECIMAL_TYPE_UNSIGNED:
case DECIMAL_TYPE_SIGNED:
case DECIMAL_TYPE_UFIXED:
case DECIMAL_TYPE_SFIXED:
return String.format("%.3f", readDecimal(val, ctx));
default:
StringBuilder sb = new StringBuilder();
......
......@@ -20,10 +20,11 @@ public class DDMIValue extends DDMIElement {
/** Raw binary type, usually used for bit-masks */
BITMAP_TYPE,
/** Integer type, max 4 bytes, always signed */
INTEGER_TYPE,
INT_TYPE,
UINT_TYPE,
/** Decimal type, interpretation depends on formatting */
DECIMAL_TYPE_UNSIGNED,
DECIMAL_TYPE_SIGNED,
DECIMAL_TYPE_UFIXED,
DECIMAL_TYPE_SFIXED,
DECIMAL_TYPE_FLOAT,
}
......@@ -33,6 +34,7 @@ public class DDMIValue extends DDMIElement {
private boolean _monitoring;
private DDMIType _type;
private String _short;
private int _divider = 1;
private ViewLevel _level;
private Map<DDMIMeta<?>, Object> _meta;
......@@ -62,6 +64,11 @@ public class DDMIValue extends DDMIElement {
_offset = offset;
}
public void setDivider(int divider) {
_divider = divider;
}
public ViewLevel getLevel() {
return _level;
}
......@@ -132,7 +139,9 @@ public class DDMIValue extends DDMIElement {
_short = s;
}
public int getDivider() {
return _divider;
}
......@@ -166,7 +175,7 @@ public class DDMIValue extends DDMIElement {
sb.append(String.format("* %-24s: ", getLabel()));
switch (_type) {
case INTEGER_TYPE:
case INT_TYPE:
int v = DDMIUtils.readInt(this, ctx);
if (DDMIMeta.LOOKUP.partOf(this)) {
DDMIMeta.LookupTable lut = DDMIMeta.LOOKUP.of(this);
......
......@@ -2,7 +2,9 @@
<!-- This file describes the SPF+ EEPROM and Diagnostic memory layout -->
<ddmi id="root">
<ddmi id="root"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="sfpdd.xsd">
<source i2c-addr="x50" id="eeprom" start="0" end="255">
<checksum offset="63" start="0" end="62"/>
......@@ -109,26 +111,21 @@
</int>
<text label="Vendor label" writable="true" name="vendor"
offset="20" length="16" level="basic">
</text>
offset="20" length="16" level="basic" />
<!-- 36:1 Transciever(2) moved up -->
<bitmap label="Vendor OUI" writable="true" name="vendor_oui"
offset="37" length="3" level="basic">
</bitmap>
offset="37" length="3" level="basic" />
<text label="Vendor PN" writable="true" name="vendor_pn"
offset="40" length="16" level="basic">
</text>
offset="40" length="16" level="basic" />
<text label="Vendor Rev" writable="true" name="vendor_rev"
offset="56" length="4" level="basic">
</text>
offset="56" length="4" level="basic" />
<int label="Wavelength" writable="true" name="wavelength"
offset="60" length="2" level="basic">
</int>
offset="60" length="2" level="basic" />
</group>
<group label="Extended ID fields" name="ext_id">
......@@ -229,69 +226,144 @@
</group>
</group>
<group label="Calibration Constants">
<float label="RX Power 4" offset="56" length="4" writable="true" />
<float label="RX Power 3" offset="60" length="4" writable="true" />
<float label="RX Power 2" offset="64" length="4" writable="true" />
<float label="RX Power 1" offset="68" length="4" writable="true" />
<float label="RX Power 0" offset="72" length="4" writable="true" />
<float label="RX Power 4"
offset="56"
length="4"
writable="true" />
<float label="RX Power 3"
offset="60"
length="4"
writable="true" />
<float label="RX Power 2"
offset="64"
length="4"
writable="true" />
<float label="RX Power 1"
offset="68"
length="4"
writable="true" />
<float label="RX Power 0"
offset="72"
length="4"
writable="true" />
<unsigned label="Tx_I(Slope)" offset="76" length="2" writable="true" name="tx_i_slope">
<convert scale="0.00390625" />
</unsigned>
<ufix label="Tx_I(Slope)"
offset="76"
length="2"
writable="true"
name="tx_i_slope"
divider="x100" />
<signed label="Tx_I(Offset)" offset="78" length="2" writable="true" name="tx_i_offset"/>
<sfix label="Tx_I(Offset)"
offset="78"
length="2"
writable="true"
name="tx_i_offset" />
<unsigned label="Tx_Pwr(Slope)" offset="80" length="2" writable="true" name="tx_pwr_slope">
<convert scale="0.00390625"/>
</unsigned>
<ufix label="Tx_Pwr(Slope)"
offset="80"
length="2"
writable="true"
name="tx_pwr_slope"
divider="x100" />
<signed label="Tx_Pwr(Offset)" offset="82" length="2" writable="true" name="tx_pwr_offset"/>
<sfix label="Tx_Pwr(Offset)"
offset="82"
length="2"
writable="true"
name="tx_pwr_offset" />
<unsigned label="T(Slope)" offset="84" length="2" writable="true" name="t_slope">
<convert scale="0.00390625" />
</unsigned>
<ufix label="T(Slope)"
offset="84"
length="2"
writable="true"
name="t_slope"
divider="x100" />
<signed label="T(Offset)" offset="86" length="2" writable="true" name="t_offset"/>
<sfix label="T(Offset)"
offset="86"
length="2"
writable="true"
name="t_offset" />
<unsigned label="V(Slope)" offset="88" length="2" writable="true" name="v_slope">
<convert scale="0.00390625" />
</unsigned>
<ufix label="V(Slope)"
offset="88"
length="2"
writable="true"
name="v_slope"
divider="x100" />
<signed label="V(Offset)" offset="90" length="2" writable="true" name="v_offset"/>
<sfix label="V(Offset)"
offset="90"
length="2"
writable="true"
name="v_offset" />
</group>
<group label="Real-time diagnostics" name="rt_diag">
<signed label="Temperature (&#176;C)" offset="96" length="2" monitor="true" name="temperature">
<convert scale="0.00390625" />
</signed>
<unsigned label="Vcc (V)" offset="98" length="2" monitor="true" name="vcc">
<convert scale="0.0001" />
</unsigned>
<unsigned label="TX Bias (mA)" offset="100" length="2" monitor="true" name="tx_bias">
<convert scale="0.002" />
</unsigned>
<unsigned label="TX Power (mW)" offset="102" length="2" monitor="true" name="tx_power">
<convert scale="0.001" />
</unsigned>
<sfix label="Temperature (&#176;C)"
offset="96"
length="2"
monitor="true"
name="temperature"
divider="256" />
<ufix label="Vcc (V)"
offset="98"
length="2"
monitor="true"
name="vcc"
divider="10000" />
<ufix label="TX Bias (mA)"
offset="100"
length="2"
monitor="true"
name="tx_bias"
divider="500" />
<ufix label="TX Power (mW)"
offset="102" length="2"
monitor="true"
name="tx_power"
divider="1000" />
<unsigned label="RX Power (mW)" offset="104" length="2" monitor="true" name="rx_bias">
<convert scale="0.001" />
</unsigned>
<ufix label="RX Power (mW)"
offset="104"
length="2"
monitor="true"
name="rx_bias"
divider="1000" />
<!-- TODO BEGIN build visual conditional here -->
<signed label="Laser temperature" offset="106" length="2" monitor="true" name="laser_temp">
<convert scale="0.00390625" />
</signed>
<sfix label="Laser temperature"
offset="106"
length="2"
monitor="true"
name="laser_temp"
divider="x100" />
<sfix label="Laser wavelength"
offset="106"
length="2"
monitor="true"
name="laser_wavelength"
divider="x100" />
<signed label="Laser wavelength" offset="106" length="2" monitor="true" name="laser_wavelength">
<convert scale="0.00390625" />
</signed>
<!-- TODO END build visual conditional here -->
<signed label="TEC current (mA)" offset="108" length="2" monitor="true" name="tec_current">
<convert scale="0.1" />
</signed>
<sfix
label="TEC current (mA)"
offset="108"
length="2"
monitor="true"
name="tec_current"
divider="10" />
<!-- Oh dear, a monitoring, changeable value... -->
<bitmap label="Status/Control" writable="true" offset="110" length="1" monitor="true" name="status_ctrl">
......
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Types -->
<xs:simpleType name="unsignedInt">
<xs:union memberTypes="xs:unsignedInt">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:pattern value="x[0-9A-Fa-f]{1,9}" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
<xs:simpleType name="unsignedByte">
<xs:union memberTypes="xs:unsignedByte">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:pattern value="x[0-9A-Fa-f]{1,3}" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
<xs:complexType name="identifier" mixed="false">
<xs:attribute type="xs:ID" name="id" use="optional" />
</xs:complexType>
<xs:complexType name="element" mixed="false">
<xs:complexContent>
<xs:extension base="identifier">
<xs:attribute type="xs:string" name="label" use="optional" />
<xs:attribute type="xs:string" name="short" use="optional" />
<xs:attribute type="xs:string" name="name" use="optional" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="value" mixed="false">
<xs:complexContent>
<xs:extension base="element">
<xs:attribute type="xs:boolean" name="writable" use="optional" />
<xs:attribute type="xs:boolean" name="monitor" use="optional" />
<xs:attribute type="xs:unsignedByte" name="offset" use="optional" />
<xs:attribute type="xs:unsignedByte" name="length" use="optional" />
<xs:attribute type="xs:string" name="level" use="optional" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="decimal" mixed="false">
<xs:complexContent>
<xs:extension base="value">
<xs:sequence>
<xs:element ref="scale" maxOccurs="unbounded" minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- Root element -->
<xs:element name="ddmi">
<xs:complexType>
<xs:complexContent>
<xs:extension base="identifier">
<xs:sequence>
<xs:element ref="source" maxOccurs="unbounded"
minOccurs="0" />
<xs:element ref="group" maxOccurs="unbounded"
minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<!-- Sources, checksums and cache -->
<xs:element name="checksum">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="unsignedByte" name="offset" use="optional" />
<xs:attribute type="unsignedByte" name="start" use="optional" />
<xs:attribute type="unsignedByte" name="end" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="cache">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="unsignedByte" name="start" use="optional" />
<xs:attribute type="unsignedByte" name="end" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="source">
<xs:complexType mixed="false">
<xs:sequence>
<xs:element ref="checksum" maxOccurs="unbounded"
minOccurs="0" />
<xs:element ref="cache" minOccurs="0" />
</xs:sequence>
<xs:attribute type="unsignedByte" name="i2c-addr" use="optional" />
<xs:attribute type="xs:ID" name="id" use="optional" />
<xs:attribute type="unsignedByte" name="start" use="optional" />
<xs:attribute type="unsignedByte" name="end" use="optional" />
<xs:attribute type="unsignedByte" name="page-select"
use="optional" />
<xs:attribute type="xs:string" name="valid-if" use="optional" />
<xs:attribute type="unsignedByte" name="page" use="optional" />
<xs:attribute type="xs:IDREF" name="parent-id" use="optional" />
</xs:complexType>
</xs:element>
<xs:element name="group">
<xs:complexType>
<xs:complexContent>
<xs:extension base="element">
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element ref="int" />
<xs:element ref="bitmap" />
<xs:element ref="text" />
<xs:element ref="group" />
<xs:element ref="float" />
<xs:element ref="ufix" />
<xs:element ref="sfix" />
</xs:choice>
<xs:attribute type="xs:IDREF" name="source-id" use="optional" />
<xs:attribute type="xs:string" name="showIf" use="optional" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="int">
<xs:complexType>
<xs:complexContent>
<xs:extension base="value">
<xs:sequence>
<xs:element ref="map" maxOccurs="unbounded" minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="uint">
<xs:complexType>
<xs:complexContent>
<xs:extension base="value">
<xs:sequence>
<xs:element ref="map" maxOccurs="unbounded" minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="bitmap">
<xs:complexType>
<xs:complexContent>
<xs:extension base="value">
<xs:sequence>
<xs:element ref="bool" maxOccurs="unbounded" minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="text">
<xs:complexType>
<xs:complexContent>
<xs:extension base="value" />
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="float">
<xs:complexType>
<xs:complexContent>
<xs:extension base="decimal" />
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="ufix">
<xs:complexType>
<xs:complexContent>
<xs:extension base="decimal">
<xs:attribute type="unsignedInt" name="divider" use="optional" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="sfix">
<xs:complexType>
<xs:complexContent>
<xs:extension base="decimal">
<xs:attribute type="unsignedInt" name="divider" use="optional" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<!-- Meta elements -->
<xs:element name="bool">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:unsignedByte" name="bit" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="scale">
<xs:complexType>
<xs:attribute type="xs:float" name="offset" use="optional" />
<xs:attribute type="xs:float" name="scale" use="optional" />
</xs:complexType>
</xs:element>
<xs:element name="map">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="unsignedByte" name="key" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<!-- Overlay support -->
<xs:element name="overlay">
<xs:complexType mixed="false">
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element ref="bool"/>
<xs:element ref="map"/>
<xs:element ref="scale"/>
<xs:element ref="sfix"/>
<xs:element ref="ufix"/>
<xs:element ref="float"/>
<xs:element ref="int"/>
<xs:element ref="uint"/>
<xs:element ref="text"/>
<xs:element ref="bitmap"/>
<xs:element ref="group"/>
<xs:element ref="ddmi"/>
<xs:element ref="source"/>
<xs:element ref="cache"/>
<xs:element ref="checksum"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
package nl.nikhef.tools.xml;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import javax.xml.XMLConstants;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
......@@ -15,29 +14,36 @@ import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class FXML {
private FXMLElement _root;
public FXML(Reader r) throws XMLStreamException {
readInternal(r);
}
public FXML(URL resource) throws IOException, XMLStreamException {
Reader r = new InputStreamReader(resource.openStream());
readInternal(r);
r.close();
public FXML(URL resource, URL xsd) throws IOException, XMLStreamException, SAXException {
readInternal(resource, xsd, false);
}
private FXML(URL resource, URL xsd, boolean ignoreIdRefs) throws IOException, XMLStreamException, SAXException {
readInternal(resource, xsd, ignoreIdRefs);
}
public FXMLElement getRoot()
{
return _root;
}
public void loadOverlay(URL resource) throws XMLStreamException, IOException
public void loadOverlay(URL resource, URL xsd) throws XMLStreamException, IOException, SAXException
{
FXML overlay = new FXML(resource);
FXML overlay = new FXML(resource, xsd, true);
FXMLElement xml = overlay.getRoot();
merge(xml);
......@@ -110,10 +116,39 @@ public class FXML {
}
private void readInternal(Reader r) throws XMLStreamException
private void readInternal(URL resource, URL xsd, final boolean ignoreIdRefs) throws XMLStreamException, IOException, SAXException
{
Validator validator = null;
if (xsd != null) {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(xsd);
validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void error(SAXParseException exception) throws SAXException {
if (ignoreIdRefs && exception.getMessage().contains("cvc-id.1")) {
return;
}
throw exception;
}
});
validator.validate(new StreamSource(resource.openStream()));
}
XMLInputFactory f = XMLInputFactory.newInstance();
XMLEventReader er = f.createXMLEventReader(r);
XMLEventReader er = f.createXMLEventReader(resource.openStream());
LinkedList<FXMLElement> stack = new LinkedList<FXMLElement>();
FXMLElement cur = null;
......@@ -181,10 +216,6 @@ public class FXML {
}
}
public void parseOverlay(Reader r)
{
}
}
......@@ -101,6 +101,9 @@ public class XOL
// Then, set attributes
for (Map.Entry<String, String> att : fxml.attributes().entrySet())
{
// ignore namespaces
if (att.getKey().contains(":")) continue;
if (att.getKey().equals("id")) {
if (_idToProxy.containsKey(att.getValue())) {
throw new RuntimeException(String.format("An entity with ID '%s' already exists", att.getValue()));
......
......@@ -4,18 +4,20 @@ import java.io.IOException;
import javax.xml.stream.XMLStreamException;
import org.xml.sax.SAXException;
import nl.nikhef.tools.xml.FXML;
public class FXMLTest {
public static void main(String[] args) throws XMLStreamException, IOException {
public static void main(String[] args) throws XMLStreamException, IOException, SAXException {
FXML fxml = new FXML(FXMLTest.class.getResource("root.xml"));
FXML fxml = new FXML(FXMLTest.class.getResource("root.xml"), null);
fxml.getRoot().prettyPrint();
fxml.loadOverlay(FXMLTest.class.getResource("overlay.xml"));
fxml.loadOverlay(FXMLTest.class.getResource("overlay.xml"), null);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================
4 apr. 2016 13:06:34
jsfp
Java SFP Library
4 apr. 2016 13:06:34
SaFariPark GUI Application
vincentb
Vincent van Beveren (v.van.beveren[at]nikhef.nl)
====================================================================== -->
<project name="safaripark" default="default">
<description>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Adds support for the OE Solutions transceivers, as used in KM3NeT -->
<overlay>
<overlay
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="sfpdd.xsd">
<group id="root">
<group label="OE Solutions custom">
<group source-id="diag" showIf="isset(id.montype, 6)">
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Adds support for the Maxim DS1856M -->
<overlay>
<overlay
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="sfpdd.xsd">
<group id="root">
<group label="Maxim DS1856M" showIf="isset(id.montype, 6)">
<group source-id="diag" label="Password">
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Adds support for the Maxim DS1856M -->
<overlay>
<overlay
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="sfpdd.xsd">
<group id="root">
<group label="Tunable SFP" source-id="diag_p2" showIf="isset(id.montype, 6)">
<bitmap label="Dithering" writable="false" offset="128" length="1" name="dithering"
......@@ -12,22 +15,22 @@
</bitmap>
<group label="Laser capabilities">
<int label="First Frequency (THz)" writable="false" name="LFL1" offset="132" length="2" level="basic" />
<unsigned label="First Frequency (GHz)" writable="false" name="LFL2" offset="134" length="2" level="basic">
<ufix label="First Frequency (GHz)" writable="false" name="LFL2" offset="134" length="2" level="basic">
<convert scale="0.1"/>
</unsigned>
</ufix>
<int label="Last Frequency (THz)" writable="false" name="LFH1" offset="136" length="2" level="basic" />
<unsigned label="Last Frequency (GHz)" writable="false" name="LFH2" offset="138" length="2" level="basic">
<ufix label="Last Frequency (GHz)" writable="false" name="LFH2" offset="138" length="2" level="basic">
<convert scale="0.1"/>
</unsigned>
<unsigned label="Minimum grid spacing (GHz)" writable="false" name="LGrid" offset="140" length="2" level="basic" >
</ufix>
<ufix label="Minimum grid spacing (GHz)" writable="false" name="LGrid" offset="140" length="2" level="basic" >
<convert scale="0.1"/>
</unsigned>
</ufix>
</group>
<group label="Frequency and wavelength control">
<int label="Channel number set" writable="true" name="chno_set" offset="144" length="2" level="basic" />
<unsigned label="Wavelength set (nm)" writable="true" name="wl_set" offset="146" length="2" level="basic" >
<ufix label="Wavelength set (nm)" writable="true" name="wl_set" offset="146" length="2" level="basic" >
<convert scale="0.05"/>
</unsigned>
</ufix>
<bitmap label="Other options" writable="true" name="tx_dither" offset="151" length="1" level="basic">
<bool bit="0">Disable dithering</bool>
</bitmap>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Adds support for the Maxim DS1856M -->
<overlay>
<overlay
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="sfpdd.xsd">
<source id="diag_p0">
<checksum offset="247" start="128" end="246"/>
<cache start="128" end="247"/>
</source>
<group id="root">
<group label="Loopback SFP" source-id="diag_p0" showIf="isset(id.montype, 6)">
<bitmap label="Magic Value" writable="true" offset="128" length="2" name="magic" level="basic" />
<int label="Version" writable="true" offset="130" length="1" name="version" level="basic" />
<bitmap label="Calibration Date" writable="true" offset="131" length="3" name="cal_date" level="basic" />
<bitmap label="OUI responsible" writable="true" offset="134" length="3" name="cal_oui" level="basic" />
<unsigned label="Tx-to-Rx Delay (ps)" writable="true" offset="140" length="4" name="tx2rx_dly" level="basic" >
<convert scale="0.0000152587890625"/>
</unsigned>
<unsigned label="Tx-to-Out Delay (ps)" writable="true" offset="144" length="4" name="tx2out_dly" level="basic" >
<convert scale="0.0000152587890625"/>
</unsigned>
<unsigned label="Rx-to-Out Delay (ps)" writable="true" offset="148" length="4" name="rx2out_dly" level="basic" >
<convert scale="0.0000152587890625"/>
</unsigned>
</group>
<bitmap label="Magic Value"
writable="true"
offset="128"
length="2"
name="magic"
level="basic" />
<int label="Version"
writable="true"
offset="130"
length="1"
name="version"
level="basic" />
<bitmap label="Calibration Date"
writable="true"
offset="131"
length="3"
name="cal_date"
level="basic" />
<bitmap label="OUI responsible"
writable="true"
offset="134"
length="3"
name="cal_oui"
level="basic" />
<ufix label="Tx-to-Rx Delay (ps)"
writable="true"
offset="140"
length="4"
name="tx2rx_dly"
level="basic"
divider="x10000"/>
<ufix label="Tx-to-Out Delay (ps)"
writable="true"
offset="144"
length="4"
name="tx2out_dly"
level="basic"
divider="x10000" />
<ufix label="Rx-to-Out Delay (ps)"
writable="true"
offset="148"
length="4"
name="rx2out_dly"
level="basic"
divider="x10000" />
</group>
</group>
</overlay>
......@@ -45,6 +45,7 @@ import javax.xml.stream.XMLStreamException;
import org.codejargon.feather.Feather;
import org.codejargon.feather.Provides;
import org.xml.sax.SAXException;
import nl.nikhef.safaripark.devmgr.BaySelectionListener;
import nl.nikhef.safaripark.devmgr.DeviceManager;
......@@ -274,7 +275,7 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
@Provides
@Singleton
DDMILoader ddmiLoader(OverlayManager ovl) throws IOException, XMLStreamException {
DDMILoader ddmiLoader(OverlayManager ovl) throws IOException, XMLStreamException, SAXException {
DDMILoader loader = new DDMILoader();
loader.loadOverlays(ovl.getOverlays());
return loader;
......
......@@ -76,7 +76,7 @@ public class FormEditPane extends JPanel {
ValueEditor comp;
switch (val.getType())
{
case INTEGER_TYPE:
case INT_TYPE:
if (DDMIMeta.LOOKUP.partOf(val)) {
comp = new EnumEditor(ctx, val, label);
} else {
......@@ -87,8 +87,8 @@ public class FormEditPane extends JPanel {
comp = new TextEditor(ctx, val, label);
break;
case DECIMAL_TYPE_FLOAT:
case DECIMAL_TYPE_SIGNED:
case DECIMAL_TYPE_UNSIGNED:
case DECIMAL_TYPE_SFIXED:
case DECIMAL_TYPE_UFIXED:
comp = new DecimalEditor(ctx, val, label);
break;
default:
......
......@@ -37,6 +37,8 @@ import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.xml.stream.XMLStreamException;
import org.xml.sax.SAXException;
import nl.nikhef.safaripark.Config;
import nl.nikhef.safaripark.extra.ExtendedAbstractAction;
import nl.nikhef.safaripark.res.Resources;
......@@ -363,7 +365,7 @@ public class ValueSelectionPane extends JPanel implements ItemListener, ItemSele
static ValueSelectionPane vsp;
public static void main(String[] args) throws IOException, XMLStreamException {
public static void main(String[] args) throws IOException, XMLStreamException, SAXException {
try {
UIManager.setLookAndFeel(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment