adammurdoch 2002/07/02 03:46:08
Modified: antlib/src/java/org/apache/antlib/template
AttributeAdapter.java AttributeDef.java
Resource.properties TemplateTask.java
Log:
Some changes to <template-def>:
- Changed 'type' attribute on <attribute> to default to java.lang.String,
if not specified.
- Changed the type of default value on <attribute> to Object (so, for
example, can use any data-type by ref as a default value).
- Moved responsibility for loading attribute class from TemplateTask,
to AttributeAdaptor, which delegates loading to the container.
Revision Changes Path
1.2 +7 -9 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/template/AttributeAdapter.java
Index: AttributeAdapter.java
===================================================================
RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/template/AttributeAdapter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AttributeAdapter.java 28 Jun 2002 09:02:07 -0000 1.1
+++ AttributeAdapter.java 2 Jul 2002 10:46:08 -0000 1.2
@@ -23,20 +23,20 @@
ResourceManager.getPackageResources( AttributeAdapter.class );
private String m_name;
- private String m_type;
- private String m_default;
+ private Class m_type;
+ private Object m_default;
public void setName( final String name )
{
m_name = name;
}
- public void setType( final String type )
+ public void setType( final Class type )
{
m_type = type;
}
- public void setDefault( final String defaultValue )
+ public void setDefault( final Object defaultValue )
{
m_default = defaultValue;
}
@@ -50,11 +50,9 @@
REZ.getString( "attribute.missing-name.error" );
throw new TaskException( message );
}
- if( null == m_name )
+ if( m_type == null )
{
- final String message =
- REZ.getString( "attribute.missing-name.error", m_name );
- throw new TaskException( message );
+ m_type = String.class;
}
return new AttributeDef( m_name, m_type, m_default );
1.2 +7 -7 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/template/AttributeDef.java
Index: AttributeDef.java
===================================================================
RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/template/AttributeDef.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AttributeDef.java 28 Jun 2002 09:02:07 -0000 1.1
+++ AttributeDef.java 2 Jul 2002 10:46:08 -0000 1.2
@@ -17,12 +17,12 @@
public class AttributeDef
{
private final String m_name;
- private final String m_type;
- private final String m_defaultValue;
+ private final Class m_type;
+ private final Object m_defaultValue;
public AttributeDef( final String name,
- final String type,
- final String defaultValue )
+ final Class type,
+ final Object defaultValue )
{
m_name = name;
m_type = type;
@@ -34,12 +34,12 @@
return m_name;
}
- public String getType()
+ public Class getType()
{
return m_type;
}
- public String getDefaultValue()
+ public Object getDefaultValue()
{
return m_defaultValue;
}
1.2 +2 -3 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/template/Resource.properties
Index: Resource.properties
===================================================================
RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/template/Resource.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Resource.properties 28 Jun 2002 09:02:07 -0000 1.1
+++ Resource.properties 2 Jul 2002 10:46:08 -0000 1.2
@@ -7,10 +7,9 @@
template-def.many-logic.error=Templates can only define a single block o logic.
template-def.missing-logic.error=TemplateDef task named "{0}" does not define a logic element.
-template-def.missing-name.error=The TemplateDef task has not specified a name.
+template-def.missing-name.error=No template name specified.
element.missing-name.error=Element does not specify a name.
element.missing-name.error=Element named "{0}" does not specify a type.
-attribute.missing-name.error=Attribute does not specify a name.
-attribute.missing-name.error=Attribute named "{0}" does not specify a type.
\ No newline at end of file
+attribute.missing-name.error=No attribute name specified.
\ No newline at end of file
1.4 +15 -16 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/template/TemplateTask.java
Index: TemplateTask.java
===================================================================
RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/template/TemplateTask.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TemplateTask.java 2 Jul 2002 02:12:57 -0000 1.3
+++ TemplateTask.java 2 Jul 2002 10:46:08 -0000 1.4
@@ -138,18 +138,21 @@
{
final AttributeDef attributeDef = attributeDefs[ i ];
final String name = attributeDef.getName();
- final String defaultValue = attributeDef.getDefaultValue();
- final String strValue = m_model.getAttribute( name, defaultValue );
- if( null == strValue )
+ Object value = m_model.getAttribute( name );
+ if( null == value )
{
- final String message =
- REZ.getString( "template.missing-attribute.error",
- name );
- throw new TaskException( message );
+ value = attributeDef.getDefaultValue();
+ if( value == null )
+ {
+ final String message =
+ REZ.getString( "template.missing-attribute.error",
+ name );
+ throw new TaskException( message );
+ }
}
- final Object value = createValue( attributeDef.getType(), strValue );
+ value = createValue( attributeDef.getType(), value );
attributes.put( name, value );
}
@@ -224,19 +227,15 @@
}
/**
- * Get the type coresponding tyo specified type. Note that
- * this mechanism is a complete hack and something more
- * useful needs to be done in future to allow classes
- * to be loaded from arbitrary classloaders.
+ * Get the type coresponding tyo specified type.
*/
- private Object createValue( final String typeName,
- final String strValue )
+ private Object createValue( final Class type,
+ final Object value )
throws TaskException
{
try
{
- final Class type = Class.forName( typeName );
- return convert( type, strValue );
+ return convert( type, value );
}
catch( final Exception e )
{
--
To unsubscribe, e-mail: <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>
|