001 /*
002 * $Id: ParameterSet.java,v 1.4 2012/02/19 17:35:53 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;
032
033
034 import org.w3c.dom.*;
035
036 import java.util.ArrayList;
037 import java.util.List;
038
039 import ucar.unidata.util.StringUtil;
040
041
042 /**
043 * An object to handle a saved parameter set.
044 */
045 public class ParameterSet {
046
047 /** Xml attribute name for the name */
048 public static final String ATTR_NAME = "name";
049
050 /** Xml attribute name for the category */
051 public static final String ATTR_CATEGORY = "category";
052
053 /** The name of the parameter set */
054 private String name;
055
056 /** The category of the parameter set */
057 private List<String> categories;
058
059 /** The type */
060 private String type;
061
062 /** The XML element */
063 private Element element;
064
065 /** prefix_ */
066 private String uniquePrefix;
067
068 public ParameterSet(String name, String category, String type) {
069 this(name, category, type, null);
070 }
071
072 public ParameterSet(String name, List<String> categories, String type) {
073 this(name, categories, type, null);
074 }
075
076 public ParameterSet(String name, String category, String type, Element element) {
077 List<String> categories = PersistenceManager.stringToCategories(category);
078 this.name = name;
079 this.categories = categories;
080 this.type = type;
081 this.element = element;
082 }
083
084 public ParameterSet(String name, List<String>categories, String type, Element element) {
085 this.name = name;
086 this.categories = categories;
087 this.type = type;
088 this.element = element;
089 }
090
091 /**
092 * set the unique prefix
093 *
094 * @param p prefix
095 */
096 protected void setUniquePrefix(String p) {
097 uniquePrefix = p;
098 }
099
100 /**
101 * Get the name to use with the categories as a prefix
102 *
103 * @return categorized name
104 */
105 public String getCategorizedName() {
106 String catString = StringUtil.join("_", categories);
107 if (uniquePrefix != null) {
108 catString = uniquePrefix + catString;
109 }
110 return catString + name;
111 }
112
113 /**
114 * Set the Name property.
115 *
116 * @param value The new value for Name
117 */
118 public void setName(String value) {
119 name = value;
120 }
121
122 /**
123 * Get the Name property.
124 *
125 * @return The Name
126 */
127 public String getName() {
128 return name;
129 }
130
131
132 /**
133 * Set the Category property.
134 *
135 * @param value The new value for Category
136 */
137 public void setCategories(List value) {
138 categories = value;
139 }
140
141 /**
142 * Get the Category property.
143 *
144 * @return The Category
145 */
146 public List getCategories() {
147 return categories;
148 }
149
150 /**
151 * Set the Type property.
152 *
153 * @param value The new value for Type
154 */
155 public void setType(String value) {
156 type = value;
157 }
158
159 /**
160 * Get the Type property.
161 *
162 * @return The Type
163 */
164 public String getType() {
165 return type;
166 }
167
168 /**
169 * Set the Element property.
170 *
171 * @param value The new value for Element
172 */
173 public void setElement(Element value) {
174 element = value;
175 }
176
177 /**
178 * Get the Element property.
179 *
180 * @return The Element
181 */
182 public Element getElement() {
183 return element;
184 }
185
186 /**
187 * Full label
188 *
189 * @return The name.
190 */
191 public String getLabel() {
192 return PersistenceManager.categoriesToString(categories)
193 + PersistenceManager.CATEGORY_SEPARATOR + name;
194 }
195
196 /**
197 * Override toString.
198 *
199 * @return The name.
200 */
201 public String toString() {
202 // String description = name + " { ";
203 // NamedNodeMap attributes = element.getAttributes();
204 // for (int i=0; i<attributes.getLength(); i++) {
205 // Node attribute = attributes.item(i);
206 // description += attribute.getNodeName() + "=" + attribute.getNodeValue();
207 // if (i < attributes.getLength() - 1) description += ", ";
208 // }
209 // description += "}";
210 // return description;
211 return name;
212 }
213
214 }
215