001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/coverage/grid/Format.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2007 by: 006 EXSE, Department of Geography, University of Bonn 007 http://www.giub.uni-bonn.de/deegree/ 008 lat/lon GmbH 009 http://www.lat-lon.de 010 011 This library is free software; you can redistribute it and/or 012 modify it under the terms of the GNU Lesser General Public 013 License as published by the Free Software Foundation; either 014 version 2.1 of the License, or (at your option) any later version. 015 016 This library is distributed in the hope that it will be useful, 017 but WITHOUT ANY WARRANTY; without even the implied warranty of 018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 Lesser General Public License for more details. 020 021 You should have received a copy of the GNU Lesser General Public 022 License along with this library; if not, write to the Free Software 023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 024 025 Contact: 026 027 Andreas Poth 028 lat/lon GmbH 029 Aennchenstr. 19 030 53115 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Prof. Dr. Klaus Greve 035 Department of Geography 036 University of Bonn 037 Meckenheimer Allee 166 038 53115 Bonn 039 Germany 040 E-Mail: greve@giub.uni-bonn.de 041 042 043 ---------------------------------------------------------------------------*/ 044 package org.deegree.model.coverage.grid; 045 046 import java.io.Serializable; 047 import java.util.Arrays; 048 import java.util.List; 049 050 import org.deegree.datatypes.Code; 051 import org.deegree.datatypes.parameter.GeneralOperationParameterIm; 052 053 /** 054 * This interface is a discovery mechanism to determine the formats supported by a 055 * {@link "org.opengis.coverage.grid.GridCoverageExchange"} implementation. A 056 * <code>GC_GridCoverageExchange</code> implementation can support a number of file format or 057 * resources. 058 * 059 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 060 * @author last edited by: $Author: apoth $ 061 * 062 * @version $Revision: 7842 $, $Date: 2007-07-25 09:44:14 +0200 (Mi, 25 Jul 2007) $ 063 */ 064 public class Format implements Serializable { 065 066 private static final long serialVersionUID = 3847909077719638612L; 067 068 private String name = null; 069 070 private String description = null; 071 072 private String docURL = null; 073 074 private String vendor = null; 075 076 private String version = null; 077 078 private List<GeneralOperationParameterIm> readParameters = null; 079 080 private List<GeneralOperationParameterIm> writeParameters = null; 081 082 /** 083 * Initializes a format with a Code containing a code that will be used as format name and a 084 * code space (optional) that will be interpreted as format vendor. 085 * 086 * @param code 087 */ 088 public Format( Code code ) { 089 this.name = code.getCode(); 090 if ( code.getCodeSpace() != null ) { 091 vendor = code.getCodeSpace().toString(); 092 } 093 } 094 095 /** 096 * @param description 097 * @param docURL 098 * @param name 099 * @param vendor 100 * @param version 101 */ 102 public Format( String name, String description, String docURL, String vendor, String version ) { 103 this.description = description; 104 this.docURL = docURL; 105 this.name = name; 106 this.vendor = vendor; 107 this.version = version; 108 } 109 110 /** 111 * @param description 112 * @param docURL 113 * @param name 114 * @param vendor 115 * @param version 116 * @param readParameters 117 * @param writeParameters 118 */ 119 public Format( String name, String description, String docURL, String vendor, String version, 120 GeneralOperationParameterIm[] readParameters, 121 GeneralOperationParameterIm[] writeParameters ) { 122 this.description = description; 123 this.docURL = docURL; 124 this.name = name; 125 this.vendor = vendor; 126 this.version = version; 127 setReadParameters( readParameters ); 128 setWriteParameters( writeParameters ); 129 } 130 131 /** 132 * @param description 133 * The description to set. 134 * 135 */ 136 public void setDescription( String description ) { 137 this.description = description; 138 } 139 140 /** 141 * @param docURL 142 * The docURL to set. 143 * 144 */ 145 public void setDocURL( String docURL ) { 146 this.docURL = docURL; 147 } 148 149 /** 150 * @param name 151 * The name to set. 152 * 153 */ 154 public void setName( String name ) { 155 this.name = name; 156 } 157 158 /** 159 * @param readParameters 160 * The readParameters to set. 161 */ 162 public void setReadParameters( GeneralOperationParameterIm[] readParameters ) { 163 if ( readParameters == null ) 164 readParameters = new GeneralOperationParameterIm[0]; 165 this.readParameters = Arrays.asList( readParameters ); 166 } 167 168 /** 169 * @param readParameter 170 */ 171 public void addReadParameter( GeneralOperationParameterIm readParameter ) { 172 this.readParameters.add( readParameter ); 173 } 174 175 /** 176 * @param vendor 177 * The vendor to set. 178 * 179 */ 180 public void setVendor( String vendor ) { 181 this.vendor = vendor; 182 } 183 184 /** 185 * @param version 186 * The version to set. 187 * 188 */ 189 public void setVersion( String version ) { 190 this.version = version; 191 } 192 193 /** 194 * @param writeParameters 195 * The writeParameters to set. 196 */ 197 public void setWriteParameters( GeneralOperationParameterIm[] writeParameters ) { 198 if ( writeParameters == null ) 199 writeParameters = new GeneralOperationParameterIm[0]; 200 this.writeParameters = Arrays.asList( writeParameters ); 201 } 202 203 /** 204 * @param writeParameter 205 */ 206 public void addWriteParameter( GeneralOperationParameterIm writeParameter ) { 207 this.readParameters.add( writeParameter ); 208 } 209 210 /** 211 * Name of the file format. 212 * 213 * @return the name of the file format. 214 * 215 */ 216 public String getName() { 217 return name; 218 } 219 220 /** 221 * Description of the file format. If no description, the value will be <code>null</code>. 222 * 223 * @return the description of the file format. 224 */ 225 public String getDescription() { 226 return description; 227 } 228 229 /** 230 * Vendor or agency for the format. 231 * 232 * @return the vendor or agency for the format. 233 */ 234 public String getVendor() { 235 return vendor; 236 } 237 238 /** 239 * Documentation URL for the format. 240 * 241 * @return the documentation URL for the format. 242 */ 243 public String getDocURL() { 244 return docURL; 245 } 246 247 /** 248 * Version number of the format. 249 * 250 * @return the version number of the format. 251 */ 252 public String getVersion() { 253 return version; 254 } 255 256 /** 257 * Retrieve the parameter information for a 258 * {@link "org.opengis.coverage.grid.GridCoverageReader#read" read} operation. 259 */ 260 public GeneralOperationParameterIm[] getReadParameters() { 261 GeneralOperationParameterIm[] rp = new GeneralOperationParameterIm[readParameters.size()]; 262 return readParameters.toArray( rp ); 263 } 264 265 /** 266 * Retrieve the parameter information for a org.opengis.coverage.grid.GridCoverageWriter#write 267 * operation. 268 * 269 * @return 270 * 271 */ 272 public GeneralOperationParameterIm[] getWriteParameters() { 273 GeneralOperationParameterIm[] rp = new GeneralOperationParameterIm[writeParameters.size()]; 274 return writeParameters.toArray( rp ); 275 } 276 277 /** 278 * performs a test if the passed Object is equal to this Format. Two Formats are equal if their 279 * names ar equal and (if not null) their vendors and versions are equal. 280 * 281 * @see java.lang.Object#equals(java.lang.Object) 282 * @param obj 283 * object to compare 284 */ 285 public boolean equals( Object obj ) { 286 if ( obj == null || !( obj instanceof Format ) ) { 287 return false; 288 } 289 Format other = (Format) obj; 290 boolean eq = this.getName().equals( other.getName() ); 291 if ( getVendor() != null && other.getVendor() != null ) { 292 eq = eq && getVendor().equals( other.getVendor() ); 293 } else if ( getVendor() == null && other.getVendor() != null ) { 294 return false; 295 } else if ( getVendor() != null && other.getVendor() == null ) { 296 return false; 297 } 298 if ( getVersion() != null && other.getVersion() != null ) { 299 eq = eq && getVersion().equals( other.getVersion() ); 300 } else if ( getVersion() == null && other.getVersion() != null ) { 301 return false; 302 } else if ( getVersion() != null && other.getVersion() == null ) { 303 return false; 304 } 305 return eq; 306 } 307 308 }