root / branches / v2_0_0_prep / libraries / libTools / src / org / gvsig / tools / persistence / xml / XMLPersistenceManager.java @ 30624
History | View | Annotate | Download (2.91 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 |
/**
|
29 |
*
|
30 |
*/
|
31 |
package org.gvsig.tools.persistence.xml; |
32 |
|
33 |
import java.io.InputStream; |
34 |
import java.io.OutputStream; |
35 |
|
36 |
import org.gvsig.tools.persistence.PersistenceException; |
37 |
import org.gvsig.tools.persistence.PersistentState; |
38 |
import org.gvsig.tools.persistence.impl.AbstractPersistenceManager; |
39 |
import org.gvsig.tools.persistence.impl.ImplementationPersistentState; |
40 |
import org.gvsig.tools.persistence.impl.PersistentContext; |
41 |
import org.kxml2.io.KXmlParser; |
42 |
import org.xmlpull.v1.XmlPullParserException; |
43 |
|
44 |
/**
|
45 |
* @author jmvivo
|
46 |
*
|
47 |
*/
|
48 |
public class XMLPersistenceManager extends AbstractPersistenceManager { |
49 |
|
50 |
private static final String VERSION = "2.0.0"; |
51 |
|
52 |
/* (non-Javadoc)
|
53 |
* @see org.gvsig.tools.persistence.impl.AbstractPersistenceManager#createPersistentStateInstance(org.gvsig.tools.persistence.impl.PersistentContext)
|
54 |
*/
|
55 |
public ImplementationPersistentState createPersistentStateInstance(
|
56 |
PersistentContext context) { |
57 |
return new XMLPersistentState(this, context); |
58 |
} |
59 |
|
60 |
/* (non-Javadoc)
|
61 |
* @see org.gvsig.tools.persistence.PersistenceManager#loadState(java.io.Reader)
|
62 |
*/
|
63 |
public PersistentState loadState(InputStream in) |
64 |
throws PersistenceException {
|
65 |
PersistentContext context = this.createPersistentContext();
|
66 |
|
67 |
XMLPersistentStateReader xmlReader = getReaderInstance(); |
68 |
|
69 |
// FIXME
|
70 |
KXmlParser parser = new KXmlParser();
|
71 |
|
72 |
try {
|
73 |
parser.setInput(in, null);
|
74 |
} catch (XmlPullParserException e) {
|
75 |
throw new PersistenceException(e); |
76 |
} |
77 |
xmlReader.read(context, parser); |
78 |
|
79 |
return context.getRootState();
|
80 |
} |
81 |
|
82 |
public void saveState(PersistentState state, OutputStream out) |
83 |
throws PersistenceException {
|
84 |
XMLPersistentStateWriter xmlWriter = getWriterInstance(); |
85 |
|
86 |
xmlWriter.write((ImplementationPersistentState) state, out); |
87 |
|
88 |
} |
89 |
|
90 |
protected XMLPersistentStateReader getReaderInstance(){
|
91 |
return new XMLPersistentStateReader(this); |
92 |
} |
93 |
|
94 |
protected XMLPersistentStateWriter getWriterInstance() {
|
95 |
return new XMLPersistentStateWriter(this); |
96 |
} |
97 |
|
98 |
public String version() { |
99 |
return VERSION;
|
100 |
} |
101 |
|
102 |
|
103 |
} |