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 @ 44750
History | View | Annotate | Download (5.64 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 org.gvsig.fmap.dal.DataManager; |
38 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW; |
39 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
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 = "DAL.SymbolTable.Feature"; |
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 |
super(DAL_SYMBOL_TABLE_FEATURE);
|
62 |
this.current_row = new AbstractFunction( |
63 |
DALFunctions.GROUP_DATA_ACCESS, |
64 |
FUNCTION_CURRENT_ROW, |
65 |
Range.is(0),
|
66 |
"Return the current row when used in a table filter.\n"
|
67 |
+ "Return null if used outer a table filter.",
|
68 |
FUNCTION_CURRENT_ROW + "()",
|
69 |
null,
|
70 |
"Feature"
|
71 |
) { |
72 |
@Override
|
73 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
74 |
return feature;
|
75 |
} |
76 |
}; |
77 |
this.storeAttributeHandler = new TableAttributeHandler() { |
78 |
@Override
|
79 |
public Object get(String name) { |
80 |
try {
|
81 |
return feature.get(name);
|
82 |
} catch (Exception ex) { |
83 |
return feature.getExtraValue(name);
|
84 |
} |
85 |
} |
86 |
|
87 |
@Override
|
88 |
public String getName() { |
89 |
return storeName;
|
90 |
} |
91 |
}; |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public FeatureSymbolTableImpl clone() throws CloneNotSupportedException { |
96 |
FeatureSymbolTableImpl other = (FeatureSymbolTableImpl) super.clone();
|
97 |
return other;
|
98 |
} |
99 |
|
100 |
@Override
|
101 |
public Function function(String name) { |
102 |
if (StringUtils.equalsIgnoreCase(name, FUNCTION_CURRENT_ROW)) {
|
103 |
return this.current_row; |
104 |
} |
105 |
return super.function(name); |
106 |
} |
107 |
|
108 |
@Override
|
109 |
public boolean exists(String name) { |
110 |
if (type == null) { |
111 |
return false; |
112 |
} |
113 |
if (type.get(name) != null) { |
114 |
return true; |
115 |
} |
116 |
if (StringUtils.equalsIgnoreCase(name, this.storeName) || |
117 |
StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_TABLE) || |
118 |
StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_ROW) ) { |
119 |
return true; |
120 |
} |
121 |
if (feature == null) { |
122 |
return false; |
123 |
} |
124 |
if (this.feature.hasExtraValue(name)) { |
125 |
return true; |
126 |
} |
127 |
return false; |
128 |
} |
129 |
|
130 |
@Override
|
131 |
public Object value(String name) { |
132 |
if (feature == null) { |
133 |
return null; |
134 |
} |
135 |
if (StringUtils.equalsIgnoreCase(name, this.storeName) || |
136 |
StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_TABLE)) { |
137 |
return this.storeAttributeHandler; |
138 |
} |
139 |
if (StringUtils.equalsIgnoreCase(name, SYMBOL_CURRENT_ROW)) {
|
140 |
return this.feature; |
141 |
} |
142 |
try {
|
143 |
return this.feature.get(name); |
144 |
} catch (Exception ex) { |
145 |
return this.feature.getExtraValue(name); |
146 |
} |
147 |
} |
148 |
|
149 |
@Override
|
150 |
public boolean isSQLCompatible(String name) { |
151 |
if (this.type == null) { |
152 |
return super.isSQLCompatible(name); |
153 |
} |
154 |
FeatureAttributeDescriptor attrdesc = this.type.getAttributeDescriptor(name);
|
155 |
if (attrdesc == null) { |
156 |
return true; |
157 |
} |
158 |
if (attrdesc.isComputed()) {
|
159 |
return false; |
160 |
} |
161 |
return true; |
162 |
} |
163 |
|
164 |
@Override
|
165 |
public void setFeature(Feature feature) { |
166 |
this.feature = feature;
|
167 |
if (this.type == null) { |
168 |
this.type = feature.getType();
|
169 |
FeatureStore store = feature.getStore(); |
170 |
if (store != null) { |
171 |
this.storeName = store.getName();
|
172 |
} |
173 |
} |
174 |
} |
175 |
|
176 |
@Override
|
177 |
public MutableSymbolTable createParent() {
|
178 |
ExpressionEvaluatorManager expManager = ExpressionEvaluatorLocator.getManager(); |
179 |
|
180 |
MutableSymbolTable symbolTable = expManager.createSymbolTable(); |
181 |
symbolTable.addSymbolTable(this);
|
182 |
return symbolTable;
|
183 |
} |
184 |
|
185 |
} |