001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE 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 Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixcore.webservice.config;
021:
022: import java.io.Serializable;
023: import java.util.Collection;
024: import java.util.Collections;
025: import java.util.HashMap;
026: import java.util.Iterator;
027:
028: /**
029: * Configuration.java
030: *
031: * Created: 22.07.2004
032: *
033: * @author mleidig@schlund.de
034: */
035: public class Configuration implements Serializable {
036:
037: private GlobalServiceConfig globConf;
038: private HashMap<String, ServiceConfig> srvsConf;
039:
040: public Configuration() {
041: srvsConf = new HashMap<String, ServiceConfig>();
042: }
043:
044: public GlobalServiceConfig getGlobalServiceConfig() {
045: return globConf;
046: }
047:
048: public void setGlobalServiceConfig(GlobalServiceConfig globConf) {
049: this .globConf = globConf;
050: }
051:
052: public void addServiceConfig(ServiceConfig srvConf) {
053: srvsConf.put(srvConf.getName(), srvConf);
054: }
055:
056: public ServiceConfig getServiceConfig(String name) {
057: return (ServiceConfig) srvsConf.get(name);
058: }
059:
060: public Collection<ServiceConfig> getServiceConfig() {
061: return Collections.unmodifiableCollection(srvsConf.values());
062: }
063:
064: @Override
065: public boolean equals(Object obj) {
066: if (obj instanceof Configuration) {
067: Configuration ref = (Configuration) obj;
068: if (!getGlobalServiceConfig().equals(
069: ref.getGlobalServiceConfig())) {
070: System.out.println("Global service not equal");
071: return false;
072: }
073: Iterator<ServiceConfig> it = srvsConf.values().iterator();
074: while (it.hasNext()) {
075: ServiceConfig sc = it.next();
076: ServiceConfig refSc = ref
077: .getServiceConfig(sc.getName());
078: if (refSc == null) {
079: System.out.println("Service not found: "
080: + sc.getName());
081: return false;
082: }
083: if (!sc.equals(refSc)) {
084: System.out.println("Service not equal: "
085: + sc.getName());
086: return false;
087: }
088: }
089: it = ref.srvsConf.values().iterator();
090: while (it.hasNext()) {
091: ServiceConfig refSc = it.next();
092: ServiceConfig sc = getServiceConfig(refSc.getName());
093: if (sc == null) {
094: System.out.println("Service not found: "
095: + refSc.getName());
096: return false;
097: }
098: }
099: return true;
100: }
101: return false;
102: }
103:
104: }
|