001 /*
002 * $Id: HydraDataSource.java,v 1.12 2012/02/19 17:35:45 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2012
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 *
012 * All Rights Reserved
013 *
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.
016 *
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 *
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
025 * GNU Lesser Public License for more details.
026 *
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program. If not, see http://www.gnu.org/licenses.
029 */
030
031 package edu.wisc.ssec.mcidasv.data;
032
033 import java.io.File;
034 import java.rmi.RemoteException;
035 import java.util.ArrayList;
036 import java.util.Hashtable;
037 import java.util.List;
038
039 import ucar.unidata.data.DataCategory;
040 import ucar.unidata.data.DataChoice;
041 import ucar.unidata.data.DataSelection;
042 import ucar.unidata.data.DataSourceDescriptor;
043 import ucar.unidata.data.DataSourceImpl;
044 import ucar.unidata.util.WrapperException;
045 import visad.Data;
046 import visad.VisADException;
047
048 public class HydraDataSource extends DataSourceImpl {
049
050 /** List of sources files */
051 protected final List sources = new ArrayList();
052
053 public static String request;
054
055 /** List of sources files */
056 protected List adapters;
057
058 /** for unpersistence */
059 protected String oldSourceFromBundles;
060
061 /**
062 * Default constructor
063 */
064 public HydraDataSource() {}
065
066 /**
067 * Create a HydraDataSource
068 *
069 * @param descriptor The datasource descriptor
070 * @param newSources List of files or urls
071 * @param description The long name
072 * @param properties properties
073 *
074 * @throws VisADException couldn't create the data
075 */
076 public HydraDataSource(DataSourceDescriptor descriptor, List newSources,
077 String description, Hashtable properties)
078 throws VisADException {
079
080 super(descriptor, "Hydra", "Hydra", properties);
081 /*
082 System.out.println("HydraDataSource:");
083 System.out.println(" descriptor=" + descriptor);
084 System.out.println(" sources=" + newSources);
085 System.out.println(" description=" + description);
086 System.out.println(" properties=" + properties);
087 */
088 if (newSources != null)
089 sources.addAll(newSources);
090 }
091
092 /**
093 * Can this data source save its dat to local disk
094 *
095 * @return can save to local disk
096 */
097 public boolean canSaveDataToLocalDisk() {
098 return !isFileBased() && (getProperty(PROP_SERVICE_HTTP) != null);
099 }
100
101 /**
102 * Are we getting data from a file or from server
103 *
104 * @return is the data from files
105 */
106 protected boolean isFileBased() {
107 if (sources.isEmpty())
108 return false;
109
110 return (new File(sources.get(0).toString())).exists();
111 }
112
113 /**
114 * This is called when the CacheManager detects the need ot clear memory.
115 * It is intended to be overwritten by derived classes that are holding cached
116 * data that is not in the normal putCache facilities provided by this class
117 * since that data is actually managed by the CacheManager
118 */
119 public void clearCachedData() {
120 super.clearCachedData();
121 }
122
123 /**
124 * Create, if needed, and return the list of adapters.
125 * Will return null if there are no valid adapters.
126 *
127 * @return List of adapters or null
128 */
129 protected List getAdapters() {
130 if ((adapters == null) || (adapters.size() == 0)) {
131 try {
132 makeAdapters(sources);
133 } catch (Exception exc) {
134 setInError(true);
135 throw new WrapperException(exc);
136 }
137 }
138 if (adapters.size() == 0) {
139 adapters = null;
140 }
141 return adapters;
142 }
143
144 /**
145 * Make the adapters for the given list of files
146 *
147 * @param files Data files
148 *
149 * @throws Exception When bad things happen
150 */
151 private void makeAdapters(List files) throws Exception {
152 adapters = new ArrayList();
153 }
154
155 /**
156 * Create the list of times associated with this DataSource.
157 * @return list of times.
158 */
159 protected List doMakeDateTimes() {
160 List times = new ArrayList();
161 return times;
162 }
163
164 /*
165 public boolean canDoGeoSelection() {
166 return true;
167 }
168 */
169
170 /**
171 * Get the data for the given DataChoice and selection criteria.
172 * @param dataChoice DataChoice for selection
173 * @param category DataCategory for the DataChoice (not used)
174 * @param subset subsetting criteria
175 * @param requestProperties extra request properties
176 * @return the Data object for the request
177 *
178 * @throws RemoteException couldn't create a remote data object
179 * @throws VisADException couldn't create the data
180 */
181 protected Data getDataInner(DataChoice dataChoice, DataCategory category,
182 DataSelection subset,
183 Hashtable requestProperties)
184 throws VisADException, RemoteException {
185 return null;
186 }
187 }