/*
* 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;
import de.odysseus.calyxo.base.conf.MethodConfig;
import de.odysseus.calyxo.base.conf.MemberConfig;
/**
* Member configuration implementation.
*
* @author Christoph Beck
*/
public class MemberConfigImpl extends ConfigImpl implements MemberConfig {
private Object value;
private String className;
private MethodConfig method;
private FieldConfig field;
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getElementName()
*/
protected String _getElementName() {
return "member";
}
/* (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(method);
elements.add(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("value", value);
}
/**
* Answer array <code>{ "value", "className" }</code>.
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getDynamicAttributes()
*/
protected String[] _getDynamicAttributes() {
return new String[]{ "value", "className" };
}
/* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.MemberConfig#get()
*/
public Object get(ClassLoader loader) throws ConfigException {
Class clazz = null;
if (className != null) {
try {
clazz = loader.loadClass(className);
} catch (Exception e) {
throw new ConfigException("Could not get class in " + toInlineString(), e);
}
} else if (value != null) {
clazz = value.getClass();
} else {
throw new ConfigException("Cannot get member from null in " + toInlineString());
}
if (method != null) {
return method.invoke(clazz, value, loader);
} else {
return field.get(clazz, value);
}
}
/**
* Get value property
*/
public Object getValue() {
return value;
}
/**
* Set value property
*/
public void setValue(Object value) {
this.value = value;
}
/**
* Get className property
*/
public String getClassName() {
return className;
}
/**
* Set className property
*/
public void setClassName(String className) {
this.className = className;
}
/**
* Get method configuration
*/
public MethodConfig getMethodConfig() {
return method;
}
/**
* Set method configuration
*/
public void setMethodConfig(MethodConfig value) {
method = value;
}
/**
* Get field configuration
*/
public FieldConfig getFieldConfig() {
return field;
}
/**
* Set field configuration
*/
public void setFieldConfig(FieldConfig field) {
this.field = field;
}
}