/* ====================================================================
* The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
*
* Copyright (c) 1995-2003 Jcorporate Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by Jcorporate Ltd.
* (http://www.jcorporate.com/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. "Jcorporate" and product names such as "Expresso" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written permission,
* please contact info@jcorporate.com.
*
* 5. Products derived from this software may not be called "Expresso",
* or other Jcorporate product names; nor may "Expresso" or other
* Jcorporate product names appear in their name, without prior
* written permission of Jcorporate Ltd.
*
* 6. No product derived from this software may compete in the same
* market space, i.e. framework, without prior written permission
* of Jcorporate Ltd. For written permission, please contact
* partners@jcorporate.com.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jcorporate Ltd. Contributions back
* to the project(s) are encouraged when you make modifications.
* Please send them to support@jcorporate.com. For more information
* on Jcorporate Ltd. and its products, please see
* <http://www.jcorporate.com/>.
*
* Portions of this software are based upon other open source
* products and are subject to their respective licenses.
*/
package com.jcorporate.expresso.kernel.metadata;
import com.jcorporate.expresso.core.dbobj.ValidValue;
import com.jcorporate.expresso.kernel.Configuration;
import com.jcorporate.expresso.kernel.digester.ComponentConfig;
import com.jcorporate.expresso.kernel.internal.DefaultConfigBean;
import com.jcorporate.expresso.kernel.util.ClassLocator;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
/**
* Metadata class that represents a simple property for an Expresso component
*
* @author Michael Rimov
* @version $Revision: 1.6 $ on $Date: 2004/11/17 20:48:17 $
*/
public class SimpleProperty extends Property {
List validValues;
String value;
/**
* Default Constructor
*/
public SimpleProperty() {
super();
validValues = new ArrayList();
}
/**
* Set the value of the property
*
* @param value java.lang.String
*/
public void setValue(String value) {
this.value = value;
}
/**
* Retrieve the value of the property
*
* @return java.lang.String
*/
public String getValue() {
return value;
}
/**
* Add a valid value for the property
*
* @param key the 'key' or internal value
* @param value the friendly value to be displayed in management systems.
*/
public void addValidValue(String key, String value) {
ValidValue vv = new ValidValue(key, value);
validValues.add(vv);
}
/**
* Retrieve a list of valid values for this particular property.
*
* @return List of valid value objects
*/
public List retrieveValidValues() {
return validValues;
}
/**
* Load the configBean with values for this property.
* If there are any values present in the ComponentConfig, then use those properties,
* if empty, use your own default values as specified in the ComponentMetadata
*
* @param targetBean The configBean to populate with this property.
* @param config the current configuration as loaded from the expresso config.xml file
* @param metadata the current metadata for this component
* @return the Configuration interface (actually uslaly the configbean parameter)
*/
public Configuration createConfigBean(DefaultConfigBean targetBean,
ComponentConfig config,
ComponentMetadata metadata) {
String newValue = config.getProperty(this.getName());
if (newValue == null || newValue.length() == 0) {
newValue = this.getValue();
}
String type = this.getType();
try {
targetBean.set(this.getName(), ConvertUtils.convert(newValue, ClassLocator.loadClass(type)));
} catch (ClassNotFoundException ex) {
Logger log = Logger.getLogger(this.getClass());
log.error("Error converting value " + value
+ " to class : " + type + " class not found.", ex);
throw new IllegalArgumentException("Class not found: " + type);
}
return targetBean;
}
}
|