~ubuntu-branches/ubuntu/precise/scilab/precise

« back to all changes in this revision

Viewing changes to modules/xcos/src/java/org/scilab/modules/graph/io/ScilabObjectCodec.java

  • Committer: Bazaar Package Importer
  • Author(s): Sylvestre Ledru
  • Date: 2010-04-16 15:57:24 UTC
  • mfrom: (1.1.9 upstream) (4.4.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100416155724-lx1sdku0oidl0ffn
Tags: 5.2.2-1
* New upstream release
* better-feedback-on-lib-error.diff, full_support.diff, renesas-sh.diff,
  s390javadetection.diff, sparc64.diff, test_run_permission.diff,
  z_cpudetection.diff removed (applied upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 
3
 * Copyright (C) 2010 - DIGITEO - Clément DAVID
 
4
 *
 
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
 
10
 *
 
11
 */
 
12
 
 
13
package org.scilab.modules.graph.io;
 
14
 
 
15
import java.util.Map;
 
16
 
 
17
import org.w3c.dom.NamedNodeMap;
 
18
import org.w3c.dom.Node;
 
19
 
 
20
import com.mxgraph.io.mxCodec;
 
21
import com.mxgraph.io.mxObjectCodec;
 
22
import com.mxgraph.model.mxCell;
 
23
 
 
24
/**
 
25
 * Codec for any Scilab object
 
26
 */
 
27
public abstract class ScilabObjectCodec extends mxObjectCodec {
 
28
        /**
 
29
         * Throw when we cannot load the XML.
 
30
         */
 
31
        public class UnrecognizeFormatException extends Exception {
 
32
                /**
 
33
                 * Default constructor
 
34
                 */
 
35
                public UnrecognizeFormatException() {
 
36
                        super();
 
37
                }
 
38
        }
 
39
 
 
40
        /**
 
41
         * The constructor used on the configuration
 
42
         * 
 
43
         * @param template
 
44
         *            Prototypical instance of the object to be encoded/decoded.
 
45
         * @param exclude
 
46
         *            Optional array of fieldnames to be ignored.
 
47
         * @param idrefs
 
48
         *            Optional array of fieldnames to be converted to/from
 
49
         *            references.
 
50
         * @param mapping
 
51
         *            Optional mapping from field- to attributenames.
 
52
         */
 
53
        public ScilabObjectCodec(Object template, String[] exclude,
 
54
                        String[] idrefs, Map<String, String> mapping) {
 
55
                super(template, exclude, idrefs, mapping);
 
56
 
 
57
        }
 
58
 
 
59
        /**
 
60
         * Apply compatibility pattern to the decoded object
 
61
         * 
 
62
         * @param dec
 
63
         *            Codec that controls the decoding process.
 
64
         * @param node
 
65
         *            XML node to decode the object from.
 
66
         * @param obj
 
67
         *            Object decoded.
 
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)
 
71
         */
 
72
        @Override
 
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());
 
80
                                }
 
81
                        }
 
82
                }
 
83
                return obj;
 
84
        }
 
85
}