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