You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Eric Galluzzo <eg...@einnovation.com> on 2003/03/05 21:09:07 UTC

[jelly] "Implement" taglib

Hello,

I've created an "implement" taglib that uses JDK 1.3 proxies to let
Jelly scripts implement interfaces.  I didn't know if Jelly would be
interested in incorporating it into the official codebase or not; but I
thought it might be of general interest, so there might be a shot. :) 
Of course, it does depend on JDK 1.3 for the dynamic proxies, but could
perhaps be an optional taglib a la SWT or Quartz, since as I understand
it the Jelly core only depends on JDK 1.2.

Here's a sample that shows how it works.  Actually, it's the interface
and Jelly script used in my testcase.


TestOverloadedMethodInterface.java:
-----------------------------------

package mypackage;

import java.util.List;

/**
 * This is a test interface in order to test implementing overloaded
 * methods from Jelly.
 * 
 * @author Eric Galluzzo
 */
public interface TestOverloadedMethodInterface
{
	boolean canRun();
	void run();
	void runWithReturn();
	int run( int inParam );
	String run( String inParam );
	String run( String inParam1, String inParam2 );
	List run( List inParam1, String inParam2 );
	void notImplemented();
}


implement.jelly:
----------------

<?xml version="1.0"?>

<j:jelly xmlns:j="jelly:core" xmlns:impl="jelly:implement">
	<impl:implement var="om"
		class="mypackage.TestOverloadedMethodInterface">
		<impl:method name="canRun">
			<impl:body>
				<impl:return value="true"/>
			</impl:body>
		</impl:method>
		
		<impl:method name="run">
			<impl:body>
				In run()
			</impl:body>
		</impl:method>
		
		<impl:method name="runWithReturn">
			<impl:body>
				In runWithReturn()
				<impl:return/>
			</impl:body>
		</impl:method>
		
		<impl:method name="run">
			<impl:parameter name="param" type="int"/>
			<impl:body>
				In run(int)
				<impl:return value="${param + 1}"/>
			</impl:body>
		</impl:method>
		
		<impl:method name="run">
			<impl:parameter name="param"
				type="java.lang.String"/>
			<impl:body>
				In run(String)
				<impl:return value="${param}"/>
			</impl:body>
		</impl:method>
		
		<impl:method name="run">
			<impl:parameter name="param1"
				type="java.lang.String"/>
			<impl:parameter name="param2"
				type="java.lang.String"/>
			<impl:body>
				In run(String, String)
				<impl:return value="${null}"/>
			</impl:body>
		</impl:method>
		
		<impl:method name="run">
			<impl:parameter name="param1"
				type="java.util.List"/>
			<impl:parameter name="param2"
				type="java.lang.String"/>
			<impl:body>
				In run(List, String)
				${param1.add(param2)}
				<impl:return value="${param1}"/>
			</impl:body>
		</impl:method>
	</impl:implement>
</j:jelly>

I've seen the following issues with the implementation:

        1. The <return> tag is implemented using a ReturnException, in a
           similar fashion to the core <break> tag.  However, that
           causes a ReturnException stack trace to be printed whenever
           anyone returns a value from a method, which seems nasty.
        2. The <parameter> tag uses a "type" attribute.  Perhaps it
           should be "class" instead, I'm not sure.  However, I couldn't
           easily put a setClass()/getClass() pair on ParameterTag, for
           obvious reasons, so I chose "type" instead. :)

Let me know what you'd like me to do; I can easily send the code to the
list, or put it on a Web server, if desired.

	Thanks,

	Eric



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org