svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libTools / src-test / org / gvsig / tools / persistence / xml / XMLPersistenceTest_Persistent2.java @ 30619
History | View | Annotate | Download (2.74 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_Persistent2 implements Persistent { |
39 |
|
40 |
private static final String ElObjeto2 = "Este es el objeto 2"; |
41 |
|
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_Persistent2_Persistent", ""); |
51 |
|
52 |
dynClass.addDynFieldSingle("ElObjeto2", DataTypes.STRING,
|
53 |
null, true, true); |
54 |
|
55 |
ToolsLocator.getPersistenceManager().registerClass( |
56 |
XMLPersistenceTest_Persistent2.class, dynClass); |
57 |
|
58 |
} |
59 |
|
60 |
private PersistentState loaded;
|
61 |
|
62 |
public void checked() throws PersistenceException { |
63 |
assertEquals(ElObjeto2, loaded.get("ElObjeto2"));
|
64 |
} |
65 |
|
66 |
|
67 |
public void saveToState(PersistentState state) throws PersistenceException { |
68 |
state.set("ElObjeto2", ElObjeto2);
|
69 |
} |
70 |
|
71 |
|
72 |
// / UTILITY METHODS
|
73 |
|
74 |
private void assertEquals(Object expected, Object value) { |
75 |
if (expected == value) {
|
76 |
return;
|
77 |
} |
78 |
if (expected == null || !value.equals(expected)) { |
79 |
throw new RuntimeException("assertEquals: Expected '" + expected |
80 |
+ "' current '" + value + "'"); |
81 |
} |
82 |
} |
83 |
|
84 |
private void assertTrue(boolean value) { |
85 |
if (!value) {
|
86 |
throw new RuntimeException("assertTrue"); |
87 |
} |
88 |
} |
89 |
|
90 |
private void assertFalse(boolean value) { |
91 |
if (value) {
|
92 |
throw new RuntimeException("assertFalse"); |
93 |
} |
94 |
} |
95 |
|
96 |
public void loadFromState(PersistentState state) |
97 |
throws PersistenceException {
|
98 |
loaded = state; |
99 |
|
100 |
} |
101 |
|
102 |
} |