Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.io / src / main / java / org / gvsig / raster / wmts / io / WMTSConnector.java @ 1812

History | View | Annotate | Download (5.37 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.wmts.io;
23

    
24
import java.io.File;
25
import java.io.IOException;
26
import java.net.ConnectException;
27
import java.net.MalformedURLException;
28
import java.net.URL;
29
import java.util.List;
30

    
31
import org.gvsig.compat.net.ICancellable;
32
import org.gvsig.raster.wmts.ogc.WMTSClient;
33
import org.gvsig.raster.wmts.ogc.WMTSOGCLocator;
34
import org.gvsig.raster.wmts.ogc.WMTSStatus;
35
import org.gvsig.raster.wmts.ogc.exception.DownloadException;
36
import org.gvsig.raster.wmts.ogc.exception.ServerErrorException;
37
import org.gvsig.raster.wmts.ogc.exception.WMTSException;
38
import org.gvsig.raster.wmts.ogc.struct.WMTSLayer;
39
import org.gvsig.raster.wmts.ogc.struct.WMTSServiceIdentification;
40
import org.gvsig.raster.wmts.ogc.struct.WMTSServiceProvider;
41
import org.gvsig.raster.wmts.ogc.struct.WMTSThemes;
42
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixSet;
43

    
44
/**
45
 * This class offers an interface of services for a WMTS  
46
 *
47
 * @author Nacho Brodin (nachobrodin@gmail.com)
48
 */
49
public class WMTSConnector  {
50
        private WMTSClient                     client        = null;
51

    
52
    public WMTSConnector(URL url) throws ConnectException, IOException {
53
            client = WMTSOGCLocator.getManager().createWMTSClient(url.toString());
54
    }
55
    
56
        /**
57
         * Creates a <code>WMTSStatus</code> structure to make a request 
58
         * @return
59
         */
60
        public WMTSStatus createStatus() {
61
                return client.createStatus();
62
        }
63
    
64
    /**
65
         * Sets longitude first in the axis order
66
         * @param force
67
         */
68
        public void setForceLongitudeFirstAxisOrder(boolean force) {
69
                if(client != null) {
70
                        client.setForceLongitudeFirstAxisOrder(force);
71
                }
72
        }
73

    
74
    /**
75
     * Establishes the connection.
76
     * @param override, if true the previous downloaded data will be overridden
77
     * @return <b>true</b> if the connection was successful, or <b>false</b> if it was no possible
78
     * to establish the connection for any reason such as version negotiation.
79
     */
80
    public boolean connect(boolean override, ICancellable cancel) {
81
            return client.connect(override, cancel);
82
    }
83

    
84
    public boolean connect(ICancellable cancel) {
85
            return client.connect(false, cancel);
86
    }
87

    
88
        /**
89
         * Gets the list of themes
90
         * @return
91
         */
92
        public WMTSThemes getThemes() {
93
                return client.getThemes();
94
        }
95
    
96
    /**
97
     * Gets a layer 
98
     * @param layerName
99
     * @return
100
     */
101
    public WMTSLayer getLayer(String layerName) {
102
            return client.getLayer(layerName);
103
    }
104
    
105
    /**
106
     * Gets the set of tiles definition
107
     * @return
108
     */
109
        public List<WMTSTileMatrixSet> getTileMatrixSet() {
110
            return client.getTileMatrixSet();
111
    }
112
    
113
    /*
114
         * (non-Javadoc)
115
         * @see org.gvsig.fmap.dal.coverage.explorer.WMTSServerExplorer#getServiceIdentification()
116
         */
117
        public WMTSServiceIdentification getServiceIdentification() {
118
                return client.getServiceIdentification();
119
        }
120
        
121
        public WMTSServiceProvider getServiceProvider() {
122
                return client.getServiceProvider();
123
        }
124

    
125
    /**
126
     * Gets the host
127
     * @return
128
     */
129
    public String getHost(){
130
            return client.getHost();
131
    }
132
   
133
    /**
134
     * <p>Gets a tile downloading using a specific path and file.</p> 
135
     * @throws ServerErrorException 
136
     */
137
    public synchronized File getTile(WMTSStatus status, ICancellable cancel, File file) throws WMTSException, ServerErrorException {   
138
        return client.getTile(status, cancel, file);
139
    }
140
    
141
    /**
142
     * <p>One of the three interfaces that OGC WMTS defines. Request a map.</p> 
143
     * @throws ServerErrorException 
144
     */
145
    public synchronized File getTile(WMTSStatus status, ICancellable cancel) throws WMTSException, ServerErrorException {   
146
        return client.getTile(status, cancel);
147
    }
148
    
149
    /**
150
     * Builds the URL to get a tile using a WMTSStatus object 
151
     * @throws ServerErrorException 
152
     */
153
    public synchronized URL getTileURL(WMTSStatus status) throws MalformedURLException {   
154
        return client.getTileURL(status);
155
    }
156
    
157
    /**
158
     * Downloads a file
159
     * @throws DownloadException 
160
     * @throws ServerErrorException 
161
     */
162
    public synchronized File downloadFile(URL url, ICancellable cancel) throws DownloadException {   
163
        return client.downloadFile(url, cancel);
164
    }
165
    
166
    /**
167
     * <p>It will send a GetFeatureInfo request to the WMTS
168
     * Parsing the response and redirecting the info to the WMTS client</p>
169
     */
170
    public String getFeatureInfo(WMTSStatus status, int x, int y, ICancellable cancel) throws WMTSException, ServerErrorException {   
171
        return client.getFeatureInfo(status, x, y, cancel);
172
    }
173
}