/*
* 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 de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.conf.FieldConfig;
/**
* Method configuration implementation.
*
* @author Christoph Beck
*/
public class FieldConfigImpl extends ConfigImpl implements FieldConfig {
private String name;
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getElementName()
*/
protected String _getElementName() {
return "field";
}
/*
* (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);
map.put("name", name);
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.FieldConfig#get(java.lang.Class, java.lang.Object)
*/
public Object get(Class clazz, Object object) throws ConfigException {
if (clazz == null) {
if (object == null) {
throw new ConfigException("Cannot get field from null in " + toInlineString());
}
clazz = object.getClass();
} else if (object != null && !clazz.isInstance(object)) {
throw new ConfigException("Specified object is not an instance of " + clazz.getName() + " in " + toInlineString());
}
try {
return clazz.getField(name).get(object);
} catch (Exception e) {
throw new ConfigException("Could not access field in " + toInlineString(), e);
}
}
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}
}