Date: 2004-06-04T13:13:34
Editor: SteveGibson <[EMAIL PROTECTED]>
Wiki: Jakarta HiveMind Wiki
Page: Examples
URL: http://wiki.apache.org/jakarta-hivemind/Examples
no comment
Change Log:
------------------------------------------------------------------------------
@@ -2,3 +2,40 @@
What would be nice to have is for example:
* How to fetch java.sql.Connection using hivemind service.
* More interceptor docs?
+
+The cool thing about HiveMind is that using services is no more complex than
the simple calculator example.
+(Oh wow, I just realized the example is a whole calculator now, not just an
Adder!)
+Configuration schema examples are something that would probably be more
beneficial.
+
+As for the interceptor - here is an ugly example of an interceptor for the
Divider (off the top of my head:
+
+public class DividerInterceptor extends AbstractServiceInterceptorFactory
+{
+ protected void addServiceMethodImplementation(
+ ClassFab classFab,
+ String methodName,
+ Class returnType,
+ Class[] parameterTypes,
+ Class[] exceptionTypes)
+ {
+ if (methodName.equals("divide"))
+ {
+ BodyBuilder builder = new BodyBuilder();
+
+ builder.begin();
+ builder.addln("if ($1 == 0)");
+ builder.addln("{");
+ builder.addln("throw new ArithmeticException(\"Division by zero\");");
+ builder.addln("}");
+ builder.addln("return ($r) _inner." + methodName + "($$);" );
+ builder.end();
+ classFab.addMethod(Modifier.PUBLIC,
+ methodName,
+ returnType,
+ parameterTypes,
+ exceptionTypes,
+ builder.toString()
+ );
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]