From: <[EMAIL PROTECTED]>
> > Incidentally, why do you want to know what your body is before you
> evaluate
> > it?
> The way Latka's JUnit integration current works is to count the <requests>
> as 'tests' and then to run the document when runTest gets called.
>
> To count the requests, I need access pre-evaluation.
There's a few ways to do this kinda thing. One way is for the <request> tag
to register some object with its parent which doesn't actually run its body,
just registers it so that the parent tag can run the child tag whenever it
wishes. Here's an example...
e.g. imagine some XML like this...
<parent>
<request name="a">...</request>
...
<request name="z">...</request>
...
<runTests/>
</parent>
The parent tag could be implemented kinda like this (using a tad of
pseudocode)...
// contains all child <request> tags that
public class ParentTag extends TagSupport {
private Map children = new HashMap();
public Map getChildren() {
return children;
}
public void addRequestTag(RequestTag tag) {
children.put(tag.getName(), tag);
}
public void doTag(XMLOutput output) {
invokeBody(output);
}
}
// registers body tag with parent tag...
public class RequestTag extends TagSupport {
private String name;
public void setName(String name) {
this.name = name;
}
public void doTag(XMLOutput output) throws Exception {
ParentTag tag = (ParentTag) findAccestorWithClass(
ParentTag.class );
if ( tag == null ) {
throw new JellyException( "<request> tag must be inside a
<parent> tag" );
}
// register my body script with my parent tag
tag.addChildTag( this );
}
}
// this tag runs all of the registered <request> tags
public class RunTestsTag extends TagSupport {
public void doTag(XMLOutput output) throws Exception {
ParentTag tag = (ParentTag) findAccestorWithClass(
ParentTag.class );
if ( tag == null ) {
throw new JellyException( "<runTests> tag must be inside a
<parent> tag" );
}
// register my body script with my parent tag
Map map = tag.getChildren();
for ( Iterator iter = map.values().iterator(); iter.hasNext(); ) {
RequestTag tag = (RequestTag) iter.next();
// now lets run the script
tag.invokeBody( output );
}
}
}
James
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>