/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.odysseus.calyxo.control.conf.impl;
import java.util.HashMap;
import java.util.Iterator;
import de.odysseus.calyxo.control.conf.DispatchConfig;
import de.odysseus.calyxo.control.conf.DispatchesConfig;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.conf.impl.ConfigImpl;
/**
* Dispatches configuration implementation.
*
* @author Christoph Beck
*/
public class DispatchesConfigImpl extends ConfigImpl implements DispatchesConfig {
private HashMap dispatches = new HashMap();
/**
* Merge other dispatches element into the receiver.
* Add all dispatch configs from other element.
*/
void merge(DispatchesConfigImpl other) throws ConfigException {
if (other != null) {
Iterator otherDispatches = other.getDispatchConfigs();
while (otherDispatches.hasNext()) {
add((DispatchConfigImpl)otherDispatches.next());
}
}
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getElementName()
*/
protected String _getElementName() {
return "dispatches";
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_addChildren(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Elements)
*/
protected void _addChildren(Elements list) {
super._addChildren(list);
list.add(getDispatchConfigs());
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_putAttributes(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Attributes)
*/
protected void _putAttributes(Attributes map) {
super._putAttributes(map);
// no attributes
}
/**
* Add dispatch element.
*/
public void add(DispatchConfigImpl value) throws ConfigException {
if (dispatches.containsKey(value.getName())) {
throw new ConfigException("Duplicate dispatch name '" + value.getName() + "' in " + toInlineString());
}
dispatches.put(value.getName(), value);
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.control.conf.DispatchesConfig#getDispatchConfig(java.lang.String)
*/
public DispatchConfig getDispatchConfig(String name) {
return (DispatchConfig)dispatches.get(name);
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.control.conf.DispatchesConfig#getDispatchConfigs()
*/
public Iterator getDispatchConfigs() {
return dispatches.values().iterator();
}
}