001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/datatypes/CodeList.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 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: package org.deegree.datatypes;
044:
045: import java.io.Serializable;
046: import java.net.URI;
047: import java.util.ArrayList;
048: import java.util.Arrays;
049: import java.util.List;
050:
051: /**
052: *
053: *
054: * @version $Revision: 9337 $
055: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
056: * @author last edited by: $Author: apoth $
057: *
058: * @version 1.0. $Revision: 9337 $, $Date: 2007-12-27 04:31:11 -0800 (Thu, 27 Dec 2007) $
059: *
060: * @since 2.0
061: */
062: public class CodeList implements Serializable {
063:
064: /**
065: *
066: */
067: private static final long serialVersionUID = 1L;
068:
069: private URI codeSpace = null;
070:
071: private String name = null;
072:
073: private List<String> codes = new ArrayList<String>();
074:
075: /**
076: * @param name
077: * @param codes
078: */
079: public CodeList(String name, String[] codes) {
080: this (name, codes, null);
081: }
082:
083: /**
084: * @param name
085: * @param codes
086: * @param codeSpace
087: */
088: public CodeList(String name, String[] codes, URI codeSpace) {
089: setName(name);
090: setCodes(codes);
091: setCodeSpace(codeSpace);
092: }
093:
094: /**
095: * @return Returns the name.
096: *
097: */
098: public String getName() {
099: return name;
100: }
101:
102: /**
103: * @param name
104: * The name to set.
105: *
106: */
107: public void setName(String name) {
108: this .name = name;
109: }
110:
111: /**
112: * @return Returns the codeSpace.
113: *
114: */
115: public URI getCodeSpace() {
116: return codeSpace;
117: }
118:
119: /**
120: * @param codeSpace
121: * The codeSpace to set.
122: *
123: */
124: public void setCodeSpace(URI codeSpace) {
125: this .codeSpace = codeSpace;
126: }
127:
128: /**
129: * @return Returns the codes.
130: *
131: */
132: public String[] getCodes() {
133: return codes.toArray(new String[codes.size()]);
134: }
135:
136: /**
137: * @param codes
138: * The codes to set.
139: */
140: public void setCodes(String[] codes) {
141: this .codes = Arrays.asList(codes);
142: }
143:
144: /**
145: * @param code
146: * The code to add
147: */
148: public void addCode(String code) {
149: codes.add(code);
150: }
151:
152: /**
153: * @param code
154: * The code to remove
155: */
156: public void removeCode(String code) {
157: codes.remove(code);
158: }
159:
160: /**
161: * returns true if a CodeList contains the passed codeSpace-value combination. Otherwise false
162: * will be returned
163: *
164: * @param value
165: * @return true if a CodeList contains the passed codeSpace-value combination. Otherwise false
166: * will be returned
167: */
168: public boolean validate(String codeSpace, String value) {
169: String[] codes = getCodes();
170: URI space = getCodeSpace();
171: String csp = null;
172: if (space != null) {
173: csp = space.toString();
174: }
175: for (int j = 0; j < codes.length; j++) {
176: if ((csp != null && csp.equals(codeSpace))
177: || (csp == null && codeSpace == null)
178: && codes[j].equals(value)) {
179: return true;
180: }
181: }
182: return false;
183: }
184:
185: }
|