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 @ 47597
History | View | Annotate | Download (6.09 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 |
return false; |
119 |
} |
120 |
if (this.feature.hasValue(name)) { |
121 |
return true; |
122 |
} |
123 |
if (StringUtils.equalsIgnoreCase(name, this.storeName) || |
124 |
StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_TABLE) || |
125 |
StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_ROW) ) { |
126 |
return true; |
127 |
} |
128 |
return false; |
129 |
} |
130 |
|
131 |
@Override
|
132 |
public Object value(String name) { |
133 |
if (feature == null) { |
134 |
return null; |
135 |
} |
136 |
try {
|
137 |
return this.feature.get(name); |
138 |
} catch (Exception ex) { |
139 |
//DO NOTHING
|
140 |
} |
141 |
if (StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_ROW)) {
|
142 |
return this.feature; |
143 |
} |
144 |
if (StringUtils.equalsIgnoreCase(name, this.storeName) |
145 |
|| StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_TABLE)) { |
146 |
return this.storeAttributeHandler; |
147 |
} |
148 |
return null; |
149 |
} |
150 |
|
151 |
public void setVar(String name, Object value) { |
152 |
if (feature instanceof EditableFeature ) { |
153 |
if( this.feature.hasValue(name) ) { |
154 |
((EditableFeature)this.feature).set(name, value);
|
155 |
return;
|
156 |
} |
157 |
} |
158 |
super.setVar(name, value);
|
159 |
} |
160 |
|
161 |
@Override
|
162 |
public boolean isSQLCompatible(String name) { |
163 |
if (this.type == null) { |
164 |
return super.isSQLCompatible(name); |
165 |
} |
166 |
FeatureAttributeDescriptor attrdesc = this.type.getAttributeDescriptor(name);
|
167 |
if (attrdesc == null) { |
168 |
return true; |
169 |
} |
170 |
if (attrdesc.isComputed()) {
|
171 |
return false; |
172 |
} |
173 |
return true; |
174 |
} |
175 |
|
176 |
@Override
|
177 |
public void setFeature(Feature feature) { |
178 |
this.feature = feature;
|
179 |
if (this.type == null && this.feature!=null ) { |
180 |
this.type = feature.getType();
|
181 |
FeatureStore store = feature.getStore(); |
182 |
if (store != null) { |
183 |
this.storeName = store.getName();
|
184 |
} |
185 |
} |
186 |
} |
187 |
|
188 |
@Override
|
189 |
public MutableSymbolTable createParent() {
|
190 |
ExpressionEvaluatorManager expManager = ExpressionEvaluatorLocator.getManager(); |
191 |
|
192 |
MutableSymbolTable symbolTable = expManager.createSymbolTable(); |
193 |
symbolTable.addSymbolTable(this);
|
194 |
return symbolTable;
|
195 |
} |
196 |
|
197 |
@Override
|
198 |
public Feature getFeature() {
|
199 |
return this.feature; |
200 |
} |
201 |
|
202 |
} |