From 09e180f169deaaae502b32b9b5d0c029a3307d60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20DAVID?= Date: Fri, 14 Mar 2014 09:08:31 +0100 Subject: [PATCH] Xcos modelica init: fix the XSD Schema The modelica compiler assume that empty elements use empty-element tags (), an exception is raised otherwise. This commit force the tag usage on and . Change-Id: I4492ccde02757a3b91e54bb62abce274c2b2e6a7 --- scilab/modules/xcos/etc/Modelica.xsd | 23 ++--- .../org/scilab/modules/xcos/modelica/Modelica.java | 2 +- .../scilab/modules/xcos/modelica/model/Model.java | 91 ++++++++++++++++---- .../modules/xcos/modelica/model/ModelicaValue.java | 9 +- .../modules/xcos/modelica/model/ObjectFactory.java | 56 ++++++------ .../scilab/modules/xcos/modelica/model/Struct.java | 15 +--- .../modules/xcos/modelica/model/Terminal.java | 54 +++++++----- .../modules/xcos/modelica/view/MainPanel.java | 13 ++- 8 files changed, 170 insertions(+), 93 deletions(-) diff --git a/scilab/modules/xcos/etc/Modelica.xsd b/scilab/modules/xcos/etc/Modelica.xsd index c1adc34..83d7b07 100644 --- a/scilab/modules/xcos/etc/Modelica.xsd +++ b/scilab/modules/xcos/etc/Modelica.xsd @@ -1,8 +1,5 @@ - - - Specify the size of all the parameters, state, inputs or outputs. @@ -24,9 +21,9 @@ - Modelica String assignation. + Modelica String assignation. The default value is specified to ease serialization. - + @@ -64,7 +61,9 @@ - + + + @@ -144,7 +143,7 @@ Wrapper around the {@link Output} list. - + @@ -163,11 +162,15 @@ - - - + + + + + + + diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/Modelica.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/Modelica.java index 0173108..21c5636 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/Modelica.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/Modelica.java @@ -148,7 +148,7 @@ public final class Modelica { public void save(Model root, File file) throws JAXBException { try { final StringWriter strw = new StringWriter(); - marshaller.marshal(unmerge(root), strw); + marshaller.marshal(new org.scilab.modules.xcos.modelica.model.ObjectFactory().createModel(unmerge(root)), strw); /* * Customize the file to be handled by the xml2modelica tool diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Model.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Model.java index dd86470..e0dc0b6 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Model.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Model.java @@ -128,10 +128,15 @@ import javax.xml.bind.annotation.XmlType; * </complexType> * </element> * <element name="when_clauses" minOccurs="0"> - * <simpleType> - * <restriction base="{http://www.w3.org/2001/XMLSchema}string"> - * </restriction> - * </simpleType> + * <complexType> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <element name="when_clause" type="{}ModelicaValue" maxOccurs="unbounded" minOccurs="0"/> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> * </element> * </sequence> * </restriction> @@ -159,7 +164,7 @@ public class Model { protected Model.Elements elements; protected Model.Equations equations; @XmlElement(name = "when_clauses") - protected String whenClauses; + protected Model.WhenClauses whenClauses; /** * Gets the value of the name property. @@ -332,10 +337,10 @@ public class Model { /** * Gets the value of the whenClauses property. * - * @return possible object is {@link String } + * @return possible object is {@link Model.WhenClauses } * */ - public String getWhenClauses() { + public Model.WhenClauses getWhenClauses() { return whenClauses; } @@ -343,10 +348,10 @@ public class Model { * Sets the value of the whenClauses property. * * @param value - * allowed object is {@link String } + * allowed object is {@link Model.WhenClauses } * */ - public void setWhenClauses(String value) { + public void setWhenClauses(Model.WhenClauses value) { this.whenClauses = value; } @@ -962,6 +967,7 @@ public class Model { @XmlType(name = "", propOrder = { "output" }) public static class Outputs { + @XmlElement(nillable = true) protected List output; /** @@ -996,16 +1002,65 @@ public class Model { } - /* - * Overriden methods - */ - /** - * @return the name - * @see java.lang.Object#toString() + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained + * within this class. + * + *

+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="when_clause" type="{}ModelicaValue" maxOccurs="unbounded" minOccurs="0"/>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
+     * 
+ * + * */ - @Override - public String toString() { - return getName(); + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { "whenClause" }) + public static class WhenClauses { + + @XmlElement(name = "when_clause", nillable = true) + protected List whenClause; + + /** + * Gets the value of the whenClause property. + * + *

+ * This accessor method returns a reference to the live list, not a + * snapshot. Therefore any modification you make to the returned list + * will be present inside the JAXB object. This is why there is not a + * set method for the whenClause property. + * + *

+ * For example, to add a new item, do as follows: + * + *

+         * getWhenClause().add(newItem);
+         * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link ModelicaValue } + * + * + */ + public List getWhenClause() { + if (whenClause == null) { + whenClause = new ArrayList(); + } + return this.whenClause; + } + } + } diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/ModelicaValue.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/ModelicaValue.java index c98b84f..d7369cb 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/ModelicaValue.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/ModelicaValue.java @@ -19,7 +19,8 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlType; /** - * Modelica String assignation. + * Modelica String assignation. The default value is specified to ease + * serialization. * *

* Java class for ModelicaValue complex type. @@ -32,7 +33,7 @@ import javax.xml.bind.annotation.XmlType; * <complexType name="ModelicaValue"> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> - * <attribute name="value" type="{http://www.w3.org/2001/XMLSchema}string" /> + * <attribute name="value" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> * </restriction> * </complexContent> * </complexType> @@ -45,9 +46,9 @@ import javax.xml.bind.annotation.XmlType; public class ModelicaValue { /* - * Value may not be null to ease serialization + * A non-null value is required by xml2modelica */ - @XmlAttribute(name = "value") + @XmlAttribute(required = true) protected String value = ""; /** diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/ObjectFactory.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/ObjectFactory.java index 21b1ba1..bad0460 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/ObjectFactory.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/ObjectFactory.java @@ -34,7 +34,6 @@ import javax.xml.namespace.QName; public class ObjectFactory { private final static QName _Model_QNAME = new QName("", "model"); - private final static QName _TerminalOutput_QNAME = new QName("", "output"); /** * Create a new ObjectFactory that can be used to create new instances of @@ -54,6 +53,14 @@ public class ObjectFactory { } /** + * Create an instance of {@link Model.WhenClauses } + * + */ + public Model.WhenClauses createModelWhenClauses() { + return new Model.WhenClauses(); + } + + /** * Create an instance of {@link ModelicaValue } * */ @@ -78,11 +85,12 @@ public class ObjectFactory { } /** - * Create an instance of {@link Output.Dependencies } + * Create an instance of + * {@link org.scilab.modules.xcos.modelica.model.Output.Dependencies } * */ - public Output.Dependencies createOutputDependencies() { - return new Output.Dependencies(); + public org.scilab.modules.xcos.modelica.model.Output.Dependencies createOutputDependencies() { + return new org.scilab.modules.xcos.modelica.model.Output.Dependencies(); } /** @@ -94,27 +102,28 @@ public class ObjectFactory { } /** - * Create an instance of {@link Output } + * Create an instance of {@link Terminal.Output } * */ - public Output createOutput() { - return new Output(); + public Terminal.Output createTerminalOutput() { + return new Terminal.Output(); } /** - * Create an instance of {@link Model.Outputs } + * Create an instance of + * {@link org.scilab.modules.xcos.modelica.model.Output } * */ - public Model.Outputs createModelOutputs() { - return new Model.Outputs(); + public org.scilab.modules.xcos.modelica.model.Output createOutput() { + return new org.scilab.modules.xcos.modelica.model.Output(); } /** - * Create an instance of {@link Model.ExplicitRelations.ExplicitRelation } + * Create an instance of {@link Model.Outputs } * */ - public Model.ExplicitRelations.ExplicitRelation createModelExplicitRelationsExplicitRelation() { - return new Model.ExplicitRelations.ExplicitRelation(); + public Model.Outputs createModelOutputs() { + return new Model.Outputs(); } /** @@ -158,11 +167,11 @@ public class ObjectFactory { } /** - * Create an instance of {@link Model.ImplicitRelations.ImplicitRelation } + * Create an instance of {@link Model.ExplicitRelations.ExplicitRelation } * */ - public Model.ImplicitRelations.ImplicitRelation createModelImplicitRelationsImplicitRelation() { - return new Model.ImplicitRelations.ImplicitRelation(); + public Model.ExplicitRelations.ExplicitRelation createModelExplicitRelationsExplicitRelation() { + return new Model.ExplicitRelations.ExplicitRelation(); } /** @@ -174,21 +183,20 @@ public class ObjectFactory { } /** - * Create an instance of {@link JAXBElement }{@code <}{@link Model }{@code >} + * Create an instance of {@link Model.ImplicitRelations.ImplicitRelation } * */ - @XmlElementDecl(namespace = "", name = "model") - public JAXBElement createModel(Model value) { - return new JAXBElement(_Model_QNAME, Model.class, null, value); + public Model.ImplicitRelations.ImplicitRelation createModelImplicitRelationsImplicitRelation() { + return new Model.ImplicitRelations.ImplicitRelation(); } /** - * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >} + * Create an instance of {@link JAXBElement }{@code <}{@link Model }{@code >} * */ - @XmlElementDecl(namespace = "", name = "output", scope = Terminal.class) - public JAXBElement createTerminalOutput(String value) { - return new JAXBElement(_TerminalOutput_QNAME, String.class, Terminal.class, value); + @XmlElementDecl(namespace = "", name = "model") + public JAXBElement createModel(Model value) { + return new JAXBElement(_Model_QNAME, Model.class, null, value); } } diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Struct.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Struct.java index 35a031b..34f9b31 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Struct.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Struct.java @@ -140,7 +140,7 @@ public class Struct { @XmlType(name = "", propOrder = { "structOrTerminal" }) public static class Subnodes { - @XmlElements( { @XmlElement(name = "terminal", type = Terminal.class), @XmlElement(name = "struct", type = Struct.class) }) + @XmlElements({ @XmlElement(name = "terminal", type = Terminal.class), @XmlElement(name = "struct", type = Struct.class) }) protected List structOrTerminal; /** @@ -175,17 +175,4 @@ public class Struct { } - /* - * Overriden methods - */ - - /** - * @return the name - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return getName(); - } - } diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Terminal.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Terminal.java index 1cd69d4..33443c5 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Terminal.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Terminal.java @@ -13,11 +13,9 @@ package org.scilab.modules.xcos.modelica.model; -import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementRef; import javax.xml.bind.annotation.XmlType; /** @@ -46,7 +44,14 @@ import javax.xml.bind.annotation.XmlType; * <element name="nominal_value" type="{}ModelicaValue" minOccurs="0"/> * <element name="comment" type="{}ModelicaValue" minOccurs="0"/> * <element name="selected" type="{}ModelicaValue" minOccurs="0"/> - * <element name="output" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> + * <element name="output" minOccurs="0"> + * <complexType> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * </restriction> + * </complexContent> + * </complexType> + * </element> * </sequence> * </restriction> * </complexContent> @@ -77,8 +82,7 @@ public class Terminal { protected ModelicaValue nominalValue; protected ModelicaValue comment; protected ModelicaValue selected; - @XmlElementRef(name = "output", type = JAXBElement.class) - protected JAXBElement output; + protected Terminal.Output output; /** * Gets the value of the name property. @@ -314,11 +318,10 @@ public class Terminal { /** * Gets the value of the output property. * - * @return possible object is {@link JAXBElement }{@code <}{@link String } - * {@code >} + * @return possible object is {@link Terminal.Output } * */ - public JAXBElement getOutput() { + public Terminal.Output getOutput() { return output; } @@ -326,25 +329,36 @@ public class Terminal { * Sets the value of the output property. * * @param value - * allowed object is {@link JAXBElement }{@code <}{@link String } - * {@code >} + * allowed object is {@link Terminal.Output } * */ - public void setOutput(JAXBElement value) { + public void setOutput(Terminal.Output value) { this.output = value; } - /* - * Overriden methods - */ - /** - * @return the id - * @see java.lang.Object#toString() + *

+ * Java class for anonymous complex type. + * + *

+ * The following schema fragment specifies the expected content contained + * within this class. + * + *

+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
+     * 
+ * + * */ - @Override - public String toString() { - return getId(); + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "") + public static class Output { + } } diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/view/MainPanel.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/view/MainPanel.java index e2bb5e3..d5f354b 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/view/MainPanel.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/view/MainPanel.java @@ -49,6 +49,7 @@ import org.scilab.modules.xcos.modelica.listener.FixDerivativesAction; import org.scilab.modules.xcos.modelica.listener.FixStatesAction; import org.scilab.modules.xcos.modelica.listener.SolveAction; import org.scilab.modules.xcos.modelica.listener.StatisticsUpdater; +import org.scilab.modules.xcos.modelica.model.Model; import org.scilab.modules.xcos.modelica.model.Struct; import org.scilab.modules.xcos.modelica.model.Terminal; @@ -144,7 +145,11 @@ public final class MainPanel extends JPanel { */ private TreeModel createTreeModel() { final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode( - controller.getRoot()); + controller.getRoot()) { + public String toString() { + return ((Model) getUserObject()).getName(); + }; + }; final TreeModel model = new DefaultTreeModel(rootNode); for (Struct struct : controller.getRoot().getElements().getStruct()) { @@ -162,7 +167,11 @@ public final class MainPanel extends JPanel { * @return the parent node */ private MutableTreeNode createNodes(Struct struct) { - DefaultMutableTreeNode structNode = new DefaultMutableTreeNode(struct); + DefaultMutableTreeNode structNode = new DefaultMutableTreeNode(struct) { + public String toString() { + return ((Struct) getUserObject()).getName(); + }; + }; for (Object child : struct.getSubnodes().getStructOrTerminal()) { // recursive call -- 1.7.9.5