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 / expressionevaluator / impl / symboltable / FeatureSymbolTableImpl.java @ 47695
History | View | Annotate | Download (6.11 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 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.expressionevaluator.impl.symboltable; |
25 |
|
26 |
import org.gvsig.fmap.dal.expressionevaluator.TableAttributeHandler; |
27 |
import org.apache.commons.lang3.Range; |
28 |
import org.apache.commons.lang3.StringUtils; |
29 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
30 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
31 |
import org.gvsig.expressionevaluator.Function; |
32 |
import org.gvsig.expressionevaluator.Interpreter; |
33 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
34 |
import org.gvsig.expressionevaluator.impl.DALFunctions; |
35 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
36 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
37 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW; |
38 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
39 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
40 |
import org.gvsig.fmap.dal.feature.Feature; |
41 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
43 |
import org.gvsig.fmap.dal.feature.FeatureType; |
44 |
|
45 |
/**
|
46 |
*
|
47 |
* @author jjdelcerro
|
48 |
*/
|
49 |
@SuppressWarnings("UseSpecificCatch") |
50 |
public class FeatureSymbolTableImpl extends AbstractSymbolTable implements FeatureSymbolTable { |
51 |
private static final String DAL_SYMBOL_TABLE_FEATURE = "DALSymbolTableFeature"; |
52 |
|
53 |
private final Function current_row; |
54 |
private Feature feature;
|
55 |
private FeatureType type;
|
56 |
private String storeName; |
57 |
private final TableAttributeHandler storeAttributeHandler; |
58 |
|
59 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
60 |
public FeatureSymbolTableImpl() {
|
61 |
this(DAL_SYMBOL_TABLE_FEATURE);
|
62 |
} |
63 |
|
64 |
public FeatureSymbolTableImpl(String name) { |
65 |
super(name);
|
66 |
this.current_row = new AbstractFunction( |
67 |
DALFunctions.GROUP_DATA_ACCESS, |
68 |
FUNCTION_CURRENT_ROW, |
69 |
Range.is(0),
|
70 |
"Return the current row when used in a table filter.\n"
|
71 |
+ "Return null if used outer a table filter.",
|
72 |
FUNCTION_CURRENT_ROW + "()",
|
73 |
null,
|
74 |
"Feature"
|
75 |
) { |
76 |
@Override
|
77 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
78 |
return feature;
|
79 |
} |
80 |
}; |
81 |
this.storeAttributeHandler = new TableAttributeHandler() { |
82 |
@Override
|
83 |
public Object get(String name) { |
84 |
if( feature==null ) { |
85 |
return null; |
86 |
} |
87 |
try {
|
88 |
return feature.get(name);
|
89 |
} catch (Exception ex) { |
90 |
return feature.getExtraValue(name);
|
91 |
} |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public String getName() { |
96 |
return storeName;
|
97 |
} |
98 |
}; |
99 |
} |
100 |
|
101 |
@Override
|
102 |
public FeatureSymbolTableImpl clone() throws CloneNotSupportedException { |
103 |
FeatureSymbolTableImpl other = (FeatureSymbolTableImpl) super.clone();
|
104 |
return other;
|
105 |
} |
106 |
|
107 |
@Override
|
108 |
public Function function(String name) { |
109 |
if (StringUtils.equalsIgnoreCase(name, FUNCTION_CURRENT_ROW)) {
|
110 |
return this.current_row; |
111 |
} |
112 |
return super.function(name); |
113 |
} |
114 |
|
115 |
@Override
|
116 |
public boolean exists(String name) { |
117 |
if (feature != null) { |
118 |
if (this.feature.hasValue(name)) { |
119 |
return true; |
120 |
} |
121 |
} |
122 |
if (StringUtils.equalsIgnoreCase(name, this.storeName) || |
123 |
StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_TABLE) || |
124 |
StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_ROW) ) { |
125 |
return true; |
126 |
} |
127 |
return super.exists(name); |
128 |
} |
129 |
|
130 |
@Override
|
131 |
public Object value(String name) { |
132 |
if (feature != null) { |
133 |
try {
|
134 |
return this.feature.get(name); |
135 |
} catch (Exception ex) { |
136 |
//DO NOTHING
|
137 |
} |
138 |
if (StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_ROW)) {
|
139 |
return this.feature; |
140 |
} |
141 |
} |
142 |
if (StringUtils.equalsIgnoreCase(name, this.storeName) |
143 |
|| StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_TABLE)) { |
144 |
return this.storeAttributeHandler; |
145 |
} |
146 |
return super.value(name); |
147 |
} |
148 |
|
149 |
public void setVar(String name, Object value) { |
150 |
if (feature instanceof EditableFeature ) { |
151 |
if( this.feature.hasValue(name) ) { |
152 |
((EditableFeature)this.feature).set(name, value);
|
153 |
return;
|
154 |
} |
155 |
} |
156 |
super.setVar(name, value);
|
157 |
} |
158 |
|
159 |
@Override
|
160 |
public boolean isSQLCompatible(String name) { |
161 |
if (this.type == null) { |
162 |
return super.isSQLCompatible(name); |
163 |
} |
164 |
FeatureAttributeDescriptor attrdesc = this.type.getAttributeDescriptor(name);
|
165 |
if (attrdesc == null) { |
166 |
return true; |
167 |
} |
168 |
if (attrdesc.isComputed()) {
|
169 |
return false; |
170 |
} |
171 |
return true; |
172 |
} |
173 |
|
174 |
@Override
|
175 |
public void setFeature(Feature feature) { |
176 |
this.feature = feature;
|
177 |
if (this.type == null && this.feature!=null ) { |
178 |
this.type = feature.getType();
|
179 |
FeatureStore store = feature.getStore(); |
180 |
if (store != null) { |
181 |
this.storeName = store.getName();
|
182 |
} |
183 |
} |
184 |
} |
185 |
|
186 |
@Override
|
187 |
public MutableSymbolTable createParent() {
|
188 |
ExpressionEvaluatorManager expManager = ExpressionEvaluatorLocator.getManager(); |
189 |
|
190 |
MutableSymbolTable symbolTable = expManager.createSymbolTable(); |
191 |
symbolTable.addSymbolTable(this);
|
192 |
return symbolTable;
|
193 |
} |
194 |
|
195 |
@Override
|
196 |
public Feature getFeature() {
|
197 |
return this.feature; |
198 |
} |
199 |
|
200 |
} |