mcconnell 2003/04/04 04:19:19
Modified: merlin/meta-spi/src/java/org/apache/avalon/meta/model
Parameter.java
Log:
Improved error handling and added todo note concerning support for primative types.
Revision Changes Path
1.2 +17 -5
avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/model/Parameter.java
Index: Parameter.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/model/Parameter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Parameter.java 13 Mar 2003 01:06:29 -0000 1.1
+++ Parameter.java 4 Apr 2003 12:19:19 -0000 1.2
@@ -86,6 +86,9 @@
* @see Import
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision$ $Date$
+ * @todo Fix usage of basic type (int, float, long, etc.) - how do we return
+ * basic types - can't use getValue() becuase it returns an Object unless
+ * have some way of packing the basic type into a carrier
*/
public class Parameter
{
@@ -285,20 +288,29 @@
else
{
//
- // the argument is a single string parameter
+ // the argument is a simple type that takes a single String value
+ // as a constructor argument
//
+ Class clazz = getParameterClass( loader );
+
try
{
final Class[] params = new Class[]{String.class};
- Constructor constructor = getParameterClass( loader
).getConstructor( params );
+ Constructor constructor = clazz.getConstructor( params );
final Object[] values = new Object[]{m_argument};
m_value = constructor.newInstance( values );
return m_value;
}
+ catch( NoSuchMethodException e )
+ {
+ final String error = "Class: '" + clazz.getName()
+ + "' does not implement a single string argument
constructor.";
+ throw new ModelException( error );
+ }
catch( InstantiationException e )
{
- final String error = "Unable to instantiate instance of class:
" + m_classname
+ final String error = "Unable to instantiate instance of class:
" + clazz.getName()
+ " with the single argument: '" + m_argument + "'";
throw new ModelException( error, e );
}
@@ -316,7 +328,6 @@
+ m_classname + "'.";
throw new ModelException( error, e );
}
-
}
}
@@ -455,6 +466,7 @@
*/
protected void asString( StringBuffer buffer, String lead )
{
+ String classname = m_classname;
buffer.append(
lead + "[\n"
+ lead + " type: " + this.getClass().getName() + "\n"
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]