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 jeeves.resources.dbms.Dbms;
027:
028: //=============================================================================
029:
030: class Task {
031: //---------------------------------------------------------------------------
032: //---
033: //--- Constructor
034: //---
035: //---------------------------------------------------------------------------
036:
037: public Task(Dbms dbms, Type type, Setting s) {
038: this .dbms = dbms;
039: this .type = type;
040: this .setting = s;
041: }
042:
043: //---------------------------------------------------------------------------
044: //---
045: //--- Static API methods
046: //---
047: //---------------------------------------------------------------------------
048:
049: public static Task getNameChangedTask(Dbms dbms, Setting s,
050: String name) {
051: Task task = new Task(dbms, Type.NAME_CHANGED, s);
052: task.name = name;
053:
054: return task;
055: }
056:
057: //---------------------------------------------------------------------------
058:
059: public static Task getValueChangedTask(Dbms dbms, Setting s,
060: String value) {
061: Task task = new Task(dbms, Type.VALUE_CHANGED, s);
062: task.value = value;
063:
064: return task;
065: }
066:
067: //---------------------------------------------------------------------------
068:
069: public static Task getAddedTask(Dbms dbms, Setting parent,
070: Setting child) {
071: Task task = new Task(dbms, Type.ADDED, child);
072: task.parent = parent;
073:
074: return task;
075: }
076:
077: //---------------------------------------------------------------------------
078:
079: public static Task getRemovedTask(Dbms dbms, Setting s) {
080: return new Task(dbms, Type.REMOVED, s);
081: }
082:
083: //---------------------------------------------------------------------------
084: //---
085: //--- API methods
086: //---
087: //---------------------------------------------------------------------------
088:
089: public boolean matches(Object resource) {
090: return (dbms == resource);
091: }
092:
093: //---------------------------------------------------------------------------
094:
095: public Setting getAddedSetting(Dbms dbms, int id) {
096: if (type == Type.ADDED && dbms == this .dbms
097: && setting.getId() == id)
098: return setting;
099:
100: return null;
101: }
102:
103: //---------------------------------------------------------------------------
104:
105: public void commit() {
106: switch (type) {
107: case NAME_CHANGED:
108: setting.setName(name);
109: break;
110:
111: case VALUE_CHANGED:
112: setting.setValue(value);
113: break;
114:
115: case ADDED:
116: parent.addChild(setting);
117: break;
118:
119: case REMOVED:
120: setting.removeFromParent();
121: break;
122: }
123: }
124:
125: //---------------------------------------------------------------------------
126: //---
127: //--- Vars
128: //---
129: //---------------------------------------------------------------------------
130:
131: private enum Type {
132: NAME_CHANGED, VALUE_CHANGED, ADDED, REMOVED
133: }
134:
135: private Dbms dbms;
136: private Type type;
137: private Setting setting;
138: private Setting parent;
139: private String name;
140: private String value;
141: }
142:
143: //=============================================================================
|