no.sesat.commons.visitor
Class AbstractReflectionVisitor

java.lang.Object
  extended by no.sesat.commons.visitor.AbstractReflectionVisitor
All Implemented Interfaces:
Visitor

public abstract class AbstractReflectionVisitor
extends Object
implements Visitor

A helper implementation of the Visitor pattern using java's reflection. This results in not having to add overloaded methods for each subclass of clause as this implementation will automatically find those overloaded methods without explicitly having to call them in each Clause class. This saves alot of work when adding new Clause subclasses. The overloaded method name is specified by VISIT_METHOD_IMPL. See http://www.javaworld.com/javaworld/javatips/jw-javatip98.html

Version:
$Id: AbstractReflectionVisitor.java 1127 2009-01-21 16:16:08Z ssmiweve $

Field Summary
static String VISIT_METHOD_IMPL
          String specifying name of method used to overload by any class extending this.
 
Constructor Summary
AbstractReflectionVisitor()
          Creates a new instance of AbstractReflectionVisitor.
 
Method Summary
 void visit(Visitable clause)
          Method implementing Visitor interface.
protected  void visitImpl(Object clause)
          Final fallback method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VISIT_METHOD_IMPL

public static final String VISIT_METHOD_IMPL
String specifying name of method used to overload by any class extending this.

See Also:
Constant Field Values
Constructor Detail

AbstractReflectionVisitor

public AbstractReflectionVisitor()
Creates a new instance of AbstractReflectionVisitor.

Method Detail

visit

public void visit(Visitable clause)
Method implementing Visitor interface. Uses reflection to find the method with name VISIT_METHOD_IMPL with the closest match to the clause subclass. We CACHE the methods used by the visitor. This is done in a soft ReferenceMap since the skins can be reloaded, and then we would have had a memory leak.

Specified by:
visit in interface Visitor
Parameters:
clause - the clause we're visiting.

visitImpl

protected void visitImpl(Object clause)
Final fallback method. This means that the object being visited is not a Clause (or subclass of) object! This behaviour is not intendedly supported and this implementation throws an IllegalArgumentException!

Parameters:
clause - the clause we're visiting (that's not acutally a clause subtype ;)


Copyright © 2009 Schibsted Søk AS. All Rights Reserved.