001: //=============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.geonet.kernel.setting;
025:
026: import java.util.ArrayList;
027: import java.util.Iterator;
028: import java.util.List;
029:
030: //=============================================================================
031:
032: class Setting {
033: //---------------------------------------------------------------------------
034: //---
035: //--- Constructor
036: //---
037: //---------------------------------------------------------------------------
038:
039: public Setting(int id, String name, String value) {
040: this .id = id;
041: this .name = name;
042: this .value = value;
043: }
044:
045: //---------------------------------------------------------------------------
046: //---
047: //--- API methods
048: //---
049: //---------------------------------------------------------------------------
050:
051: public Setting getParent() {
052: return parent;
053: }
054:
055: public int getId() {
056: return id;
057: }
058:
059: public String getName() {
060: return name;
061: }
062:
063: public String getValue() {
064: return value;
065: }
066:
067: public void setName(String name) {
068: this .name = name;
069: }
070:
071: public void setValue(String value) {
072: this .value = value;
073: }
074:
075: //---------------------------------------------------------------------------
076:
077: public Iterable<Setting> getChildren() {
078: return children;
079: }
080:
081: //---------------------------------------------------------------------------
082:
083: public Setting getChild(String name) {
084: Iterator<Setting> i = getChildren(name).iterator();
085:
086: if (!i.hasNext())
087: return null;
088: else
089: return i.next();
090: }
091:
092: //---------------------------------------------------------------------------
093:
094: public Iterable<Setting> getChildren(String name) {
095: ArrayList<Setting> list = new ArrayList<Setting>();
096:
097: for (Setting s : children)
098: if (name == null || name.equals(s.getName()))
099: list.add(s);
100:
101: return list;
102: }
103:
104: //---------------------------------------------------------------------------
105:
106: public void addChild(Setting s) {
107: s.parent = this ;
108:
109: children.add(s);
110: }
111:
112: //---------------------------------------------------------------------------
113:
114: public void removeFromParent() {
115: parent.children.remove(this );
116: }
117:
118: //---------------------------------------------------------------------------
119: //---
120: //--- Vars
121: //---
122: //---------------------------------------------------------------------------
123:
124: private int id;
125: private String name;
126: private String value;
127: private Setting parent;
128:
129: private List<Setting> children = new ArrayList<Setting>();
130: }
131:
132: //=============================================================================
|