/*
* 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.base.conf.impl;
import java.util.ArrayList;
import java.util.Iterator;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.conf.FeatureConfig;
import de.odysseus.calyxo.base.conf.FeaturesConfig;
import de.odysseus.calyxo.base.conf.MethodConfig;
import de.odysseus.calyxo.base.conf.PropertyConfig;
/**
* Features configuration implementation.
*
* @author Christoph Beck
*/
public abstract class FeaturesConfigImpl extends ConfigImpl implements FeaturesConfig {
private ArrayList features = new ArrayList();
/* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_addChildren(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Elements)
*/
protected void _addChildren(Elements elements) {
super._addChildren(elements);
elements.add(features.iterator());
}
/**
* Apply features (call methods and set properties)
*/
protected void apply(Object value, ClassLoader loader) throws ConfigException {
Iterator features = getFeatureConfigs();
while (features.hasNext()) {
FeatureConfig feature = (FeatureConfig)features.next();
if (feature instanceof MethodConfig) {
((MethodConfig)feature).invoke(value.getClass(), value, loader);
} else if (feature instanceof PropertyConfig) {
((PropertyConfig)feature).set(value, loader);
}
}
}
/**
* Add property configuration
*/
public void add(PropertyConfigImpl value) throws ConfigException {
features.add(value);
}
/**
* Add method configuration
*/
public void add(MethodConfigImpl value) throws ConfigException {
features.add(value);
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.FeaturesConfig#getFeatureConfigs()
*/
public Iterator getFeatureConfigs() {
return features.iterator();
}
}