svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libTools / src / org / gvsig / tools / dynobject / impl / DefaultDynObject.java @ 24846
History | View | Annotate | Download (2.52 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Gobernment (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 |
* 2008 {DiSiD Technologies} {Create DynObjects implementation}
|
26 |
*/
|
27 |
package org.gvsig.tools.dynobject.impl; |
28 |
|
29 |
import java.util.HashMap; |
30 |
import java.util.Map; |
31 |
|
32 |
import org.gvsig.tools.dynobject.DynClass; |
33 |
import org.gvsig.tools.dynobject.DynField; |
34 |
import org.gvsig.tools.dynobject.DynObject; |
35 |
|
36 |
/**
|
37 |
* @author <a href="mailto:jjdelcerro@gvsig.org">Joaqu?n Jos? del Cerro</a>
|
38 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
39 |
*/
|
40 |
public class DefaultDynObject implements DynObject { |
41 |
|
42 |
private DynClass dynClass;
|
43 |
private Map values; |
44 |
|
45 |
public DefaultDynObject(DynClass dynClass) {
|
46 |
this.dynClass = dynClass;
|
47 |
this.values = new HashMap(); |
48 |
} |
49 |
|
50 |
// public void implement(DynClass dynClass) {
|
51 |
// dynClass.extend(dynClass);
|
52 |
// }
|
53 |
|
54 |
public DynClass getDynClass() {
|
55 |
return this.dynClass; |
56 |
} |
57 |
|
58 |
public Object getValue(String name) { |
59 |
DynField descriptor = dynClass.getDynField(name); |
60 |
if (descriptor == null) { |
61 |
throw new DynFieldNotFoundException(name, getDynClass().getName()); |
62 |
} |
63 |
Object value = values.get(name);
|
64 |
if (value == null) { |
65 |
if (!this.values.containsKey(name)) { |
66 |
return descriptor.getDefaultValue();
|
67 |
} |
68 |
} |
69 |
return value;
|
70 |
} |
71 |
|
72 |
public void setValue(String name, Object value) { |
73 |
DefaultDynField descriptor = (DefaultDynField) dynClass |
74 |
.getDynField(name); |
75 |
if (descriptor == null) { |
76 |
throw new DynFieldNotFoundException(name, getDynClass().getName()); |
77 |
} |
78 |
values.put(name, descriptor.coerce(value)); |
79 |
} |
80 |
|
81 |
} |