svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / spi / AbstractDataParameters.java @ 25785
History | View | Annotate | Download (4.44 KB)
1 |
package org.gvsig.fmap.dal.spi; |
---|---|
2 |
|
3 |
import java.util.Iterator; |
4 |
|
5 |
import org.gvsig.fmap.dal.DataParameters; |
6 |
import org.gvsig.fmap.dal.exception.CopyParametersException; |
7 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
8 |
import org.gvsig.tools.dynobject.DynClass; |
9 |
import org.gvsig.tools.dynobject.DynField; |
10 |
import org.gvsig.tools.dynobject.DynObject; |
11 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
12 |
import org.gvsig.tools.persistence.AbstractPersistenceManager; |
13 |
import org.gvsig.tools.persistence.PersistenceException; |
14 |
import org.gvsig.tools.persistence.PersistenceValueNotFoundException; |
15 |
import org.gvsig.tools.persistence.PersistentState; |
16 |
|
17 |
|
18 |
/* gvSIG. Geographic Information System of the Valencian Government
|
19 |
*
|
20 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
21 |
* of the Valencian Government (CIT)
|
22 |
*
|
23 |
* This program is free software; you can redistribute it and/or
|
24 |
* modify it under the terms of the GNU General Public License
|
25 |
* as published by the Free Software Foundation; either version 2
|
26 |
* of the License, or (at your option) any later version.
|
27 |
*
|
28 |
* This program is distributed in the hope that it will be useful,
|
29 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31 |
* GNU General Public License for more details.
|
32 |
*
|
33 |
* You should have received a copy of the GNU General Public License
|
34 |
* along with this program; if not, write to the Free Software
|
35 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
36 |
* MA 02110-1301, USA.
|
37 |
*
|
38 |
*/
|
39 |
|
40 |
/*
|
41 |
* AUTHORS (In addition to CIT):
|
42 |
* 2008 IVER T.I. S.A. {{Task}}
|
43 |
*/
|
44 |
|
45 |
/**
|
46 |
*
|
47 |
*/
|
48 |
/**
|
49 |
* @author jmvivo
|
50 |
*
|
51 |
*/
|
52 |
public abstract class AbstractDataParameters implements DataParameters { |
53 |
protected DelegatedDynObject delegatedDynObjet;
|
54 |
|
55 |
public Object getDynValue(String name) { |
56 |
return this.delegatedDynObjet.getDynValue(name); |
57 |
} |
58 |
|
59 |
public void setDynValue(String name, Object value) { |
60 |
this.delegatedDynObjet.setDynValue(name, value);
|
61 |
// return this ???
|
62 |
} |
63 |
|
64 |
public void clear() { |
65 |
// TODO Delegar en el DynObject cuando tenga este servicio
|
66 |
|
67 |
DynField[] fields = delegatedDynObjet.getDynClass()
|
68 |
.getDeclaredDynFields(); |
69 |
|
70 |
for (int i = 0; i < fields.length; i++) { |
71 |
this.setDynValue(fields[i].getName(), fields[i].getDefaultValue());
|
72 |
} |
73 |
} |
74 |
|
75 |
protected void copyValuesTo(AbstractDataParameters target) { |
76 |
// TODO Delegar en el DynObject cuando tenga este servicio
|
77 |
DynField[] fields = delegatedDynObjet.getDynClass()
|
78 |
.getDeclaredDynFields(); |
79 |
|
80 |
|
81 |
for (int i = 0; i < fields.length; i++) { |
82 |
target.setDynValue(fields[i].getName(), this.getDynValue(fields[i]
|
83 |
.getName())); |
84 |
} |
85 |
} |
86 |
|
87 |
public DataParameters getCopy() {
|
88 |
// TODO Delegar en el DynObject cuando tenga este servicio
|
89 |
AbstractDataParameters copy; |
90 |
try {
|
91 |
copy = (AbstractDataParameters) this.getClass().newInstance();
|
92 |
} catch (InstantiationException e) { |
93 |
throw new CopyParametersException("data parameters", e); |
94 |
} catch (IllegalAccessException e) { |
95 |
throw new CopyParametersException("data parameters", e); |
96 |
} |
97 |
this.copyValuesTo(copy);
|
98 |
return copy;
|
99 |
} |
100 |
|
101 |
public PersistentState getState() throws PersistenceException { |
102 |
return AbstractPersistenceManager.getState(this); |
103 |
} |
104 |
|
105 |
public void loadState(PersistentState state) throws PersistenceException { |
106 |
DynField[] fields = delegatedDynObjet.getDynClass()
|
107 |
.getDeclaredDynFields(); |
108 |
|
109 |
for (int i = 0; i < fields.length; i++) { |
110 |
state.set(fields[i].getName(), this
|
111 |
.getDynValue(fields[i].getName())); |
112 |
} |
113 |
} |
114 |
|
115 |
public void setState(PersistentState state) throws PersistenceException { |
116 |
Iterator it = state.getNames();
|
117 |
while (it.hasNext()) {
|
118 |
String name = (String) it.next(); |
119 |
try {
|
120 |
this.setDynValue(name, state.get(name));
|
121 |
} catch (PersistenceValueNotFoundException e) {
|
122 |
// Ignore
|
123 |
} |
124 |
} |
125 |
} |
126 |
|
127 |
public void delegate(DynObject dynObject) { |
128 |
this.delegatedDynObjet.delegate(dynObject);
|
129 |
|
130 |
} |
131 |
|
132 |
public DynClass getDynClass() {
|
133 |
return this.delegatedDynObjet.getDynClass(); |
134 |
} |
135 |
|
136 |
public boolean hasDynValue(String name) { |
137 |
return this.delegatedDynObjet.hasDynValue(name); |
138 |
} |
139 |
|
140 |
public void implement(DynClass dynClass) { |
141 |
this.delegatedDynObjet.implement(dynClass);
|
142 |
} |
143 |
|
144 |
public Object invokeDynMethod(String name, DynObject context) |
145 |
throws DynMethodException {
|
146 |
return this.delegatedDynObjet.invokeDynMethod(this, name, context); |
147 |
} |
148 |
|
149 |
public Object invokeDynMethod(int code, DynObject context) |
150 |
throws DynMethodException {
|
151 |
return this.delegatedDynObjet.invokeDynMethod(this, code, context); |
152 |
} |
153 |
|
154 |
} |