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