/*
* 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.ActionConfig;
import de.odysseus.calyxo.control.conf.ActionsConfig;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.conf.impl.ConfigImpl;
/**
* Actions configuration implementation.
*
* @author Christoph Beck
*/
public class ActionsConfigImpl extends ConfigImpl implements ActionsConfig {
private HashMap actions = new HashMap();
/**
* Merge other actions configuration into receiver.
* Adds all actions form other actions element.
*/
void merge(ActionsConfigImpl other) throws ConfigException {
if (other != null) {
Iterator otherActions = other.getActionConfigs();
while (otherActions.hasNext()) {
add((ActionConfigImpl)otherActions.next());
}
}
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getElementName()
*/
protected String _getElementName() {
return "actions";
}
/*
* (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(getActionConfigs());
}
/*
* (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 action.
* @exception ConfigException if an action with same path already exists
*/
public void add(ActionConfigImpl action) throws ConfigException {
if (actions.containsKey(action.getPath())) {
throw new ConfigException("Duplicate action path '" + action.getPath() + "' in " + toInlineString());
}
actions.put(action.getPath(), action);
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.control.conf.ActionsConfig#getActionConfig(java.lang.String)
*/
public ActionConfig getActionConfig(String path) {
return (ActionConfig)actions.get(path);
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.control.conf.ActionsConfig#getActionConfigs()
*/
public Iterator getActionConfigs() {
return actions.values().iterator();
}
}