001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.daemon.configuration;
027:
028: import com.sshtools.j2ssh.configuration.ConfigurationContext;
029: import com.sshtools.j2ssh.configuration.ConfigurationException;
030: import com.sshtools.j2ssh.configuration.ConfigurationLoader;
031:
032: import java.util.HashMap;
033:
034: /**
035: *
036: *
037: * @author $author$
038: * @version $Revision: 1.13 $
039: */
040: public class XmlServerConfigurationContext implements
041: ConfigurationContext {
042: HashMap configurations = new HashMap();
043: String serverResource = null;
044: String platformResource = null;
045: boolean failOnError = true;
046:
047: /**
048: * Creates a new XmlServerConfigurationContext object.
049: */
050: public XmlServerConfigurationContext() {
051: }
052:
053: /**
054: *
055: *
056: * @param serverResource
057: */
058: public void setServerConfigurationResource(String serverResource) {
059: this .serverResource = serverResource;
060: }
061:
062: /**
063: *
064: *
065: * @param platformResource
066: */
067: public void setPlatformConfigurationResource(String platformResource) {
068: this .platformResource = platformResource;
069: }
070:
071: /**
072: *
073: *
074: * @param failOnError
075: */
076: public void setFailOnError(boolean failOnError) {
077: this .failOnError = failOnError;
078: }
079:
080: /**
081: *
082: *
083: * @throws ConfigurationException
084: */
085: public void initialize() throws ConfigurationException {
086: if (serverResource != null) {
087: try {
088: ServerConfiguration y = new ServerConfiguration(
089: ConfigurationLoader.loadFile(serverResource));
090: configurations.put(ServerConfiguration.class, y);
091: } catch (Exception ex) {
092: if (failOnError) {
093: throw new ConfigurationException(ex.getMessage());
094: }
095: }
096: }
097:
098: if (platformResource != null) {
099: try {
100: PlatformConfiguration z = new PlatformConfiguration(
101: ConfigurationLoader.loadFile(platformResource));
102: configurations.put(PlatformConfiguration.class, z);
103: } catch (Exception ex) {
104: if (failOnError) {
105: throw new ConfigurationException(ex.getMessage());
106: }
107: }
108: }
109: }
110:
111: /**
112: *
113: *
114: * @param cls
115: *
116: * @return
117: */
118: public boolean isConfigurationAvailable(Class cls) {
119: return configurations.containsKey(cls);
120: }
121:
122: /**
123: *
124: *
125: * @param cls
126: *
127: * @return
128: *
129: * @throws ConfigurationException
130: */
131: public Object getConfiguration(Class cls)
132: throws ConfigurationException {
133: if (configurations.containsKey(cls)) {
134: return configurations.get(cls);
135: } else {
136: throw new ConfigurationException(cls.getName()
137: + " configuration not available");
138: }
139: }
140: }
|