001: /*
002: Copyright (C) 2004 David Bucciarelli (davibu@interfree.it)
003:
004: This program is free software; you can redistribute it and/or
005: modify it under the terms of the GNU General Public License
006: as published by the Free Software Foundation; either version 2
007: of the License, or (at your option) any later version.
008:
009: This program is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: GNU General Public License for more details.
013:
014: You should have received a copy of the GNU General Public License
015: along with this program; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: */
018:
019: package org.homedns.dade.jcgrid;
020:
021: import java.io.*;
022: import java.util.*;
023:
024: import org.homedns.dade.jcgrid.server.*;
025:
026: public abstract class GridNodeConfig implements Cloneable {
027: public final static String TYPE_WORKER = "WORKER";
028: public final static String TYPE_CLIENT = "CLIENT";
029: public final static String TYPE_ADMIN = "ADMIN";
030: public final static String TYPE_SERVER = "SERVER";
031:
032: private GridConfig gCfg;
033:
034: private String nodeType;
035: private String workingDir;
036:
037: public GridNodeConfig(Properties prop) {
038: gCfg = new GridConfig(prop);
039:
040: nodeType = prop.getProperty("grid.node.type", TYPE_CLIENT);
041: workingDir = prop.getProperty("grid.node.workingdir", System
042: .getProperty("user.dir")
043: + File.separator + "cache");
044: }
045:
046: public GridNodeConfig(String type) {
047: gCfg = new GridConfig();
048:
049: nodeType = type;
050: workingDir = System.getProperty("user.dir") + File.separator
051: + "cache";
052: }
053:
054: public Object clone() {
055: try {
056: GridNodeConfig cfg = (GridNodeConfig) super .clone();
057: cfg.gCfg = gCfg;
058:
059: cfg.nodeType = nodeType;
060: cfg.workingDir = workingDir;
061:
062: return cfg;
063: } catch (CloneNotSupportedException e) {
064: throw new InternalError(e.toString());
065: }
066: }
067:
068: public Properties toProperties() {
069: Properties prop = gCfg.toProperties();
070:
071: prop.put("grid.node.type", nodeType);
072: prop.put("grid.node.workingdir", workingDir);
073:
074: return prop;
075: }
076:
077: //------------------------------- Get & Set --------------------------------
078:
079: public GridConfig getGridConfig() {
080: return gCfg;
081: }
082:
083: public void setGridConfig(GridConfig cfg) {
084: gCfg = cfg;
085: }
086:
087: public String getWorkingDir() {
088: return workingDir;
089: }
090:
091: public void setWorkingDir(String dir) {
092: workingDir = dir;
093: }
094:
095: public String getType() {
096: return nodeType;
097: }
098:
099: public void setType(String type) {
100: nodeType = type;
101: }
102: }
|