Search in sources :

Example 6 with XSDType

use of easik.xml.xsd.nodes.types.XSDType in project fql by CategoricalData.

the class XSDExporter method createConstraint.

/**
 * Add an annotation explaining the product.
 * <p/>
 * Today, this is simply done by creating an annotation. For example in the
 * standard product constraint in constraints.easik gives this annotation:
 *
 * <pre>
 * &lt;xs:annotation>
 *  &lt;xs:documentation>
 *     ForAll.elem1 in (P1), ForAll.elem2 in (P2)
 *     Exists.p=(elem1,elem2) in Product
 *   &lt;/xs:documentation>
 * &lt;/xs:annotation>
 * </pre>
 *
 * @param prod
 *            the product diagram constraint.
 */
private void createConstraint(final ProductConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> prod) {
    final List<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = prod.getPaths();
    final EntityNode dom = paths.get(0).getDomain();
    final XSDType domType = dom.getXsdType();
    final List<String> elts = new ArrayList<>(paths.size());
    int id = 0;
    @SuppressWarnings("unused") final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
    final List<String> values = new ArrayList<>(paths.size());
    for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : paths) {
        id++;
        final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
        tmpPath.removeFirst();
        final String elem = "elem" + id;
        elts.add(elem);
        if (tmpPath.size() == 0) {
            values.add("ForAll." + elem + " in (" + path.getCoDomain().getName() + ')');
        } else {
            values.add("ForAll." + elem + " in " + xmlJoinPath(tmpPath, true));
        }
    }
    final String documentation = EasikTools.join(", ", values);
    final String elements = "Exists.p=(" + EasikTools.join(",", elts) + ") in " + dom.getName();
    domType.addAnnotation(new XSDAnnotation(documentation + lineSep + elements));
}
Also used : ArrayList(java.util.ArrayList) LimitConstraint(easik.model.constraint.LimitConstraint) EqualizerConstraint(easik.model.constraint.EqualizerConstraint) ProductConstraint(easik.model.constraint.ProductConstraint) SumConstraint(easik.model.constraint.SumConstraint) PullbackConstraint(easik.model.constraint.PullbackConstraint) ModelConstraint(easik.model.constraint.ModelConstraint) LinkedList(java.util.LinkedList) EntityNode(easik.sketch.vertex.EntityNode) XSDType(easik.xml.xsd.nodes.types.XSDType) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) SketchEdge(easik.sketch.edge.SketchEdge) ModelPath(easik.model.path.ModelPath) Sketch(easik.sketch.Sketch) XSDAnnotation(easik.xml.xsd.nodes.XSDAnnotation)

Aggregations

XSDType (easik.xml.xsd.nodes.types.XSDType)6 Sketch (easik.sketch.Sketch)5 SketchEdge (easik.sketch.edge.SketchEdge)5 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)5 EntityNode (easik.sketch.vertex.EntityNode)5 SketchFrame (easik.ui.SketchFrame)5 XSDAnnotation (easik.xml.xsd.nodes.XSDAnnotation)5 ArrayList (java.util.ArrayList)5 ModelPath (easik.model.path.ModelPath)4 LinkedList (java.util.LinkedList)4 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)2 LimitConstraint (easik.model.constraint.LimitConstraint)2 ModelConstraint (easik.model.constraint.ModelConstraint)2 ProductConstraint (easik.model.constraint.ProductConstraint)2 PullbackConstraint (easik.model.constraint.PullbackConstraint)2 SumConstraint (easik.model.constraint.SumConstraint)2 XSDElement (easik.xml.xsd.nodes.elements.XSDElement)2 XSDComplexType (easik.xml.xsd.nodes.types.XSDComplexType)2 Prettify (easik.xml.Prettify)1 XSDBaseNode (easik.xml.xsd.nodes.XSDBaseNode)1