Revision 30619

View differences:

branches/v2_0_0_prep/libraries/libTools/src-test/org/gvsig/tools/persistence/xml/XMLPersistenceTest.java
66 66
//
67 67
//		toolsLib.postInitialize();
68 68
//		xmlPersistenceLib.postInitialize();
69

  
70
		ToolsLocator
71
				.registerPersistenceManager(XMLPersistenceManager.class);
72

  
73
		XMLPersistenceTest_Persistent.registerPersistent();
74
		XMLPersistenceTest_Persistent2.registerPersistent();
75
		XMLPersistenceTest_Persistent_ciclical.registerPersistent();
69 76
	}
70 77

  
71 78
	public void test() throws Exception {
branches/v2_0_0_prep/libraries/libTools/src-test/org/gvsig/tools/persistence/xml/XMLPersistenceTest_Persistent.java
28 28
package org.gvsig.tools.persistence.xml;
29 29

  
30 30
import java.util.ArrayList;
31
import java.util.Date;
31 32
import java.util.HashMap;
32 33
import java.util.List;
33 34
import java.util.Map;
34 35
import java.util.Set;
35 36
import java.util.TreeSet;
36 37

  
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dataTypes.DataTypes;
40
import org.gvsig.tools.dynobject.DynClass;
41
import org.gvsig.tools.dynobject.DynObjectManager;
37 42
import org.gvsig.tools.persistence.PersistenceException;
38 43
import org.gvsig.tools.persistence.Persistent;
39 44
import org.gvsig.tools.persistence.PersistentState;
......
51 56
	private static final Integer UnInteger = new Integer(1);
52 57
	private static final Double UnDouble = new Double(1.234);
53 58
	private static final Float UnFloat = new Float(1.234);
59
	private static final Date UnDate = new Date(System.currentTimeMillis());
54 60

  
55 61

  
62
	/**
63
	 * Register the class on PersistenceManager
64
	 *
65
	 */
66
	public static void registerPersistent() {
67
		DynObjectManager dynMan = ToolsLocator.getDynObjectManager();
68
		DynClass dynClass = dynMan.add(
69
				"XMLPersistenceTest_Persistent_Persistent", "");
70

  
71
		dynClass.addDynFieldSingle("UnString", DataTypes.STRING, null, true,
72
				true);
73
		dynClass.addDynFieldSingle("UnStringValorLargo", DataTypes.STRING,
74
				null, true, true);
75
		dynClass.addDynFieldSingle("UnStringValorNoXML", DataTypes.STRING,
76
				null, true, true);
77
		dynClass
78
				.addDynFieldSingle("UnLong", DataTypes.LONG, null,
79
				true, true);
80
		dynClass
81
				.addDynFieldSingle("UnInteger", DataTypes.INT, null, true, true);
82
		dynClass.addDynFieldSingle("UnDouble", DataTypes.DOUBLE, null, true,
83
				true);
84

  
85
		dynClass
86
				.addDynFieldSingle("unList", DataTypes.LIST, null, true, true);
87

  
88
		dynClass.addDynFieldSingle("unListPorIterador", DataTypes.LIST, null,
89
				true, true);
90

  
91
		dynClass.addDynFieldSingle("unSet", DataTypes.SET, null, true, true);
92

  
93
		dynClass.addDynFieldSingle("yoMismo", DataTypes.OBJECT, null, true,
94
				true);
95

  
96
		dynClass.addDynFieldSingle("unMap", DataTypes.MAP, null, true, true);
97

  
98
		dynClass.addDynFieldSingle("otro_Objeto", DataTypes.OBJECT, null, true,
99
				true);
100

  
101
		dynClass.addDynFieldSingle("referencia_ciclica", DataTypes.OBJECT,
102
				null, true, true);
103

  
104
		dynClass.addDynFieldSingle("unDate", DataTypes.DATE, null, true, true);
105

  
106
		dynClass.addDynFieldSingle("UnBooleanoTrue", DataTypes.BOOLEAN, null,
107
				true, true);
108
		dynClass.addDynFieldSingle("UnBooleanoFalse", DataTypes.BOOLEAN, null,
109
				true, true);
110

  
111
		dynClass
112
				.addDynFieldSingle("UnNulo", DataTypes.STRING, null, true,
113
				true);
114

  
115

  
116
		ToolsLocator.getPersistenceManager().registerClass(
117
				XMLPersistenceTest_Persistent.class, dynClass);
118

  
119
	}
120

  
121

  
122

  
56 123
	private PersistentState loaded;
57 124

  
58 125
	public void checked() throws PersistenceException {
......
62 129
		assertEquals(UnLong, loaded.get("UnLong"));
63 130
		assertEquals(UnInteger, loaded.get("UnInger"));
64 131
		assertEquals(UnDouble, loaded.get("UnDouble"));
132
		assertEquals(UnDate, loaded.get("UnDate"));
65 133

  
66 134
		// TODO check rest of values
67 135

  
......
140 208

  
141 209

  
142 210

  
211

  
143 212
	}
144 213

  
145 214

  
......
150 219
		state.set("UnLong", UnLong);
151 220
		state.set("UnInger", UnInteger);
152 221
		state.set("UnDouble", UnDouble);
222
		state.set("UnDate", UnDate);
153 223

  
154 224
		ArrayList list = new ArrayList(3);
155 225
		list.add(new Integer(1));
branches/v2_0_0_prep/libraries/libTools/src-test/org/gvsig/tools/persistence/xml/XMLPersistenceTest_Persistent2.java
27 27

  
28 28
package org.gvsig.tools.persistence.xml;
29 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;
30 34
import org.gvsig.tools.persistence.PersistenceException;
31 35
import org.gvsig.tools.persistence.Persistent;
32 36
import org.gvsig.tools.persistence.PersistentState;
......
35 39

  
36 40
	private static final String ElObjeto2 = "Este es el objeto 2";
37 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

  
38 60
	private PersistentState loaded;
39 61

  
40 62
	public void checked() throws PersistenceException {
branches/v2_0_0_prep/libraries/libTools/src-test/org/gvsig/tools/persistence/xml/XMLPersistenceTest_Persistent_ciclical.java
27 27

  
28 28
package org.gvsig.tools.persistence.xml;
29 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;
30 34
import org.gvsig.tools.persistence.PersistenceException;
31 35
import org.gvsig.tools.persistence.Persistent;
32 36
import org.gvsig.tools.persistence.PersistentState;
......
36 40

  
37 41
	private static final String ElObjeto3 = "Este es el objeto 2";
38 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

  
39 64
	private PersistentState loaded;
40 65

  
41 66
	private XMLPersistenceTest_Persistent source;
branches/v2_0_0_prep/libraries/libTools/src-test/org/gvsig/tools/persistence/xml/ZipXMLPersistenceTest.java
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
/**
29
 *
30
 */
31
package org.gvsig.tools.persistence.xml;
32

  
33
import java.io.ByteArrayInputStream;
34
import java.io.ByteArrayOutputStream;
35
import java.io.File;
36
import java.io.FileOutputStream;
37
import java.util.ArrayList;
38
import java.util.Iterator;
39
import java.util.List;
40

  
41
import junit.framework.TestCase;
42

  
43
import org.gvsig.tools.ToolsLibrary;
44
import org.gvsig.tools.ToolsLocator;
45
import org.gvsig.tools.persistence.PersistenceManager;
46
import org.gvsig.tools.persistence.Persistent;
47
import org.gvsig.tools.persistence.PersistentState;
48

  
49
/**
50
 * @author jmvivo
51
 *
52
 */
53
public class ZipXMLPersistenceTest extends TestCase {
54

  
55
	/* (non-Javadoc)
56
	 * @see junit.framework.TestCase#setUp()
57
	 */
58
	protected void setUp() throws Exception {
59
		super.setUp();
60
		ToolsLibrary toolsLib = new ToolsLibrary();
61
		XMLPersistenceLibrary xmlPersistenceLib = new XMLPersistenceLibrary();
62

  
63
		toolsLib.initialize();
64
		xmlPersistenceLib.initialize();
65

  
66
		toolsLib.postInitialize();
67
		xmlPersistenceLib.postInitialize();
68

  
69

  
70
		ToolsLocator.registerPersistenceManager(ZipXMLPersistenceManager.class);
71

  
72
		XMLPersistenceTest_Persistent.registerPersistent();
73
		XMLPersistenceTest_Persistent2.registerPersistent();
74
		XMLPersistenceTest_Persistent_ciclical.registerPersistent();
75
	}
76

  
77
	public void test() throws Exception {
78
		Persistent myPersistent = new XMLPersistenceTest_Persistent();
79

  
80
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
81

  
82
		PersistentState state = manager.getState(myPersistent);
83

  
84
		ByteArrayOutputStream out = new ByteArrayOutputStream(100 * 1024);
85

  
86
		manager.saveState(state, out);
87
		out.flush();
88

  
89
		byte[] bytesOut = out.toByteArray();
90

  
91

  
92
		File file = new File("out.zip");
93

  
94
		FileOutputStream fout = new FileOutputStream(file);
95

  
96
		fout.write(bytesOut);
97

  
98
		fout.flush();
99
		fout.close();
100
		System.out.println("Writed file:" + file.getAbsolutePath());
101

  
102
		ByteArrayInputStream in = new ByteArrayInputStream(bytesOut);
103
		PersistentState stateIn = manager.loadState(in);
104

  
105
		List names = new ArrayList();
106
		List namesIn = new ArrayList();
107

  
108
		Iterator iter = state.getNames();
109
		while (iter.hasNext()) {
110
			names.add(iter.next());
111
		}
112
		iter = stateIn.getNames();
113
		while (iter.hasNext()) {
114
			namesIn.add(iter.next());
115
		}
116

  
117
		assertEquals(names.size(), namesIn.size());
118

  
119
		iter = names.iterator();
120
		while (iter.hasNext()) {
121
			assertTrue(namesIn.contains(iter.next()));
122
		}
123

  
124
		Object loadedPersistent = manager.create(stateIn);
125

  
126
		assertTrue(loadedPersistent instanceof XMLPersistenceTest_Persistent);
127

  
128
		((XMLPersistenceTest_Persistent) loadedPersistent).checked();
129

  
130

  
131

  
132
	}
133

  
134

  
135
}
0 136

  
branches/v2_0_0_prep/libraries/libTools/src-test/org/gvsig/tools/persistence/impl/AbstractPersistenceManagerTest.java
41 41
import org.gvsig.tools.dynobject.DynField;
42 42
import org.gvsig.tools.dynobject.DynStruct;
43 43
import org.gvsig.tools.persistence.PersistenceException;
44
import org.gvsig.tools.persistence.PersistenceFactory;
45 44
import org.gvsig.tools.persistence.PersistenceManager;
46 45
import org.gvsig.tools.persistence.PersistenceValidateExceptions;
47 46
import org.gvsig.tools.persistence.Persistent;
......
161 160

  
162 161
		myPersistenceManager.setMockPersistentState(persistentState);
163 162

  
163
		myPersistenceManager.registerClass(DummyPersistent.class);
164 164
		myPersistenceManager.addAlias("org.gvsig.OldPersistent",
165 165
				DummyPersistent.class);
166 166

  
......
203 203
	 * Test method for {@link org.gvsig.tools.persistence.impl.AbstractPersistenceManager#create(org.gvsig.tools.persistence.PersistentState)}.
204 204
	 */
205 205
	/* TODO FIXME API CHANGED
206
	public void testCreate() throws Exception {		
206
	public void testCreate() throws Exception {
207 207
		persistentStateControl.expectAndReturn(persistentState
208 208
				.getTheClassName(), DummyPersistent.class.getName(), 2);
209 209

  
......
262 262
		Iterator iter = myPersistenceManager.getPersistentClasses();
263 263
		assertNotNull(iter);
264 264
		assertTrue(iter.hasNext());
265
		assertEquals(DummyPersistent.class.getName(), iter.next());
265
		assertEquals(DummyPersistent.class, iter.next());
266 266
		assertFalse(iter.hasNext());
267 267

  
268 268
	}
269 269

  
270
	/**
271
	 * Test method for {@link org.gvsig.tools.persistence.impl.AbstractPersistenceManager#removeDefinition(java.lang.Class)}.
272
	 */
273
	public void testRemoveDefinition() {
274
		myPersistenceManager.registerClass(DummyPersistent.class, dynStruct);
275
		myPersistenceManager.removeDefinition(DummyPersistent.class);
276
		assertNull(myPersistenceManager.getDefinition(DummyPersistent.class));
277
	}
278 270

  
279 271
	/**
280 272
	 * Test method for {@link org.gvsig.tools.persistence.impl.AbstractPersistenceManager#validate(org.gvsig.tools.persistence.PersistentState)}.
......
592 584

  
593 585
		Persistent aPersistent = new DummyPersistent();
594 586

  
587
		myPersistenceManager.registerClass(aPersistent.getClass());
595 588
		PersistentState aState = myPersistenceManager.getState(aPersistent);
596 589
		assertTrue(((DummyPersistent) aPersistent).saveCalled);
597 590

  
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/impl/AbstractPersistenceManager.java
1 1
package org.gvsig.tools.persistence.impl;
2 2

  
3
import java.util.Collections;
3 4
import java.util.HashMap;
4 5
import java.util.Iterator;
5 6
import java.util.List;
6 7
import java.util.Map;
7 8
import java.util.Set;
9
import java.util.TreeSet;
10
import java.util.Map.Entry;
11
import java.util.regex.Pattern;
8 12

  
9 13
import org.gvsig.tools.dynobject.DynClass;
10 14
import org.gvsig.tools.dynobject.DynObject;
......
12 16
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
13 17
import org.gvsig.tools.dynobject.exception.DynMethodException;
14 18
import org.gvsig.tools.dynobject.exception.DynObjectValidateException;
19
import org.gvsig.tools.persistence.PersistenceClassNotRegistered;
15 20
import org.gvsig.tools.persistence.PersistenceCreateException;
16 21
import org.gvsig.tools.persistence.PersistenceException;
17 22
import org.gvsig.tools.persistence.PersistenceFactory;
18 23
import org.gvsig.tools.persistence.PersistenceManager;
24
import org.gvsig.tools.persistence.PersistenceRuntimeException;
19 25
import org.gvsig.tools.persistence.PersistenceTypeNotSupportedException;
20 26
import org.gvsig.tools.persistence.PersistenceValidateExceptions;
21 27
import org.gvsig.tools.persistence.Persistent;
......
25 31

  
26 32
public abstract class AbstractPersistenceManager implements
27 33
		ImplementationPersistenceManager {
28
	protected HashMap definitions = new HashMap();
34
	public static final String DEFAULT_DOMAIN_URL = "http://www.gvsig.org";
35
	public static final String DEFAULT_DOMAIN_NAME = "gvSIG";
36

  
37
	public static final Pattern VALID_DOMAIN_NAME_PATTERN = Pattern
38
			.compile("[\\w][\\d\\w_]*");
29 39
	protected Map classes;
40
	protected Map domainsURL;
30 41
	protected int autoValidationMode = PersistenceManager.DISABLED;
31 42

  
32 43

  
44
	private class ClassInfo {
45
		public DynStruct definition = null;
46
		public String domainName = null;
47
		public Object theClass = null;
48
	}
49

  
50

  
33 51
	protected AbstractPersistenceManager() {
34 52
		classes = new HashMap();
53
		domainsURL = new HashMap();
35 54
	}
36 55

  
37
	public void addAlias(String name, Class aClass) {
38
		classes.put(name, aClass);
56
	public void addAlias(String name, Class aClass)
57
			throws PersistenceClassNotRegistered {
58
		ClassInfo info = (ClassInfo) classes.get(aClass.getName());
59
		if (info == null) {
60
			throw new PersistenceClassNotRegistered(aClass.getName());
61
		}
62
		classes.put(name, info);
39 63
	}
40 64

  
41 65
	/* (non-Javadoc)
42 66
	 * @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#createInstaceOfObject(org.gvsig.tools.persistence.PersistentState)
43 67
	 */
44 68
	public Object createInstaceOfObject(PersistentState state, Class classOfState, PersistenceFactory factory)
45
			throws PersistenceException, PersistenceCreateException {
69
			throws PersistenceException, PersistenceCreateException,
70
			PersistenceClassNotRegistered {
71
		// TODO IMPLEMENTAR FACTORY
46 72
		String className = state.getTheClassName();
47 73
		if (className == null) {
48 74
			throw new PersistenceException("The class name is not stored in the state.");
......
50 76
		try {
51 77
			Class theClass;
52 78

  
53
			Object x = classes.get(className);
79
			ClassInfo info = (ClassInfo) classes.get(className);
80

  
81
			if (info == null) {
82
				throw new PersistenceClassNotRegistered(className);
83
			}
84

  
85
			Object x = info.theClass;
86

  
87

  
54 88
			if (x instanceof Class) {
55 89
				theClass = (Class) x;
56 90
			} else if (x instanceof String) {
......
66 100
		} catch (IllegalAccessException e) {
67 101
			throw new PersistenceCreateException(state, e);
68 102
		}
69

  
70 103
	}
71 104

  
72 105

  
......
92 125
	}
93 126

  
94 127
	public void registerClass(Class persistentClass, DynStruct definition) {
95
		definitions.put(persistentClass.getName(), definition);
96
		classes.put(persistentClass.getName(), persistentClass);
128
		registerClass(persistentClass, definition, null);
97 129
	}
98 130

  
99 131
	public DynStruct getDefinition(Class persistentClass) {
100
		return (DynStruct) definitions.get(persistentClass.getName());
132
		return getDefinition(persistentClass.getName());
101 133
	}
102 134

  
103 135
	/* (non-Javadoc)
104 136
	 * @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#getDefinition(java.lang.String)
105 137
	 */
106 138
	public DynStruct getDefinition(String persistentClassName) {
107
		return (DynStruct) definitions.get(persistentClassName);
139
		ClassInfo info = (ClassInfo) classes.get(persistentClassName);
140
		if (info == null) {
141
			return null;
142
		}
143
		return info.definition;
108 144
	}
109 145

  
110 146

  
111 147
	public Iterator getPersistentClasses() {
112
		return definitions.keySet().iterator();
148
		Iterator iter = classes.values().iterator();
149
		Set classesSet = new TreeSet();
150
		ClassInfo info;
151
		while (iter.hasNext()) {
152
			info = (ClassInfo) iter.next();
153
			classesSet.add(info.theClass);
154
		}
155
		return classesSet.iterator();
113 156
	}
114 157

  
115
	public void removeDefinition(Class persistentClass) {
116
		definitions.remove(persistentClass.getName());
117
	}
118 158

  
119 159
	/*
120 160
	 * (non-Javadoc)
......
279 319
	 */
280 320
	public ImplementationPersistentState createState(Object theOriginal,
281 321
			PersistentContext context)
282
			throws PersistenceException {
322
			throws PersistenceException,
323
			PersistenceClassNotRegistered, PersistenceTypeNotSupportedException {
283 324

  
284 325
		ImplementationPersistentState state = createPersistentStateInstance(context);
285
		state.setTheClassName(theOriginal.getClass().getName());
326
		String theClass = theOriginal.getClass().getName();
327
		state.setTheClassName(theClass);
328
		if (!classes.containsKey(theClass)) {
329
			throw new PersistenceClassNotRegistered(theClass);
330
		}
286 331
		context.addReference(theOriginal, state);
287 332
		PersistenceFactory factory = getFactoryFor(theOriginal);
288 333
		if (factory != null) {
......
317 362

  
318 363
	/*
319 364
	 * (non-Javadoc)
320
	 * 
365
	 *
321 366
	 * @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
322 367
	 * createrObjectReference(java.lang.Integer)
323 368
	 */
......
333 378
	 * .Class)
334 379
	 */
335 380
	public void registerClass(Class persistentClass) {
336
		classes.put(persistentClass.getName(), persistentClass);
337

  
381
		registerClass(persistentClass, null, null, null);
338 382
	}
339 383

  
340 384
	/*
......
400 444
	 * .Class, org.gvsig.tools.dynobject.DynStruct, java.lang.String)
401 445
	 */
402 446
	public void registerClass(Class persistentClass, DynStruct definition,
403
			String namespace) {
404
		// TODO process namespace
405
		registerClass(persistentClass, definition);
447
			String domainName) {
406 448

  
449
		registerClass(persistentClass, definition, domainName, null);
450

  
407 451
	}
408 452

  
409 453
	/*
410 454
	 * (non-Javadoc)
411 455
	 *
412 456
	 * @see
457
	 * org.gvsig.tools.persistence.PersistenceManager#registerClass(java.lang
458
	 * .Class, org.gvsig.tools.dynobject.DynStruct, java.lang.String)
459
	 */
460
	public void registerClass(Class persistentClass, DynStruct definition,
461
			String domainName, String domainURL) {
462

  
463
		String domainURLStored = (String) domainsURL.get(domainName);
464
		String domainURLToUse;
465
		ClassInfo info = new ClassInfo();
466
		info.definition = definition;
467
		info.theClass = persistentClass;
468
		if (domainName == null) {
469
			info.domainName = DEFAULT_DOMAIN_NAME;
470
			domainURLToUse = DEFAULT_DOMAIN_URL;
471
		} else {
472
			if (!VALID_DOMAIN_NAME_PATTERN.matcher(domainName).matches()) {
473
				throw new PersistenceRuntimeException(
474
						"invalid domain name identifier: '" + domainName + "'");
475
			}
476
			info.domainName = domainName;
477
			if (domainURL == null) {
478
				if (domainURLStored == null) {
479
					domainURLToUse = DEFAULT_DOMAIN_URL;
480
				} else {
481
					domainURLToUse = domainURLStored;
482
				}
483
			} else {
484
				domainURLToUse = domainURL;
485
			}
486
		}
487

  
488
		if (domainURLStored == null) {
489
			domainsURL.put(info.domainName, domainURLToUse);
490
		} else if (!domainURLStored.equals(domainURLToUse)){
491
			throw new PersistenceRuntimeException("Domain URL conflict in "
492
					+ info.domainName + ": " + domainURLStored + " "
493
					+ domainURLToUse);
494
		}
495

  
496
		classes.put(persistentClass.getName(), info);
497

  
498

  
499
	}
500

  
501

  
502
	/*
503
	 * (non-Javadoc)
504
	 *
505
	 * @see
413 506
	 * org.gvsig.tools.persistence.PersistenceManager#registerFactory(org.gvsig
414 507
	 * .tools.persistence.PersistenceFactory)
415 508
	 */
......
421 514
	/*
422 515
	 * (non-Javadoc)
423 516
	 *
424
	 * @seeorg.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
517
	 * @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
425 518
	 * getFactoryFor(java.lang.Object)
426 519
	 */
427 520
	public PersistenceFactory getFactoryFor(Object object) {
......
432 525
	/*
433 526
	 * (non-Javadoc)
434 527
	 *
435
	 * @seeorg.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
528
	 * @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
436 529
	 * getFactoryFor(org.gvsig.tools.persistence.PersistentState)
437 530
	 */
438 531
	public PersistenceFactory getFactoryFor(PersistentState state) {
......
455 548
	/*
456 549
	 * (non-Javadoc)
457 550
	 *
458
	 * @seeorg.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
551
	 * @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
459 552
	 * getFactoryFor(java.lang.Class)
460 553
	 */
461 554
	public PersistenceFactory getFactoryFor(Class klass) {
......
484 577
		}
485 578

  
486 579
	}
580

  
581
	/*
582
	 * (non-Javadoc)
583
	 *
584
	 * @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
585
	 * getDomainName(java.lang.String)
586
	 */
587
	public String getDomainName(String theClassName)
588
			throws PersistenceClassNotRegistered {
589
		ClassInfo info = (ClassInfo) classes.get(theClassName);
590
		if (info == null) {
591
			throw new PersistenceClassNotRegistered(theClassName);
592
		}
593
		return info.domainName;
594
	}
595

  
596
	/*
597
	 * (non-Javadoc)
598
	 *
599
	 * @see
600
	 * org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#getDomains
601
	 * ()
602
	 */
603
	public Map getDomains() {
604
		return Collections.unmodifiableMap(domainsURL);
605
	}
606

  
607
	/*
608
	 * (non-Javadoc)
609
	 *
610
	 * @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
611
	 * getDomainURL(java.lang.String)
612
	 */
613
	public String getDomainURL(String domainName) {
614
		return (String) domainsURL.get(domainName);
615
	}
616

  
617
	/*
618
	 * (non-Javadoc)
619
	 *
620
	 * @see org.gvsig.tools.persistence.impl.ImplementationPersistenceManager#
621
	 * getDomainDefinitions(java.lang.String)
622
	 */
623
	public Map getDomainDefinitions(String domainName) {
624
		if (!domainsURL.containsKey(domainName)) {
625
			throw new PersistenceRuntimeException("Domain not registered");
626
		}
627
		Map definitions = new HashMap();
628
		Entry entry;
629
		ClassInfo info;
630
		Iterator iter = classes.entrySet().iterator();
631
		while (iter.hasNext()) {
632
			entry = (Entry) iter.next();
633
			info = (ClassInfo) entry.getValue();
634
			if (domainName.equals(info.domainName)) {
635
				definitions.put(entry.getKey(), info.definition);
636
			}
637
		}
638
		return definitions;
639
	}
487 640
}
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/impl/ImplementationPersistenceManager.java
32 32
import java.util.Set;
33 33

  
34 34
import org.gvsig.tools.dynobject.DynStruct;
35
import org.gvsig.tools.persistence.PersistenceClassNotRegistered;
35 36
import org.gvsig.tools.persistence.PersistenceCreateException;
36 37
import org.gvsig.tools.persistence.PersistenceException;
37 38
import org.gvsig.tools.persistence.PersistenceFactory;
......
101 102
	 */
102 103
	public PersistenceFactory getFactoryFor(PersistentState state);
103 104

  
105

  
106
	public String getDomainName(String theClassName)
107
			throws PersistenceClassNotRegistered;
108

  
109
	public String getDomainURL(String domainName);
110

  
111
	/**
112
	 * Return a read only Map with <code>domainName</code> as key and
113
	 * <code>domainURL</code> as value.
114
	 *
115
	 * @return Map<String,String>
116
	 */
117
	public Map getDomains();
118

  
119
	/**
120
	 * Return a read only Map with <code>className</code> as key and
121
	 * <code>definition</code> as value of a domainName.
122
	 * 
123
	 * @return Map<String,DynStruct>
124
	 */
125
	public Map getDomainDefinitions(String domainName);
104 126
}
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/PersistenceCreateException.java
10 10
	 */
11 11
	private static final long serialVersionUID = 1173336779528392650L;
12 12
	private final static String MESSAGE_FORMAT = "Exception creating new instance of '%(class)'.";
13
	private final static String MESSAGE_KEY = "_PersistenceIDNotLoadedException";
13
	private final static String MESSAGE_KEY = "_PersistenceCreateException";
14 14
	private PersistentState state;
15 15

  
16 16
	public PersistenceCreateException(PersistentState state, Throwable cause) {
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/PersistenceClassNotRegistered.java
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
/**
29
 *
30
 */
31
package org.gvsig.tools.persistence;
32

  
33
import java.util.Collections;
34
import java.util.Map;
35

  
36
/**
37
 * @author jmvivo
38
 *
39
 */
40
public class PersistenceClassNotRegistered extends PersistenceException {
41

  
42

  
43
	/**
44
	 *
45
	 */
46
	private static final long serialVersionUID = -5117203477405844983L;
47
	private final static String MESSAGE_FORMAT = "Class not registered in manager '%(class)'.";
48
	private final static String MESSAGE_KEY = "_PersistenceClassNotRegistered";
49

  
50
	private String theClass;
51

  
52
	public PersistenceClassNotRegistered(Class theClass) {
53
		this(theClass.getName());
54
	}
55

  
56
	public PersistenceClassNotRegistered(String theClass){
57
		super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
58
		this.theClass = theClass;
59
	}
60

  
61
	public String getTheClass() {
62
		return this.theClass;
63
	}
64

  
65
    protected Map values() {
66
		return Collections.singletonMap("class", theClass);
67
	}
68
}
0 69

  
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/PersistenceManager.java
53 53
	 *         Persistent Object.
54 54
	 * @throws PersistenceException
55 55
	 * @throws PersistenceValidateExceptions
56
	 * @throws PersistenceTypeNotSupportedException TODO
56
	 * @throws PersistenceTypeNotSupportedException
57
	 * @throws PersistenceClassNotRegistered
57 58
	 */
58 59
	public PersistentState getState(Object obj)
59
			throws PersistenceException, PersistenceValidateExceptions, PersistenceTypeNotSupportedException;
60
			throws PersistenceException,
61
			PersistenceValidateExceptions,
62
			PersistenceTypeNotSupportedException, PersistenceClassNotRegistered;
60 63

  
61 64
	/**
62 65
	 * <p>
......
78 81
			throws PersistenceException, PersistenceCreateException;
79 82

  
80 83
	/**
81
	 * <p>Associates an alias with a class. This is similar to a symbolic link, which allows
82
	 * to access the class by means of its alias.</p>
84
	 * <p>
85
	 * Associates an alias with a class. This is similar to a symbolic link,
86
	 * which allows to access the class by means of its alias.
87
	 * </p>
83 88
	 *
84
	 * <p>When an alias is defined, it replaces any
85
	 * class whose qualified name is equal to the alias. Therefore, this class will never
86
	 * be instantiated, and instead the class pointed by the the alias will be instantiated.</p>
89
	 * <p>
90
	 * When an alias is defined, it replaces any class whose qualified name is
91
	 * equal to the alias. Therefore, this class will never be instantiated, and
92
	 * instead the class pointed by the the alias will be instantiated.
93
	 * </p>
87 94
	 *
88
	 * <p>For example, if the following alias is defined:</p>
95
	 * <p>
96
	 * For example, if the following alias is defined:
97
	 * </p>
89 98
	 *
90
	 * <pre>Class aClass = org.gvsig.fmap.mapcontext.rendering.symbols.SimpleMarkerSymbol.class;
91
	 * manager.addAlias("org.gvsig.fmap.mapcontext.rendering.symbols.ArrowMarkerSymbol", aClass);
99
	 * <pre>
100
	 * Class aClass = org.gvsig.fmap.mapcontext.rendering.symbols.SimpleMarkerSymbol.class;
101
	 * manager
102
	 * 		.addAlias(
103
	 * 				&quot;org.gvsig.fmap.mapcontext.rendering.symbols.ArrowMarkerSymbol&quot;,
104
	 * 				aClass);
92 105
	 * </pre>
93
	 * <p>then, SimpleMarkerSymbol will be instantiated instead of ArrowMarkerSymbol from any
94
	 * PersistentState which references ArrowMarkerSymbol.</p>
106
	 * <p>
107
	 * then, SimpleMarkerSymbol will be instantiated instead of
108
	 * ArrowMarkerSymbol from any PersistentState which references
109
	 * ArrowMarkerSymbol.
110
	 * </p>
95 111
	 *
96
	 * <p>Aliases are useful to provided backward-compatibility paths (as old unexisting classes
97
	 * may be aliased to substitution classes), but are also useful to avoid limitations on
98
	 * ClassLoaders. As a Class object is provided, it will be possible to instantiate it even
99
	 * if the current ClassLoader has no direct visibility of the class to instantiate.</p>
112
	 * <p>
113
	 * Aliases are useful to provided backward-compatibility paths (as old no
114
	 * existing classes may be aliased to substitution classes), but are also
115
	 * useful to avoid limitations on ClassLoaders. As a Class object is
116
	 * provided, it will be possible to instantiate it even if the current
117
	 * ClassLoader has no direct visibility of the class to instantiate.
118
	 * </p>
100 119
	 *
101
	 * @param alias The alias to reference a class
102
	 * @param aClass The class to be referenced by the alias
120
	 * @param alias
121
	 *            The alias to reference a class
122
	 * @param aClass
123
	 *            The class to be referenced by the alias
124
	 *
125
	 * @throws PersistenceClassNotRegistered
126
	 *             if <code>aClass</code> is not registered
103 127
	 */
104
	public void addAlias(String alias, Class aClass);
128
	public void addAlias(String alias, Class aClass)
129
			throws PersistenceClassNotRegistered;
105 130

  
106 131
	/**
107 132
	 * <p>
......
125 150
	/**
126 151
	 * <p>
127 152
	 * Register a class that implements {@link Persistent} for use in the
128
	 * manager with definition to validate it and a namespace identification.
153
	 * manager with definition to validate it and a domainName identification.
154
	 * The domainURL will be the previously set, if it's not set will the gvSIG
155
	 * standard domainURL.
129 156
	 * </p>
130 157
	 *
131 158
	 * @param persistentClass
......
140 167
	 * @see #create(PersistentState)
141 168
	 */
142 169
	public void registerClass(Class persistentClass, DynStruct definition,
143
			String namespace);
170
			String domainName);
144 171

  
145 172
	/**
146 173
	 * <p>
147 174
	 * Register a class that implements {@link Persistent} for use in the
175
	 * manager with definition to validate it and a domainName identification
176
	 * and the domainURL.
177
	 * </p>
178
	 *
179
	 *<p>
180
	 * <b>Note:</b> A <code>domainName</code> can by in only one
181
	 *<code>domainURL</code>. If you try to register the same
182
	 * <code>domainName</code> with two URL an exception will be raised.
183
	 *</p>
184
	 *
185
	 * @param persistentClass
186
	 *            The class to register
187
	 * @param definition
188
	 *            The definition of the attributes allowed for the
189
	 *            persistentClass
190
	 *
191
	 * @see #validateAll(PersistentState, int)
192
	 * @see #validateAll(PersistentState)
193
	 * @see #registerClass(Class)
194
	 * @see #create(PersistentState)
195
	 */
196
	public void registerClass(Class persistentClass, DynStruct definition,
197
			String domainName, String domainURL);
198

  
199
	/**
200
	 * <p>
201
	 * Register a class that implements {@link Persistent} for use in the
148 202
	 * manager.
149 203
	 * </p>
150 204
	 *
......
171 225
	 *
172 226
	 * @param persistentClass
173 227
	 *
174
	 * @see #registerClass(Class)
228
	 * @see #registerClass(Class, DynStruct, String)
229
	 *
230
	 * @throws PersistenceClassNotRegistered
231
	 *             if <code>persistentClass</code> is not registered
175 232
	 */
176
	public void unregisterClass(Class persistentClass);
233
	public void unregisterClass(Class persistentClass)
234
			throws PersistenceClassNotRegistered;
177 235

  
178 236
	/**
179 237
	 * <p>
......
183 241
	 * @param persistentClass
184 242
	 *
185 243
	 * @see #registerClass(Class)
244
	 *
245
	 * @throws PersistenceClassNotRegistered
246
	 *             if <code>className</code> is not registered
186 247
	 */
187
	public void unregisterClass(String className);
248
	public void unregisterClass(String className)
249
			throws PersistenceClassNotRegistered;
188 250

  
189 251
	/**
190 252
	 * <p>
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/xml/XMLPersistenceLibrary.java
41 41
public class XMLPersistenceLibrary extends BaseLibrary {
42 42

  
43 43
	protected void doInitialize() throws LibraryException {
44
		ToolsLocator.registerPersistenceManager(XMLPersistenceManager.class);
44
		ToolsLocator.registerPersistenceManager(ZipXMLPersistenceManager.class);
45 45
	}
46 46

  
47 47
	protected void doPostInitialize() throws LibraryException {
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/xml/XMLPersistentConstants.java
68 68
	 * XML Root item tag name
69 69
	 */
70 70
	public static final String ROOT_TAG = "XMLPersitence";
71

  
71 72
	/**
72
	 * XML Root item start.<br>
73
	 * XML Root item format.<br>
74
	 * Parameters:
75
	 * <ol>
76
	 * <li>domain notation (Ej. 'tools:')</li>
77
	 * <li>additional definitions</li>
78
	 * </ol>
73 79
	 */
74
	public static final String ROOT_START = "<" + ROOT_TAG
75
			+ " xmlns:xlink=\"http://www.w3.org/1999/xlink\">";
80
	public static final String ROOT_VALUE = "<{0}" + ROOT_TAG
81
			+ " xmlns:xlink=\"http://www.w3.org/1999/xlink\" {1}>";
82

  
83
	public static final String BASE_DOMIAN_URL = "http://www.gvsig.org/libTools";
84
	public static final String BASE_DOMIAN_NAME = "tools";
85

  
76 86
	/**
87
	 * Schema File name format. <br>
88
	 * Parameters:
89
	 * <ol>
90
	 * <li>schema name</li>
91
	 * </ol>
92
	 *
93
	 */
94
	public static final String SCHEMA_FILE_NAME_VALUE = "{0}.xsd";
95

  
96
	/**
97
	 * Schema definition format<br>
98
	 * Parameters:
99
	 * <ol>
100
	 * <li>domain URL</li>
101
	 * <li>domain name</li>
102
	 * </ol>
103
	 */
104
	public static final String SCHEMA_DEFINITON_VALUE = "{0} {1}.xsd \n";
105

  
106
	/**
107
	 * SCHEMA attribute for ROOT tag.<br>
108
	 * Parameters:
109
	 * <ol>
110
	 * <li>Schema definition list</li>
111
	 * </ol>
112
	 */
113
	public static final String DEFAULT_SCHEMA_ATTRIBUTE_VALUE = INDENDT_3
114
			+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
115
			+ "xsi:SchemaLocation=\"{0}\"";
116

  
117

  
118
	/**
119
	 * domain Name definition format. Parameters:
120
	 * <ol>
121
	 * <li>domain name</li>
122
	 * <li>domain URL</li>
123
	 * </ol>
124
	 */
125
	public static final String DOMAIN_NAME_ATTRIBUTE_VALUE = INDENDT_3
126
			+ "xmlns:{0}=\"{1}\"";
127

  
128
	/**
77 129
	 * XML Root item end.<br>
130
	 * <ol>
131
	 * <li>domain definition (Ej.: "tools:")</li>
132
	 * </ol>
78 133
	 */
79
	public static final String ROOT_END = "</" + ROOT_TAG + ">";
134
	public static final String ROOT_END_VALUE = "</{0}" + ROOT_TAG + ">";
80 135

  
81 136

  
82 137
	// Version definition
......
146 201
	/**
147 202
	 * State item start format.<br>
148 203
	 * Parameters:
149
	 *  <ol>
150
	 *  	<li>id state</li>
151
	 *  	<li>theClassName</li>
152
	 *  </ol>
204
	 * <ol>
205
	 * <li>domain prefix (ex: 'aDomain:')</li>
206
	 * <li>theClassName</li>
207
	 * <li>id state</li>
208
	 * </ol>
153 209
	 */
154
	public static final String STATE_START = INDENDT_1 + "<{1} "
155
			+ STATE_ID_ATTR + "=\"{0}\">";
210
	public static final String STATE_START = INDENDT_1 + "<{0}{1} "
211
			+ STATE_ID_ATTR + "=\"{2}\">";
156 212

  
157 213
	/**
158 214
	 * State item end format.<br>
159 215
	 * Parameters:
160 216
	 * <ol>
217
	 * <li>domain prefix (ex: 'aDomain:')</li>
218
	 * <li>theClassName</li>
161 219
	 * <li>id state</li>
162
	 * <li>theClassName</li>
163 220
	 * </ol>
164 221
	 */
165
	public static final String STATE_END = INDENDT_1 + "</{1}>";
222
	public static final String STATE_END = INDENDT_1 + "</{0}{1}>";
166 223

  
167 224

  
168 225

  
......
339 396
	 */
340 397
	public static final String CDATA_END = "]]>";
341 398

  
399

  
342 400
}
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/xml/XMLPersistentStateWriter.java
59 59
	private PrintWriter print;
60 60
	private static Method getCharSetMethod = null;
61 61
	private static Method getCharSetNameMethod = null;
62
	private static Map csMap = null;
63 62
	private static boolean useCsMap = false;
63
	private static boolean useDomains = false;
64 64

  
65 65
	private final static Pattern DOT_PATTERN = Pattern.compile("[.]");
66 66

  
......
70 70

  
71 71
	public void write(ImplementationPersistentState state, OutputStream out)
72 72
			throws PersistenceException {
73
		write(state, out, null);
74
	}
75

  
76
	public void write(ImplementationPersistentState state, OutputStream out,
77
			Map domains)
78
			throws PersistenceException {
73 79
		ImplementationPersistentState root = state;
74 80
		String rootId = root.getId().toString();
75 81
		PersistentContext context = state.getContext();
......
80 86
		print.println(MessageFormat.format(XML_HEADER,
81 87
				new String[] { getCharset(outWrite.getEncoding()) }));
82 88

  
89
		// Prepare schema
90
		String rootAttributes = "";
91
		if (domains != null && domains.size() > 0) {
92
			useDomains = true;
93
			StringBuffer buffRootAttr = new StringBuffer();
94

  
95
			buffRootAttr.append('\n');
96
			buffRootAttr.append(MessageFormat.format(
97
					DOMAIN_NAME_ATTRIBUTE_VALUE, new Object[] {
98
							BASE_DOMIAN_NAME, BASE_DOMIAN_URL }));
99
			Iterator iter = domains.entrySet().iterator();
100
			Entry entry;
101
			while (iter.hasNext()) {
102
				entry = (Entry) iter.next();
103
				buffRootAttr.append('\n');
104
				buffRootAttr.append(MessageFormat.format(DOMAIN_NAME_ATTRIBUTE_VALUE,
105
						new Object[] { entry.getKey(), entry.getValue() }));
106
			}
107
			iter = domains.entrySet().iterator();
108
			StringBuffer buffSchemas = new StringBuffer();
109

  
110
			buffSchemas.append('\n');
111
			buffSchemas.append(MessageFormat.format(SCHEMA_DEFINITON_VALUE,
112
					new Object[] { BASE_DOMIAN_NAME, BASE_DOMIAN_URL }));
113
			while (iter.hasNext()) {
114
				entry = (Entry) iter.next();
115
				buffSchemas.append('\n');
116
				buffSchemas.append(MessageFormat.format(SCHEMA_DEFINITON_VALUE,
117
						new Object[] { entry.getValue(), entry.getKey() }));
118
			}
119
			buffRootAttr.append('\n');
120
			buffRootAttr.append(MessageFormat.format(DEFAULT_SCHEMA_ATTRIBUTE_VALUE,
121
					new Object[] { buffSchemas.toString() }));
122
			rootAttributes = buffRootAttr.toString();
123
		}
124

  
83 125
		// Root tag:
84
		print.println(ROOT_START);
126
//		if (useDomains) {
127
//			print.println(MessageFormat.format(ROOT_VALUE, new Object[] {
128
//					BASE_DOMIAN_NAME + ":", rootAttributes }));
129
//		} else {
130
			print.println(MessageFormat.format(ROOT_VALUE,
131
					new Object[] { "",
132
					rootAttributes }));
133
//		}
85 134

  
86 135
		// Version
87 136
		print.println(MessageFormat.format(VERSION_VALUE,
......
107 156
		print.println(STATES_END);
108 157

  
109 158
		// Root end:
110
		print.println(ROOT_END);
159
//		if (useDomains) {
160
//			print.println(MessageFormat.format(ROOT_END_VALUE,
161
//					new Object[] { BASE_DOMIAN_NAME + ":" }));
162
//		} else {
163
			print.println(MessageFormat.format(ROOT_END_VALUE,
164
					new Object[] { "" }));
165
//		}
111 166

  
112 167
		print.flush();
113 168

  
......
120 175
		Object value;
121 176

  
122 177
		itNames = curState.getNames();
178
		String theClassName = curState.getTheClassName();
179
		String domainName = "";
180
		if (useDomains) {
181
			domainName = manager.getDomainName(theClassName) + ":";
182
		}
123 183

  
124 184
		// add state start
125 185
		print.println(MessageFormat.format(STATE_START, new Object[] {
126
				curState.getId(), curState.getTheClassName() }));
186
				domainName, theClassName, curState.getId() }));
127 187

  
128 188
		boolean useNameAsTag;
129 189
		String format, type;
......
150 210

  
151 211
		// add state end
152 212
		print.println(MessageFormat.format(STATE_END, new Object[] {
153
				curState.getId(), curState.getTheClassName() }));
213
				domainName, theClassName, curState.getId() }));
154 214

  
155 215
	}
156 216

  
......
220 280

  
221 281
	private String transformValue(Date value, StringBuffer strb) {
222 282
		strb.append(value.getTime());
223
		return TYPE_BOOLEAN;
283
		return TYPE_DATE;
224 284
	}
225 285

  
226 286
	private String transformValue(ObjectReference value, StringBuffer strb) {
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/xml/XMLPersistenceManager.java
64 64
			throws PersistenceException {
65 65
		PersistentContext context = this.createPersistentContext();
66 66

  
67
		XMLPersistentStateReader xmlReader = new XMLPersistentStateReader(this);
67
		XMLPersistentStateReader xmlReader = getReaderInstance();
68 68

  
69 69
		// FIXME
70 70
		KXmlParser parser = new KXmlParser();
......
81 81

  
82 82
	public void saveState(PersistentState state, OutputStream out)
83 83
			throws PersistenceException {
84
		XMLPersistentStateWriter xmlWriter = new XMLPersistentStateWriter(this);
84
		XMLPersistentStateWriter xmlWriter = getWriterInstance();
85 85

  
86 86
		xmlWriter.write((ImplementationPersistentState) state, out);
87 87

  
88 88
	}
89 89

  
90
	protected XMLPersistentStateReader getReaderInstance(){
91
		return new XMLPersistentStateReader(this);
92
	}
93

  
94
	protected XMLPersistentStateWriter getWriterInstance() {
95
		return new XMLPersistentStateWriter(this);
96
	}
97

  
90 98
	public String version() {
91 99
		return VERSION;
92 100
	}
101

  
102

  
93 103
}
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/persistence/xml/ZipXMLSchemaConstants.java
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
/**
29
 *
30
 */
31
package org.gvsig.tools.persistence.xml;
32

  
33
import java.text.MessageFormat;
34

  
35
/**
36
 * @author jmvivo
37
 *
38
 */
39
public interface ZipXMLSchemaConstants {
40

  
41
	/**
42
	 * <ol>
43
	 * <li>domain name</li>
44
	 * <li>domain URL</li>
45
	 * </ol>
46
	 */
47
	public static final String XSD_IMPORT_SCHEMA_VALUE =
48
		"<xs:import namespace=\"{1}\" schemaLocation=\"{0}\"/>\n\n";
49

  
50
	/**
51
	 * Current Schema file name.
52
	 */
53
	public static final String BASE_SCHEMA_FILE_NAME = MessageFormat.format(
54
			XMLPersistentConstants.SCHEMA_FILE_NAME_VALUE,
55
			new Object[] { "persistentState_base" });
56

  
57
	/**
58
	 * <ol>
59
	 * <li>domain name</li>
60
	 * <li>domain URL</li>
61
	 * </ol>
62
	 */
63
	public static final String XSD_HEAD_VALUE =
64
			"<?xml version=\"1.0\"?>\n"+
65
			"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n"+
66
			"  targetNamespace=\"{1}\"" +
67
			"  xmlns:tools=\""+XMLPersistentConstants.BASE_DOMIAN_URL+"\"\n"+
68
			"  xmlns:{0}=\"{1}\"\n"+
69
			"  elementFormDefault=\"qualified\"\n"+
70
			"  attributeFormDefault=\"qualified\">"+
71
			MessageFormat.format(
72
				XSD_IMPORT_SCHEMA_VALUE,
73
				new Object[] {
74
					BASE_SCHEMA_FILE_NAME,
75
					XMLPersistentConstants.BASE_DOMIAN_URL });
76

  
77
	public static final String XSD_END = "</xs:schema>";
78

  
79
	/**
80
	 * <ol>
81
	 * <li>class name</li>
82
	 * </ol>
83
	 */
84
	public static final String XSD_START_CLASS_VALUE =
85
		"    <xs:element name=\"{0}\">\n" +
86
        "      <xs:complexType>\n" +
87
        "        <xs:all>\n";
88

  
89

  
90
	public static final String XSD_END_CLASS =
91
		"        </xs:all>\n" +
92
		"        <xs:attributeGroup ref=\"tools:state_attributes\"/>"+
93
        "      </xs:complexType>\n" +
94
		"    </xs:element>\n";
95

  
96
	/**
97
	 * <ol>
98
	 * <li>attribute name</li>
99
	 * <li>attribute type (use
100
	 *   {@link #XSD_ATTRUBUTE_TYPE_INTEGER},
101
	 *   {@link #XSD_ATTRUBUTE_TYPE_LONG},
102
	 *   {@link #XSD_ATTRUBUTE_TYPE_NULL},
103
	 *   etc..
104
	 *    ) </li>
105
	 * </ol>
106
	 */
107
	public static final String XSD_ATTRUBUTE_VALUE =
108
		"          <xs:element name=\"{0}\" type=\"{1}\"/>";
109

  
110
	/**
111
	 * <ol>
112
	 * <li>attribute name</li>
113
	 * <li>attribute type (use {@link #XSD_ATTRUBUTE_TYPE_INTEGER},
114
	 * {@link #XSD_ATTRUBUTE_TYPE_LONG}, {@link #XSD_ATTRUBUTE_TYPE_STRING},
115
	 * etc.. )</li>
116
	 * </ol>
117
	 */
118
	public static final String XSD_ATTRUBUTE_MANDATORY_VALUE =
119
		"          <xs:element name=\"{0}\" type=\"{1}\" minOccurs=\"1\"/>";
120

  
121

  
122
	public static final String XSD_ATTRUBUTE_TYPE_NULL = "tools:state_attribute_Null";
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff