001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.catalog.internal.arcsde;
018:
019: import java.io.Serializable;
020: import java.net.MalformedURLException;
021: import java.net.URL;
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import net.refractions.udig.catalog.AbstractDataStoreServiceExtension;
026: import net.refractions.udig.catalog.IService;
027: import net.refractions.udig.catalog.ServiceExtension;
028: import net.refractions.udig.catalog.arcsde.internal.Messages;
029:
030: import org.geotools.data.DataStoreFactorySpi;
031: import org.geotools.data.arcsde.ArcSDEDataStoreFactory;
032:
033: /**
034: * Arc SDE Service Extension Implementation.
035: *
036: * @author David Zwiers, Refractions Research
037: * @since 0.6
038: */
039: public class ArcServiceExtension extends
040: AbstractDataStoreServiceExtension implements ServiceExtension {
041:
042: public IService createService(URL id,
043: Map<String, Serializable> params) {
044: if (params != null
045: && params
046: .containsKey(getFactory().getParametersInfo()[3].key)
047: && params.get(getFactory().getParametersInfo()[3].key) instanceof String) {
048: String val = (String) params.get(getFactory()
049: .getParametersInfo()[3].key);
050: params.remove(val);
051: params.put(getFactory().getParametersInfo()[3].key,
052: new Integer(val));
053: }
054:
055: if (!getFactory().canProcess(params))
056: return null;
057: if (id == null) {
058: String host = (String) params.get(getFactory()
059: .getParametersInfo()[2].key);
060: String port = params.get(
061: getFactory().getParametersInfo()[3].key).toString();
062: String db = (String) params.get(getFactory()
063: .getParametersInfo()[4].key);
064: try {
065: return new ArcServiceImpl(
066: new URL(
067: "http://" + host + ".arcsde.jdbc:" + (port) + "/" + db), params); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
068: } catch (MalformedURLException e) {
069: // log this?
070: e.printStackTrace();
071: return null;
072: }
073: }
074: return new ArcServiceImpl(id, params);
075: }
076:
077: public Map<String, Serializable> createParams(URL url) {
078:
079: if (!isArcSDE(url))
080: return null;
081:
082: ParamInfo info = parseParamInfo(url);
083:
084: Map<String, Serializable> params = new HashMap<String, Serializable>();
085: params.put(getFactory().getParametersInfo()[1].key, "arcsde"); // dbtype //$NON-NLS-1$
086: params.put(getFactory().getParametersInfo()[2].key, info.host); // host
087: params.put(getFactory().getParametersInfo()[3].key,
088: info.the_port); // port
089: params.put(getFactory().getParametersInfo()[4].key,
090: info.the_database); // database
091: params.put(getFactory().getParametersInfo()[5].key,
092: info.username); // user
093: params.put(getFactory().getParametersInfo()[6].key,
094: info.password); // pass
095:
096: if (getFactory().canProcess(params)) {
097: return params;
098: }
099: return null;
100: }
101:
102: /** A couple quick checks on the url */
103: public static final boolean isArcSDE(URL url) {
104: if (url == null)
105: return false;
106: return url.getProtocol().toLowerCase().equals("arcsde"); //$NON-NLS-1$
107: }
108:
109: private static ArcSDEDataStoreFactory factory = null;
110:
111: protected static ArcSDEDataStoreFactory getFactory() {
112: if (factory == null) {
113: factory = new ArcSDEDataStoreFactory();
114: }
115: return factory;
116: }
117:
118: @Override
119: protected String doOtherChecks(Map<String, Serializable> params) {
120: return null;
121: }
122:
123: @Override
124: protected DataStoreFactorySpi getDataStoreFactory() {
125: return getFactory();
126: }
127:
128: public String reasonForFailure(URL url) {
129: if (url == null)
130: return Messages.ArcServiceExtension_urlNull;
131: if (!isArcSDE(url))
132: return Messages.ArcServiceExtension_notSDEURL;
133: return reasonForFailure(createParams(url));
134: }
135: }
|