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 | 44853 | jjdelcerro | package org.gvsig.expressionevaluator.impl.function.dataaccess; |
---|---|---|---|
2 | |||
3 | 45043 | jjdelcerro | import javax.json.JsonObject; |
4 | 44853 | jjdelcerro | import org.apache.commons.lang3.Range; |
5 | 45043 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
6 | import org.gvsig.expressionevaluator.I18N; |
||
7 | 44853 | jjdelcerro | import org.gvsig.expressionevaluator.Interpreter; |
8 | import org.gvsig.expressionevaluator.spi.AbstractFunction; |
||
9 | 45043 | jjdelcerro | import org.gvsig.expressionevaluator.spi.JsonUtils; |
10 | import org.gvsig.fmap.dal.DALLocator; |
||
11 | import org.gvsig.fmap.dal.DataManager; |
||
12 | 44853 | jjdelcerro | import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW; |
13 | 46087 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
14 | 45043 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
15 | 44853 | jjdelcerro | import org.gvsig.fmap.dal.feature.Feature; |
16 | 45043 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
17 | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
||
18 | import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
||
19 | 44853 | jjdelcerro | |
20 | /**
|
||
21 | *
|
||
22 | 45043 | jjdelcerro | * @author gvSIG Team
|
23 | 44853 | jjdelcerro | */
|
24 | 45043 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
25 | 44853 | jjdelcerro | 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 | 45043 | jjdelcerro | 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 | 46087 | jjdelcerro | return featureType;
|
90 | 45043 | jjdelcerro | } |
91 | 46087 | jjdelcerro | |
92 | 44853 | jjdelcerro | } |