|
From: <lk...@us...> - 2004-11-20 13:11:54
|
Update of /cvsroot/openorb/OpenORB/src/main/org/openorb/orb/config In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26244/src/main/org/openorb/orb/config Modified Files: Property.java Log Message: The value of boolean properties must now be one of true, false, yes, no, on, off. Other values are no longer recognized and will lead to INITIALIZE exceptions. Index: Property.java =================================================================== RCS file: /cvsroot/openorb/OpenORB/src/main/org/openorb/orb/config/Property.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Property.java 13 May 2004 04:09:26 -0000 1.6 +++ Property.java 20 Nov 2004 13:11:44 -0000 1.7 @@ -11,9 +11,14 @@ import java.net.URL; import java.net.MalformedURLException; +import java.util.Set; +import java.util.TreeSet; + import org.openorb.util.ExceptionTool; import org.openorb.util.NumberCache; +import org.omg.CORBA.INITIALIZE; + /** * This class provides information about an OpenORB property. The class cannot * be constructed outside of the Properties class. @@ -23,25 +28,40 @@ */ public class Property { - Property( String name, String value, Properties props ) + private static final Set TRUE_SET = new TreeSet( String.CASE_INSENSITIVE_ORDER ); + private static final Set FALSE_SET = new TreeSet( String.CASE_INSENSITIVE_ORDER ); + + static + { + TRUE_SET.add( "true" ); + FALSE_SET.add( "false" ); + + TRUE_SET.add( "yes" ); + FALSE_SET.add( "no" ); + + TRUE_SET.add( "on" ); + FALSE_SET.add( "off" ); + } + + private final String m_name; + private final String m_value; + private Object m_typed; + private Properties m_props; + + Property( final String name, final String value, final Properties props ) { m_name = name; m_value = value; m_props = props; } - Property( String name, String value, Object typed ) + Property( final String name, final String value, final Object typed ) { m_name = name; m_value = value; m_typed = typed; } - private final String m_name; - private final String m_value; - private Object m_typed = null; - private Properties m_props = null; - /** * Get the property name. */ @@ -60,7 +80,7 @@ /** * Get the property value as an integer. - * @throws org.omg.CORBA.INITIALIZE the property value cannot be parsed as an int. + * @throws INITIALIZE the property value cannot be parsed as an int. */ public int getIntValue() { @@ -97,7 +117,7 @@ } catch ( final NumberFormatException ex ) { - throw ExceptionTool.initCause( new org.omg.CORBA.INITIALIZE( + throw ExceptionTool.initCause( new INITIALIZE( "The property value \"" + m_name + "\" cannot be parsed as an integer (" + ex + ")" ), ex ); } @@ -107,8 +127,8 @@ } /** - * Get the property value as a boolean. Property values of false or no are - * parsed as false, all other values are parsed as true. + * Get the property value as a boolean. + * @throws INITIALIZE the property value cannot be parsed as a boolean. */ public boolean getBooleanValue() { @@ -116,16 +136,24 @@ { return ( ( Boolean ) m_typed ).booleanValue(); } - boolean ret = !( m_value.equalsIgnoreCase( "false" ) || m_value.equalsIgnoreCase( "no" ) ); - - m_typed = ret ? Boolean.TRUE : Boolean.FALSE; - return ret; + if ( TRUE_SET.contains( m_value ) ) + { + m_typed = Boolean.TRUE; + return true; + } + else if ( FALSE_SET.contains( m_value ) ) + { + m_typed = Boolean.FALSE; + return false; + } + throw new INITIALIZE( "The property value \"" + m_name + + "\" cannot be parsed as a boolean (" + m_value + ")" ); } /** * Get the property value as a Class object. - * @throws org.omg.CORBA.INITIALIZE the property value cannot be loaded as a class. + * @throws INITIALIZE the property value cannot be loaded as a class. */ public Class getClassValue() { @@ -141,7 +169,7 @@ } catch ( final ClassNotFoundException ex ) { - throw ExceptionTool.initCause( new org.omg.CORBA.INITIALIZE( + throw ExceptionTool.initCause( new INITIALIZE( "The property value \"" + m_name + "\" cannot be loaded as a class (" + ex + ")" ), ex ); } @@ -149,7 +177,7 @@ /** * Get the property value as a URL. - * @throws org.omg.CORBA.INITIALIZE the property value cannot be parsed as a URL. + * @throws INITIALIZE the property value cannot be parsed as a URL. */ public URL getURLValue() { @@ -183,7 +211,7 @@ } } - throw ExceptionTool.initCause( new org.omg.CORBA.INITIALIZE( + throw ExceptionTool.initCause( new INITIALIZE( "The property value \"" + m_name + "\" cannot be parsed as a URL (" + ex + ")" ), ex ); } |