01: package org.geotools.data.jdbc.datasource;
02:
03: import java.io.IOException;
04: import java.util.Collections;
05: import java.util.Map;
06:
07: import org.geotools.data.DataStoreFactorySpi.Param;
08:
09: public abstract class AbstractDataSourceFactorySpi implements
10: DataSourceFactorySpi {
11:
12: /**
13: * Default Implementation abuses the naming convention.
14: * <p>
15: * Will return <code>Foo</code> for <code>org.geotools.data.foo.FooFactory</code>.
16: * </p>
17: *
18: * @return return display name based on class name
19: */
20: public String getDisplayName() {
21: String name = this .getClass().getName();
22:
23: name = name.substring(name.lastIndexOf('.'));
24: if (name.endsWith("Factory")) {
25: name = name.substring(0, name.length() - 7);
26: } else if (name.endsWith("FactorySpi")) {
27: name = name.substring(0, name.length() - 10);
28: }
29: return name;
30: }
31:
32: public boolean canProcess(Map params) {
33: if (params == null) {
34: return false;
35: }
36: Param arrayParameters[] = getParametersInfo();
37: for (int i = 0; i < arrayParameters.length; i++) {
38: Param param = arrayParameters[i];
39: Object value;
40: if (!params.containsKey(param.key)) {
41: if (param.required) {
42: return false; // missing required key!
43: } else {
44: continue;
45: }
46: }
47: try {
48: value = param.lookUp(params);
49: } catch (IOException e) {
50: // could not upconvert/parse to expected type!
51: // even if this parameter is not required
52: // we are going to refuse to process
53: // these params
54: return false;
55: }
56: if (value == null) {
57: if (param.required) {
58: return (false);
59: }
60: } else {
61: if (!param.type.isInstance(value)) {
62: return false; // value was not of the required type
63: }
64: }
65: }
66: return true;
67: }
68:
69: /**
70: * Returns the implementation hints. The default implementation returns en empty map.
71: */
72: public Map getImplementationHints() {
73: return Collections.EMPTY_MAP;
74: }
75: }
|