Search in sources :

Example 1 with XSDAnnotation

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

the class XSDExporter method createConstraint.

/**
 * Add an annotation explaining the equalizer and effect the isA.
 * <p/>
 * Today, this has two parts. First the annotation. For example in the
 * standard equalizer constraint in constraints.easik gives this annotation:
 *
 * <pre>
 * &lt;xs:annotation>
 *  &lt;xs:documentation>
 *     Equalizer(f3); B(f4) ;C(f5) ;Codomain =
 *     Equalizer(f1); D(f2) ;Codomain
 *   &lt;/xs:documentation>
 * &lt;/xs:annotation>
 * </pre>
 * <p/>
 * In addition, the equalizer entity has an "isA" relationship to another
 * entity at the start of the diagram, so this is reflected in the typing.
 * First, an element of equalizer type is added to the target of the "isA"
 * relationship. Second, since there is no need for a separate element in
 * the schema for the equalizer entity, its element is removed from the
 * sketch entity.
 *
 * @param eq
 *            the equalizer diagram constraint.
 * @todo Why not do this with standard isA relationships as well?
 * @todo The equalizer element should be added in some way so there is a
 *       "minoccurs" of zero.
 * @todo The equalizer does not really need a "key" element, but what if
 *       other constraints refer to it.
 */
private void createConstraint(final EqualizerConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> eq) {
    final List<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = eq.getEqualizerPaths();
    final EntityNode equalizer = eq.getEqualizerEntity();
    final XSDType domType = equalizer.getXsdType();
    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) {
        final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
        tmpPath.removeFirst();
        if (tmpPath.size() == 0) {
            values.add(equalizer.getName() + '(' + path.getFirstEdge().getForeignKeyName(keyrefName) + ')');
        } else {
            values.add(equalizer.getName() + '(' + path.getFirstEdge().getForeignKeyName(keyrefName) + ')' + xmlJoinPath(tmpPath, true));
        }
    }
    final EntityNode isaNode = paths.get(0).getDomain();
    final XSDComplexType isaNodeType = (XSDComplexType) isaNode.getXsdType();
    final XSDElement element = equalizer.getXsdElement();
    element.setParent(isaNode.getXsdElement());
    isaNodeType.addAtom(element);
    equalizer.setXsdElement(null);
    domType.addAnnotation(new XSDAnnotation(EasikTools.join(" = " + lineSep, values)));
}
Also used : ArrayList(java.util.ArrayList) XSDElement(easik.xml.xsd.nodes.elements.XSDElement) 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) XSDComplexType(easik.xml.xsd.nodes.types.XSDComplexType)

Example 2 with XSDAnnotation

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

the class XSDExporter method createConstraint.

/**
 * Add an annotation explaining the commutativity of the diagram.
 * <p/>
 * Today, this is simply done by creating an annotation. For example in the
 * standard cd in constraints.easik gives this annotation:
 *
 * <pre>
 * &lt;xs:annotation>
 *  &lt;xs:documentation>
 *     Domain(f1); A(f2) ;Codomain =
 *     Domain(f3); B(f4) ;Codomain
 *   &lt;/xs:documentation>
 * &lt;/xs:annotation>
 * </pre>
 *
 * @param cd
 *            the commutative diagram constraint.
 */
private void createConstraint(final CommutativeDiagram<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> cd) {
    final List<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = cd.getPaths();
    final EntityNode dom = paths.get(0).getDomain();
    final XSDType domType = dom.getXsdType();
    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) {
        final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
        tmpPath.removeFirst();
        if (tmpPath.size() == 0) {
            values.add(dom.getName() + '(' + path.getFirstEdge().getForeignKeyName(keyrefName) + ')');
        } else {
            values.add(dom.getName() + '(' + path.getFirstEdge().getForeignKeyName(keyrefName) + ')' + xmlJoinPath(tmpPath, true));
        }
    }
    domType.addAnnotation(new XSDAnnotation(EasikTools.join(" = " + lineSep, values)));
}
Also used : ArrayList(java.util.ArrayList) 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)

Example 3 with XSDAnnotation

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

the class XSDExporter method createConstraint.

/**
 * Add an annotation explaining the sum constraint and effect the isAs.
 * <p/>
 * Today, this has two parts. First the annotation is truly just
 * documentation in this case. The second part of the constraint creation,
 * where the isA parts are added as elements of the type suffices to explain
 * everything that is needed. In the standard sum constraint in
 * constraints.easik gives this annotation:
 *
 * <pre>
 * &lt;xs:annotation>
 *  &lt;xs:documentation>
 *     Sum is a disjoint generalization of Summand1 and Summand2 and Summand3
 *   &lt;/xs:documentation>
 * &lt;/xs:annotation>
 * </pre>
 * <p/>
 * Each of the Summand entities have an "isA" relationship to the Sum entity
 * at the start of the diagram, so this is reflected in the typing. First,
 * an element of each Summand type is added to the target of the "isA"
 * relationship. Second, since there is no need for a separate element in
 * the schema for the Summand entity, its element is removed from the sketch
 * entity.
 *
 * @param sum
 *            the summand diagram constraint.
 * @todo Why not do this with standard isA relationships as well?
 */
private static void createConstraint(final SumConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> sum) {
    final Map<String, StringBuilder> codMap = new HashMap<>(10);
    final Map<String, XSDType> codToXMLType = new HashMap<>(10);
    XSDChoiceCompositor summands = new XSDChoiceCompositor(new ArrayList<XSDAbstractElement>(sum.getPaths().size()));
    String cdTypeName = "";
    XSDComplexType lastCodomainType = null;
    for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : sum.getPaths()) {
        final EntityNode coDomain = path.getCoDomain();
        final EntityNode dom = path.getDomain();
        final String coDomainName = coDomain.getName();
        final StringBuilder coDomainAnnotation;
        if (codMap.containsKey(coDomainName)) {
            coDomainAnnotation = codMap.get(coDomainName);
            coDomainAnnotation.append(" and ").append(dom.getName());
        } else {
            coDomainAnnotation = new StringBuilder(100);
            coDomainAnnotation.append(coDomain.getName()).append(" is a disjoint generalization of ").append(dom.getName());
        }
        final XSDComplexType codomainType = (XSDComplexType) coDomain.getXsdType();
        if ((null != lastCodomainType) && !cdTypeName.equals(codomainType.getName())) {
            if (!summands.isEmpty()) {
                lastCodomainType.addAtom(summands);
                summands = new XSDChoiceCompositor(new ArrayList<XSDAbstractElement>(sum.getPaths().size()));
            }
        }
        lastCodomainType = codomainType;
        cdTypeName = codomainType.getName();
        codToXMLType.put(coDomainName, codomainType);
        codMap.put(coDomainName, coDomainAnnotation);
        final XSDElement element = dom.getXsdElement();
        element.setParent(coDomain.getXsdElement());
        summands.addSubElement(element);
        dom.setXsdElement(null);
    }
    if (null != lastCodomainType) {
        if (!summands.isEmpty()) {
            lastCodomainType.addAtom(summands);
            summands = null;
        }
    }
    for (final Map.Entry<String, StringBuilder> entry : codMap.entrySet()) {
        final XSDType typ = codToXMLType.get(entry.getKey());
        typ.addAnnotation(new XSDAnnotation(entry.getValue().toString()));
    }
}
Also used : HashMap(java.util.HashMap) XSDAbstractElement(easik.xml.xsd.nodes.elements.XSDAbstractElement) ArrayList(java.util.ArrayList) XSDElement(easik.xml.xsd.nodes.elements.XSDElement) XSDType(easik.xml.xsd.nodes.types.XSDType) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode) SketchFrame(easik.ui.SketchFrame) SketchEdge(easik.sketch.edge.SketchEdge) Sketch(easik.sketch.Sketch) XSDChoiceCompositor(easik.xml.xsd.nodes.elements.XSDChoiceCompositor) XSDAnnotation(easik.xml.xsd.nodes.XSDAnnotation) HashMap(java.util.HashMap) Map(java.util.Map) XSDComplexType(easik.xml.xsd.nodes.types.XSDComplexType)

Example 4 with XSDAnnotation

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

the class XSDExporter method createConstraint.

/**
 * Add an annotation explaining the pullback.
 * <p/>
 * Today, this is simply done by creating an annotation. For example in the
 * standard pullback constraint in constraints.easik gives this annotation:
 *
 * <pre>
 * &lt;xs:annotation>
 *  &lt;xs:documentation>
 *     ForAll.elemA in B, ForAll.elemB in C :
 *     elemA.f1 in A=elemB.isA_1 in A
 *     ==> Exists.p=(elemA,elemB) in Pullback
 *   &lt;/xs:documentation>
 * &lt;/xs:annotation>
 * </pre>
 *
 * @param pb
 *            the product diagram constraint.
 */
private void createConstraint(final PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> pb) {
    final List<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = pb.getPaths();
    final EntityNode dom = paths.get(0).getDomain();
    final XSDType domType = dom.getXsdType();
    final List<String> elts = new ArrayList<>(paths.size());
    @SuppressWarnings("unused") final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
    final List<String> values = new ArrayList<>();
    final List<String> equalities = new ArrayList<>();
    // WPBEDIT CF2012
    for (int i = 0; i < pb.getWidth(); i++) {
        final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path = pb.getFullPath(i);
        final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
        tmpPath.removeFirst();
        values.add("ForAll.elem" + i + " in " + xmlPBJoinPath(tmpPath, false));
        equalities.add("elem" + i + '.' + xmlPBelemJoinPath(tmpPath, true));
        elts.add("elem" + i);
    }
    final String valdocumentation = EasikTools.join(", ", values);
    final String equalDoc = EasikTools.join("=", equalities);
    final String elements = "==> Exists.p=(" + EasikTools.join(",", elts) + ") in " + dom.getName();
    domType.addAnnotation(new XSDAnnotation(valdocumentation + " : " + lineSep + equalDoc + 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)

Example 5 with XSDAnnotation

use of easik.xml.xsd.nodes.XSDAnnotation 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

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 XSDType (easik.xml.xsd.nodes.types.XSDType)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 XSDAbstractElement (easik.xml.xsd.nodes.elements.XSDAbstractElement)1 XSDChoiceCompositor (easik.xml.xsd.nodes.elements.XSDChoiceCompositor)1