Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libTools / src-test / org / gvsig / tools / persistence / xml / XMLPersistenceTest_Persistent_ciclical.java @ 30619

History | View | Annotate | Download (3.16 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
27

    
28
package org.gvsig.tools.persistence.xml;
29

    
30
import org.gvsig.tools.ToolsLocator;
31
import org.gvsig.tools.dataTypes.DataTypes;
32
import org.gvsig.tools.dynobject.DynClass;
33
import org.gvsig.tools.dynobject.DynObjectManager;
34
import org.gvsig.tools.persistence.PersistenceException;
35
import org.gvsig.tools.persistence.Persistent;
36
import org.gvsig.tools.persistence.PersistentState;
37

    
38
public class XMLPersistenceTest_Persistent_ciclical implements Persistent {
39

    
40

    
41
        private static final String ElObjeto3 = "Este es el objeto 2";
42

    
43
        /**
44
         * Register the class on PersistenceManager
45
         *
46
         */
47
        public static void registerPersistent() {
48
                DynObjectManager dynMan = ToolsLocator.getDynObjectManager();
49
                DynClass dynClass = dynMan.add(
50
                                "XMLPersistenceTest_Persistent_ciclical", "");
51

    
52
                dynClass.addDynFieldSingle("ElObjeto3", DataTypes.STRING, null, true,
53
                                true);
54

    
55
                dynClass
56
                                .addDynFieldSingle("Source", DataTypes.OBJECT, null, true,
57
                                true);
58

    
59
                ToolsLocator.getPersistenceManager().registerClass(
60
                                XMLPersistenceTest_Persistent_ciclical.class, dynClass);
61

    
62
        }
63

    
64
        private PersistentState loaded;
65

    
66
        private XMLPersistenceTest_Persistent source;
67

    
68
        public XMLPersistenceTest_Persistent_ciclical() {
69
        }
70

    
71
        public XMLPersistenceTest_Persistent_ciclical(
72
                        XMLPersistenceTest_Persistent objSource) {
73
                source = objSource;
74
        }
75

    
76
        public void checked(XMLPersistenceTest_Persistent source)
77
                        throws PersistenceException {
78
                assertEquals(ElObjeto3, loaded.get("ElObjeto3"));
79
                assertEquals(source, loaded.get("Source"));
80
        }
81

    
82

    
83
        public void saveToState(PersistentState state) throws PersistenceException {
84
                state.set("ElObjeto3", ElObjeto3);
85
                state.set("Source", source);
86
        }
87

    
88

    
89
        // / UTILITY METHODS
90

    
91
        private void assertEquals(Object expected, Object value) {
92
                if (expected == value) {
93
                        return;
94
                }
95
                if (expected == null || !value.equals(expected)) {
96
                        throw new RuntimeException("assertEquals: Expected '" + expected
97
                                        + "' current '" + value + "'");
98
                }
99
        }
100

    
101
        private void assertTrue(boolean value) {
102
                if (!value) {
103
                        throw new RuntimeException("assertTrue");
104
                }
105
        }
106

    
107
        private void assertFalse(boolean value) {
108
                if (value) {
109
                        throw new RuntimeException("assertFalse");
110
                }
111
        }
112

    
113
        public void loadFromState(PersistentState state)
114
                        throws PersistenceException {
115
                loaded = state;
116

    
117
        }
118

    
119
}