2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015-2015 - Scilab Enterprises - Clement DAVID
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 package org.scilab.modules.xcos.io.sax;
15 import java.util.ArrayList;
17 import org.scilab.modules.xcos.Kind;
18 import org.scilab.modules.xcos.ObjectProperties;
19 import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
20 import org.scilab.modules.xcos.io.HandledElement;
21 import org.scilab.modules.xcos.io.sax.XcosSAXHandler.UnresolvedReference;
22 import org.scilab.modules.xcos.link.BasicLink;
23 import org.scilab.modules.xcos.link.CommandControlLink;
24 import org.scilab.modules.xcos.link.ExplicitLink;
25 import org.scilab.modules.xcos.link.ImplicitLink;
26 import org.xml.sax.Attributes;
27 import org.xml.sax.SAXParseException;
29 class LinkHandler implements ScilabHandler {
31 private final XcosSAXHandler saxHandler;
37 * the shared sax handler
39 LinkHandler(XcosSAXHandler saxHandler) {
40 this.saxHandler = saxHandler;
44 public BasicLink startElement(HandledElement found, Attributes atts) {
48 final long uid = saxHandler.controller.createObject(Kind.LINK);
51 case CommandControlLink:
52 link = new CommandControlLink(uid);
56 link = new ExplicitLink(uid);
60 link = new ImplicitLink(uid);
64 throw new IllegalArgumentException();
70 v = atts.getValue("id");
73 saxHandler.allChildren.peek().put(v, uid);
76 saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.KIND, linkKind);
78 v = atts.getValue("source");
80 Long src = saxHandler.allChildren.peek().get(v);
82 // if the attribute is present then the connected port is already
83 // decoded and present in the map
84 saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.SOURCE_PORT, src.longValue());
85 saxHandler.controller.setObjectProperty(src.longValue(), Kind.PORT, ObjectProperties.CONNECTED_SIGNALS, uid);
87 // if not present then it will be resolved later
88 ArrayList<UnresolvedReference> refList = saxHandler.unresolvedReferences.get(v);
89 if (refList == null) {
90 refList = new ArrayList<>();
91 saxHandler.unresolvedReferences.put(v, refList);
93 refList.add(new UnresolvedReference(new ScicosObjectOwner(uid, Kind.LINK), ObjectProperties.SOURCE_PORT, ObjectProperties.CONNECTED_SIGNALS, 0));
97 v = atts.getValue("target");
99 Long dst = saxHandler.allChildren.peek().get(v);
101 // if the attribute is present then the connected port is already
102 // decoded and present in the map
103 saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.DESTINATION_PORT, dst.longValue());
104 saxHandler.controller.setObjectProperty(dst.longValue(), Kind.PORT, ObjectProperties.CONNECTED_SIGNALS, uid);
106 // if not present then it will be resolved later
107 ArrayList<UnresolvedReference> refList = saxHandler.unresolvedReferences.get(v);
108 if (refList == null) {
109 refList = new ArrayList<>();
110 saxHandler.unresolvedReferences.put(v, refList);
112 refList.add(new UnresolvedReference(new ScicosObjectOwner(uid, Kind.LINK), ObjectProperties.DESTINATION_PORT, ObjectProperties.CONNECTED_SIGNALS, 0));
116 v = atts.getValue("style");
118 saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.STYLE, v);
121 v = atts.getValue("value");
123 saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.LABEL, v);
126 saxHandler.insertChild(link);
131 public void endElement(HandledElement found) {