svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / dataaccess / AbstractFeatureFunction.java @ 46087
History | View | Annotate | Download (3.74 KB)
1 |
package org.gvsig.expressionevaluator.impl.function.dataaccess; |
---|---|
2 |
|
3 |
import javax.json.JsonObject; |
4 |
import org.apache.commons.lang3.Range; |
5 |
import org.apache.commons.lang3.StringUtils; |
6 |
import org.gvsig.expressionevaluator.I18N; |
7 |
import org.gvsig.expressionevaluator.Interpreter; |
8 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
9 |
import org.gvsig.expressionevaluator.spi.JsonUtils; |
10 |
import org.gvsig.fmap.dal.DALLocator; |
11 |
import org.gvsig.fmap.dal.DataManager; |
12 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW; |
13 |
import org.gvsig.fmap.dal.DataStore; |
14 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
15 |
import org.gvsig.fmap.dal.feature.Feature; |
16 |
import org.gvsig.fmap.dal.feature.FeatureType; |
17 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
18 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
19 |
|
20 |
/**
|
21 |
*
|
22 |
* @author gvSIG Team
|
23 |
*/
|
24 |
@SuppressWarnings("UseSpecificCatch") |
25 |
public abstract class AbstractFeatureFunction extends AbstractFunction { |
26 |
|
27 |
protected AbstractFeatureFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType, boolean sqlCompatible) { |
28 |
super(group, name, argc, description, template, descriptionArgs, returnType, sqlCompatible);
|
29 |
} |
30 |
|
31 |
protected AbstractFeatureFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType) { |
32 |
super(group, name, argc, description, template, descriptionArgs, returnType);
|
33 |
} |
34 |
|
35 |
public Feature current_row(Interpreter interpreter) {
|
36 |
try {
|
37 |
Feature f = (Feature) interpreter.call(FUNCTION_CURRENT_ROW); |
38 |
return f;
|
39 |
} catch (Exception ex) { |
40 |
return null; |
41 |
} |
42 |
} |
43 |
|
44 |
protected NewFeatureStoreParameters getNewFeatureStoreParameters(Object[] args, int n) { |
45 |
Object v = getObject(args, n);
|
46 |
if( v instanceof NewFeatureStoreParameters ) { |
47 |
return (NewFeatureStoreParameters) v;
|
48 |
} |
49 |
NewFeatureStoreParameters parameters; |
50 |
JsonObject jsonObj = getJsonObject(args, n); |
51 |
try {
|
52 |
String providerName = jsonObj.getString(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
|
53 |
|
54 |
DataManager dataManager = DALLocator.getDataManager(); |
55 |
parameters = (NewFeatureStoreParameters) dataManager.createNewStoreParameters(providerName); |
56 |
for (String paramName : jsonObj.keySet()) { |
57 |
if( StringUtils.equalsIgnoreCase(paramName, DataStoreProviderServices.PROVIDER_PARAMTER_NAME)) {
|
58 |
continue;
|
59 |
} |
60 |
parameters.setDynValue(paramName, JsonUtils.getitem(jsonObj, paramName)); |
61 |
} |
62 |
} catch (Exception ex) { |
63 |
String type = v.getClass().getCanonicalName();
|
64 |
throw new IllegalArgumentException( |
65 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " +
|
66 |
I18N.Expected_XexpectedX_and_found_XfoundX("NewFeatureStoreParameters",type)
|
67 |
); |
68 |
} |
69 |
return parameters;
|
70 |
} |
71 |
|
72 |
protected FeatureType getFeatureType(Object[] args, int n) { |
73 |
Object v = getObject(args, n);
|
74 |
if( v instanceof FeatureType ) { |
75 |
return (FeatureType) v;
|
76 |
} |
77 |
EditableFeatureType featureType; |
78 |
JsonObject jsonObj = getJsonObject(args, n); |
79 |
try {
|
80 |
DataManager dataManager = DALLocator.getDataManager(); |
81 |
featureType = dataManager.createFeatureType(jsonObj); |
82 |
} catch (Exception ex) { |
83 |
String type = v.getClass().getCanonicalName();
|
84 |
throw new IllegalArgumentException( |
85 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " +
|
86 |
I18N.Expected_XexpectedX_and_found_XfoundX("NewFeatureStoreParameters",type)
|
87 |
); |
88 |
} |
89 |
return featureType;
|
90 |
} |
91 |
|
92 |
} |