Revision 43989
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableOperations.java | ||
---|---|---|
313 | 313 |
tmpfnames.add(ad.getName()); |
314 | 314 |
} |
315 | 315 |
|
316 |
CreateNewAttributePanel panelNewField = new CreateNewAttributePanel(); |
|
316 |
CreateNewAttributePanel panelNewField = new CreateNewAttributePanel(featureStore);
|
|
317 | 317 |
panelNewField.setCurrentFieldNames(tmpfnames.toArray(new String[0])); |
318 | 318 |
DataManager dataManager = DALLocator.getDataManager(); |
319 | 319 |
FeatureStoreProviderFactory factory = |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/gui/EmulatedFieldExpression.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.app.project.documents.table.gui; |
|
7 |
|
|
8 |
import java.util.ArrayList; |
|
9 |
import java.util.List; |
|
10 |
import java.util.logging.Level; |
|
11 |
import java.util.logging.Logger; |
|
12 |
import org.apache.commons.collections.ListUtils; |
|
13 |
import org.apache.commons.lang3.StringUtils; |
|
14 |
import org.gvsig.expressionevaluator.Code; |
|
15 |
import org.gvsig.expressionevaluator.Code.Identifier; |
|
16 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
17 |
import org.gvsig.fmap.dal.feature.Feature; |
|
18 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
|
19 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
20 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
21 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
|
22 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
23 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
24 |
import org.gvsig.tools.ToolsLocator; |
|
25 |
import org.gvsig.tools.dynobject.DynStruct; |
|
26 |
import org.gvsig.tools.exception.BaseException; |
|
27 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
28 |
import org.gvsig.tools.persistence.Persistent; |
|
29 |
import org.gvsig.tools.persistence.PersistentState; |
|
30 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
31 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
32 |
import org.gvsig.tools.visitor.Visitor; |
|
33 |
|
|
34 |
/** |
|
35 |
* |
|
36 |
* @author osc |
|
37 |
*/ |
|
38 |
public class EmulatedFieldExpression implements FeatureAttributeEmulator, Persistent { |
|
39 |
|
|
40 |
String[] requiredFields = null; |
|
41 |
String code = ""; |
|
42 |
Code codeCompiled = null; |
|
43 |
MutableSymbolTable symbolTable = null; |
|
44 |
ExpressionEvaluatorManager expressionManager = null; |
|
45 |
private static final String EMULEFIELDEXP_PERSISTENCE_DEFINITION_NAME |
|
46 |
= "EmulatedFieldExpression"; |
|
47 |
private boolean valid; |
|
48 |
private String errorMessage; |
|
49 |
|
|
50 |
public EmulatedFieldExpression() { |
|
51 |
} |
|
52 |
|
|
53 |
EmulatedFieldExpression(FeatureType featureType, String code) { |
|
54 |
this.setCode(code); |
|
55 |
this.checkVars(featureType); |
|
56 |
|
|
57 |
} |
|
58 |
|
|
59 |
public boolean isValid() { |
|
60 |
return this.valid; |
|
61 |
} |
|
62 |
|
|
63 |
private void checkVars(final FeatureType featureType) { |
|
64 |
this.valid = true; |
|
65 |
final List<String> theUsedFields = new ArrayList<>(); |
|
66 |
final List<String> undefinedFields = new ArrayList<>(); |
|
67 |
|
|
68 |
try { |
|
69 |
Code theCodeCompiled = this.getCodeCompiled(); |
|
70 |
theCodeCompiled.accept(new Visitor() { |
|
71 |
@Override |
|
72 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
|
73 |
Code code = (Code) obj; |
|
74 |
if (code instanceof Identifier) { |
|
75 |
String name = ((Identifier) code).name(); |
|
76 |
if (featureType.get(name) == null) { |
|
77 |
undefinedFields.add(name); |
|
78 |
valid = false; |
|
79 |
} else { |
|
80 |
theUsedFields.add(name); |
|
81 |
} |
|
82 |
} |
|
83 |
} |
|
84 |
}); |
|
85 |
if(!undefinedFields.isEmpty()){ |
|
86 |
this.errorMessage = "undefined fields " + StringUtils.join(undefinedFields,", "); |
|
87 |
} |
|
88 |
} catch (BaseException ex) { |
|
89 |
valid = false; |
|
90 |
this.errorMessage = ex.getMessage(); |
|
91 |
} |
|
92 |
this.requiredFields = theUsedFields.toArray(new String[theUsedFields.size()]); |
|
93 |
} |
|
94 |
|
|
95 |
public static void registerPersistenceDefinition() { |
|
96 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
97 |
|
|
98 |
if (manager.getDefinition(EMULEFIELDEXP_PERSISTENCE_DEFINITION_NAME) |
|
99 |
== null) { |
|
100 |
DynStruct definition = manager.addDefinition( |
|
101 |
EmulatedFieldExpression.class, |
|
102 |
EMULEFIELDEXP_PERSISTENCE_DEFINITION_NAME, |
|
103 |
EMULEFIELDEXP_PERSISTENCE_DEFINITION_NAME |
|
104 |
+ " Persistent definition", |
|
105 |
null, |
|
106 |
null |
|
107 |
); |
|
108 |
definition.addDynFieldString("code") |
|
109 |
.setMandatory(true) |
|
110 |
.setPersistent(true); |
|
111 |
definition.addDynFieldArray("fields") |
|
112 |
.setClassOfItems(String.class) |
|
113 |
.setMandatory(true) |
|
114 |
.setPersistent(true); |
|
115 |
definition.addDynFieldBoolean("valid") |
|
116 |
.setMandatory(true) |
|
117 |
.setPersistent(true); |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
private Code getCodeCompiled() { |
|
122 |
if (this.codeCompiled == null) { |
|
123 |
this.codeCompiled = this.getExpressionManager().compile(code); |
|
124 |
} |
|
125 |
return this.codeCompiled; |
|
126 |
} |
|
127 |
|
|
128 |
private MutableSymbolTable getSymbolTable() { |
|
129 |
if (this.symbolTable == null) { |
|
130 |
this.symbolTable = this.getExpressionManager().createSymbolTable(); |
|
131 |
} |
|
132 |
return this.symbolTable; |
|
133 |
} |
|
134 |
|
|
135 |
private ExpressionEvaluatorManager getExpressionManager() { |
|
136 |
if (this.expressionManager == null) { |
|
137 |
this.expressionManager |
|
138 |
= ExpressionEvaluatorLocator.getManager(); |
|
139 |
} |
|
140 |
return this.expressionManager; |
|
141 |
} |
|
142 |
|
|
143 |
@Override |
|
144 |
public Object get(Feature feature) { |
|
145 |
if (!this.valid) { |
|
146 |
return null; |
|
147 |
} |
|
148 |
MutableSymbolTable symbol = this.getSymbolTable(); |
|
149 |
for (FeatureAttributeDescriptor descriptor : feature.getType()) { |
|
150 |
if (!descriptor.isComputed()) { // si eres tu mismo |
|
151 |
String fieldName = descriptor.getName(); |
|
152 |
Object value = feature.get(fieldName); |
|
153 |
symbol.setVar(fieldName, value); |
|
154 |
} |
|
155 |
} |
|
156 |
Code codeCompilation = this.getCodeCompiled(); |
|
157 |
Object result = this.getExpressionManager().evaluate(symbol, codeCompilation); |
|
158 |
return result; |
|
159 |
} |
|
160 |
|
|
161 |
@Override |
|
162 |
public void set(EditableFeature feature, Object value) { |
|
163 |
//throw new UnsupportedOperationException("Not supported yet."); |
|
164 |
} |
|
165 |
|
|
166 |
@Override |
|
167 |
public boolean allowSetting() { |
|
168 |
return false; |
|
169 |
} |
|
170 |
|
|
171 |
@Override |
|
172 |
public String[] getRequiredFieldNames() { |
|
173 |
return this.requiredFields; |
|
174 |
} |
|
175 |
|
|
176 |
public String getCode() { |
|
177 |
return this.code; |
|
178 |
} |
|
179 |
|
|
180 |
@Override |
|
181 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
182 |
state.set("fields", this.getRequiredFieldNames()); |
|
183 |
state.set("code", this.getCode()); |
|
184 |
state.set("valid", this.isValid()); |
|
185 |
|
|
186 |
} |
|
187 |
|
|
188 |
@Override |
|
189 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
190 |
String stateCode = state.getString("code"); |
|
191 |
String[] stateFields = state.getStringArray("fields"); |
|
192 |
this.valid = state.getBoolean("valid"); |
|
193 |
this.setCode(stateCode); |
|
194 |
this.setFields(stateFields); |
|
195 |
} |
|
196 |
|
|
197 |
private void setCode(String code) { |
|
198 |
this.code = code; |
|
199 |
} |
|
200 |
|
|
201 |
private void setFields(String[] fields) { |
|
202 |
this.requiredFields = fields; |
|
203 |
} |
|
204 |
|
|
205 |
public String getErrorMessage() { |
|
206 |
return this.errorMessage; |
|
207 |
} |
|
208 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/gui/CreateNewAttributePanel.java | ||
---|---|---|
27 | 27 |
import java.awt.GridBagConstraints; |
28 | 28 |
import java.awt.GridBagLayout; |
29 | 29 |
import java.awt.GridLayout; |
30 |
import java.awt.LayoutManager; |
|
31 | 30 |
import java.awt.event.ActionEvent; |
32 | 31 |
import java.awt.event.ActionListener; |
33 | 32 |
import java.awt.event.KeyEvent; |
... | ... | |
49 | 48 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
50 | 49 |
import org.gvsig.app.ApplicationLocator; |
51 | 50 |
import org.gvsig.app.ApplicationManager; |
51 |
import org.gvsig.expressionevaluator.swing.Element; |
|
52 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
|
53 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
|
54 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
|
55 |
import org.gvsig.fmap.dal.DALLocator; |
|
52 | 56 |
import org.gvsig.fmap.dal.DataTypes; |
57 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
|
53 | 58 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
54 | 59 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
55 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
|
|
56 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
|
|
60 |
import org.gvsig.fmap.dal.feature.FeatureStore;
|
|
61 |
import org.gvsig.fmap.dal.swing.DataSwingManager;
|
|
57 | 62 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
58 | 63 |
import org.gvsig.i18n.Messages; |
59 | 64 |
import org.gvsig.tools.ToolsLocator; |
... | ... | |
120 | 125 |
} |
121 | 126 |
}; |
122 | 127 |
private String[] currentFieldNames; |
128 |
private ExpressionPickerController expressionPicker; |
|
129 |
private FeatureStore store; |
|
123 | 130 |
|
124 |
public CreateNewAttributePanel() { |
|
131 |
// public CreateNewAttributePanel() { |
|
132 |
// super(); |
|
133 |
// initialize(); |
|
134 |
// } |
|
135 |
|
|
136 |
public CreateNewAttributePanel(FeatureStore store) { |
|
125 | 137 |
super(); |
138 |
this.store = store; |
|
126 | 139 |
initialize(); |
127 | 140 |
} |
128 | 141 |
|
129 |
public CreateNewAttributePanel(boolean isDoubleBuffered) { |
|
130 |
super(isDoubleBuffered); |
|
131 |
initialize(); |
|
132 |
} |
|
142 |
// public CreateNewAttributePanel(boolean isDoubleBuffered) { |
|
143 |
// super(isDoubleBuffered); |
|
144 |
// initialize(); |
|
145 |
// } |
|
146 |
// |
|
147 |
// public CreateNewAttributePanel(LayoutManager layout) { |
|
148 |
// super(layout); |
|
149 |
// initialize(); |
|
150 |
// } |
|
151 |
// |
|
152 |
// public CreateNewAttributePanel(LayoutManager layout, |
|
153 |
// boolean isDoubleBuffered) { |
|
154 |
// super(layout, isDoubleBuffered); |
|
155 |
// initialize(); |
|
156 |
// } |
|
133 | 157 |
|
134 |
public CreateNewAttributePanel(LayoutManager layout) { |
|
135 |
super(layout); |
|
136 |
initialize(); |
|
137 |
} |
|
138 |
|
|
139 |
public CreateNewAttributePanel(LayoutManager layout, |
|
140 |
boolean isDoubleBuffered) { |
|
141 |
super(layout, isDoubleBuffered); |
|
142 |
initialize(); |
|
143 |
} |
|
144 |
|
|
145 | 158 |
public WindowInfo getWindowInfo() { |
146 | 159 |
if (viewInfo == null) { |
147 | 160 |
viewInfo = new WindowInfo(WindowInfo.MODALDIALOG); |
... | ... | |
164 | 177 |
this.setPreferredSize(new java.awt.Dimension(300, 310)); |
165 | 178 |
this.add(getJPanel(), java.awt.BorderLayout.CENTER); |
166 | 179 |
this.add(getJPanelOkCancel(), java.awt.BorderLayout.SOUTH); |
180 |
|
|
181 |
jBtnExpression.setText(""); |
|
182 |
ExpressionEvaluatorSwingManager manager = ExpressionEvaluatorSwingLocator.getManager(); |
|
183 |
this.expressionPicker = manager.createExpressionPickerController(jTxtExpression, jBtnExpression); |
|
184 |
if( this.store != null ) { |
|
185 |
Element element = manager.createElement( |
|
186 |
DataSwingManager.FEATURE_STORE_EXPRESSION_ELEMENT, |
|
187 |
this.expressionPicker, |
|
188 |
this.store |
|
189 |
); |
|
190 |
if( element != null ) { |
|
191 |
this.expressionPicker.getElements().add(element); |
|
192 |
} |
|
193 |
} |
|
167 | 194 |
} |
168 | 195 |
|
169 | 196 |
/** |
... | ... | |
336 | 363 |
} |
337 | 364 |
EditableFeatureAttributeDescriptor ead = null; |
338 | 365 |
if (getJRdbFieldVirtual().isSelected()) { |
339 |
String code = getJTxtExpression().getText(); |
|
340 |
EmulatedFieldExpression myEmulated = |
|
341 |
new EmulatedFieldExpression( |
|
342 |
featureType, |
|
343 |
code); |
|
366 |
FeatureAttributeEmulatorExpression myEmulated = DALLocator.getDataManager().createFeatureAttributeEmulatorExpression( |
|
367 |
featureType, |
|
368 |
this.expressionPicker.get() |
|
369 |
); |
|
344 | 370 |
if (!myEmulated.isValid()) { |
345 | 371 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
346 | 372 |
ApplicationManager application = ApplicationLocator.getManager(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/gui/FeatureTypeEditingPanel.java | ||
---|---|---|
97 | 97 |
|
98 | 98 |
private JButton jBtnCancel = null; |
99 | 99 |
|
100 |
private CreateNewAttributePanel panelNewField = |
|
101 |
new CreateNewAttributePanel(); |
|
100 |
private CreateNewAttributePanel panelNewField; |
|
102 | 101 |
|
103 | 102 |
private FeatureStore featureStore = null; |
104 | 103 |
|
... | ... | |
238 | 237 |
super(); |
239 | 238 |
this.featureStore = fs; |
240 | 239 |
this.editableType = fs.getDefaultFeatureType().getEditable(); |
240 |
this.panelNewField = new CreateNewAttributePanel(this.featureStore); |
|
241 |
|
|
241 | 242 |
initialize(); |
242 | 243 |
// Add a new row |
243 | 244 |
TableModel tm; |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/TableExtension.java | ||
---|---|---|
26 | 26 |
import org.gvsig.andami.plugins.Extension; |
27 | 27 |
import org.gvsig.app.ApplicationLocator; |
28 | 28 |
import org.gvsig.app.project.documents.table.TableManager; |
29 |
import org.gvsig.app.project.documents.table.gui.EmulatedFieldExpression; |
|
30 | 29 |
import org.gvsig.app.project.documents.table.gui.toc.ShowAttributesTableTocMenuEntry; |
31 | 30 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerTableWizardPanel; |
32 | 31 |
import org.gvsig.tools.ToolsLocator; |
... | ... | |
41 | 40 |
*/ |
42 | 41 |
public class TableExtension extends Extension { |
43 | 42 |
|
43 |
@Override |
|
44 | 44 |
public void initialize() { |
45 | 45 |
|
46 | 46 |
ExtensionPointManager epMan = ToolsLocator.getExtensionPointManager(); |
... | ... | |
56 | 56 |
ShowAttributesTableTocMenuEntry.EXTENSION_POINT_NAME, |
57 | 57 |
"TOC popup menu to show vector layer's attributes table", |
58 | 58 |
new ShowAttributesTableTocMenuEntry()); |
59 |
// Adding emulatedfieldexpression |
|
60 |
EmulatedFieldExpression.registerPersistenceDefinition(); |
|
61 | 59 |
} |
62 | 60 |
|
61 |
@Override |
|
63 | 62 |
public void postInitialize() { |
64 | 63 |
TableManager.register(); |
65 | 64 |
ApplicationLocator.getManager().registerAddTableWizard("File", |
66 | 65 |
"File Table", FilesystemExplorerTableWizardPanel.class); |
67 | 66 |
} |
68 | 67 |
|
68 |
@Override |
|
69 | 69 |
public boolean isEnabled() { |
70 | 70 |
return true; |
71 | 71 |
} |
72 | 72 |
|
73 |
@Override |
|
73 | 74 |
public boolean isVisible() { |
74 | 75 |
return true; |
75 | 76 |
} |
76 | 77 |
|
78 |
@Override |
|
77 | 79 |
public void execute(String actionCommand) { |
78 | 80 |
// Nothing to do |
79 | 81 |
} |
80 | 82 |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/pom.xml | ||
---|---|---|
94 | 94 |
<dependency> |
95 | 95 |
<groupId>org.gvsig</groupId> |
96 | 96 |
<artifactId>org.gvsig.expressionevaluator.swing.api</artifactId> |
97 |
<scope>compile</scope>
|
|
97 |
<scope>compile</scope> |
|
98 | 98 |
</dependency> |
99 |
<dependency> |
|
100 |
<groupId>org.gvsig</groupId> |
|
101 |
<artifactId>org.gvsig.expressionevaluator.lib.api</artifactId> |
|
102 |
<scope>compile</scope> |
|
103 |
</dependency> |
|
99 | 104 |
</dependencies> |
100 | 105 |
|
101 | 106 |
<build> |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultExpression.java | ||
---|---|---|
4 | 4 |
import java.util.ArrayList; |
5 | 5 |
import java.util.Iterator; |
6 | 6 |
import java.util.List; |
7 |
import java.util.logging.Level; |
|
8 |
import java.util.logging.Logger; |
|
9 | 7 |
import org.apache.commons.lang3.StringUtils; |
10 | 8 |
import org.gvsig.expressionevaluator.Code; |
11 | 9 |
import org.gvsig.expressionevaluator.Expression; |
... | ... | |
118 | 116 |
} |
119 | 117 |
|
120 | 118 |
@Override |
121 |
public Object execute(SymbolTable symbolTable) {
|
|
119 |
public Code getCode() {
|
|
122 | 120 |
if (this.code == null) { |
123 | 121 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
124 | 122 |
this.code = manager.compile(this.phrase); |
125 | 123 |
} |
124 |
return code; |
|
125 |
} |
|
126 |
|
|
127 |
|
|
128 |
@Override |
|
129 |
public Object execute(SymbolTable symbolTable) { |
|
126 | 130 |
if (this.interpreter == null) { |
127 | 131 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
128 | 132 |
this.interpreter = manager.createInterpreter(); |
129 | 133 |
} |
130 | 134 |
this.interpreter.setSymbolTable(symbolTable); |
131 |
Object x = this.interpreter.run(code);
|
|
135 |
Object x = this.interpreter.run(this.getCode());
|
|
132 | 136 |
return x; |
133 | 137 |
} |
134 | 138 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/CeilFunction.java | ||
---|---|---|
17 | 17 |
new String[]{ |
18 | 18 |
"a - a value." |
19 | 19 |
}, |
20 |
"Double" |
|
20 |
"Double", |
|
21 |
true |
|
21 | 22 |
); |
22 | 23 |
this.addAlias("CEILING"); |
23 | 24 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/BitGetFunction.java | ||
---|---|---|
19 | 19 |
"bits - a bit set", |
20 | 20 |
"nbit - bit to check" |
21 | 21 |
}, |
22 |
"Boolean" |
|
22 |
"Boolean", |
|
23 |
true |
|
23 | 24 |
); |
24 | 25 |
} |
25 | 26 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/BitOrFunction.java | ||
---|---|---|
17 | 17 |
"expr1 - the fisrt argument", |
18 | 18 |
"expr2 - the second argument" |
19 | 19 |
}, |
20 |
"Long" |
|
20 |
"Long", |
|
21 |
true |
|
21 | 22 |
); |
22 | 23 |
} |
23 | 24 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/ATanFunction.java | ||
---|---|---|
16 | 16 |
new String[]{ |
17 | 17 |
"a - the value whose arc tangent is to be returned." |
18 | 18 |
}, |
19 |
"Double" |
|
19 |
"Double", |
|
20 |
true |
|
20 | 21 |
); |
21 | 22 |
} |
22 | 23 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/CosFunction.java | ||
---|---|---|
15 | 15 |
new String[]{ |
16 | 16 |
"a - an angle, in radians." |
17 | 17 |
}, |
18 |
"Double" |
|
18 |
"Double", |
|
19 |
true |
|
19 | 20 |
); |
20 | 21 |
} |
21 | 22 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/AffineTransformFunction.java | ||
---|---|---|
23 | 23 |
"m02 - the X coordinate translation element of the 3x3 matrix", |
24 | 24 |
"m12 - the Y coordinate translation element of the 3x3 matrix" |
25 | 25 |
}, |
26 |
"AffineTransform" |
|
26 |
"AffineTransform", |
|
27 |
false |
|
27 | 28 |
); |
28 | 29 |
} |
29 | 30 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/ACosFunction.java | ||
---|---|---|
14 | 14 |
new String[]{ |
15 | 15 |
"value whose arc tangent is to be returned" |
16 | 16 |
}, |
17 |
"Double" |
|
17 |
"Double", |
|
18 |
true |
|
18 | 19 |
); |
19 | 20 |
} |
20 | 21 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/ASinFunction.java | ||
---|---|---|
16 | 16 |
new String[]{ |
17 | 17 |
"a - the value whose arc sine is to be returned" |
18 | 18 |
}, |
19 |
"Double" |
|
19 |
"Double", |
|
20 |
true |
|
20 | 21 |
); |
21 | 22 |
} |
22 | 23 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/CoshFunction.java | ||
---|---|---|
18 | 18 |
new String[]{ |
19 | 19 |
"x - The number whose hyperbolic cosine is to be returned." |
20 | 20 |
}, |
21 |
"Double" |
|
21 |
"Double", |
|
22 |
true |
|
22 | 23 |
); |
23 | 24 |
} |
24 | 25 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/BitAndFunction.java | ||
---|---|---|
17 | 17 |
"expr1 - the fisrt argument", |
18 | 18 |
"expr2 - the second argument" |
19 | 19 |
}, |
20 |
"Long" |
|
20 |
"Long", |
|
21 |
true |
|
21 | 22 |
); |
22 | 23 |
} |
23 | 24 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/AbsFunction.java | ||
---|---|---|
18 | 18 |
new String[]{ |
19 | 19 |
"a - the argument whose absolute value is to be determined" |
20 | 20 |
}, |
21 |
"Double" |
|
21 |
"Double", |
|
22 |
true |
|
22 | 23 |
); |
23 | 24 |
} |
24 | 25 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/numeric/BitXorFunction.java | ||
---|---|---|
17 | 17 |
"expr1 - the fisrt argument", |
18 | 18 |
"expr2 - the second argument" |
19 | 19 |
}, |
20 |
"Long" |
|
20 |
"Long", |
|
21 |
true |
|
21 | 22 |
); |
22 | 23 |
} |
23 | 24 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/SQLLexicalAnalyzer.java | ||
---|---|---|
169 | 169 |
buffer.add(ch); |
170 | 170 |
ch = getch(); |
171 | 171 |
} |
172 |
if( !isEOF() ) {
|
|
172 |
if( ch != EOF ) {
|
|
173 | 173 |
ungetch(); |
174 | 174 |
} |
175 | 175 |
String id = buffer.toString(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestCompiler.java | ||
---|---|---|
225 | 225 |
assertEquals("=([1990], [precio])", code.toString()); |
226 | 226 |
} |
227 | 227 |
|
228 |
|
|
229 |
public void testInvokeFunction1() { |
|
230 |
String source = "ST_Area(GEOMETRY)"; |
|
231 |
|
|
232 |
Compiler compiler = createCompiler(); |
|
233 |
|
|
234 |
Code code = compiler.compileExpression(source); |
|
235 |
assertEquals("ST_Area([GEOMETRY])", code.toString()); |
|
236 |
} |
|
237 |
|
|
228 | 238 |
public void testInvokeMethod1() { |
229 | 239 |
String source = "'hola'.length()"; |
230 | 240 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestCodeToStringConverter.java | ||
---|---|---|
1 |
package org.gvsig.expresionevaluator.impl; |
|
2 |
|
|
3 |
import static junit.framework.Assert.assertEquals; |
|
4 |
import junit.framework.TestCase; |
|
5 |
import org.gvsig.expressionevaluator.impl.ExpressionEvaluatorImplLibrary; |
|
6 |
import org.gvsig.expressionevaluator.spi.AbstractCodeToStringConverter; |
|
7 |
import org.gvsig.expressionevaluator.Code; |
|
8 |
import org.gvsig.expressionevaluator.CodeToStringConverter; |
|
9 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
10 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
11 |
import org.gvsig.expressionevaluator.Function; |
|
12 |
import org.gvsig.expressionevaluator.Compiler; |
|
13 |
import org.gvsig.expressionevaluator.LexicalAnalyzer; |
|
14 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
15 |
import org.gvsig.expressionevaluator.impl.DefaultCompiler; |
|
16 |
import org.gvsig.expressionevaluator.impl.SQLLexicalAnalyzer; |
|
17 |
|
|
18 |
/** |
|
19 |
* |
|
20 |
* @author jjdelcerro |
|
21 |
*/ |
|
22 |
public class TestCodeToStringConverter extends TestCase { |
|
23 |
|
|
24 |
public TestCodeToStringConverter(String testName) { |
|
25 |
super(testName); |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
protected void setUp() throws Exception { |
|
30 |
super.setUp(); |
|
31 |
new ExpressionEvaluatorImplLibrary().initialize(); |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
protected void tearDown() throws Exception { |
|
36 |
super.tearDown(); |
|
37 |
} |
|
38 |
|
|
39 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
40 |
// public void testHello() {} |
|
41 |
|
|
42 |
protected LexicalAnalyzer createLexicalAnalyzer() { |
|
43 |
SQLLexicalAnalyzer lexer = new SQLLexicalAnalyzer(); |
|
44 |
return lexer; |
|
45 |
} |
|
46 |
|
|
47 |
protected Compiler createCompiler() { |
|
48 |
Compiler compiler = new DefaultCompiler(); |
|
49 |
compiler.setLexicalAnalyzer(createLexicalAnalyzer()); |
|
50 |
return compiler; |
|
51 |
} |
|
52 |
|
|
53 |
private static class SimpleCodeToStringConverter extends AbstractCodeToStringConverter { |
|
54 |
|
|
55 |
public SimpleCodeToStringConverter() { |
|
56 |
super(); |
|
57 |
initFunctions(); |
|
58 |
} |
|
59 |
|
|
60 |
private void initFunctions() { |
|
61 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
62 |
SymbolTable symbolTable = manager.getSymbolTable("SQL"); |
|
63 |
for (Function function : symbolTable.functions()) { |
|
64 |
this.addSupportedFunction(function.name()); |
|
65 |
} |
|
66 |
symbolTable = manager.getSymbolTable("OGC"); |
|
67 |
for (Function function : symbolTable.functions()) { |
|
68 |
this.addSupportedFunction(function.name()); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
protected String functionToString(String functionName, Code.Caller.Arguments args) { |
|
74 |
switch (functionName.toLowerCase()) { |
|
75 |
case "date": |
|
76 |
return "DATE " + toString(args.get(0)) + " "; |
|
77 |
case "time": |
|
78 |
return "TIME " + toString(args.get(0)) + " "; |
|
79 |
case "timestamp": |
|
80 |
return "TIMESTAMP " + toString(args.get(0)) + " "; |
|
81 |
} |
|
82 |
return super.functionToString(functionName, args); |
|
83 |
} |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
public void testSimpleExpression() { |
|
88 |
String source = "(precio + 10) * 2 + 20 + 30 / 2"; |
|
89 |
|
|
90 |
CodeToStringConverter converter = new SimpleCodeToStringConverter(); |
|
91 |
Compiler compiler = createCompiler(); |
|
92 |
|
|
93 |
Code code = compiler.compileExpression(source); |
|
94 |
assertEquals("(((\"precio\" + 10) * 2) + 20) + (30 / 2)", converter.toString(code)); |
|
95 |
} |
|
96 |
|
|
97 |
public void testFunctionExpression1() { |
|
98 |
String source = "(precio + 10) * abs(2 + 20) + 30 / 2"; |
|
99 |
|
|
100 |
CodeToStringConverter converter = new SimpleCodeToStringConverter(); |
|
101 |
Compiler compiler = createCompiler(); |
|
102 |
|
|
103 |
Code code = compiler.compileExpression(source); |
|
104 |
assertEquals(true, converter.isValid(code)); |
|
105 |
assertEquals("((\"precio\" + 10) * (abs(2 + 20))) + (30 / 2)", converter.toString(code)); |
|
106 |
} |
|
107 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/Function.java | ||
---|---|---|
38 | 38 |
public boolean isOperator(); |
39 | 39 |
|
40 | 40 |
public boolean useArgumentsInsteadObjects(); |
41 |
|
|
42 |
public boolean isSQLCompatible(); |
|
41 | 43 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/CodeToStringConverter.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator; |
|
2 |
|
|
3 |
/** |
|
4 |
* |
|
5 |
* @author jjdelcerro |
|
6 |
*/ |
|
7 |
public interface CodeToStringConverter { |
|
8 |
|
|
9 |
public boolean isValid(); |
|
10 |
|
|
11 |
public boolean isValid(Code code); |
|
12 |
|
|
13 |
@Override |
|
14 |
public String toString(); |
|
15 |
|
|
16 |
public String toString(Code code); |
|
17 |
|
|
18 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/Expression.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
public Object execute(SymbolTable symbolTable); |
38 | 38 |
|
39 |
public Code getCode(); |
|
40 |
|
|
39 | 41 |
public String toJSON(); |
40 | 42 |
|
41 | 43 |
public void fromJSON(String json); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractCodeToStringConverter.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.spi; |
|
2 |
|
|
3 |
import org.gvsig.expressionevaluator.CodeToStringConverter; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.HashSet; |
|
6 |
import java.util.Map; |
|
7 |
import java.util.Set; |
|
8 |
import org.gvsig.expressionevaluator.Code; |
|
9 |
import org.gvsig.expressionevaluator.Code.Caller; |
|
10 |
import org.gvsig.expressionevaluator.Code.Caller.Arguments; |
|
11 |
import org.gvsig.expressionevaluator.Code.Constant; |
|
12 |
import org.gvsig.expressionevaluator.Code.Identifier; |
|
13 |
import org.gvsig.expressionevaluator.Code.Method; |
|
14 |
import org.gvsig.tools.exception.BaseException; |
|
15 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
16 |
import org.gvsig.tools.visitor.Visitor; |
|
17 |
|
|
18 |
/** |
|
19 |
* |
|
20 |
* @author jjdelcerro |
|
21 |
*/ |
|
22 |
public class AbstractCodeToStringConverter implements CodeToStringConverter { |
|
23 |
|
|
24 |
private final Code code; |
|
25 |
protected Set<String> supportedFunctionsNames; |
|
26 |
protected Map<String, String> translatedFunctionsNames; |
|
27 |
|
|
28 |
public AbstractCodeToStringConverter() { |
|
29 |
this(null); |
|
30 |
} |
|
31 |
|
|
32 |
public AbstractCodeToStringConverter(Code code) { |
|
33 |
this.supportedFunctionsNames = new HashSet<>(); |
|
34 |
this.translatedFunctionsNames = new HashMap<>(); |
|
35 |
this.code = code; |
|
36 |
} |
|
37 |
|
|
38 |
protected final void addSupportedFunction(String name) { |
|
39 |
this.supportedFunctionsNames.add(name.toLowerCase()); |
|
40 |
} |
|
41 |
|
|
42 |
protected final void addSupportedFunction(String name, String outputName) { |
|
43 |
this.supportedFunctionsNames.add(name.toLowerCase()); |
|
44 |
this.translatedFunctionsNames.put(name.toLowerCase(), outputName); |
|
45 |
} |
|
46 |
|
|
47 |
protected final boolean isFunctionSupported(String functionName) { |
|
48 |
functionName = functionName.toLowerCase(); |
|
49 |
for (String name : supportedFunctionsNames) { |
|
50 |
if (functionName.equals(name)) { |
|
51 |
return true; |
|
52 |
} |
|
53 |
} |
|
54 |
return false; |
|
55 |
} |
|
56 |
|
|
57 |
protected final String translateFunctionName(String functionName) { |
|
58 |
return this.translatedFunctionsNames.getOrDefault(functionName, functionName); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public boolean isValid() { |
|
63 |
if( code == null ) { |
|
64 |
return false; |
|
65 |
} |
|
66 |
return this.isValid(code); |
|
67 |
} |
|
68 |
|
|
69 |
@SuppressWarnings("UseSpecificCatch") |
|
70 |
@Override |
|
71 |
public boolean isValid(Code code) { |
|
72 |
try { |
|
73 |
code.accept(new Visitor() { |
|
74 |
@Override |
|
75 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
|
76 |
Code code = (Code) o; |
|
77 |
switch (code.code()) { |
|
78 |
case Code.CALLER: |
|
79 |
Caller caller = (Caller) code; |
|
80 |
if (!isFunctionSupported(caller.name())) { |
|
81 |
throw new UnsupportedOperationException("Function '" + caller.name() + "' not supported."); |
|
82 |
} |
|
83 |
case Code.CONSTANT: |
|
84 |
case Code.IDENTIFIER: |
|
85 |
break; |
|
86 |
|
|
87 |
case Code.METHOD: |
|
88 |
throw new UnsupportedOperationException("Method call not supported."); |
|
89 |
|
|
90 |
default: |
|
91 |
throw new UnsupportedOperationException("Code type not supported."); |
|
92 |
} |
|
93 |
} |
|
94 |
}); |
|
95 |
return true; |
|
96 |
} catch (Exception ex) { |
|
97 |
return false; |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public String toString() { |
|
103 |
if( code == null ) { |
|
104 |
return null; |
|
105 |
} |
|
106 |
return this.toString(code); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public String toString(Code code) { |
|
111 |
switch (code.code()) { |
|
112 |
case Code.CONSTANT: |
|
113 |
return constantToString((Constant) code); |
|
114 |
|
|
115 |
case Code.IDENTIFIER: |
|
116 |
return identifierToString((Identifier) code); |
|
117 |
|
|
118 |
case Code.CALLER: |
|
119 |
return callerToString((Caller) code); |
|
120 |
|
|
121 |
case Code.METHOD: |
|
122 |
return methodToString((Method) code); |
|
123 |
|
|
124 |
default: |
|
125 |
return ""; |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
protected String callerToString(Caller code) { |
|
130 |
switch (code.type()) { |
|
131 |
case Caller.BINARY_OPERATOR: |
|
132 |
if (!this.isFunctionSupported(code.name())) { |
|
133 |
throw new UnsupportedOperationException("Operator '" + code.name() + "' not supported."); |
|
134 |
} |
|
135 |
return binaryOperatorToString(code.name(), code.args().get(0), code.args().get(1)); |
|
136 |
|
|
137 |
case Caller.UNARY_OPERATOR: |
|
138 |
if (!this.isFunctionSupported(code.name())) { |
|
139 |
throw new UnsupportedOperationException("Operator '" + code.name() + "' not supported."); |
|
140 |
} |
|
141 |
return unaryOperatorToString(code.name(), code.args().get(0)); |
|
142 |
|
|
143 |
case Caller.FUNCTION: |
|
144 |
default: |
|
145 |
if (!this.isFunctionSupported(code.name())) { |
|
146 |
throw new UnsupportedOperationException("Function '" + code.name() + "' not supported."); |
|
147 |
} |
|
148 |
String fname = this.translateFunctionName(code.name()); |
|
149 |
return functionToString(fname, code.args()); |
|
150 |
|
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
protected String constantToString(Constant code) { |
|
155 |
return code.toString(); |
|
156 |
} |
|
157 |
|
|
158 |
protected String identifierToString(Identifier code) { |
|
159 |
return "\"" + code.name() + "\""; |
|
160 |
} |
|
161 |
|
|
162 |
protected String methodToString(Method code) { |
|
163 |
throw new UnsupportedOperationException("Method call not supported (method name '" + code.name() + "')."); |
|
164 |
} |
|
165 |
|
|
166 |
protected String binaryOperatorToString(String name, Code oper1, Code oper2) { |
|
167 |
if (oper1.code() == Code.CONSTANT || oper1.code() == Code.IDENTIFIER) { |
|
168 |
if (oper2.code() == Code.CONSTANT || oper2.code() == Code.IDENTIFIER) { |
|
169 |
return this.toString(oper1) + " " + name + " " + this.toString(oper2); |
|
170 |
} else { |
|
171 |
return this.toString(oper1) + " " + name + " (" + this.toString(oper2) + ")"; |
|
172 |
} |
|
173 |
} else if (oper2.code() == Code.CONSTANT || oper2.code() == Code.IDENTIFIER) { |
|
174 |
return "(" + this.toString(oper1) + ") " + name + " " + this.toString(oper2); |
|
175 |
} |
|
176 |
return "(" + this.toString(oper1) + ") " + name + " (" + this.toString(oper2) + ")"; |
|
177 |
} |
|
178 |
|
|
179 |
protected String unaryOperatorToString(String name, Code oper) { |
|
180 |
if (oper.code() == Code.CONSTANT || oper.code() == Code.IDENTIFIER) { |
|
181 |
return name + " " + this.toString(oper); |
|
182 |
} |
|
183 |
return name + " (" + this.toString(oper) + ")"; |
|
184 |
} |
|
185 |
|
|
186 |
protected String functionToString(String functionName, Arguments args) { |
|
187 |
StringBuilder builder = new StringBuilder(); |
|
188 |
builder.append(functionName); |
|
189 |
builder.append("("); |
|
190 |
boolean firstArg = true; |
|
191 |
for (Code arg : args) { |
|
192 |
if (firstArg) { |
|
193 |
firstArg = false; |
|
194 |
builder.append(this.toString(arg)); |
|
195 |
} else { |
|
196 |
builder.append(", "); |
|
197 |
builder.append(this.toString(arg)); |
|
198 |
} |
|
199 |
} |
|
200 |
builder.append(")"); |
|
201 |
return builder.toString(); |
|
202 |
} |
|
203 |
|
|
204 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractFunction.java | ||
---|---|---|
23 | 23 |
private List<String> alias; |
24 | 24 |
private String template; |
25 | 25 |
private String returnType; |
26 |
private boolean sqlCompatible; |
|
26 | 27 |
|
27 |
protected AbstractFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType) { |
|
28 |
protected AbstractFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType, boolean sqlCompatible) {
|
|
28 | 29 |
this.name = name; |
29 | 30 |
this.group = group; |
30 | 31 |
this.argc = argc; |
... | ... | |
32 | 33 |
this.template = template; |
33 | 34 |
this.descriptionArgs = descriptionArgs; |
34 | 35 |
this.returnType = returnType; |
36 |
this.sqlCompatible = sqlCompatible; |
|
35 | 37 |
} |
36 |
|
|
38 |
protected AbstractFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType) { |
|
39 |
this(group, name, argc, description, template, descriptionArgs, returnType, false); |
|
40 |
} |
|
41 |
|
|
37 | 42 |
protected AbstractFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs) { |
38 | 43 |
this(group, name, argc, description, template, null, null); |
39 | 44 |
} |
... | ... | |
105 | 110 |
} |
106 | 111 |
|
107 | 112 |
@Override |
113 |
public boolean isSQLCompatible() { |
|
114 |
return sqlCompatible; |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
108 | 118 |
public Object call(Interpreter interpreter, Arguments args) throws Exception { |
109 | 119 |
return null; |
110 | 120 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/java/org/gvsig/expressionevaluator/swing/impl/DefaultJExpressionBuilder.java | ||
---|---|---|
7 | 7 |
import java.awt.event.ActionListener; |
8 | 8 |
import java.awt.event.KeyAdapter; |
9 | 9 |
import java.awt.event.KeyEvent; |
10 |
import java.awt.event.KeyListener; |
|
11 | 10 |
import java.awt.event.MouseAdapter; |
12 | 11 |
import java.awt.event.MouseEvent; |
13 | 12 |
import java.net.URL; |
... | ... | |
167 | 166 |
|
168 | 167 |
public DefaultJExpressionBuilder(ExpressionEvaluatorSwingManager manager, ExpressionBuilderConfig config) { |
169 | 168 |
this.manager = manager; |
170 |
this.config = new DefaultExpressionBuilderConfig(manager); |
|
169 |
if( config == null ) { |
|
170 |
this.config = new DefaultExpressionBuilderConfig(manager); |
|
171 |
} else { |
|
172 |
this.config = config; |
|
173 |
} |
|
171 | 174 |
this.initComponents(); |
172 | 175 |
} |
173 | 176 |
|
... | ... | |
249 | 252 |
doFilter(); |
250 | 253 |
} |
251 | 254 |
}); |
255 |
|
|
256 |
this.lstSimpleElement.setModel(new FilteredListModel()); |
|
252 | 257 |
this.lstSimpleElement.setCellRenderer(new DefaultListCellRenderer() { |
253 | 258 |
@Override |
254 | 259 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
... | ... | |
301 | 306 |
} |
302 | 307 |
} |
303 | 308 |
} |
304 |
|
|
305 |
@Override |
|
306 |
public void keyTyped(KeyEvent e) { |
|
307 |
if( e.getKeyCode()==KeyEvent.VK_ENTER ) { |
|
308 |
ListElement<SimpleElement> element = (ListElement<SimpleElement>) lstSimpleElement.getSelectedValue(); |
|
309 |
if (element != null) { |
|
310 |
doSelectElement(element.getValue()); |
|
311 |
doInsert(element.getValue()); |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 | 309 |
}); |
310 |
|
|
316 | 311 |
this.btnSimpleElementTimeLimit.addActionListener(new ActionListener() { |
317 | 312 |
@Override |
318 | 313 |
public void actionPerformed(ActionEvent e) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/java/org/gvsig/expressionevaluator/swing/impl/elements/DefaultFunctionElement.java | ||
---|---|---|
20 | 20 |
private final Function function; |
21 | 21 |
|
22 | 22 |
public DefaultFunctionElement(Function function) { |
23 |
super(function.name(), function.description(), "expressionbuilder-element-function"); |
|
23 |
super( |
|
24 |
function.name(), |
|
25 |
function.description(), |
|
26 |
function.isSQLCompatible()? |
|
27 |
"expressionbuilder-element-function-sql": |
|
28 |
"expressionbuilder-element-function" |
|
29 |
); |
|
24 | 30 |
this.function = function; |
25 | 31 |
} |
26 | 32 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/java/org/gvsig/expressionevaluator/swing/impl/ExpressionEvaluatorSwingLibraryImpl.java | ||
---|---|---|
34 | 34 |
new String[] { "picker", "picker-expression" }, |
35 | 35 |
new String[] { "element", "expressionbuilder-element-constant" }, |
36 | 36 |
new String[] { "element", "expressionbuilder-element-function" }, |
37 |
new String[] { "element", "expressionbuilder-element-function-sql" }, |
|
37 | 38 |
new String[] { "element", "expressionbuilder-element-group" }, |
38 | 39 |
new String[] { "element", "expressionbuilder-element" }, |
39 | 40 |
new String[] { "action", "expressionbuilder-filter-values" }, |
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/impl/DefaultDataManager.java | ||
---|---|---|
33 | 33 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
34 | 34 |
import org.gvsig.fmap.dal.exception.CreateFileStoreException; |
35 | 35 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
36 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
|
36 | 37 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
37 | 38 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
38 | 39 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
... | ... | |
53 | 54 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
54 | 55 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultEvaluatorFactory; |
55 | 56 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultExpressionEvaluator; |
57 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
|
56 | 58 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureSymbolTable; |
57 | 59 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreFactory; |
58 | 60 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreOldFactory; |
... | ... | |
918 | 920 |
EvaluatorFactory f = new DefaultEvaluatorFactory(); |
919 | 921 |
return f; |
920 | 922 |
} |
921 |
|
|
923 |
|
|
924 |
@Override |
|
925 |
public FeatureAttributeEmulatorExpression createFeatureAttributeEmulatorExpression(FeatureType type, Expression expression) { |
|
926 |
FeatureAttributeEmulatorExpression emulator = new DefaultFeatureAttributeEmulatorExpression(type, expression); |
|
927 |
return emulator; |
|
928 |
} |
|
929 |
|
|
930 |
|
|
922 | 931 |
} |
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/impl/DALDefaultImplLibrary.java | ||
---|---|---|
50 | 50 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.relations.DALLink_getRelatedFeatures; |
51 | 51 |
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResource; |
52 | 52 |
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResourceParameters; |
53 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
|
53 | 54 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureSymbolTable; |
54 | 55 |
import org.gvsig.fmap.dal.resource.impl.DefaultResourceManager; |
55 | 56 |
import org.gvsig.fmap.dal.resource.spi.MultiResource; |
... | ... | |
116 | 117 |
AbstractFeatureStoreTransform.registerPersistent(); |
117 | 118 |
DefaultFeatureReferenceSelection.registerPersistent(); |
118 | 119 |
DefaultFeatureSelection.registerPersistent(); |
119 |
// DefaultCoverageStore.registerPersistent(); |
|
120 | 120 |
|
121 | 121 |
DefaultFeatureStore.registerPersistenceDefinition(); |
122 | 122 |
DefaultDataServerExplorerPool.registerPersistenceDefinition(); |
123 | 123 |
DefaultDataServerExplorerPoolEntry.registerPersistenceDefinition(); |
124 | 124 |
|
125 | 125 |
DALFile.registerPersistenceDefinition(); |
126 |
DefaultFeatureAttributeEmulatorExpression.registerPersistenceDefinition(); |
|
127 |
|
|
126 | 128 |
try { |
127 | 129 |
DefaultFeatureStore.registerMetadataDefinition(); |
128 | 130 |
} catch (MetadataException e) { |
... | ... | |
137 | 139 |
throw new ReferenceNotRegisteredException( |
138 | 140 |
DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance()); |
139 | 141 |
} |
140 |
// dataManager.registerFeatureAttributeGetter("milliToRelativeInstant", MilliToRelativeInstantFeatureAttributeGetter.class); |
|
141 |
// dataManager.registerFeatureAttributeGetter("milliToAbsoluteInstant", MilliToAbsoluteInstantFeatureAttributeGetter.class); |
|
142 |
// dataManager.registerFeatureAttributeGetter("secondToRelativeInstant", SecondToRelativeInstantFeatureAttributeGetter.class); |
|
143 |
// dataManager.registerFeatureAttributeGetter("secondToAbsoluteInstant",SecondToAbsoluteInstantFeatureAttributeGetter.class); |
|
144 |
// dataManager.registerFeatureAttributeGetter("minuteToRelativeInstant",MinuteToRelativeInstantFeatureAttributeGetter.class); |
|
145 |
// dataManager.registerFeatureAttributeGetter("minuteToAbsoluteInstant", MinuteToAbsoluteInstantFeatureAttributeGetter.class); |
|
146 |
// dataManager.registerFeatureAttributeGetter("hourToRelativeInstant", HourToRelativeInstantFeatureAttributeGetter.class); |
|
147 |
// dataManager.registerFeatureAttributeGetter("hourToAbsoluteInstant", HourToAbsoluteInstantFeatureAttributeGetter.class); |
|
148 |
// dataManager.registerFeatureAttributeGetter("dayToAbsoluteInstant", DayToAbsoluteInstantFeatureAttributeGetter.class); |
|
149 |
// dataManager.registerFeatureAttributeGetter("dayToRelativeInstant", DayToRelativeInstantFeatureAttributeGetter.class); |
|
150 |
// dataManager.registerFeatureAttributeGetter("monthToAbsoluteInstant", MonthToAbsoluteInstantFeatureAttributeGetter.class); |
|
151 |
// dataManager.registerFeatureAttributeGetter("yearToAbsoluteInstant", YearToAbsoluteInstantFeatureAttributeGetter.class); |
|
152 | 142 |
|
153 | 143 |
// Register a default spatial index based in the default memory spatial index of geom library |
154 | 144 |
if( !dataManager.getFeatureIndexRegister().exits(MemorySpatialIndexProvider.NAME) ) { |
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/impl/expressionevaluator/DefaultFeatureAttributeEmulatorExpression.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.impl.expressionevaluator; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 |
import org.gvsig.expressionevaluator.Code; |
|
7 |
import org.gvsig.expressionevaluator.Code.Identifier; |
|
8 |
import org.gvsig.expressionevaluator.Expression; |
|
9 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
10 |
import org.gvsig.fmap.dal.feature.Feature; |
|
11 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
12 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
13 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
14 |
import org.gvsig.fmap.dal.DataManager; |
|
15 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
|
16 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
17 |
import org.gvsig.tools.ToolsLocator; |
|
18 |
import org.gvsig.tools.dynobject.DynStruct; |
|
19 |
import org.gvsig.tools.exception.BaseException; |
|
20 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
21 |
import org.gvsig.tools.persistence.PersistentState; |
|
22 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
23 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
24 |
import org.gvsig.tools.visitor.Visitor; |
|
25 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @author osc |
|
30 |
*/ |
|
31 |
@SuppressWarnings("UseSpecificCatch") |
|
32 |
public class DefaultFeatureAttributeEmulatorExpression implements FeatureAttributeEmulatorExpression { |
|
33 |
|
|
34 |
private static final String EMULEFIELDEXP_PERSISTENCE_DEFINITION_NAME = "EmulatedFieldExpression"; |
|
35 |
|
|
36 |
private String[] requiredFields = null; |
|
37 |
private Expression expression = null; |
|
38 |
private SymbolTable symbolTable = null; |
|
39 |
private FeatureSymbolTable featureSymbolTable = null; |
|
40 |
|
|
41 |
private boolean valid; |
|
42 |
private String errorMessage; |
|
43 |
|
|
44 |
public DefaultFeatureAttributeEmulatorExpression() { |
|
45 |
} |
|
46 |
|
|
47 |
public DefaultFeatureAttributeEmulatorExpression(FeatureType featureType, Expression expression) { |
|
48 |
this.expression = expression; |
|
49 |
this.checkVars(featureType); |
|
50 |
} |
|
51 |
|
|
52 |
private void checkVars(final FeatureType featureType) { |
|
53 |
this.valid = true; |
|
54 |
final List<String> theUsedFields = new ArrayList<>(); |
|
55 |
final List<String> undefinedFields = new ArrayList<>(); |
|
56 |
|
|
57 |
try { |
|
58 |
Code code = this.expression.getCode(); |
|
59 |
code.accept(new Visitor() { |
|
60 |
@Override |
|
61 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
|
62 |
Code code = (Code) obj; |
|
63 |
if (code instanceof Identifier) { |
|
64 |
String name = ((Identifier) code).name(); |
|
65 |
if (featureType.get(name) == null) { |
|
66 |
undefinedFields.add(name); |
|
67 |
valid = false; |
|
68 |
} else { |
|
69 |
theUsedFields.add(name); |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
}); |
|
74 |
if(!undefinedFields.isEmpty()){ |
|
75 |
this.errorMessage = "undefined fields " + StringUtils.join(undefinedFields,", "); |
|
76 |
} |
|
77 |
} catch (Exception ex) { |
|
78 |
valid = false; |
|
79 |
this.errorMessage = ex.getMessage(); |
|
80 |
} |
|
81 |
this.requiredFields = theUsedFields.toArray(new String[theUsedFields.size()]); |
|
82 |
} |
|
83 |
|
|
84 |
@Override |
|
85 |
public SymbolTable getSymbolTable() { |
|
86 |
if (this.symbolTable == null) { |
|
87 |
ExpressionEvaluatorManager expressionManager = ExpressionEvaluatorLocator.getManager(); |
|
88 |
this.featureSymbolTable = (FeatureSymbolTable) expressionManager.getSymbolTable( |
|
89 |
DataManager.FEATURE_SYMBOL_TABLE |
|
90 |
); |
|
91 |
this.symbolTable = expressionManager.createSymbolTable(); |
|
92 |
this.symbolTable.addSymbolTable(this.featureSymbolTable); |
|
93 |
} |
|
94 |
return this.symbolTable; |
|
95 |
} |
|
96 |
|
|
97 |
private FeatureSymbolTable getFeatureSymbolTable() { |
|
98 |
if (this.featureSymbolTable == null) { |
|
99 |
this.getSymbolTable(); |
|
100 |
} |
|
101 |
return this.featureSymbolTable; |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public boolean isValid() { |
|
106 |
return this.valid; |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public Object get(Feature feature) { |
|
111 |
if (!this.valid) { |
|
112 |
return null; |
|
113 |
} |
|
114 |
this.getFeatureSymbolTable().setFeature(feature); |
|
115 |
Object result = this.expression.execute(this.getSymbolTable()); |
|
116 |
return result; |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public void set(EditableFeature feature, Object value) { |
|
121 |
// Do nothing |
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public boolean allowSetting() { |
|
126 |
return false; |
|
127 |
} |
|
128 |
|
|
129 |
@Override |
|
130 |
public String[] getRequiredFieldNames() { |
|
131 |
return this.requiredFields; |
|
132 |
} |
|
133 |
|
|
134 |
@Override |
|
135 |
public Expression getExpression() { |
|
136 |
return this.expression; |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public String getErrorMessage() { |
|
141 |
return this.errorMessage; |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
146 |
state.set("fields", this.requiredFields); |
|
147 |
state.set("expression", this.expression); |
|
148 |
state.set("valid", this.valid); |
|
149 |
|
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
154 |
this.valid = state.getBoolean("valid"); |
|
155 |
this.expression = (Expression) state.get("expression"); |
|
156 |
this.requiredFields = state.getStringArray("fields"); |
|
157 |
} |
|
158 |
|
|
159 |
public static void registerPersistenceDefinition() { |
|
160 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
161 |
|
|
162 |
if (manager.getDefinition(EMULEFIELDEXP_PERSISTENCE_DEFINITION_NAME) |
|
163 |
== null) { |
|
164 |
DynStruct definition = manager.addDefinition(DefaultFeatureAttributeEmulatorExpression.class, |
|
165 |
EMULEFIELDEXP_PERSISTENCE_DEFINITION_NAME, |
|
166 |
EMULEFIELDEXP_PERSISTENCE_DEFINITION_NAME |
|
167 |
+ " Persistent definition", |
|
168 |
null, |
|
169 |
null |
|
170 |
); |
|
171 |
definition.addDynFieldObject("expression") |
|
172 |
.setMandatory(true) |
|
173 |
.setPersistent(true) |
|
174 |
.setClassOfValue(Expression.class); |
|
175 |
definition.addDynFieldArray("fields") |
|
176 |
.setClassOfItems(String.class) |
|
177 |
.setMandatory(true) |
|
178 |
.setPersistent(true); |
|
179 |
definition.addDynFieldBoolean("valid") |
|
180 |
.setMandatory(true) |
|
181 |
.setPersistent(true); |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/expressionevaluator/FeatureAttributeEmulatorExpression.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.expressionevaluator; |
|
2 |
|
|
3 |
import org.gvsig.expressionevaluator.Expression; |
|
4 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
5 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
|
6 |
import org.gvsig.tools.persistence.Persistent; |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
* @author jjdelcerro |
|
11 |
*/ |
|
12 |
public interface FeatureAttributeEmulatorExpression extends FeatureAttributeEmulator, Persistent { |
|
13 |
|
|
14 |
public Expression getExpression(); |
|
15 |
|
|
16 |
public SymbolTable getSymbolTable(); |
|
17 |
|
|
18 |
public String getErrorMessage(); |
|
19 |
|
|
20 |
public boolean isValid(); |
|
21 |
|
|
22 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataManager.java | ||
---|---|---|
36 | 36 |
import org.gvsig.fmap.dal.feature.FeatureIndex; |
37 | 37 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
38 | 38 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
39 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
39 | 40 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
40 | 41 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
41 | 42 |
import org.gvsig.tools.dataTypes.DataType; |
Also available in: Unified diff