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.wfs;
018:
019: import java.io.IOException;
020: import java.io.Serializable;
021: import java.net.URL;
022: import java.util.Map;
023:
024: import net.refractions.udig.catalog.wfs.internal.Messages;
025:
026: import org.geotools.data.DataStore;
027: import org.geotools.data.ows.WFSCapabilities;
028: import org.geotools.data.wfs.WFSDataStore;
029: import org.geotools.data.wfs.WFSDataStoreFactory;
030: import org.xml.sax.SAXException;
031:
032: /**
033: * Provides ...TODO summary sentence
034: * <p>
035: * TODO Description
036: * </p>
037: * @author David Zwiers, Refractions Research
038: * @since 0.6
039: */
040: public class UDIGWFSDataStoreFactory extends WFSDataStoreFactory {
041:
042: /**
043: * DOCUMENT ME!
044: *
045: * @return DOCUMENT ME!
046: *
047: * @throws IOException
048: *
049: * @see org.geotools.data.DataStoreFactorySpi#createNewDataStore(java.util.Map)
050: */
051: @SuppressWarnings("unchecked")
052: public DataStore createNewDataStore(Map arg0) throws IOException {
053: Map<String, Serializable> params = (Map<String, Serializable>) arg0;
054: URL host = (URL) URL.lookUp(params);
055:
056: Boolean protocol = (Boolean) PROTOCOL.lookUp(params);
057:
058: String user;
059: String pass;
060: user = pass = null;
061:
062: int timeout = 3000;
063: int buffer = 10;
064: boolean tryGZIP = true;
065:
066: if (params.containsKey(TRY_GZIP.key)) {
067: Boolean b = (Boolean) TRY_GZIP.lookUp(params);
068: if (b != null)
069: tryGZIP = b.booleanValue();
070: }
071: if (params.containsKey(TIMEOUT.key)) {
072: Integer i = (Integer) TIMEOUT.lookUp(params);
073: if (i != null)
074: timeout = i.intValue();
075: }
076:
077: if (params.containsKey(BUFFER_SIZE.key)) {
078: Integer i = (Integer) BUFFER_SIZE.lookUp(params);
079: if (i != null)
080: buffer = i.intValue();
081: }
082:
083: if (params.containsKey(USERNAME.key)) {
084: user = (String) USERNAME.lookUp(params);
085: }
086:
087: if (params.containsKey(PASSWORD.key)) {
088: pass = (String) PASSWORD.lookUp(params);
089: }
090:
091: if (((user == null) && (pass != null))
092: || ((pass == null) && (user != null))) {
093: throw new IOException(
094: Messages.UDIGWFSDataStoreFactory_error_usernameAndPassword);
095: }
096:
097: DataStore ds = null;
098:
099: try {
100: ds = new UDIGWFSDataStore(host, protocol, user, pass,
101: timeout, buffer, tryGZIP);
102: cache.put(params, ds);
103: } catch (SAXException e) {
104: WfsPlugin.log("Encountered SAXException", e); //$NON-NLS-1$
105: throw (IOException) new IOException().initCause(e);
106: }
107:
108: return ds;
109: }
110:
111: public static class UDIGWFSDataStore extends WFSDataStore {
112:
113: /**
114: * Construct <code>UDIGWFSDataStore</code>.
115: *
116: * @param arg0
117: * @param arg1
118: * @param arg2
119: * @param arg3
120: * @param arg4
121: * @param arg5
122: * @param arg6
123: * @throws SAXException
124: * @throws IOException
125: */
126: UDIGWFSDataStore(URL host, Boolean protocol, String username,
127: String password, int timeout, int buffer,
128: boolean tryGZIP) throws SAXException, IOException {
129: super (host, protocol, username, password, timeout, buffer,
130: tryGZIP);
131: }
132:
133: public WFSCapabilities getCapabilities() {
134: return capabilities;
135: }
136:
137: protected static URL createGetCapabilitiesRequest(URL host) {
138: return WFSDataStore.createGetCapabilitiesRequest(host);
139: }
140: }
141: }
|