2
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3
* Copyright (C) 2010 - DIGITEO - Clément 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-en.txt
13
package org.scilab.modules.graph.io;
17
import org.w3c.dom.NamedNodeMap;
18
import org.w3c.dom.Node;
20
import com.mxgraph.io.mxCodec;
21
import com.mxgraph.io.mxObjectCodec;
22
import com.mxgraph.model.mxCell;
25
* Codec for any Scilab object
27
public abstract class ScilabObjectCodec extends mxObjectCodec {
29
* Throw when we cannot load the XML.
31
public class UnrecognizeFormatException extends Exception {
35
public UnrecognizeFormatException() {
41
* The constructor used on the configuration
44
* Prototypical instance of the object to be encoded/decoded.
46
* Optional array of fieldnames to be ignored.
48
* Optional array of fieldnames to be converted to/from
51
* Optional mapping from field- to attributenames.
53
public ScilabObjectCodec(Object template, String[] exclude,
54
String[] idrefs, Map<String, String> mapping) {
55
super(template, exclude, idrefs, mapping);
60
* Apply compatibility pattern to the decoded object
63
* Codec that controls the decoding process.
65
* XML node to decode the object from.
68
* @return The Object transformed
69
* @see org.scilab.modules.xcos.io.XcosObjectCodec#afterDecode(com.mxgraph.io.mxCodec,
70
* org.w3c.dom.Node, java.lang.Object)
73
public Object afterDecode(mxCodec dec, Node node, Object obj) {
74
if (node.getNodeName().equals("mxCell")) {
75
NamedNodeMap attrs = node.getAttributes();
76
for (int i = 0; i < attrs.getLength(); i++) {
77
Node attr = attrs.item(i);
78
if (attr.getNodeName().compareToIgnoreCase("id") == 0) {
79
((mxCell) obj).setId(attr.getNodeValue());