View Javadoc
1 /* 2 * SetValueCfg.java 3 * Created on September 20, 2003 4 * 5 * The Blues Framework - A lightweight application framework 6 * Copyright (C) 2003 Lonnie Pryor 7 * http://blues.lonniepryor.com 8 * 9 * This library is free software; you can redistribute it and/or modify it under the 10 * terms of the GNU Lesser General Public License as published by the Free Software 11 * Foundation; either version 2.1 of the License, or (at your option) any later 12 * version. 13 * 14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY 15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 16 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License along 19 * with this library; if not, write to: 20 * 21 * The Free Software Foundation, Inc. 22 * 59 Temple Place, Suite 330 23 * Boston, MA 02111-1307 USA 24 * 25 */ 26 package com.lonniepryor.blues.cfg; 27 28 import com.lonniepryor.blues.util.BeanHelper; 29 30 /*** 31 * Child element for setting java beans properties to a basic value. 32 * 33 * @author Lonnie Pryor 34 * @version $Revision: 1.1 $ 35 */ 36 public class SetValueCfg implements SetCfg, Verifiable { 37 /*** The name of the property to set. */ 38 private String property; 39 /*** The value of the property. */ 40 private String value; 41 42 /*** 43 * Creates a new SetValueCfg object. 44 */ 45 public SetValueCfg () { 46 } 47 48 /*** 49 * Sets the name of the property to set. 50 * 51 * @param property The name of the property to set. 52 */ 53 public void setProperty (String property) { 54 this.property = property; 55 } 56 57 /*** 58 * Sets the value of the property. 59 * 60 * @param value The value of the property. 61 */ 62 public void setValue (String value) { 63 this.value = value; 64 } 65 66 /* (non-Javadoc) 67 * @see com.lonniepryor.blues.cfg.Verifiable#verify() 68 */ 69 public void verify () { 70 if (property == null) 71 throw new IllegalStateException("No property name specified"); 72 if (property.length() == 0) 73 throw new IllegalStateException("Illegal empty property name"); 74 if (value == null) 75 throw new IllegalStateException("No property value specified"); 76 } 77 78 /* (non-Javadoc) 79 * @see com.lonniepryor.blues.cfg.SetCfg#configure( 80 * com.lonniepryor.blues.util.BeanHelper, java.lang.Object) 81 */ 82 public void configure ( 83 BeanHelper helper, Object beanInstance, Directory serviceDirectory) { 84 if (helper == null) 85 throw new NullPointerException("Bean helper cannot be null"); 86 if (beanInstance == null) 87 throw new NullPointerException("Bean instance cannot be null"); 88 if (!helper.setPropertyAsString(beanInstance, property, value)) 89 throw new IllegalStateException( 90 "Cannot set property '" + property + "' on " + beanInstance.getClass() 91 + " to value '" + value + "'"); 92 } 93 }

This page was automatically generated by Maven