Revision 43939
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.daltransform.app/org.gvsig.daltransform.app.mainplugin/src/main/java/org/gvsig/daltransform/app/mainplugin/DataTransformExtension.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
package org.gvsig.daltransform.app.mainplugin; |
30 | 30 |
|
31 |
import java.awt.Component; |
|
32 |
import java.awt.GridBagConstraints; |
|
33 | 31 |
|
34 | 32 |
import javax.swing.JOptionPane; |
35 | 33 |
|
... | ... | |
39 | 37 |
import org.gvsig.andami.IconThemeHelper; |
40 | 38 |
import org.gvsig.andami.PluginServices; |
41 | 39 |
import org.gvsig.andami.plugins.Extension; |
42 |
import org.gvsig.andami.ui.ToolsWindowManager; |
|
43 | 40 |
import org.gvsig.app.ApplicationLocator; |
44 | 41 |
import org.gvsig.app.ApplicationManager; |
45 | 42 |
import org.gvsig.daltransform.DataTransformLocator; |
46 | 43 |
import org.gvsig.daltransform.DataTransformManager; |
47 | 44 |
import org.gvsig.daltransform.swing.JDialogDataTransformList; |
48 | 45 |
import org.gvsig.i18n.Messages; |
46 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
49 | 47 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
50 | 48 |
|
51 | 49 |
/** |
... | ... | |
96 | 94 |
JDialogDataTransformList dialog = |
97 | 95 |
manager.createJDialogDataTransformList(); |
98 | 96 |
|
99 |
ToolsWindowManager wm = new ToolsWindowManager(); |
|
100 |
wm.showWindow(dialog, Messages.getText("view_transforms"), |
|
101 |
WindowManager.MODE.WINDOW, GridBagConstraints.CENTER); |
|
97 |
|
|
98 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
|
99 |
wm.showWindow( |
|
100 |
dialog, |
|
101 |
Messages.getText("view_transforms"), |
|
102 |
WindowManager.MODE.WINDOW |
|
103 |
); |
|
102 | 104 |
} |
103 | 105 |
|
104 | 106 |
} |
trunk/org.gvsig.desktop/pom.xml | ||
---|---|---|
1234 | 1234 |
</dependency> |
1235 | 1235 |
<dependency> |
1236 | 1236 |
<groupId>org.gvsig</groupId> |
1237 |
<artifactId>org.gvsig.expressionevaluator.swing.api</artifactId> |
|
1238 |
<version>2.0.230-SNAPSHOT</version> |
|
1239 |
</dependency> |
|
1240 |
<dependency> |
|
1241 |
<groupId>org.gvsig</groupId> |
|
1242 |
<artifactId>org.gvsig.expressionevaluator.swing.impl</artifactId> |
|
1243 |
<version>2.0.230-SNAPSHOT</version> |
|
1244 |
</dependency> |
|
1245 |
<dependency> |
|
1246 |
<groupId>org.gvsig</groupId> |
|
1237 | 1247 |
<artifactId>org.gvsig.temporarystorage.lib.api</artifactId> |
1238 | 1248 |
<version>2.0.230-SNAPSHOT</version> |
1239 | 1249 |
</dependency> |
... | ... | |
2643 | 2653 |
|
2644 | 2654 |
<jython.artifactId>jython-standalone</jython.artifactId> |
2645 | 2655 |
<!-- External project versions --> |
2646 |
<gvsig.tools.version>3.0.161</gvsig.tools.version>
|
|
2656 |
<gvsig.tools.version>3.0.163</gvsig.tools.version>
|
|
2647 | 2657 |
<gvsig.proj.version>1.0.4</gvsig.proj.version> |
2648 | 2658 |
<gvsig.projection.api.version>2.0.25</gvsig.projection.api.version> |
2649 | 2659 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportGeometryHelper.java | ||
---|---|---|
83 | 83 |
} |
84 | 84 |
} |
85 | 85 |
|
86 |
IProjection sourceProjection = this.parameters.getTargetProjection();
|
|
87 |
IProjection targetProjection = sourceGeomAtt.getSRS();
|
|
86 |
IProjection targetProjection = this.parameters.getTargetProjection();
|
|
87 |
IProjection sourceProjection = sourceGeomAtt.getSRS();
|
|
88 | 88 |
if( targetProjection == null ) { |
89 | 89 |
targetProjection = sourceProjection; |
90 | 90 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AbstractExportParametersGeometry.java | ||
---|---|---|
77 | 77 |
|
78 | 78 |
@Override |
79 | 79 |
public IProjection getTargetProjection() { |
80 |
if( this.targetProjection == null ) { |
|
81 |
return this.sourceProjection; |
|
82 |
} |
|
80 | 83 |
return this.targetProjection; |
81 | 84 |
} |
82 | 85 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AbstractExportService.java | ||
---|---|---|
1 |
|
|
2 | 1 |
package org.gvsig.export.spi; |
3 | 2 |
|
4 | 3 |
import java.util.ArrayList; |
... | ... | |
32 | 31 |
* |
33 | 32 |
* @author jjdelcerro |
34 | 33 |
*/ |
35 |
public abstract class AbstractExportService
|
|
36 |
implements ExportService |
|
37 |
{ |
|
34 |
public abstract class AbstractExportService |
|
35 |
implements ExportService {
|
|
36 |
|
|
38 | 37 |
protected static final Logger LOG = LoggerFactory.getLogger(AbstractExportService.class); |
39 | 38 |
|
40 | 39 |
private final ExportParameters parameters; |
... | ... | |
42 | 41 |
protected AttributeNamesTranslator attributeNamesTranslator; |
43 | 42 |
private SimpleTaskStatus taskStatus; |
44 | 43 |
private final ExportServiceFactory factory; |
45 |
|
|
44 |
|
|
46 | 45 |
protected AbstractExportService(ExportServiceFactory factory, ExportParameters parameters) { |
47 | 46 |
this.factory = factory; |
48 | 47 |
this.parameters = parameters; |
49 | 48 |
this.finishListeners = new HashSet<>(); |
50 | 49 |
} |
51 |
|
|
50 |
|
|
52 | 51 |
@Override |
53 | 52 |
public ExportParameters getParameters() { |
54 | 53 |
return this.parameters; |
... | ... | |
62 | 61 |
@Override |
63 | 62 |
public void addFinishListener(ExportFinishListener listener) { |
64 | 63 |
this.finishListeners.add(listener); |
65 |
}
|
|
66 |
|
|
64 |
} |
|
65 |
|
|
67 | 66 |
protected void fireFinishedListener() { |
68 | 67 |
for (ExportFinishListener listener : finishListeners) { |
69 | 68 |
try { |
70 | 69 |
listener.finished(this); |
71 |
} catch(Exception ex) { |
|
72 |
|
|
70 |
} catch (Exception ex) {
|
|
71 |
|
|
73 | 72 |
} |
74 | 73 |
} |
75 | 74 |
} |
... | ... | |
78 | 77 |
for (ExportFinishListener listener : finishListeners) { |
79 | 78 |
try { |
80 | 79 |
listener.cancelled(this); |
81 |
} catch(Exception ex) { |
|
82 |
|
|
80 |
} catch (Exception ex) {
|
|
81 |
|
|
83 | 82 |
} |
84 | 83 |
} |
85 | 84 |
} |
86 | 85 |
|
87 | 86 |
@Override |
88 | 87 |
public SimpleTaskStatus getTaskStatus() { |
89 |
if( this.taskStatus== null ) {
|
|
88 |
if (this.taskStatus == null) {
|
|
90 | 89 |
this.taskStatus = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Export"); |
91 | 90 |
} |
92 | 91 |
return this.taskStatus; |
93 | 92 |
} |
94 |
|
|
93 |
|
|
95 | 94 |
@Override |
96 | 95 |
public boolean isCancellationRequested() { |
97 | 96 |
return this.getTaskStatus().isCancellationRequested(); |
... | ... | |
104 | 103 |
|
105 | 104 |
@Override |
106 | 105 |
public AttributeNamesTranslator getAttributeNamesTranslator() { |
107 |
if( attributeNamesTranslator==null ) {
|
|
106 |
if (attributeNamesTranslator == null) {
|
|
108 | 107 |
this.attributeNamesTranslator = ExportLocator.getServiceManager().createAttributeNamesTranslator(); |
109 | 108 |
} |
110 | 109 |
return this.attributeNamesTranslator; |
... | ... | |
116 | 115 |
r.add(this.createTargetOpenStoreParameters()); |
117 | 116 |
return r; |
118 | 117 |
} |
119 |
|
|
118 |
|
|
120 | 119 |
abstract protected DataServerExplorer createServerExplorer() throws ExportException; |
121 | 120 |
|
122 | 121 |
abstract protected NewDataStoreParameters createTargetNewStoreParameters() throws ExportException; |
123 | 122 |
|
124 |
abstract protected OpenDataStoreParameters createTargetOpenStoreParameters() throws ExportException;
|
|
123 |
abstract protected OpenDataStoreParameters createTargetOpenStoreParameters() throws ExportException; |
|
125 | 124 |
|
126 |
|
|
127 | 125 |
protected static class InvalidGeometryException extends ExportException { |
128 | 126 |
|
129 | 127 |
public InvalidGeometryException(Feature feature, String checkMessage) { |
... | ... | |
136 | 134 |
DataServerExplorer explorer = createServerExplorer(); |
137 | 135 |
NewDataStoreParameters newStoreParameters = createTargetNewStoreParameters(); |
138 | 136 |
OpenDataStoreParameters openStoreParameters = createTargetOpenStoreParameters(); |
139 |
|
|
137 |
|
|
140 | 138 |
String providerName = newStoreParameters.getDataStoreName(); |
141 | 139 |
String explorerName = explorer.getProviderName(); |
142 | 140 |
|
... | ... | |
155 | 153 |
FeatureType theSourceFeatureType = featureSet.getDefaultFeatureType(); |
156 | 154 |
|
157 | 155 |
ExportGeometryHelper geomHelper = null; |
158 |
if( this.getParameters() instanceof ExportParametersGeometry ) {
|
|
156 |
if (this.getParameters() instanceof ExportParametersGeometry) {
|
|
159 | 157 |
geomHelper = ExportLocator.getServiceManager().createGeometryHelper( |
160 | 158 |
(ExportParametersGeometry) this.getParameters(), |
161 |
theTargetFeatureType,
|
|
159 |
theTargetFeatureType, |
|
162 | 160 |
theSourceFeatureType |
163 | 161 |
); |
164 |
if( !geomHelper.canProcessGeometry() ) {
|
|
162 |
if (!geomHelper.canProcessGeometry()) {
|
|
165 | 163 |
geomHelper = null; |
166 | 164 |
} |
167 | 165 |
} |
168 | 166 |
// ============================================ |
169 |
|
|
167 |
|
|
170 | 168 |
target.edit(FeatureStore.MODE_APPEND); |
171 | 169 |
it = featureSet.fastIterator(); |
172 | 170 |
|
... | ... | |
177 | 175 |
Feature sourceFeature = (Feature) it.next(); |
178 | 176 |
targetFeature = target.createNewFeature(theTargetFeatureType, true); |
179 | 177 |
copyValues(sourceFeature, targetFeature); |
180 |
|
|
181 |
if( geomHelper!=null ) {
|
|
182 |
switch(geomHelper.copyGeometry(sourceFeature,targetFeature)) {
|
|
178 |
|
|
179 |
if (geomHelper != null) {
|
|
180 |
switch (geomHelper.copyGeometry(sourceFeature, targetFeature)) {
|
|
183 | 181 |
case FixGeometryStatus.STATE_OK: |
184 | 182 |
break; |
185 | 183 |
case FixGeometryStatus.STATE_SKIP: |
... | ... | |
188 | 186 |
throw new InvalidGeometryException(targetFeature, geomHelper.getLastErrorMessage()); |
189 | 187 |
} |
190 | 188 |
} |
191 |
|
|
189 |
|
|
192 | 190 |
target.insert(targetFeature); |
193 | 191 |
|
194 | 192 |
featureCount++; |
... | ... | |
208 | 206 |
DisposeUtils.dispose(it); |
209 | 207 |
DisposeUtils.dispose(featureSet); |
210 | 208 |
DisposeUtils.dispose(target); |
209 |
} |
|
211 | 210 |
} |
212 |
} |
|
213 |
|
|
211 |
|
|
214 | 212 |
protected void copyValues(Feature source, EditableFeature target) { |
215 |
FeatureType sourceType= source.getType(); |
|
213 |
FeatureType sourceType = source.getType();
|
|
216 | 214 |
FeatureType targetType = target.getType(); |
217 |
for( FeatureAttributeDescriptor targetAttr: targetType) {
|
|
215 |
for (FeatureAttributeDescriptor targetAttr : targetType) {
|
|
218 | 216 |
String targetAttrName = targetAttr.getName(); |
219 | 217 |
String sourceAttrName = getAttributeNamesTranslator().getSourceName(targetAttrName); |
220 | 218 |
FeatureAttributeDescriptor sourceAttr = sourceType.getAttributeDescriptor(sourceAttrName); |
221 |
if( sourceAttr!=null ) {
|
|
219 |
if (sourceAttr != null) {
|
|
222 | 220 |
Object value = source.get(sourceAttrName); |
223 |
if( value == null ) {
|
|
224 |
if( targetAttr.allowNull() ) {
|
|
221 |
if (value == null) {
|
|
222 |
if (targetAttr.allowNull()) {
|
|
225 | 223 |
target.set(targetAttrName, null); |
226 | 224 |
} |
227 | 225 |
} else { |
... | ... | |
231 | 229 |
} |
232 | 230 |
} |
233 | 231 |
|
234 |
|
|
235 | 232 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.shape/src/main/java/org/gvsig/export/shape/service/ExportShapeService.java | ||
---|---|---|
65 | 65 |
|
66 | 66 |
private final List<OpenDataStoreParameters>targetOpenStoreParameters; |
67 | 67 |
|
68 |
protected ExportShapeService(ExportServiceFactory factory, ExportShapeParameters parameters) {
|
|
68 |
public ExportShapeService(ExportServiceFactory factory, ExportShapeParameters parameters) {
|
|
69 | 69 |
super(factory, parameters); |
70 | 70 |
this.targetOpenStoreParameters = new ArrayList<>(); |
71 | 71 |
} |
... | ... | |
149 | 149 |
public OpenDataStoreParameters createTargetOpenStoreParameters() throws ExportException { |
150 | 150 |
try { |
151 | 151 |
DataManager dataManager = DALLocator.getDataManager(); |
152 |
OpenFeatureStoreParameters openStoreParameters = (OpenFeatureStoreParameters) dataManager.createStoreParameters("DBF");
|
|
152 |
OpenFeatureStoreParameters openStoreParameters = (OpenFeatureStoreParameters) dataManager.createStoreParameters("Shape");
|
|
153 | 153 |
((HasAFile)openStoreParameters).setFile(getParameters().getFile()); |
154 | 154 |
openStoreParameters.setDynValue("Encoding", getParameters().getEncoding()); |
155 | 155 |
openStoreParameters.setDynValue("CRS", this.getParameters().getTargetProjection()); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.swing/org.gvsig.timesupport.swing.impl/src/main/resources/org/gvsig/timesupport/swing/impl/images/.directory | ||
---|---|---|
1 |
[Dolphin] |
|
2 |
PreviewsShown=true |
|
3 |
Timestamp=2017,11,12,0,58,54 |
|
4 |
Version=3 |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/MapControl.java | ||
---|---|---|
1215 | 1215 |
clearImage(image); |
1216 | 1216 |
} |
1217 | 1217 |
repaint(); |
1218 |
revalidate(); |
|
1218 | 1219 |
} |
1219 | 1220 |
|
1220 | 1221 |
/** |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/pom.xml | ||
---|---|---|
10 | 10 |
</parent> |
11 | 11 |
<modules> |
12 | 12 |
<module>org.gvsig.expressionevaluator.lib</module> |
13 |
<module>org.gvsig.expressionevaluator.swing</module> |
|
13 | 14 |
</modules> |
14 | 15 |
</project> |
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 | ||
---|---|---|
6 | 6 |
import org.gvsig.expressionevaluator.LexicalAnalyzer; |
7 | 7 |
import org.gvsig.expressionevaluator.Compiler; |
8 | 8 |
import org.gvsig.expressionevaluator.Code; |
9 |
import org.gvsig.expressionevaluator.impl.ExpressionEvaluatorImplLibrary; |
|
9 | 10 |
|
10 | 11 |
|
11 | 12 |
public class TestCompiler extends TestCase { |
... | ... | |
17 | 18 |
@Override |
18 | 19 |
protected void setUp() throws Exception { |
19 | 20 |
super.setUp(); |
21 |
new ExpressionEvaluatorImplLibrary().initialize(); |
|
20 | 22 |
} |
21 | 23 |
|
22 | 24 |
@Override |
... | ... | |
222 | 224 |
assertEquals("=([1990], [precio])", code.toString()); |
223 | 225 |
} |
224 | 226 |
|
227 |
public void testInvokeMethod1() { |
|
228 |
String source = "'hola'.length()"; |
|
229 |
|
|
230 |
Compiler compiler = createCompiler(); |
|
231 |
|
|
232 |
Code code = compiler.compileExpression(source); |
|
233 |
assertEquals("'hola'->length()", code.toString()); |
|
234 |
} |
|
235 |
|
|
236 |
|
|
237 |
public void testInvokeMethod2() { |
|
238 |
String source = "'hola'.indexOf('l')"; |
|
239 |
|
|
240 |
Compiler compiler = createCompiler(); |
|
241 |
|
|
242 |
Code code = compiler.compileExpression(source); |
|
243 |
assertEquals("'hola'->indexOf('l')", code.toString()); |
|
244 |
} |
|
245 |
|
|
225 | 246 |
} |
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/TestSQLLexer.java | ||
---|---|---|
4 | 4 |
import junit.framework.TestCase; |
5 | 5 |
import org.gvsig.expressionevaluator.LexicalAnalyzer; |
6 | 6 |
import org.gvsig.expressionevaluator.LexicalAnalyzer.Token; |
7 |
import org.gvsig.expressionevaluator.impl.ExpressionEvaluatorImplLibrary; |
|
7 | 8 |
|
8 | 9 |
public class TestSQLLexer extends TestCase { |
9 | 10 |
|
... | ... | |
14 | 15 |
@Override |
15 | 16 |
protected void setUp() throws Exception { |
16 | 17 |
super.setUp(); |
18 |
new ExpressionEvaluatorImplLibrary().initialize(); |
|
17 | 19 |
} |
18 | 20 |
|
19 | 21 |
@Override |
... | ... | |
232 | 234 |
operator("and", Token.OP_AND); |
233 | 235 |
operator("%", Token.OP_MOD); |
234 | 236 |
operator("is", Token.PRED_IS); |
237 |
operator("->", Token.OP_GETATTR); |
|
238 |
operator(".", Token.OP_GETATTR); |
|
235 | 239 |
|
236 | 240 |
} |
237 | 241 |
|
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/TestInterpreter.java | ||
---|---|---|
3 | 3 |
import org.gvsig.expressionevaluator.impl.DefaultInterpreter; |
4 | 4 |
import org.gvsig.expressionevaluator.impl.DefaultSymbolTable; |
5 | 5 |
import org.gvsig.expressionevaluator.impl.SQLLexicalAnalyzer; |
6 |
import org.gvsig.expressionevaluator.impl.SQLSymbolTable; |
|
7 | 6 |
import org.gvsig.expressionevaluator.impl.DefaultCompiler; |
8 | 7 |
import junit.framework.TestCase; |
9 | 8 |
import org.gvsig.expressionevaluator.LexicalAnalyzer; |
... | ... | |
11 | 10 |
import org.gvsig.expressionevaluator.SymbolTable; |
12 | 11 |
import org.gvsig.expressionevaluator.Interpreter; |
13 | 12 |
import org.gvsig.expressionevaluator.Code; |
13 |
import org.gvsig.expressionevaluator.impl.ExpressionEvaluatorImplLibrary; |
|
14 | 14 |
|
15 | 15 |
public class TestInterpreter extends TestCase { |
16 | 16 |
|
... | ... | |
21 | 21 |
@Override |
22 | 22 |
protected void setUp() throws Exception { |
23 | 23 |
super.setUp(); |
24 |
new ExpressionEvaluatorImplLibrary().initialize(); |
|
24 | 25 |
} |
25 | 26 |
|
26 | 27 |
@Override |
... | ... | |
43 | 44 |
} |
44 | 45 |
|
45 | 46 |
protected SymbolTable createSymbolTable() { |
46 |
DefaultSymbolTable symbolTable = new DefaultSymbolTable(SQLSymbolTable.getInstance());
|
|
47 |
symbolTable.addVar("precio", 200);
|
|
48 |
symbolTable.addVar("1990", 0.168873933773767);
|
|
47 |
DefaultSymbolTable symbolTable = new DefaultSymbolTable(); |
|
48 |
symbolTable.setVar("precio", 200);
|
|
49 |
symbolTable.setVar("1990", 0.168873933773767);
|
|
49 | 50 |
return symbolTable; |
50 | 51 |
} |
51 | 52 |
|
... | ... | |
275 | 276 |
Code code = compiler.compileExpression(source); |
276 | 277 |
Object v = interpreter.run(code); |
277 | 278 |
assertEquals(false, ((Boolean)v).booleanValue()); |
278 |
}} |
|
279 |
} |
|
280 |
|
|
281 |
|
|
282 |
public void testInvokeMethod1() { |
|
283 |
String source = "'hola'.length()"; |
|
284 |
|
|
285 |
SymbolTable symbolTable = createSymbolTable(); |
|
286 |
Compiler compiler = createCompiler(); |
|
287 |
Interpreter interpreter = createInterpreter(symbolTable); |
|
288 |
|
|
289 |
Code code = compiler.compileExpression(source); |
|
290 |
Object v = interpreter.run(code); |
|
291 |
|
|
292 |
assertEquals(4, ((Number)v).intValue()); |
|
293 |
} |
|
294 |
|
|
295 |
|
|
296 |
public void testInvokeMethod2() { |
|
297 |
String source = "'hola'.indexOf('l')"; |
|
298 |
|
|
299 |
SymbolTable symbolTable = createSymbolTable(); |
|
300 |
Compiler compiler = createCompiler(); |
|
301 |
Interpreter interpreter = createInterpreter(symbolTable); |
|
302 |
|
|
303 |
Code code = compiler.compileExpression(source); |
|
304 |
Object v = interpreter.run(code); |
|
305 |
|
|
306 |
assertEquals(2, ((Number)v).intValue()); |
|
307 |
} |
|
308 |
|
|
309 |
|
|
310 |
} |
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/SQLSymbolTable.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.expressionevaluator.impl; |
|
3 |
|
|
4 |
import java.util.Iterator; |
|
5 |
import org.gvsig.expressionevaluator.impl.function.operator.AddOperator; |
|
6 |
import org.gvsig.expressionevaluator.impl.function.operator.AndOperator; |
|
7 |
import org.gvsig.expressionevaluator.impl.function.operator.DivOperator; |
|
8 |
import org.gvsig.expressionevaluator.impl.function.operator.EqOperator; |
|
9 |
import org.gvsig.expressionevaluator.impl.function.operator.GeOperator; |
|
10 |
import org.gvsig.expressionevaluator.impl.function.operator.GtOperator; |
|
11 |
import org.gvsig.expressionevaluator.impl.function.operator.LeOperator; |
|
12 |
import org.gvsig.expressionevaluator.impl.function.operator.LtOperator; |
|
13 |
import org.gvsig.expressionevaluator.impl.function.operator.ModOperator; |
|
14 |
import org.gvsig.expressionevaluator.impl.function.operator.MulOperator; |
|
15 |
import org.gvsig.expressionevaluator.impl.function.operator.NeOperator; |
|
16 |
import org.gvsig.expressionevaluator.impl.function.operator.NotOperator; |
|
17 |
import org.gvsig.expressionevaluator.impl.function.operator.OrOperator; |
|
18 |
import org.gvsig.expressionevaluator.impl.function.operator.SubstOperator; |
|
19 |
import org.gvsig.expressionevaluator.impl.function.predicate.IlikeOperator; |
|
20 |
import org.gvsig.expressionevaluator.impl.function.predicate.LikeOperator; |
|
21 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
22 |
import org.gvsig.expressionevaluator.impl.function.numeric.ACosFunction; |
|
23 |
import org.gvsig.expressionevaluator.impl.function.numeric.ASinFunction; |
|
24 |
import org.gvsig.expressionevaluator.impl.function.numeric.ATanFunction; |
|
25 |
import org.gvsig.expressionevaluator.impl.function.numeric.AbsFunction; |
|
26 |
import org.gvsig.expressionevaluator.impl.function.numeric.BitAndFunction; |
|
27 |
import org.gvsig.expressionevaluator.impl.function.numeric.BitOrFunction; |
|
28 |
import org.gvsig.expressionevaluator.impl.function.numeric.BitXorFunction; |
|
29 |
import org.gvsig.expressionevaluator.impl.function.numeric.CeilFunction; |
|
30 |
import org.gvsig.expressionevaluator.impl.function.numeric.CosFunction; |
|
31 |
import org.gvsig.expressionevaluator.impl.function.numeric.CoshFunction; |
|
32 |
import org.gvsig.expressionevaluator.impl.function.numeric.CotFunction; |
|
33 |
import org.gvsig.expressionevaluator.impl.function.numeric.DegreesFunction; |
|
34 |
import org.gvsig.expressionevaluator.impl.function.numeric.ExpFunction; |
|
35 |
import org.gvsig.expressionevaluator.impl.function.numeric.FloorFunction; |
|
36 |
import org.gvsig.expressionevaluator.impl.function.numeric.Log10Function; |
|
37 |
import org.gvsig.expressionevaluator.impl.function.numeric.LogFunction; |
|
38 |
import org.gvsig.expressionevaluator.impl.function.numeric.PiFunction; |
|
39 |
import org.gvsig.expressionevaluator.impl.function.numeric.PowFunction; |
|
40 |
import org.gvsig.expressionevaluator.impl.function.numeric.RadiansFunction; |
|
41 |
import org.gvsig.expressionevaluator.impl.function.numeric.RandFunction; |
|
42 |
import org.gvsig.expressionevaluator.impl.function.numeric.RoundFunction; |
|
43 |
import org.gvsig.expressionevaluator.impl.function.numeric.SignFunction; |
|
44 |
import org.gvsig.expressionevaluator.impl.function.numeric.SinFunction; |
|
45 |
import org.gvsig.expressionevaluator.impl.function.numeric.SinhFunction; |
|
46 |
import org.gvsig.expressionevaluator.impl.function.numeric.SqrtFunction; |
|
47 |
import org.gvsig.expressionevaluator.impl.function.numeric.TanFunction; |
|
48 |
import org.gvsig.expressionevaluator.impl.function.numeric.TanhFunction; |
|
49 |
import org.gvsig.expressionevaluator.impl.function.numeric.ZeroFunction; |
|
50 |
import org.gvsig.expressionevaluator.impl.function.spatial.STAreaFunction; |
|
51 |
import org.gvsig.expressionevaluator.impl.function.spatial.STAsTextFunction; |
|
52 |
import org.gvsig.expressionevaluator.impl.function.spatial.STBufferFunction; |
|
53 |
import org.gvsig.expressionevaluator.impl.function.spatial.STCentroidFunction; |
|
54 |
import org.gvsig.expressionevaluator.impl.function.spatial.STContainsFunction; |
|
55 |
import org.gvsig.expressionevaluator.impl.function.spatial.STConvexHullFunction; |
|
56 |
import org.gvsig.expressionevaluator.impl.function.spatial.STCoveredByFunction; |
|
57 |
import org.gvsig.expressionevaluator.impl.function.spatial.STCoversFunction; |
|
58 |
import org.gvsig.expressionevaluator.impl.function.spatial.STCrossesFunction; |
|
59 |
import org.gvsig.expressionevaluator.impl.function.spatial.STDifferenceFunction; |
|
60 |
import org.gvsig.expressionevaluator.impl.function.spatial.STDimensionFunction; |
|
61 |
import org.gvsig.expressionevaluator.impl.function.spatial.STDisjointFunction; |
|
62 |
import org.gvsig.expressionevaluator.impl.function.spatial.STDistanceFunction; |
|
63 |
import org.gvsig.expressionevaluator.impl.function.spatial.STEndPointFunction; |
|
64 |
import org.gvsig.expressionevaluator.impl.function.spatial.STEnvelopeFunction; |
|
65 |
import org.gvsig.expressionevaluator.impl.function.spatial.STGeomFromTextFunction; |
|
66 |
import org.gvsig.expressionevaluator.impl.function.spatial.STGeometryNFunction; |
|
67 |
import org.gvsig.expressionevaluator.impl.function.spatial.STIntersectionFunction; |
|
68 |
import org.gvsig.expressionevaluator.impl.function.spatial.STIntersectsFunction; |
|
69 |
import org.gvsig.expressionevaluator.impl.function.spatial.STIsSimpleFunction; |
|
70 |
import org.gvsig.expressionevaluator.impl.function.spatial.STIsValidFunction; |
|
71 |
import org.gvsig.expressionevaluator.impl.function.spatial.STNumGeometriesFunction; |
|
72 |
import org.gvsig.expressionevaluator.impl.function.spatial.STNumPointsFunction; |
|
73 |
import org.gvsig.expressionevaluator.impl.function.spatial.STOverlapsFunction; |
|
74 |
import org.gvsig.expressionevaluator.impl.function.spatial.STPointNFunction; |
|
75 |
import org.gvsig.expressionevaluator.impl.function.spatial.STStartPointFunction; |
|
76 |
import org.gvsig.expressionevaluator.impl.function.spatial.STTouchesFunction; |
|
77 |
import org.gvsig.expressionevaluator.impl.function.spatial.STUnionFunction; |
|
78 |
import org.gvsig.expressionevaluator.impl.function.spatial.STWithinFunction; |
|
79 |
import org.gvsig.expressionevaluator.impl.function.spatial.STXFunction; |
|
80 |
import org.gvsig.expressionevaluator.impl.function.spatial.STYFunction; |
|
81 |
import org.gvsig.expressionevaluator.impl.function.spatial.STZFunction; |
|
82 |
import org.gvsig.expressionevaluator.impl.function.string.AsciiFunction; |
|
83 |
import org.gvsig.expressionevaluator.impl.function.string.CharFunction; |
|
84 |
import org.gvsig.expressionevaluator.impl.function.string.ConcatFunction; |
|
85 |
import org.gvsig.expressionevaluator.impl.function.string.InstrFunction; |
|
86 |
import org.gvsig.expressionevaluator.impl.function.string.LTrimFunction; |
|
87 |
import org.gvsig.expressionevaluator.impl.function.string.LeftFunction; |
|
88 |
import org.gvsig.expressionevaluator.impl.function.string.LengthFunction; |
|
89 |
import org.gvsig.expressionevaluator.impl.function.string.LocateFunction; |
|
90 |
import org.gvsig.expressionevaluator.impl.function.string.LowerFunction; |
|
91 |
import org.gvsig.expressionevaluator.impl.function.string.LpadFunction; |
|
92 |
import org.gvsig.expressionevaluator.impl.function.string.PositionFunction; |
|
93 |
import org.gvsig.expressionevaluator.impl.function.string.RTrimFunction; |
|
94 |
import org.gvsig.expressionevaluator.impl.function.string.RepeatFunction; |
|
95 |
import org.gvsig.expressionevaluator.impl.function.string.ReplaceFunction; |
|
96 |
import org.gvsig.expressionevaluator.impl.function.string.RightFunction; |
|
97 |
import org.gvsig.expressionevaluator.impl.function.string.RpadFunction; |
|
98 |
import org.gvsig.expressionevaluator.impl.function.string.SpaceFunction; |
|
99 |
import org.gvsig.expressionevaluator.impl.function.string.SubstringFunction; |
|
100 |
import org.gvsig.expressionevaluator.impl.function.string.TrimFunction; |
|
101 |
import org.gvsig.expressionevaluator.impl.function.string.UpperFunction; |
|
102 |
|
|
103 |
|
|
104 |
public class SQLSymbolTable extends AbstractSymbolTable implements SymbolTable { |
|
105 |
|
|
106 |
|
|
107 |
private static SQLSymbolTable instance = null; |
|
108 |
|
|
109 |
public static SQLSymbolTable getInstance() { |
|
110 |
if( instance == null ) { |
|
111 |
instance = new SQLSymbolTable(); |
|
112 |
} |
|
113 |
return instance; |
|
114 |
} |
|
115 |
|
|
116 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
117 |
private SQLSymbolTable() { |
|
118 |
super(); |
|
119 |
|
|
120 |
addFunction(new AndOperator()); |
|
121 |
addFunction(new AddOperator()); |
|
122 |
addFunction(new DivOperator()); |
|
123 |
addFunction(new EqOperator()); |
|
124 |
addFunction(new GeOperator()); |
|
125 |
addFunction(new GtOperator()); |
|
126 |
addFunction(new LeOperator()); |
|
127 |
addFunction(new LtOperator()); |
|
128 |
addFunction(new ModOperator()); |
|
129 |
addFunction(new NeOperator()); |
|
130 |
addFunction(new ModOperator()); |
|
131 |
addFunction(new MulOperator()); |
|
132 |
addFunction(new NeOperator()); |
|
133 |
addFunction(new NotOperator()); |
|
134 |
addFunction(new OrOperator()); |
|
135 |
addFunction(new SubstOperator()); |
|
136 |
|
|
137 |
addFunction(new IlikeOperator()); |
|
138 |
addFunction(new LikeOperator()); |
|
139 |
|
|
140 |
addFunction(new ACosFunction()); |
|
141 |
addFunction(new ASinFunction()); |
|
142 |
addFunction(new ATanFunction()); |
|
143 |
addFunction(new AbsFunction()); |
|
144 |
addFunction(new BitAndFunction()); |
|
145 |
addFunction(new BitOrFunction()); |
|
146 |
addFunction(new BitXorFunction()); |
|
147 |
addFunction(new CeilFunction()); |
|
148 |
addFunction(new CosFunction()); |
|
149 |
addFunction(new CoshFunction()); |
|
150 |
addFunction(new CotFunction()); |
|
151 |
addFunction(new DegreesFunction()); |
|
152 |
addFunction(new ExpFunction()); |
|
153 |
addFunction(new FloorFunction()); |
|
154 |
addFunction(new Log10Function()); |
|
155 |
addFunction(new LogFunction()); |
|
156 |
addFunction(new PiFunction()); |
|
157 |
addFunction(new PowFunction()); |
|
158 |
addFunction(new RadiansFunction()); |
|
159 |
addFunction(new RandFunction()); |
|
160 |
addFunction(new RoundFunction()); |
|
161 |
addFunction(new SignFunction()); |
|
162 |
addFunction(new SinFunction()); |
|
163 |
addFunction(new SinhFunction()); |
|
164 |
addFunction(new SqrtFunction()); |
|
165 |
addFunction(new TanFunction()); |
|
166 |
addFunction(new TanhFunction()); |
|
167 |
addFunction(new ZeroFunction()); |
|
168 |
addFunction(new LogFunction()); |
|
169 |
|
|
170 |
addFunction(new AsciiFunction()); |
|
171 |
addFunction(new CharFunction()); |
|
172 |
addFunction(new ConcatFunction()); |
|
173 |
addFunction(new InstrFunction()); |
|
174 |
addFunction(new LTrimFunction()); |
|
175 |
addFunction(new LeftFunction()); |
|
176 |
addFunction(new LengthFunction()); |
|
177 |
addFunction(new LocateFunction()); |
|
178 |
addFunction(new LowerFunction()); |
|
179 |
addFunction(new LpadFunction()); |
|
180 |
addFunction(new PositionFunction()); |
|
181 |
addFunction(new RTrimFunction()); |
|
182 |
addFunction(new RepeatFunction()); |
|
183 |
addFunction(new ReplaceFunction()); |
|
184 |
addFunction(new RightFunction()); |
|
185 |
addFunction(new RpadFunction()); |
|
186 |
addFunction(new SpaceFunction()); |
|
187 |
addFunction(new SubstringFunction()); |
|
188 |
addFunction(new TrimFunction()); |
|
189 |
addFunction(new UpperFunction()); |
|
190 |
|
|
191 |
addFunction(new STAreaFunction()); |
|
192 |
addFunction(new STAsTextFunction()); |
|
193 |
addFunction(new STBufferFunction()); |
|
194 |
addFunction(new STCentroidFunction()); |
|
195 |
addFunction(new STContainsFunction()); |
|
196 |
addFunction(new STConvexHullFunction()); |
|
197 |
addFunction(new STCoveredByFunction()); |
|
198 |
addFunction(new STCoversFunction()); |
|
199 |
addFunction(new STCrossesFunction()); |
|
200 |
addFunction(new STDifferenceFunction()); |
|
201 |
addFunction(new STDimensionFunction()); |
|
202 |
addFunction(new STDisjointFunction()); |
|
203 |
addFunction(new STDistanceFunction()); |
|
204 |
addFunction(new STEndPointFunction()); |
|
205 |
addFunction(new STEnvelopeFunction()); |
|
206 |
addFunction(new STGeomFromTextFunction()); |
|
207 |
addFunction(new STGeometryNFunction()); |
|
208 |
addFunction(new STIntersectionFunction()); |
|
209 |
addFunction(new STIntersectsFunction()); |
|
210 |
addFunction(new STIsSimpleFunction()); |
|
211 |
addFunction(new STIsValidFunction()); |
|
212 |
addFunction(new STNumGeometriesFunction()); |
|
213 |
addFunction(new STNumPointsFunction()); |
|
214 |
addFunction(new STOverlapsFunction()); |
|
215 |
addFunction(new STPointNFunction()); |
|
216 |
addFunction(new STStartPointFunction()); |
|
217 |
addFunction(new STTouchesFunction()); |
|
218 |
addFunction(new STUnionFunction()); |
|
219 |
addFunction(new STWithinFunction()); |
|
220 |
addFunction(new STXFunction()); |
|
221 |
addFunction(new STYFunction()); |
|
222 |
addFunction(new STZFunction()); |
|
223 |
} |
|
224 |
|
|
225 |
@Override |
|
226 |
public boolean exists(String name) { |
|
227 |
return false; |
|
228 |
} |
|
229 |
|
|
230 |
@Override |
|
231 |
public Object value(String name) { |
|
232 |
return null; |
|
233 |
} |
|
234 |
|
|
235 |
@Override |
|
236 |
public Iterator<String> itervars() { |
|
237 |
return new Iterator<String>() { |
|
238 |
@Override |
|
239 |
public boolean hasNext() { |
|
240 |
return false; |
|
241 |
} |
|
242 |
|
|
243 |
@Override |
|
244 |
public String next() { |
|
245 |
return null; |
|
246 |
} |
|
247 |
}; |
|
248 |
} |
|
249 |
|
|
250 |
} |
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/DefaultScripts.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.impl; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import org.apache.commons.lang3.StringUtils; |
|
5 |
import org.gvsig.expressionevaluator.Scripts; |
|
6 |
import org.gvsig.tools.ToolsLocator; |
|
7 |
import org.gvsig.tools.script.Script; |
|
8 |
import org.gvsig.tools.script.ScriptManager; |
|
9 |
|
|
10 |
/** |
|
11 |
* |
|
12 |
* @author jjdelcerro |
|
13 |
*/ |
|
14 |
public class DefaultScripts |
|
15 |
extends ArrayList<Script> |
|
16 |
implements Scripts |
|
17 |
{ |
|
18 |
|
|
19 |
public DefaultScripts() { |
|
20 |
|
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
public Object clone() { |
|
25 |
return super.clone(); |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
public void add(String name) { |
|
30 |
if( StringUtils.isEmpty(name) ) { |
|
31 |
return; |
|
32 |
} |
|
33 |
ScriptManager scriptManager = ToolsLocator.getScriptManager(); |
|
34 |
Script script = scriptManager.locateScript(name); |
|
35 |
if( script == null ) { |
|
36 |
return; |
|
37 |
} |
|
38 |
this.add(script); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public boolean add(Script script) { |
|
43 |
if( this.contains(script) ) { |
|
44 |
return true; |
|
45 |
} |
|
46 |
return super.add(script); |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
} |
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/DefaultCompiler.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
public class DefaultCompiler implements Compiler { |
11 | 11 |
|
12 |
private boolean objectAccessSupported; |
|
12 | 13 |
private LexicalAnalyzer lexer; |
13 | 14 |
private CodeBuilder codeBuilder; |
14 | 15 |
// |
... | ... | |
18 | 19 |
public DefaultCompiler() { |
19 | 20 |
this.lexer = new SQLLexicalAnalyzer(); |
20 | 21 |
this.codeBuilder = new DefaultCodeBuilder(); |
22 |
this.objectAccessSupported = true; |
|
21 | 23 |
} |
22 | 24 |
|
23 | 25 |
@Override |
... | ... | |
45 | 47 |
} |
46 | 48 |
|
47 | 49 |
@Override |
50 |
public boolean isObjectAccessSupported() { |
|
51 |
return this.objectAccessSupported; |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public void setObjectAccessSupported(boolean objectAccessSupported) { |
|
56 |
this.objectAccessSupported = objectAccessSupported; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
48 | 60 |
public Code compileExpression(String expression) { |
49 | 61 |
this.lexer.setSource(expression); |
50 | 62 |
return parseExpression(); |
... | ... | |
185 | 197 |
} |
186 | 198 |
|
187 | 199 |
private Code parse_factor() { |
188 |
Code op1 = parse_termino();
|
|
200 |
Code op1 = parse_getattr();
|
|
189 | 201 |
Code op2; |
190 | 202 |
while( true ) { |
191 | 203 |
Token token = lexer.look(); |
192 | 204 |
switch( token.getType() ) { |
193 | 205 |
case Token.OP_MULT: |
194 | 206 |
lexer.next(); |
195 |
op2 = parse_termino();
|
|
207 |
op2 = parse_getattr();
|
|
196 | 208 |
op1 = codeBuilder.mult(op1, op2); |
197 | 209 |
break; |
198 | 210 |
case Token.OP_DIV: |
199 | 211 |
lexer.next(); |
200 |
op2 = parse_termino();
|
|
212 |
op2 = parse_getattr();
|
|
201 | 213 |
op1 = codeBuilder.div(op1, op2); |
202 | 214 |
break; |
203 | 215 |
case Token.OP_MOD: |
204 | 216 |
lexer.next(); |
205 |
op2 = parse_termino();
|
|
217 |
op2 = parse_getattr();
|
|
206 | 218 |
op1 = codeBuilder.mod(op1, op2); |
207 | 219 |
break; |
208 | 220 |
default: |
... | ... | |
211 | 223 |
} |
212 | 224 |
} |
213 | 225 |
|
226 |
private Code parse_getattr() { |
|
227 |
Code op1 = parse_termino(); |
|
228 |
if( !isObjectAccessSupported() ) { |
|
229 |
return op1; |
|
230 |
} |
|
231 |
while( true ) { |
|
232 |
Token next = lexer.look(); |
|
233 |
switch( next.getType() ) { |
|
234 |
case Token.OP_GETATTR: |
|
235 |
lexer.next(); |
|
236 |
next = lexer.look(); |
|
237 |
if( next.getType()!=Token.IDENTIFIER ) { |
|
238 |
throw new RuntimeException("An attribute identifier was expected and '"+next.getLiteral()+"' was found"); |
|
239 |
} |
|
240 |
String id = (String) next.getLiteral(); |
|
241 |
lexer.next(); |
|
242 |
next = lexer.look(); |
|
243 |
if( next.getType() == Token.PARENTHESIS_OPEN ) { |
|
244 |
lexer.next(); |
|
245 |
Arguments args = parseArgs(); |
|
246 |
next = lexer.next(); |
|
247 |
if( next.getType() != Token.PARENTHESIS_CLOSE ) { |
|
248 |
throw new RuntimeException("Closing parenthesis was expected and '"+next.getLiteral()+"' was found"); |
|
249 |
} |
|
250 |
return codeBuilder.method(op1, id, args); |
|
251 |
} else { |
|
252 |
return codeBuilder.getattr(op1, id); |
|
253 |
} |
|
254 |
default: |
|
255 |
return op1; |
|
256 |
} |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
214 | 260 |
private Code parse_termino() { |
215 | 261 |
|
216 | 262 |
Token token = lexer.look(); |
... | ... | |
220 | 266 |
Code value = parseExpression(); |
221 | 267 |
Token next = lexer.next(); |
222 | 268 |
if( next.getType() != Token.PARENTHESIS_CLOSE ) { |
223 |
throw new RuntimeException(); |
|
269 |
throw new RuntimeException("Closing parenthesis was expected and '"+next.getLiteral()+"' was found");
|
|
224 | 270 |
} |
225 | 271 |
return value; |
226 | 272 |
} |
... | ... | |
233 | 279 |
Arguments args = parseArgs(); |
234 | 280 |
next = lexer.next(); |
235 | 281 |
if( next.getType() != Token.PARENTHESIS_CLOSE ) { |
236 |
throw new RuntimeException("Expected ')'.");
|
|
282 |
throw new RuntimeException("Closing parenthesis was expected and '"+next.getLiteral()+"' was found");
|
|
237 | 283 |
} |
238 | 284 |
return codeBuilder.function(id, args); |
239 | 285 |
} else { |
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/AbstractSymbolTable.java | ||
---|---|---|
1 | 1 |
|
2 | 2 |
package org.gvsig.expressionevaluator.impl; |
3 | 3 |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.Collection; |
|
4 | 6 |
import java.util.HashMap; |
5 | 7 |
import java.util.Iterator; |
8 |
import java.util.List; |
|
6 | 9 |
import java.util.Map; |
10 |
import org.apache.commons.lang3.StringUtils; |
|
11 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
12 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
7 | 13 |
import org.gvsig.expressionevaluator.Function; |
8 | 14 |
import org.gvsig.expressionevaluator.SymbolTable; |
9 | 15 |
import org.gvsig.expressionevaluator.impl.function.ScriptFunction; |
... | ... | |
19 | 25 |
|
20 | 26 |
protected Map<String, Function> functions; |
21 | 27 |
protected SymbolTable delegatedSymbolTable; |
22 |
protected Script script = null; |
|
23 | 28 |
|
24 |
|
|
25 | 29 |
public AbstractSymbolTable() { |
26 | 30 |
this.functions = new HashMap<>(); |
27 | 31 |
} |
28 | 32 |
|
33 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
29 | 34 |
public AbstractSymbolTable(SymbolTable delegatedSymbolTable) { |
30 | 35 |
this(); |
31 | 36 |
this.delegatedSymbolTable = delegatedSymbolTable; |
37 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
38 |
this.addFunctions(manager.getAllOperators().values()); |
|
32 | 39 |
} |
33 | 40 |
|
34 | 41 |
@Override |
... | ... | |
40 | 47 |
other.functions = new HashMap<>(functions); |
41 | 48 |
return other; |
42 | 49 |
} |
43 |
|
|
44 |
@Override |
|
45 |
public Script getScript() { |
|
46 |
return this.script; |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public void setScript(String name) { |
|
51 |
ScriptManager scriptManager = ToolsLocator.getScriptManager(); |
|
52 |
this.script = scriptManager.locateScript(name); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public void setScript(Script script) { |
|
57 |
this.script = script; |
|
58 |
} |
|
59 |
|
|
50 |
|
|
60 | 51 |
public void addFunction(Function function) { |
61 | 52 |
this.functions.put(function.name(), function); |
62 | 53 |
} |
63 | 54 |
|
64 | 55 |
@Override |
65 | 56 |
public Function function(String name) { |
66 |
Function fn = this.functions.get(name); |
|
57 |
if( StringUtils.isEmpty(name) ) { |
|
58 |
return null; |
|
59 |
} |
|
60 |
Function fn = this.functions.get(name.toUpperCase()); |
|
67 | 61 |
if( fn == null ) { |
68 | 62 |
if( this.delegatedSymbolTable != null ) { |
69 |
fn = this.delegatedSymbolTable.function(name); |
|
63 |
fn = this.delegatedSymbolTable.function(name.toUpperCase());
|
|
70 | 64 |
} |
71 |
if( fn == null && this.script != null ) { |
|
72 |
fn = new ScriptFunction(this.script, name); |
|
73 |
} |
|
74 | 65 |
} |
75 | 66 |
return fn; |
76 | 67 |
} |
... | ... | |
96 | 87 |
public void removeFunction(String name) { |
97 | 88 |
this.functions.remove(name); |
98 | 89 |
} |
90 |
|
|
91 |
public void addFunctions(Collection<Function> functions) { |
|
92 |
for (Function function : functions) { |
|
93 |
this.addFunction(function); |
|
94 |
} |
|
95 |
} |
|
99 | 96 |
} |
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/DefaultExpressionEvaluatorManager.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl; |
2 | 2 |
|
3 |
import java.util.Collections; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.Map; |
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
3 | 7 |
import org.gvsig.expressionevaluator.Code; |
4 | 8 |
import org.gvsig.expressionevaluator.CodeBuilder; |
5 | 9 |
import org.gvsig.expressionevaluator.Compiler; |
6 | 10 |
import org.gvsig.expressionevaluator.ExpressionEvaluator; |
7 | 11 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
12 |
import org.gvsig.expressionevaluator.Function; |
|
8 | 13 |
import org.gvsig.expressionevaluator.Interpreter; |
9 | 14 |
import org.gvsig.expressionevaluator.LexicalAnalyzer; |
10 | 15 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
11 | 16 |
import org.gvsig.expressionevaluator.SymbolTable; |
17 |
import org.gvsig.expressionevaluator.impl.function.numeric.ACosFunction; |
|
18 |
import org.gvsig.expressionevaluator.impl.function.numeric.ASinFunction; |
|
19 |
import org.gvsig.expressionevaluator.impl.function.numeric.ATanFunction; |
|
20 |
import org.gvsig.expressionevaluator.impl.function.numeric.AbsFunction; |
|
21 |
import org.gvsig.expressionevaluator.impl.function.numeric.BitAndFunction; |
|
22 |
import org.gvsig.expressionevaluator.impl.function.numeric.BitOrFunction; |
|
23 |
import org.gvsig.expressionevaluator.impl.function.numeric.BitXorFunction; |
|
24 |
import org.gvsig.expressionevaluator.impl.function.numeric.CeilFunction; |
|
25 |
import org.gvsig.expressionevaluator.impl.function.numeric.CosFunction; |
|
26 |
import org.gvsig.expressionevaluator.impl.function.numeric.CoshFunction; |
|
27 |
import org.gvsig.expressionevaluator.impl.function.numeric.CotFunction; |
|
28 |
import org.gvsig.expressionevaluator.impl.function.numeric.DegreesFunction; |
|
29 |
import org.gvsig.expressionevaluator.impl.function.numeric.ExpFunction; |
|
30 |
import org.gvsig.expressionevaluator.impl.function.numeric.FloorFunction; |
|
31 |
import org.gvsig.expressionevaluator.impl.function.numeric.Log10Function; |
|
32 |
import org.gvsig.expressionevaluator.impl.function.numeric.LogFunction; |
|
33 |
import org.gvsig.expressionevaluator.impl.function.numeric.PiFunction; |
|
34 |
import org.gvsig.expressionevaluator.impl.function.numeric.PowFunction; |
|
35 |
import org.gvsig.expressionevaluator.impl.function.numeric.RadiansFunction; |
|
36 |
import org.gvsig.expressionevaluator.impl.function.numeric.RandFunction; |
|
37 |
import org.gvsig.expressionevaluator.impl.function.numeric.RoundFunction; |
|
38 |
import org.gvsig.expressionevaluator.impl.function.numeric.SignFunction; |
|
39 |
import org.gvsig.expressionevaluator.impl.function.numeric.SinFunction; |
|
40 |
import org.gvsig.expressionevaluator.impl.function.numeric.SinhFunction; |
|
41 |
import org.gvsig.expressionevaluator.impl.function.numeric.SqrtFunction; |
|
42 |
import org.gvsig.expressionevaluator.impl.function.numeric.TanFunction; |
|
43 |
import org.gvsig.expressionevaluator.impl.function.numeric.TanhFunction; |
|
44 |
import org.gvsig.expressionevaluator.impl.function.numeric.ZeroFunction; |
|
45 |
import org.gvsig.expressionevaluator.impl.function.obj.GetattrFunction; |
|
46 |
import org.gvsig.expressionevaluator.impl.function.obj.InvokeMethodFunction; |
|
47 |
import org.gvsig.expressionevaluator.impl.function.operator.AddOperator; |
|
48 |
import org.gvsig.expressionevaluator.impl.function.operator.AndOperator; |
|
49 |
import org.gvsig.expressionevaluator.impl.function.operator.DivOperator; |
|
50 |
import org.gvsig.expressionevaluator.impl.function.operator.EqOperator; |
|
51 |
import org.gvsig.expressionevaluator.impl.function.operator.GeOperator; |
|
52 |
import org.gvsig.expressionevaluator.impl.function.operator.GtOperator; |
|
53 |
import org.gvsig.expressionevaluator.impl.function.operator.LeOperator; |
|
54 |
import org.gvsig.expressionevaluator.impl.function.operator.LtOperator; |
|
55 |
import org.gvsig.expressionevaluator.impl.function.operator.ModOperator; |
|
56 |
import org.gvsig.expressionevaluator.impl.function.operator.MulOperator; |
|
57 |
import org.gvsig.expressionevaluator.impl.function.operator.NeOperator; |
|
58 |
import org.gvsig.expressionevaluator.impl.function.operator.NotOperator; |
|
59 |
import org.gvsig.expressionevaluator.impl.function.operator.OrOperator; |
|
60 |
import org.gvsig.expressionevaluator.impl.function.operator.SubstOperator; |
|
61 |
import org.gvsig.expressionevaluator.impl.function.predicate.IlikeOperator; |
|
62 |
import org.gvsig.expressionevaluator.impl.function.predicate.LikeOperator; |
|
63 |
import org.gvsig.expressionevaluator.impl.function.spatial.STAreaFunction; |
|
64 |
import org.gvsig.expressionevaluator.impl.function.spatial.STAsTextFunction; |
|
65 |
import org.gvsig.expressionevaluator.impl.function.spatial.STBufferFunction; |
|
66 |
import org.gvsig.expressionevaluator.impl.function.spatial.STCentroidFunction; |
|
67 |
import org.gvsig.expressionevaluator.impl.function.spatial.STContainsFunction; |
|
68 |
import org.gvsig.expressionevaluator.impl.function.spatial.STConvexHullFunction; |
|
69 |
import org.gvsig.expressionevaluator.impl.function.spatial.STCoveredByFunction; |
|
70 |
import org.gvsig.expressionevaluator.impl.function.spatial.STCoversFunction; |
|
71 |
import org.gvsig.expressionevaluator.impl.function.spatial.STCrossesFunction; |
|
72 |
import org.gvsig.expressionevaluator.impl.function.spatial.STDifferenceFunction; |
|
73 |
import org.gvsig.expressionevaluator.impl.function.spatial.STDimensionFunction; |
|
74 |
import org.gvsig.expressionevaluator.impl.function.spatial.STDisjointFunction; |
|
75 |
import org.gvsig.expressionevaluator.impl.function.spatial.STDistanceFunction; |
|
76 |
import org.gvsig.expressionevaluator.impl.function.spatial.STEndPointFunction; |
|
77 |
import org.gvsig.expressionevaluator.impl.function.spatial.STEnvelopeFunction; |
|
78 |
import org.gvsig.expressionevaluator.impl.function.spatial.STGeomFromTextFunction; |
|
79 |
import org.gvsig.expressionevaluator.impl.function.spatial.STGeometryNFunction; |
|
80 |
import org.gvsig.expressionevaluator.impl.function.spatial.STIntersectionFunction; |
|
81 |
import org.gvsig.expressionevaluator.impl.function.spatial.STIntersectsFunction; |
|
82 |
import org.gvsig.expressionevaluator.impl.function.spatial.STIsSimpleFunction; |
|
83 |
import org.gvsig.expressionevaluator.impl.function.spatial.STIsValidFunction; |
|
84 |
import org.gvsig.expressionevaluator.impl.function.spatial.STNumGeometriesFunction; |
|
85 |
import org.gvsig.expressionevaluator.impl.function.spatial.STNumPointsFunction; |
|
86 |
import org.gvsig.expressionevaluator.impl.function.spatial.STOverlapsFunction; |
|
87 |
import org.gvsig.expressionevaluator.impl.function.spatial.STPointNFunction; |
|
88 |
import org.gvsig.expressionevaluator.impl.function.spatial.STStartPointFunction; |
|
89 |
import org.gvsig.expressionevaluator.impl.function.spatial.STTouchesFunction; |
|
90 |
import org.gvsig.expressionevaluator.impl.function.spatial.STUnionFunction; |
|
91 |
import org.gvsig.expressionevaluator.impl.function.spatial.STWithinFunction; |
|
92 |
import org.gvsig.expressionevaluator.impl.function.spatial.STXFunction; |
|
93 |
import org.gvsig.expressionevaluator.impl.function.spatial.STYFunction; |
|
94 |
import org.gvsig.expressionevaluator.impl.function.spatial.STZFunction; |
|
95 |
import org.gvsig.expressionevaluator.impl.function.string.AsciiFunction; |
|
96 |
import org.gvsig.expressionevaluator.impl.function.string.CharFunction; |
|
97 |
import org.gvsig.expressionevaluator.impl.function.string.ConcatFunction; |
|
98 |
import org.gvsig.expressionevaluator.impl.function.string.InstrFunction; |
|
99 |
import org.gvsig.expressionevaluator.impl.function.string.LTrimFunction; |
|
100 |
import org.gvsig.expressionevaluator.impl.function.string.LeftFunction; |
|
101 |
import org.gvsig.expressionevaluator.impl.function.string.LengthFunction; |
|
102 |
import org.gvsig.expressionevaluator.impl.function.string.LocateFunction; |
|
103 |
import org.gvsig.expressionevaluator.impl.function.string.LowerFunction; |
|
104 |
import org.gvsig.expressionevaluator.impl.function.string.LpadFunction; |
|
105 |
import org.gvsig.expressionevaluator.impl.function.string.PositionFunction; |
|
106 |
import org.gvsig.expressionevaluator.impl.function.string.RTrimFunction; |
|
107 |
import org.gvsig.expressionevaluator.impl.function.string.RepeatFunction; |
|
108 |
import org.gvsig.expressionevaluator.impl.function.string.ReplaceFunction; |
|
109 |
import org.gvsig.expressionevaluator.impl.function.string.RightFunction; |
|
110 |
import org.gvsig.expressionevaluator.impl.function.string.RpadFunction; |
|
111 |
import org.gvsig.expressionevaluator.impl.function.string.SpaceFunction; |
|
112 |
import org.gvsig.expressionevaluator.impl.function.string.SubstringFunction; |
|
113 |
import org.gvsig.expressionevaluator.impl.function.string.TrimFunction; |
|
114 |
import org.gvsig.expressionevaluator.impl.function.string.UpperFunction; |
|
12 | 115 |
import org.gvsig.fmap.dal.EvaluatorFactory; |
13 | 116 |
import org.gvsig.expressionevaluator.integration.DefaultEvaluatorFactory; |
14 | 117 |
import org.gvsig.expressionevaluator.integration.DefaultExpressionEvaluator; |
... | ... | |
17 | 120 |
public class DefaultExpressionEvaluatorManager implements ExpressionEvaluatorManager { |
18 | 121 |
|
19 | 122 |
private Double accuracy; |
123 |
private final Map<String,Function> functions; |
|
124 |
private final Map<String,Function> operators; |
|
20 | 125 |
|
21 | 126 |
public DefaultExpressionEvaluatorManager() { |
127 |
this.functions = new HashMap<>(); |
|
128 |
this.operators = new HashMap<>(); |
|
129 |
initFunctionsAndOperators(); |
|
130 |
} |
|
131 |
|
|
132 |
private void initFunctionsAndOperators() { |
|
133 |
this.addFunction(new GetattrFunction()); |
|
134 |
this.addFunction(new InvokeMethodFunction()); |
|
135 |
|
|
136 |
this.addOperator(new AndOperator()); |
|
137 |
this.addOperator(new AddOperator()); |
|
138 |
this.addOperator(new DivOperator()); |
|
139 |
this.addOperator(new EqOperator()); |
|
140 |
this.addOperator(new GeOperator()); |
|
141 |
this.addOperator(new GtOperator()); |
|
142 |
this.addOperator(new LeOperator()); |
|
143 |
this.addOperator(new LtOperator()); |
|
144 |
this.addOperator(new ModOperator()); |
|
145 |
this.addOperator(new NeOperator()); |
|
146 |
this.addOperator(new ModOperator()); |
|
147 |
this.addOperator(new MulOperator()); |
|
148 |
this.addOperator(new NeOperator()); |
|
149 |
this.addOperator(new NotOperator()); |
|
150 |
this.addOperator(new OrOperator()); |
|
151 |
this.addOperator(new SubstOperator()); |
|
22 | 152 |
|
153 |
this.addOperator(new IlikeOperator()); |
|
154 |
this.addOperator(new LikeOperator()); |
|
155 |
|
|
156 |
this.addFunction(new ACosFunction()); |
|
157 |
this.addFunction(new ASinFunction()); |
|
158 |
this.addFunction(new ATanFunction()); |
|
159 |
this.addFunction(new AbsFunction()); |
|
160 |
this.addFunction(new BitAndFunction()); |
|
161 |
this.addFunction(new BitOrFunction()); |
|
162 |
this.addFunction(new BitXorFunction()); |
|
163 |
this.addFunction(new CeilFunction()); |
|
164 |
this.addFunction(new CosFunction()); |
|
165 |
this.addFunction(new CoshFunction()); |
|
166 |
this.addFunction(new CotFunction()); |
|
167 |
this.addFunction(new DegreesFunction()); |
|
168 |
this.addFunction(new ExpFunction()); |
|
169 |
this.addFunction(new FloorFunction()); |
|
170 |
this.addFunction(new Log10Function()); |
|
171 |
this.addFunction(new LogFunction()); |
|
172 |
this.addFunction(new PiFunction()); |
|
173 |
this.addFunction(new PowFunction()); |
|
174 |
this.addFunction(new RadiansFunction()); |
|
175 |
this.addFunction(new RandFunction()); |
|
176 |
this.addFunction(new RoundFunction()); |
|
177 |
this.addFunction(new SignFunction()); |
|
178 |
this.addFunction(new SinFunction()); |
|
179 |
this.addFunction(new SinhFunction()); |
|
180 |
this.addFunction(new SqrtFunction()); |
|
181 |
this.addFunction(new TanFunction()); |
|
182 |
this.addFunction(new TanhFunction()); |
|
183 |
this.addFunction(new ZeroFunction()); |
|
184 |
this.addFunction(new LogFunction()); |
|
185 |
|
|
186 |
this.addFunction(new AsciiFunction()); |
|
187 |
this.addFunction(new CharFunction()); |
|
188 |
this.addFunction(new ConcatFunction()); |
|
189 |
this.addFunction(new InstrFunction()); |
|
190 |
this.addFunction(new LTrimFunction()); |
|
191 |
this.addFunction(new LeftFunction()); |
|
192 |
this.addFunction(new LengthFunction()); |
|
193 |
this.addFunction(new LocateFunction()); |
|
194 |
this.addFunction(new LowerFunction()); |
|
195 |
this.addFunction(new LpadFunction()); |
|
196 |
this.addFunction(new PositionFunction()); |
|
197 |
this.addFunction(new RTrimFunction()); |
|
198 |
this.addFunction(new RepeatFunction()); |
|
199 |
this.addFunction(new ReplaceFunction()); |
|
200 |
this.addFunction(new RightFunction()); |
|
201 |
this.addFunction(new RpadFunction()); |
|
202 |
this.addFunction(new SpaceFunction()); |
|
203 |
this.addFunction(new SubstringFunction()); |
|
204 |
this.addFunction(new TrimFunction()); |
|
205 |
this.addFunction(new UpperFunction()); |
|
206 |
|
|
207 |
this.addFunction(new STAreaFunction()); |
|
208 |
this.addFunction(new STAsTextFunction()); |
|
209 |
this.addFunction(new STBufferFunction()); |
|
210 |
this.addFunction(new STCentroidFunction()); |
|
211 |
this.addFunction(new STContainsFunction()); |
|
212 |
this.addFunction(new STConvexHullFunction()); |
|
213 |
this.addFunction(new STCoveredByFunction()); |
|
214 |
this.addFunction(new STCoversFunction()); |
|
215 |
this.addFunction(new STCrossesFunction()); |
|
216 |
this.addFunction(new STDifferenceFunction()); |
|
217 |
this.addFunction(new STDimensionFunction()); |
|
218 |
this.addFunction(new STDisjointFunction()); |
|
219 |
this.addFunction(new STDistanceFunction()); |
|
220 |
this.addFunction(new STEndPointFunction()); |
|
221 |
this.addFunction(new STEnvelopeFunction()); |
|
222 |
this.addFunction(new STGeomFromTextFunction()); |
|
223 |
this.addFunction(new STGeometryNFunction()); |
|
224 |
this.addFunction(new STIntersectionFunction()); |
|
225 |
this.addFunction(new STIntersectsFunction()); |
|
226 |
this.addFunction(new STIsSimpleFunction()); |
|
227 |
this.addFunction(new STIsValidFunction()); |
|
228 |
this.addFunction(new STNumGeometriesFunction()); |
|
229 |
this.addFunction(new STNumPointsFunction()); |
|
230 |
this.addFunction(new STOverlapsFunction()); |
|
231 |
this.addFunction(new STPointNFunction()); |
|
232 |
this.addFunction(new STStartPointFunction()); |
|
233 |
this.addFunction(new STTouchesFunction()); |
|
234 |
this.addFunction(new STUnionFunction()); |
|
235 |
this.addFunction(new STWithinFunction()); |
|
236 |
this.addFunction(new STXFunction()); |
|
237 |
this.addFunction(new STYFunction()); |
|
238 |
this.addFunction(new STZFunction()); |
|
239 |
|
|
23 | 240 |
} |
24 | 241 |
|
25 | 242 |
@Override |
243 |
public Map<String, Function> getAllFunctions() { |
|
244 |
return Collections.unmodifiableMap(functions); |
|
245 |
} |
|
246 |
|
|
247 |
@Override |
|
248 |
public Map<String, Function> getAllOperators() { |
|
249 |
return Collections.unmodifiableMap(operators); |
|
250 |
} |
|
251 |
|
|
252 |
@Override |
|
253 |
public void addFunction(Function function) { |
|
254 |
this.functions.put(function.name().toUpperCase(), function); |
|
255 |
} |
|
256 |
|
|
257 |
public void addOperator(Function function) { |
|
258 |
this.operators.put(function.name().toUpperCase(), function); |
|
259 |
} |
|
260 |
|
|
261 |
public void removeFunction(String name) { |
|
262 |
if( StringUtils.isEmpty(name) ) { |
|
263 |
return; |
|
264 |
} |
|
265 |
this.functions.remove(name.toUpperCase()); |
|
266 |
} |
|
267 |
|
|
268 |
@Override |
|
26 | 269 |
public Object evaluate(String source) { |
27 | 270 |
DefaultInterpreter interpreter = new DefaultInterpreter(); |
28 | 271 |
DefaultCompiler compiler = new DefaultCompiler(); |
... | ... | |
63 | 306 |
public MutableSymbolTable createSymbolTable() { |
64 | 307 |
return new DefaultSymbolTable(); |
65 | 308 |
} |
66 |
|
|
309 |
|
|
67 | 310 |
@Override |
68 | 311 |
public LexicalAnalyzer createLexicalAnalyzer() { |
69 | 312 |
return new SQLLexicalAnalyzer(); |
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/DefaultSymbolTable.java | ||
---|---|---|
4 | 4 |
import java.util.HashMap; |
5 | 5 |
import java.util.Iterator; |
6 | 6 |
import java.util.Map; |
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
9 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
10 |
import org.gvsig.expressionevaluator.Function; |
|
7 | 11 |
import org.gvsig.expressionevaluator.SymbolTable; |
8 | 12 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
13 |
import org.gvsig.expressionevaluator.Scripts; |
|
14 |
import org.gvsig.expressionevaluator.impl.function.ScriptFunction; |
|
9 | 15 |
|
10 | 16 |
|
11 | 17 |
public class DefaultSymbolTable extends AbstractSymbolTable implements MutableSymbolTable { |
12 | 18 |
|
13 | 19 |
private Map<String,Object> vars; |
20 |
protected DefaultScripts scripts = null; |
|
14 | 21 |
|
22 |
public DefaultSymbolTable() { |
|
23 |
this(null); |
|
24 |
} |
|
25 |
|
|
15 | 26 |
public DefaultSymbolTable(SymbolTable delegatedSymbolTable) { |
16 | 27 |
super(delegatedSymbolTable); |
17 | 28 |
this.vars = new HashMap<>(); |
29 |
this.scripts = new DefaultScripts(); |
|
30 |
this.init(); |
|
18 | 31 |
} |
19 | 32 |
|
20 |
public DefaultSymbolTable() { |
|
21 |
this(null); |
|
33 |
private void init() { |
|
34 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
35 |
this.addFunctions(manager.getAllFunctions().values()); |
|
36 |
this.addFunctions(manager.getAllOperators().values()); |
|
22 | 37 |
} |
23 |
|
|
38 |
|
|
24 | 39 |
@Override |
25 | 40 |
public MutableSymbolTable clone() throws CloneNotSupportedException { |
26 | 41 |
DefaultSymbolTable other = (DefaultSymbolTable) super.clone(); |
27 | 42 |
other.vars = new HashMap<>(vars); |
43 |
other.scripts =(DefaultScripts) scripts.clone(); |
|
28 | 44 |
return other; |
29 | 45 |
} |
46 |
|
|
47 |
@Override |
|
48 |
public Function function(String name) { |
|
49 |
if( StringUtils.isEmpty(name) ) { |
|
50 |
return null; |
|
51 |
} |
|
52 |
Function fn = super.function(name); |
|
53 |
if( fn == null && !this.scripts.isEmpty() ) { |
|
54 |
fn = new ScriptFunction(this.scripts, name); |
|
55 |
} |
|
56 |
return fn; |
|
57 |
} |
|
30 | 58 |
|
31 | 59 |
@Override |
32 |
public void addVar(String name, Object value) {
|
|
60 |
public void setVar(String name, Object value) {
|
|
33 | 61 |
this.vars.put(name, value); |
34 | 62 |
} |
35 | 63 |
|
... | ... | |
59 | 87 |
public Iterator<String> itervars() { |
60 | 88 |
return this.vars.keySet().iterator(); |
61 | 89 |
} |
62 |
|
|
90 |
|
|
91 |
@Override |
|
92 |
public Scripts getScripts() { |
|
93 |
return this.scripts; |
|
94 |
} |
|
95 |
|
|
63 | 96 |
} |
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 | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.impl.function.numeric; |
|
2 |
|
|
3 |
import java.awt.geom.AffineTransform; |
|
4 |
import org.apache.commons.lang3.Range; |
|
5 |
import org.gvsig.expressionevaluator.Interpreter; |
|
6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
7 |
|
|
8 |
public class AffineTransformFunction extends AbstractFunction { |
|
9 |
|
|
10 |
public AffineTransformFunction() { |
|
11 |
super( |
|
12 |
"Numeric", |
|
13 |
"AffineTransform", |
|
14 |
Range.between(0, 6), |
|
15 |
"With 0 parameters create an AffineTransform representing the Identity transformation\n" + |
|
16 |
"With 6 parameters create an AffineTransform with the 6 specifiable entries of the 3x3 transformation matrix.\n" + |
|
17 |
"- m00 the X coordinate scaling element of the 3x3 matrix\n" + |
|
18 |
"- m10 the Y coordinate shearing element of the 3x3 matrix\n" + |
|
19 |
"- m01 the X coordinate shearing element of the 3x3 matrix\n" + |
|
20 |
"- m11 the Y coordinate scaling element of the 3x3 matrix\n" + |
|
21 |
"- m02 the X coordinate translation element of the 3x3 matrix\n" + |
|
22 |
"- m12 the Y coordinate translation element of the 3x3 matrix", |
|
23 |
"AffineTransform( m00, m10, m01, m11, m02, m12 )" |
|
24 |
); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public Object call(Interpreter interpreter, Object[] args) { |
|
29 |
AffineTransform at; |
|
30 |
switch(args.length) { |
|
31 |
case 0: |
|
32 |
at = new AffineTransform(); |
|
33 |
return at; |
|
34 |
case 6: |
|
35 |
double m00 = getDouble(args, 0); |
|
36 |
double m10 = getDouble(args, 0); |
|
37 |
double m01 = getDouble(args, 0); |
|
38 |
double m11 = getDouble(args, 0); |
|
39 |
double m02 = getDouble(args, 0); |
|
40 |
double m12 = getDouble(args, 0); |
|
41 |
at = new AffineTransform(m00, m10, m01, m11, m02, m12); |
|
42 |
return at; |
|
43 |
default: |
|
44 |
throw new IllegalArgumentException("The AffinaTransform function requires 0 or 6 parameters."); |
|
45 |
} |
|
46 |
} |
|
47 |
} |
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/PowFunction.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl.function.numeric; |
2 | 2 |
|
3 |
import java.util.List; |
|
4 | 3 |
import org.apache.commons.lang3.Range; |
5 | 4 |
import org.gvsig.expressionevaluator.Interpreter; |
6 | 5 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
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/ScriptFunction.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl.function; |
2 | 2 |
|
3 |
import java.util.List; |
|
3 | 4 |
import org.apache.commons.lang3.Range; |
4 | 5 |
import org.gvsig.expressionevaluator.Interpreter; |
5 | 6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
... | ... | |
11 | 12 |
*/ |
12 | 13 |
public class ScriptFunction extends AbstractFunction { |
13 | 14 |
|
14 |
private final Script script;
|
|
15 |
private final List<Script> scripts;
|
|
15 | 16 |
|
16 | 17 |
/** |
17 | 18 |
* |
18 |
* @param script |
|
19 |
* @param scripts
|
|
19 | 20 |
* @param funcName |
20 | 21 |
*/ |
21 |
public ScriptFunction(Script script, String funcName) {
|
|
22 |
public ScriptFunction(List<Script> scripts, String funcName) {
|
|
22 | 23 |
super("Script", funcName, Range.between(1,Integer.MAX_VALUE)); |
23 |
this.script = script;
|
|
24 |
this.scripts = scripts;
|
|
24 | 25 |
|
25 | 26 |
} |
26 | 27 |
|
27 | 28 |
@Override |
28 | 29 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
29 |
return this.script.invokeFunction(this.name(), args); |
|
30 |
for (Script script : this.scripts) { |
|
31 |
try { |
Also available in: Unified diff