001/* 002 * Copyright (c) 2003-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.objectmanager.data; 031 032import java.util.Vector; 033 034import org.kepler.objectmanager.data.db.DSTableFieldIFace; 035 036/** 037 * This object represents an DataObjectDescription. A DataObjectDescription 038 * stores information about a DataItem that is used in a Step in the pipeline. 039 */ 040public class DataObjectDescription implements DSTableFieldIFace { 041 protected String id; 042 protected String name; 043 protected String dataType; 044 protected String definition; 045 protected Vector missingValueCode = new Vector(); 046 047 /** 048 * Construct a DataObjectDescription. 049 */ 050 public DataObjectDescription(String id, String name, String dataType) { 051 this(id, name, dataType, null); 052 } 053 054 /** 055 * Construct a DataObjectDescription with a description. 056 */ 057 public DataObjectDescription(String id, String name, String dataType, 058 String definition) { 059 if (id == null) { 060 this.id = ""; 061 } else { 062 this.id = id; 063 } 064 if (name == null) { 065 this.name = ""; 066 } else { 067 this.name = name.trim(); 068 } 069 if (dataType == null) { 070 this.dataType = ""; 071 } else { 072 this.dataType = dataType; 073 } 074 if (definition == null) { 075 this.definition = ""; 076 } else { 077 this.definition = definition; 078 } 079 } 080 081 /** 082 * Return the unique ID for this data item. It is unique within the scope of 083 * the Step in which it is described. 084 */ 085 public String getId() { 086 return this.id; 087 } 088 089 /** 090 * Return the name for this data item. 091 */ 092 public String getName() { 093 return this.name; 094 } 095 096 /** 097 * Return the data type for this data item. 098 */ 099 public String getDataType() { 100 return this.dataType; 101 } 102 103 /** 104 * Return the definition for this data item. 105 */ 106 public String getDefinition() { 107 return this.definition; 108 } 109 110 /** 111 * returns true if all of the fields of didesc are equal to the fields of 112 * this object. 113 */ 114 public boolean equals(DataObjectDescription didesc) { 115 if (didesc.getId().trim().equals(this.id.trim()) 116 && didesc.getName().trim().equals(this.name.trim()) 117 && didesc.getDataType().trim().equals(this.dataType.trim()) 118 && didesc.getDefinition().trim().equals(this.definition.trim())) { 119 return true; 120 } 121 122 return false; 123 } 124 125 /** 126 * Set the identifier for this data item. 127 */ 128 public void setId(String id) { 129 this.id = id; 130 } 131 132 /** 133 * Set the name for this data item. 134 */ 135 public void setName(String name) { 136 this.name = name; 137 } 138 139 /** 140 * Set the type for this data item. 141 */ 142 public void setDataType(String dataType) { 143 this.dataType = dataType; 144 } 145 146 /** 147 * Set the definition for this data item. 148 */ 149 public void setDefinition(String definition) { 150 this.definition = definition; 151 } 152 153 /** 154 * Produce a string view of the item, just the name. 155 */ 156 public String toString() { 157 return name; 158 } 159 160 /** 161 * Method to add missing value code into a vector. This method will be used 162 * to store the missing value code in metadata 163 * 164 * @param code 165 */ 166 public void addMissingValueCode(String code) { 167 if (code != null) { 168 missingValueCode.add(code); 169 } 170 } 171 172 /** 173 * Method to return the vector which store the missing value code. If this 174 * attribute doesn't has the missing value code, empty vector will be 175 * returned. 176 * 177 * */ 178 public Vector getMissingValueCode() { 179 return missingValueCode; 180 } 181 182 /** 183 * Method to return the vector which store the missing value code. If this 184 * attribute doesn't has the missing value code, empty vector will be 185 * returned. 186 * 187 * */ 188 public void setMissingValueCode(Vector missingValueVector) { 189 missingValueCode = missingValueVector; 190 } 191 192 /** 193 * Utility for writing out XML elements 194 * 195 * @param StringBuffer 196 * the buffer to write to 197 * @param the 198 * name of the element to create 199 * @param the 200 * value for the element 201 */ 202 protected static void appendElement(StringBuffer x, String name, 203 String value) { 204 x.append("<"); 205 x.append(name); 206 x.append(">"); 207 x.append(value); 208 x.append("</"); 209 x.append(name); 210 x.append(">\n"); 211 } 212 213}