Statistics
| Revision:

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 @ 40559

History | View | Annotate | Download (3.66 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.feature.impl.featureset;
25

    
26
import org.gvsig.fmap.dal.feature.EditableFeature;
27
import org.gvsig.fmap.dal.feature.Feature;
28
import org.gvsig.tools.dynobject.DynClass;
29
import org.gvsig.tools.dynobject.DynObject;
30
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
31
import org.gvsig.tools.dynobject.exception.DynMethodException;
32

    
33
/**
34
 * {@link DynObject} implementation to facade a Feature and allow to be used
35
 * as a {@link DynObject}.
36
 * 
37
 * This implementation may be reused to be used with many {@link Feature}
38
 * objects, but not at the same time.
39
 * 
40
 * @author gvSIG Team
41
 * @version $Id$
42
 */
43
public class DynObjectFeatureFacade implements DynObject {
44

    
45
    private Feature feature;
46
    
47
    private EditableFeature editable;
48

    
49
    private final Object lock = new Object();
50

    
51
    /**
52
     * Empty constructor.
53
     */
54
    public DynObjectFeatureFacade() {
55
        // Nothing to do
56
    }
57

    
58
    /**
59
     * Creates a facade over a {@link Feature}.
60
     */
61
    public DynObjectFeatureFacade(Feature feature) {
62
        setFeatureCopy(feature);
63
    }
64

    
65
    public DynClass getDynClass() {
66
        return getFeature().getType();
67
    }
68

    
69
    public Object getDynValue(String name) throws DynFieldNotFoundException {
70
        return getFeature().get(name);
71
    }
72

    
73
    public void setDynValue(String name, Object value)
74
        throws DynFieldNotFoundException {
75
        synchronized (lock) {
76
            if (editable == null) {
77
                editable = feature.getEditable();
78
            }            
79
        }
80
        editable.set(name, value);
81
    }
82

    
83
    public boolean hasDynValue(String name) {
84
        return getFeature().get(name) != null;
85
    }
86

    
87
    public Object invokeDynMethod(String name, DynObject context)
88
        throws DynMethodException {
89
        throw new UnsupportedOperationException();
90
    }
91

    
92
    public Object invokeDynMethod(int code, DynObject context)
93
        throws DynMethodException {
94
        throw new UnsupportedOperationException();
95
    }
96

    
97
    public void implement(DynClass dynClass) {
98
        throw new UnsupportedOperationException();
99
    }
100

    
101
    public void delegate(DynObject dynObject) {
102
        throw new UnsupportedOperationException();
103
    }
104

    
105
    public void clear() {
106
        // Nothing to do
107
    }
108
    
109
    public Feature getFeature() {
110
        return editable == null ? feature : editable;
111
    }
112
    
113
    public void setFeatureCopy(Feature feature) {
114
        synchronized (lock) {
115
            this.feature = feature.getCopy();
116
            this.editable = null;
117
        }
118
    }
119

    
120
    public void setFeature(Feature feature) {
121
        synchronized (lock) {
122
            this.feature = feature;
123
            this.editable = null;
124
        }
125
    }
126

    
127
    public EditableFeature getEditable() {
128
        return editable;
129
    }
130

    
131
}