Skip to Content.
Sympa Menu

notify-dpml - r1035 - in trunk/main: metro/tools/src/main/net/dpml/metro/tools planet/web/server

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1035 - in trunk/main: metro/tools/src/main/net/dpml/metro/tools planet/web/server
  • Date: Sun, 5 Feb 2006 11:00:37 +0100

Author: mcconnell
Date: 2006-02-05 11:00:36 +0100 (Sun, 05 Feb 2006)
New Revision: 1035

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ArrayDataType.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/EntryDataType.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueBuilder.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueDataType.java
trunk/main/planet/web/server/build.xml
Log:
add class checking on value declarations and validation of class
assignability of values declared within a typed array

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ArrayDataType.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/ArrayDataType.java
2006-02-05 09:15:08 UTC (rev 1034)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/ArrayDataType.java
2006-02-05 10:00:36 UTC (rev 1035)
@@ -25,6 +25,8 @@
import net.dpml.transit.Construct;
import net.dpml.transit.Construct.Array;

+import org.apache.tools.ant.BuildException;
+
/**
* Defintion of a context entry parameter directive.
*
@@ -42,7 +44,6 @@
*/
public void setClass( final String classname )
{
- System.out.println( "SET CLASSNAME: " + classname );
m_classname = classname;
}

@@ -61,8 +62,10 @@
*/
public void addConfiguredValue( ValueDataType param )
{
- System.out.println( "ADD CONFIGURED VALUE: " + param );
- param.setClass( m_classname );
+ if( null == param.getClassname() )
+ {
+ param.setClass( m_classname );
+ }
m_params.add( param );
}

@@ -72,8 +75,10 @@
*/
public void addConfiguredArray( ArrayDataType param )
{
- System.out.println( "ADD CONFIGURED ARRAY: " + param );
- param.setClass( m_classname );
+ if( null == param.getClassname() )
+ {
+ param.setClass( m_classname );
+ }
m_params.add( param );
}

@@ -88,19 +93,79 @@

/**
* Build a value datastructure.
+ * @param classloader the working classloader
* @return the serializable value descriptor
*/
- public Value buildValue()
+ public Value buildValue( ClassLoader classloader )
{
String classname = getClassname();
- ValueBuilder[] params = getValueBuilders();
- Value[] values = new Value[ params.length ];
- for( int i=0; i<values.length; i++ )
+ Class base = getBaseClass( classloader, classname );
+ try
{
- ValueBuilder p = params[i];
- values[i] = p.buildValue();
+ ValueBuilder[] params = getValueBuilders();
+ Value[] values = new Value[ params.length ];
+ for( int i=0; i<values.length; i++ )
+ {
+ ValueBuilder p = params[i];
+ Class target = p.getTargetClass( classloader );
+ if( base.isAssignableFrom( target ) )
+ {
+ values[i] = p.buildValue( classloader );
+ }
+ else
+ {
+ final String error =
+ "A value entry of the type ["
+ + target.getName()
+ + "] is not assignable to the array class ["
+ + base.getName()
+ + "].";
+ throw new BuildException( error );
+ }
+ }
+ return new Array( classname, values );
}
- return new Array( classname, values );
+ catch( BuildException e )
+ {
+ throw e;
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "An error occured while building array datatype.";
+ throw new BuildException( error, e );
+ }
}

+ /**
+ * Return the base classname.
+ * @param classloader the working classloader
+ * @return the target class
+ */
+ public Class getTargetClass( ClassLoader classloader )
+ {
+ String classname = getClassname();
+ return getBaseClass( classloader, classname );
+ }
+
+ private Class getBaseClass( ClassLoader classloader, String classname )
+ {
+ if( null == classname )
+ {
+ return Object.class;
+ }
+ else
+ {
+ try
+ {
+ return classloader.loadClass( classname );
+ }
+ catch( ClassNotFoundException e )
+ {
+ final String error =
+ "The array type [" + classname + "] is unknown.";
+ throw new BuildException( error, e );
+ }
+ }
+ }
}

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/EntryDataType.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/EntryDataType.java
2006-02-05 09:15:08 UTC (rev 1034)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/EntryDataType.java
2006-02-05 10:00:36 UTC (rev 1035)
@@ -226,6 +226,22 @@
{
String key = getKey();
String classname = getClassname();
+ if( null != classname )
+ {
+ try
+ {
+ classloader.loadClass( classname );
+ }
+ catch( ClassNotFoundException e )
+ {
+ final String error =
+ "Entry directive overriding class ["
+ + classname
+ + "] is unknown.";
+ throw new BuildException( error, e );
+ }
+ }
+
String method = getMethodName();

if( null != type )
@@ -255,7 +271,7 @@
+ "].";
throw new ConstructionException( error );
}
-
+
String value = getValue();
if( null != value )
{
@@ -268,7 +284,7 @@
for( int i=0; i<params.length; i++ )
{
ValueBuilder p = params[i];
- values[i] = p.buildValue();
+ values[i] = p.buildValue( classloader );
}
return new ValueDirective( classname, method, values );
}

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueBuilder.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueBuilder.java
2006-02-05 09:15:08 UTC (rev 1034)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueBuilder.java
2006-02-05 10:00:36 UTC (rev 1035)
@@ -31,8 +31,15 @@
{
/**
* Build a value datastructure.
+ * @param classloader the working classloader
* @return the serializable value descriptor
*/
- Value buildValue();
+ Value buildValue( ClassLoader classloader );

+ /**
+ * Return the base classname.
+ * @param classloader the working classloader
+ * @return the target class
+ */
+ Class getTargetClass( ClassLoader classloader );
}

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueDataType.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueDataType.java
2006-02-05 09:15:08 UTC (rev 1034)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/ValueDataType.java
2006-02-05 10:00:36 UTC (rev 1035)
@@ -26,6 +26,8 @@
import net.dpml.transit.Construct;
import net.dpml.transit.Value;

+import org.apache.tools.ant.BuildException;
+
/**
* Defintion of a context entry parameter directive.
*
@@ -126,9 +128,10 @@

/**
* Build a value datastructure.
+ * 2param classloader the working classloader
* @return the serializable value descriptor
*/
- public Value buildValue()
+ public Value buildValue( ClassLoader classloader )
{
String classname = getClassname();
String method = getMethodName();
@@ -144,9 +147,41 @@
for( int i=0; i<values.length; i++ )
{
ValueBuilder p = params[i];
- values[i] = p.buildValue();
+ values[i] = p.buildValue( classloader );
}
return new ValueDirective( classname, method, values );
}
}
+
+ /**
+ * Return the base classname.
+ * @param classloader the working classloader
+ * @return the target class
+ */
+ public Class getTargetClass( ClassLoader classloader )
+ {
+ String classname = getClassname();
+ return getBaseClass( classloader, classname );
+ }
+
+ private Class getBaseClass( ClassLoader classloader, String classname )
+ {
+ if( null == classname )
+ {
+ return String.class;
+ }
+ else
+ {
+ try
+ {
+ return classloader.loadClass( classname );
+ }
+ catch( ClassNotFoundException e )
+ {
+ final String error =
+ "The value type base class [" + classname + "] is
unknown.";
+ throw new BuildException( error, e );
+ }
+ }
+ }
}

Modified: trunk/main/planet/web/server/build.xml
===================================================================
--- trunk/main/planet/web/server/build.xml 2006-02-05 09:15:08 UTC (rev
1034)
+++ trunk/main/planet/web/server/build.xml 2006-02-05 10:00:36 UTC (rev
1035)
@@ -92,18 +92,18 @@
<component key="servlets" type="net.dpml.web.server.ContextHandler">
<context>
<entry key="server" validate="false"/>
- <entry key="resourceBase"
value="${dpml.data}/temp/http/context"/>
+ <entry key="resourceBase" value="${dpml.data}"/>
<entry key="contextPath" value="/"/>
<entry key="handler" class="net.dpml.web.server.ServletHandler">
<array class="net.dpml.web.server.ServletHolder">
<value>
- <value value="hello"/>
+ <value value="data"/>
<value value="org.mortbay.jetty.servlet.DefaultServlet"/>
</value>
</array>
<array class="net.dpml.web.server.ServletMapping">
<value>
- <value value="hello"/>
+ <value value="data"/>
<value value="/"/>
</value>
</array>




  • r1035 - in trunk/main: metro/tools/src/main/net/dpml/metro/tools planet/web/server, mcconnell at BerliOS, 02/05/2006

Archive powered by MHonArc 2.6.24.

Top of Page