From: cvs@openprivacy.orgCVS update: talon/src/java/talon/util
Date: Sunday February 11, 19101 @ 14:02
Author: burton
CVSWEB Options: -------------------
Main CVSWeb: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi
View this module: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/util
-----------------------------------
Update of /usr/local/cvs/public/talon/src/java/talon/util
In directory giga:/tmp/cvs-serv4717/src/java/talon/util
Modified Files:
BasePropertyManager.java
Log Message:
ug... added some more features necessary for M1. Stupid bug in java.lang.Properties which took a while to fix.
*****************************************************************
File: talon/src/java/talon/util/BasePropertyManager.java
CVSWEB Options: -------------------
CVSWeb: Annotate this file: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/util/BasePropertyManager.java?annotate=1.6
CVSWeb: View this file: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/util/BasePropertyManager.java?rev=1.6&content-type=text/x-cvsweb-markup
CVSWeb: Diff to previous version: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/util/BasePropertyManager.java.diff?r1=1.6&r2=1.5
-----------------------------------
Index: talon/src/java/talon/util/BasePropertyManager.java
diff -u talon/src/java/talon/util/BasePropertyManager.java:1.5 talon/src/java/talon/util/BasePropertyManager.java:1.6
--- talon/src/java/talon/util/BasePropertyManager.java:1.5 Thu Feb 8 22:31:42 2001
+++ talon/src/java/talon/util/BasePropertyManager.java Sun Feb 11 14:02:12 2001
@@ -15,34 +15,35 @@
import talon.*;
import talon.interfaces.*;
+import talon.implementations.*;
/**
* Base class for handling properties.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: BasePropertyManager.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
*/
public abstract class BasePropertyManager extends BaseComponent implements Component, PropertyManager {
- private Properties props = new Properties();
+ private Hashtable props = new Hashtable();
/**
* @see PropertyManager
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: BasePropertyManager.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
*/
- public String getProperty( String name ) {
- return this.props.getProperty( name );
+ public Object getProperty( String name ) {
+ return this.props.get( name );
}
/**
* @see PropertyManager
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: BasePropertyManager.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
*/
- public String getProperty( String name, String _default ) {
+ public Object getProperty( String name, Object _default ) {
- String value = (String)this.props.getProperty( name );
+ Object value = (String)this.props.get( name );
if ( value == null ) {
value = _default;
@@ -54,10 +55,10 @@
/**
* @see PropertyManager
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: BasePropertyManager.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
*/
public boolean getBoolean( String name ) {
- String value = getProperty( name );
+ String value = getString( name );
//if it is null assume false.
if ( value == null ) {
@@ -68,10 +69,65 @@
}
+
+ /**
+ * @see PropertyManager
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
+ */
+ public PropertyManager setBoolean( String name, boolean value ) {
+
+ if ( value ) {
+ setProperty( name, "true" );
+ } else {
+ setProperty( name, "false" );
+ }
+ return this;
+ }
+
+
+ /**
+ * @see PropertyManager
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
+ */
+ public PropertyManager setString( String name, String value ) {
+ setProperty( name, value );
+ return this;
+ }
+
+ /**
+ * @see PropertyManager
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
+ */
+ public String getString( String name ) {
+ return (String)getProperty( name );
+ }
+
+
+ /**
+ * @see PropertyManager
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
+ */
+ public String getString( String _name, String _default ) {
+
+ String value = getString( _name );
+
+ if ( value == null ) {
+ return _default;
+ } else {
+ return value;
+ }
+
+ }
+
+
/**
* @see PropertyManager
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: BasePropertyManager.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
*/
public Vector getVector( String name ) {
@@ -80,7 +136,7 @@
int i = 0;
while( true ) {
- String prop = getProperty( name + "." + i );
+ String prop = getString( name + "." + i );
//terminate the while loop if we have no more variables.
if ( prop == null) {
@@ -98,13 +154,15 @@
/**
* @see PropertyManager
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: BasePropertyManager.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
*/
- public Hashtable getGroup( String key ) {
+ public PropertyManager getGroup( String key ) {
Enumeration keys = getKeys();
- Hashtable result = new Hashtable();
+ SimplePropertyManager result = new SimplePropertyManager();
+ boolean noKeysFound = true;
+
while ( keys.hasMoreElements() ) {
String name = (String)keys.nextElement();
@@ -112,18 +170,20 @@
//test if the current name is valid.
if ( name.indexOf( key ) == 0 ) {
- String value = getProperty( name );
+ noKeysFound = false;
+
+ Object value = getProperty( name );
//update the name.
name = name.substring( key.length() + 1, name.length() );
- result.put( name, value );
+ result.setProperty( name, value );
}
}
//if no values were found... return null
- if ( result.size() == 0 ) {
+ if ( noKeysFound ) {
return null;
} else {
return result;
@@ -135,45 +195,111 @@
/**
* @see PropertyManager
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: BasePropertyManager.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
*/
- public PropertyManager setProperty( String name, String value ) {
+ public PropertyManager setProperty( String name, Object value ) {
+
+ if ( name == null || value == null ) {
+ throw new IllegalArgumentException( "Name and value must not be null" );
+ }
+
this.props.put( name, value );
+
return this;
}
+
+ /**
+ * @see PropertyManager
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
+ */
+ public Enumeration getKeys() {
+ return this.props.keys();
+ }
+
+ /**
+ * @see PropertyManager
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
+ */
+ public void setProperties( Properties props ) {
+ this.props = props;
+ }
/**
* @see PropertyManager
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: BasePropertyManager.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
*/
- public PropertyManager setBoolean( String name, boolean value ) {
+ public void require( String[] properties ) throws TalonException {
- if ( value ) {
- this.props.put( name, "true" );
- } else {
- this.props.put( name, "false" );
- }
- return this;
+ for ( int i = 0; i < properties.length; ++i ) {
+ if ( ! this.exists( properties[i] ) ) {
+ throw new TalonException( "The required property for this component does not exist: " + properties[i] );
+ }
+
+ }
+
}
-
+
/**
* @see PropertyManager
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: BasePropertyManager.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
*/
- public Enumeration getKeys() {
- return this.props.keys();
+ public boolean exists( String key ) {
+ return props.get( key ) != null;
+ }
+
+ /**
+ * @see PropertyManager
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
+ */
+ public void list() {
+ list( System.out );
}
+
+ /**
+ * @see PropertyManager
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
+ */
+ public void list( PrintStream ps) {
+
+ ps.println( getPrettyPrint() );
+ }
/**
- *
- *
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: BasePropertyManager.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ * @version $Id: BasePropertyManager.java,v 1.6 2001/02/11 22:02:12 burton Exp $
*/
- public void setProperties( Properties props ) {
- this.props = props;
+ private String getPrettyPrint() {
+
+ Enumeration keys = getKeys();
+
+ StringBuffer buff = new StringBuffer();
+
+ buff.append( "-- listing properties --\n" );
+
+ while ( keys.hasMoreElements() ) {
+
+ String name = (String)keys.nextElement();
+
+ Object value = getProperty( name );
+
+ System.out.println( " FIXME: (debug): name: " + name );
+
+ if ( value == null ) {
+ System.out.println( " FIXME: (debug): value is null!!!! " );
+ }
+
+
+ buff.append( name.toString() + " = " + value.toString() + "\n" );
+
+ }
+
+ return buff.toString();
}
}
This archive was generated by hypermail 2b30 : Sun Feb 11 2001 - 14:03:43 PST