svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / featureset / DynObjectFeatureFacade.java @ 40435
History | View | Annotate | Download (3.61 KB)
1 | 40435 | jjdelcerro | /* 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 | package org.gvsig.fmap.dal.feature.impl.featureset; |
||
23 | |||
24 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
25 | import org.gvsig.fmap.dal.feature.Feature; |
||
26 | import org.gvsig.tools.dynobject.DynClass; |
||
27 | import org.gvsig.tools.dynobject.DynObject; |
||
28 | import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
||
29 | import org.gvsig.tools.dynobject.exception.DynMethodException; |
||
30 | |||
31 | /**
|
||
32 | * {@link DynObject} implementation to facade a Feature and allow to be used
|
||
33 | * as a {@link DynObject}.
|
||
34 | *
|
||
35 | * This implementation may be reused to be used with many {@link Feature}
|
||
36 | * objects, but not at the same time.
|
||
37 | *
|
||
38 | * @author gvSIG Team
|
||
39 | * @version $Id$
|
||
40 | */
|
||
41 | public class DynObjectFeatureFacade implements DynObject { |
||
42 | |||
43 | private Feature feature;
|
||
44 | |||
45 | private EditableFeature editable;
|
||
46 | |||
47 | private final Object lock = new Object(); |
||
48 | |||
49 | /**
|
||
50 | * Empty constructor.
|
||
51 | */
|
||
52 | public DynObjectFeatureFacade() {
|
||
53 | // Nothing to do
|
||
54 | } |
||
55 | |||
56 | /**
|
||
57 | * Creates a facade over a {@link Feature}.
|
||
58 | */
|
||
59 | public DynObjectFeatureFacade(Feature feature) {
|
||
60 | setFeatureCopy(feature); |
||
61 | } |
||
62 | |||
63 | public DynClass getDynClass() {
|
||
64 | return getFeature().getType();
|
||
65 | } |
||
66 | |||
67 | public Object getDynValue(String name) throws DynFieldNotFoundException { |
||
68 | return getFeature().get(name);
|
||
69 | } |
||
70 | |||
71 | public void setDynValue(String name, Object value) |
||
72 | throws DynFieldNotFoundException {
|
||
73 | synchronized (lock) {
|
||
74 | if (editable == null) { |
||
75 | editable = feature.getEditable(); |
||
76 | } |
||
77 | } |
||
78 | editable.set(name, value); |
||
79 | } |
||
80 | |||
81 | public boolean hasDynValue(String name) { |
||
82 | return getFeature().get(name) != null; |
||
83 | } |
||
84 | |||
85 | public Object invokeDynMethod(String name, DynObject context) |
||
86 | throws DynMethodException {
|
||
87 | throw new UnsupportedOperationException(); |
||
88 | } |
||
89 | |||
90 | public Object invokeDynMethod(int code, DynObject context) |
||
91 | throws DynMethodException {
|
||
92 | throw new UnsupportedOperationException(); |
||
93 | } |
||
94 | |||
95 | public void implement(DynClass dynClass) { |
||
96 | throw new UnsupportedOperationException(); |
||
97 | } |
||
98 | |||
99 | public void delegate(DynObject dynObject) { |
||
100 | throw new UnsupportedOperationException(); |
||
101 | } |
||
102 | |||
103 | public void clear() { |
||
104 | // Nothing to do
|
||
105 | } |
||
106 | |||
107 | public Feature getFeature() {
|
||
108 | return editable == null ? feature : editable; |
||
109 | } |
||
110 | |||
111 | public void setFeatureCopy(Feature feature) { |
||
112 | synchronized (lock) {
|
||
113 | this.feature = feature.getCopy();
|
||
114 | this.editable = null; |
||
115 | } |
||
116 | } |
||
117 | |||
118 | public void setFeature(Feature feature) { |
||
119 | synchronized (lock) {
|
||
120 | this.feature = feature;
|
||
121 | this.editable = null; |
||
122 | } |
||
123 | } |
||
124 | |||
125 | public EditableFeature getEditable() {
|
||
126 | return editable;
|
||
127 | } |
||
128 | |||
129 | } |