Author: ssmiweve
Date: 2008-11-28 10:05:20 +0100 (Fri, 28 Nov 2008)
New Revision: 6999
Removed:
branches/2.18/query-api/src/main/java/no/sesat/search/query/Visitable.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/Visitor.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
Modified:
branches/2.18/data-model-javabean-impl/src/test/java/no/sesat/search/datamodel/DataModelSerializeTest.java
branches/2.18/generic.sesam/search-command-control/default/src/main/java/no/sesat/search/mode/command/PicSearchCommand.java
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/AbstractESPFastSearchCommand.java
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/NewsSearchCommand.java
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/WebSearchCommand.java
branches/2.18/pom.xml
branches/2.18/query-api/pom.xml
branches/2.18/query-api/src/main/java/no/sesat/search/query/Clause.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/analyser/Scorer.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/Counter.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/FirstLeafFinder.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ForestFinder.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ParentFinder.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/PredicateCollector.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/PredicateFinder.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/WhoWhereSplitter.java
branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java
branches/2.18/query-api/src/test/java/no/sesat/search/query/parser/TestVisitor.java
branches/2.18/query-transform-control-spi/src/main/java/no/sesat/search/query/transform/AbstractQueryTransformer.java
branches/2.18/query-transform-control-spi/src/main/java/no/sesat/search/query/transform/QueryTransformer.java
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/AbstractTransformerTestCase.java
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/QueryTransformerTestContext.java
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/SynonymQueryTransformerTest.java
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/AbstractSearchCommand.java
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/QueryBuilder.java
Log:
Move the visitor pattern and its base implementation that uses reflection into
a commons package.
Modified:
branches/2.18/data-model-javabean-impl/src/test/java/no/sesat/search/datamodel/DataModelSerializeTest.java
===================================================================
---
branches/2.18/data-model-javabean-impl/src/test/java/no/sesat/search/datamodel/DataModelSerializeTest.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/data-model-javabean-impl/src/test/java/no/sesat/search/datamodel/DataModelSerializeTest.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -54,7 +54,7 @@
import no.sesat.search.view.navigation.NavigationConfig;
import no.sesat.search.query.Clause;
import no.sesat.search.query.Query;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.finder.ParentFinder;
import no.sesat.search.query.parser.AbstractQuery;
import no.sesat.search.query.token.Categories;
Modified:
branches/2.18/generic.sesam/search-command-control/default/src/main/java/no/sesat/search/mode/command/PicSearchCommand.java
===================================================================
---
branches/2.18/generic.sesam/search-command-control/default/src/main/java/no/sesat/search/mode/command/PicSearchCommand.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/generic.sesam/search-command-control/default/src/main/java/no/sesat/search/mode/command/PicSearchCommand.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -32,7 +32,7 @@
import java.net.URLEncoder;
import java.text.MessageFormat;
import no.sesat.search.mode.command.querybuilder.FilterBuilder;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.XorClause;
import no.sesat.search.result.ResultItem;
import no.sesat.search.result.ResultList;
Modified:
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/AbstractESPFastSearchCommand.java
===================================================================
---
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/AbstractESPFastSearchCommand.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/AbstractESPFastSearchCommand.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -42,7 +42,7 @@
import no.sesat.search.query.NotClause;
import no.sesat.search.query.OrClause;
import no.sesat.search.query.UrlClause;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.XorClause;
import no.sesat.search.result.BasicResultList;
import no.sesat.search.result.BasicResultItem;
Modified:
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/NewsSearchCommand.java
===================================================================
---
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/NewsSearchCommand.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/NewsSearchCommand.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -25,7 +25,7 @@
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import no.sesat.search.query.LeafClause;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.XorClause;
import no.sesat.search.query.token.Categories;
Modified:
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/WebSearchCommand.java
===================================================================
---
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/WebSearchCommand.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/generic.sesam/search-command-control/fast/src/main/java/no/sesat/search/mode/command/WebSearchCommand.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -24,7 +24,7 @@
package no.sesat.search.mode.command;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.XorClause;
/**
Modified: branches/2.18/pom.xml
===================================================================
--- branches/2.18/pom.xml 2008-11-27 19:22:27 UTC (rev 6998)
+++ branches/2.18/pom.xml 2008-11-28 09:05:20 UTC (rev 6999)
@@ -876,6 +876,11 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>sesat</groupId>
+ <artifactId>commons-visitor</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
Modified: branches/2.18/query-api/pom.xml
===================================================================
--- branches/2.18/query-api/pom.xml 2008-11-27 19:22:27 UTC (rev 6998)
+++ branches/2.18/query-api/pom.xml 2008-11-28 09:05:20 UTC (rev 6999)
@@ -44,6 +44,10 @@
<groupId>sesat</groupId>
<artifactId>commons-reference-map</artifactId>
</dependency>
+ <dependency>
+ <groupId>sesat</groupId>
+ <artifactId>commons-visitor</artifactId>
+ </dependency>
<dependency>
<groupId>sesat</groupId>
<artifactId>sesat-site-spi</artifactId>
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/Clause.java
===================================================================
--- branches/2.18/query-api/src/main/java/no/sesat/search/query/Clause.java
2008-11-27 19:22:27 UTC (rev 6998)
+++ branches/2.18/query-api/src/main/java/no/sesat/search/query/Clause.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -1,5 +1,5 @@
/*
- * Copyright (2005-2007) Schibsted Søk AS
+ * Copyright (2005-2008) Schibsted Søk AS
* This file is part of SESAT.
*
* SESAT is free software: you can redistribute it and/or modify
@@ -17,6 +17,7 @@
*/
package no.sesat.search.query;
+import no.sesat.commons.visitor.Visitable;
import java.util.Set;
import no.sesat.search.query.token.TokenPredicate;
Deleted:
branches/2.18/query-api/src/main/java/no/sesat/search/query/Visitable.java
===================================================================
--- branches/2.18/query-api/src/main/java/no/sesat/search/query/Visitable.java
2008-11-27 19:22:27 UTC (rev 6998)
+++ branches/2.18/query-api/src/main/java/no/sesat/search/query/Visitable.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -1,43 +0,0 @@
-/* Copyright (2005-2007) Schibsted Søk AS
- * This file is part of SESAT.
- *
- * SESAT is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published
by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SESAT is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with SESAT. If not, see <http://www.gnu.org/licenses/>.
- * Visitable.java
- *
- * Created on 7 January 2006, 16:04
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package no.sesat.search.query;
-
-import java.io.Serializable;
-
-/** Interface for Classes that will implement the Visitor pattern.
- * See complimentary Visitor interface.
- *
- * @version $Id$
- *
- */
-public interface Visitable extends Serializable {
-
- /** Method to accept a visitor.
- * This method usually doesn't do more than
- * <code>visitor.visit(this);</code>
- *
- * @param visitor the visitor knocking on the door.
- */
- void accept(Visitor visitor);
-}
Deleted:
branches/2.18/query-api/src/main/java/no/sesat/search/query/Visitor.java
===================================================================
--- branches/2.18/query-api/src/main/java/no/sesat/search/query/Visitor.java
2008-11-27 19:22:27 UTC (rev 6998)
+++ branches/2.18/query-api/src/main/java/no/sesat/search/query/Visitor.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -1,33 +0,0 @@
-/*
- * Copyright (2005-2008) Schibsted Søk AS
- * This file is part of SESAT.
- *
- * SESAT is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published
by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SESAT is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with SESAT. If not, see <http://www.gnu.org/licenses/>.
- */
-package no.sesat.search.query;
-
-/** Interface for Classes that will implement the Visitor pattern.
- * See complimentary Visitable interface.
- *
- * @version $Id$
- *
- */
-public interface Visitor {
-
- /** Method to hold implementation for what the visitor is supposed to do
to the clause object.
- *
- * @param clause the object the visitor will operate on.
- */
- void visit(Clause clause);
-}
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/analyser/Scorer.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/analyser/Scorer.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/analyser/Scorer.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -23,7 +23,7 @@
package no.sesat.search.query.analyser;
import java.io.IOException;
-import no.sesat.search.query.parser.AbstractReflectionVisitor;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.query.token.TokenPredicate;
import org.apache.commons.collections.Predicate;
import org.apache.log4j.Logger;
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -16,6 +16,7 @@
*/
package no.sesat.search.query.finder;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.query.Clause;
import no.sesat.search.query.BinaryClause;
import no.sesat.search.query.LeafClause;
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/Counter.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/Counter.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/Counter.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -16,6 +16,7 @@
*/
package no.sesat.search.query.finder;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import java.io.Serializable;
import no.sesat.search.query.Clause;
import no.sesat.search.query.BinaryClause;
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/FirstLeafFinder.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/FirstLeafFinder.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/FirstLeafFinder.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -16,6 +16,7 @@
*/
package no.sesat.search.query.finder;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import java.io.Serializable;
import no.sesat.search.query.AndNotClause;
import no.sesat.search.query.Clause;
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ForestFinder.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ForestFinder.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ForestFinder.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -17,6 +17,7 @@
*/
package no.sesat.search.query.finder;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ParentFinder.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ParentFinder.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ParentFinder.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -26,7 +26,7 @@
import no.sesat.search.query.BinaryClause;
import no.sesat.search.query.LeafClause;
import no.sesat.search.query.UnaryClause;
-import no.sesat.search.query.parser.AbstractReflectionVisitor;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.query.token.TokenPredicate;
import org.apache.log4j.Logger;
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/PredicateCollector.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/PredicateCollector.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/PredicateCollector.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -29,7 +29,7 @@
import no.sesat.search.query.BinaryClause;
import no.sesat.search.query.Query;
import no.sesat.search.query.XorClause;
-import no.sesat.search.query.parser.AbstractReflectionVisitor;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.query.Clause;
import no.sesat.search.query.NotClause;
import no.sesat.search.query.token.TokenPredicate;
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/PredicateFinder.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/PredicateFinder.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/PredicateFinder.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -28,7 +28,7 @@
import no.sesat.search.query.AndNotClause;
import no.sesat.search.query.BinaryClause;
import no.sesat.search.query.XorClause;
-import no.sesat.search.query.parser.AbstractReflectionVisitor;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.query.Clause;
import no.sesat.search.query.NotClause;
import no.sesat.search.query.token.TokenEvaluationEngine;
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/WhoWhereSplitter.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/WhoWhereSplitter.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/WhoWhereSplitter.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -36,7 +36,7 @@
import no.sesat.search.query.UnaryClause;
import no.sesat.search.query.QueryContext;
import no.sesat.search.query.XorClause;
-import no.sesat.search.query.parser.AbstractReflectionVisitor;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.query.token.Categories;
import no.sesat.search.query.token.TokenPredicate;
Modified:
branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -26,7 +26,7 @@
import java.util.Set;
import no.sesat.commons.ref.ReferenceMap;
import no.sesat.search.query.Clause;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.token.TokenEvaluator;
import no.sesat.search.query.token.TokenEvaluationEngine;
import no.sesat.search.query.token.TokenPredicate;
Deleted:
branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
===================================================================
---
branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -1,259 +0,0 @@
-/* Copyright (2005-2008) Schibsted Søk AS
- * This file is part of SESAT.
- *
- * SESAT is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published
by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SESAT is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with SESAT. If not, see <http://www.gnu.org/licenses/>.
- *
- * AbstractReflectionVisitor.java
- *
- * Created on 7 January 2006, 16:12
- *
- */
-
-package no.sesat.search.query.parser;
-
-import java.lang.ref.Reference;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.WeakHashMap;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import no.sesat.Interpreter;
-import no.sesat.Interpreter.Context;
-import no.sesat.commons.ref.ReferenceMap;
-import no.sesat.search.query.Clause;
-import no.sesat.search.query.Visitor;
-import org.apache.log4j.Logger;
-
-
-/** 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$
- *
- */
-public abstract class AbstractReflectionVisitor implements Visitor {
-
- /** String specifying name of method used to overload by any class
extending this. **/
- public static final String VISIT_METHOD_IMPL = "visitImpl";
-
- private static final Logger LOG =
Logger.getLogger(AbstractReflectionVisitor.class);
-
- private static final String ERR_CLAUSE_SUBTYPE_NOT_FOUND = "Current
visitor implementation does not handle visiting "
- + "non clause subtypes. Tried to visit object ";
- private static final String ERR_FAILED_TO_VISIT = "Failed to visit object
";
- private static final String ERR_FAILED_TO_FIND_VISIT_IMPL_OBJECT = "Failed
to find method that exists in this class!!"
- + "Was trying to visit object ";
- private static final String DEBUG_LOOKING_AT = "Looking for method "
- + VISIT_METHOD_IMPL + "(";
- private static final String TRACE_KEEP_LOOKING = "keep looking";
- private static final String RB = ")";
-
- private static final ReferenceMap<Class<? extends Visitor>,Map<Class<?
extends Clause>,Method>> CACHE =
- new ReferenceMap<Class<? extends Visitor>,Map<Class<? extends
Clause>,Method>>(
- ReferenceMap.Type.SOFT,
- new ConcurrentHashMap<Class<? extends
Visitor>,Reference<Map<Class<? extends Clause>,Method>>>());
-
-
- /** Creates a new instance of AbstractReflectionVisitor.
- */
- public AbstractReflectionVisitor() {
- }
-
- /**
- * 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.
- *
- * @param clause the clause we're visiting.
- */
- public void visit(final Clause clause) {
-
- Map<Class<? extends Clause>,Method> map = CACHE.get(getClass());
-
- if (null == map) {
-
- map = new ConcurrentHashMap<Class<? extends Clause>,Method>();
-
- CACHE.put(getClass(), map);
- }
-
- Method method = map.get(clause.getClass());
- if (null == method) {
- method = getMethod(clause.getClass());
- method.setAccessible(true);
- map.put(clause.getClass(), method);
- }
- assert method.equals(getMethod(clause.getClass()));
- try {
- method.invoke(this, new Object[] {clause});
-
- } catch (IllegalArgumentException ex) {
- LOG.error(ERR_FAILED_TO_VISIT + clause, ex);
-
- } catch (InvocationTargetException ex) {
- LOG.error(ERR_FAILED_TO_VISIT + clause, ex);
- // IllegalArgumentException often mean an underlying exception.
- // If the underlying exception has a blank stacktrace it's most
likely a sun bug
- // when running hotspot compiled methods
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4966410
- // The JVM flag -XX:-OmitStackTraceInFastThrow fixes it.
- for (Throwable t = ex; t != null; t = t.getCause()) {
- LOG.error(t.getMessage(), t);
- }
-
- } catch (IllegalAccessException ex) {
- LOG.error(ERR_FAILED_TO_VISIT + clause, ex);
- }
- }
-
- /**
- * 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!
- * @param clause the clause we're visiting (that's not acutally a clause
subtype ;)
- */
- protected void visitImpl(final Object clause) {
- throw new IllegalArgumentException(ERR_CLAUSE_SUBTYPE_NOT_FOUND +
clause.getClass().getName());
- }
-
- private Method getMethod(final Class clauseClass) {
- Method method = null;
-
- LOG.trace("getMethod(" + clauseClass.getName() + ")");
-
- // Try the superclasses
- Class currClauseClass = clauseClass;
- while (method == null && currClauseClass != Object.class) {
- LOG.trace(DEBUG_LOOKING_AT + currClauseClass.getName() + RB);
-
- method = getDeclaredMethod(currClauseClass);
-
- if (method == null) {
- currClauseClass = currClauseClass.getSuperclass();
- }
- }
-
- // Try the interfaces.
- // Gets alittle bit tricky because we must not only search
subinterfaces
- // but search both interfaces and superinterfaces of superclasses...
- currClauseClass = clauseClass;
- while (method == null && currClauseClass != Object.class) {
-
- method = getMethodFromInterface(currClauseClass);
- currClauseClass = currClauseClass.getSuperclass();
- }
-
- // fallback to visitImpl(Object)
- if (method == null) {
-
- method = getDeclaredMethod(Object.class);
-
- if (method == null) {
- LOG.fatal(ERR_FAILED_TO_FIND_VISIT_IMPL_OBJECT +
clauseClass.getName());
- }
-
- }
- LOG.trace("end getMethod(" + clauseClass.getName() + ")");
- return method;
- }
-
- /** The interfaces in this array will already be in a suitable order.
- According to java reflection's getMethod contract this order will
match the order listed in the
- implements(/extends) definition of the Clause subclass.
- **/
- private Method getMethodFromInterface(final Class clauseClass) {
-
- Method method = null;
-
- LOG.trace("getMethodFromInterface(" + clauseClass.getName() + ")");
-
- final Class[] interfaces = clauseClass.getInterfaces();
- for (int i = 0; i < interfaces.length && method == null; i++) {
-
- LOG.trace(DEBUG_LOOKING_AT + interfaces[i].getName() + RB);
-
-
- method = getDeclaredMethod(interfaces[i]);
-
-
- if (method == null) {
- // [RECURSION] Look for super interfaces
- method = getMethodFromInterface(interfaces[i]);
- } else {
- // This is the most useful log statement in this file,
- // but gets called too many times per request to be promoted
to debug.
- LOG.trace("Found method accepting <" +
interfaces[i].getSimpleName()
- + "> in " +
method.getDeclaringClass().getSimpleName());
- }
- }
-
- LOG.trace("end getMethodFromInterface(" + clauseClass.getName() + ")");
- return method;
- }
-
- /** Because Class.getDeclaredMethod(..) behaves differently to
getMethod(..) in
- * that it does not look into superclasses we must manually look through
the superclass
- * heirarchy. We don't want to use getMethod(..) either because it will
only return public methods,
- * and we would like our visitImpl methods to remain private/protected.
- **/
- private Method getDeclaredMethod(final Class clauseClass) {
-
- for (Class cls = getClass();; cls = cls.getSuperclass()) {
- if (cls != null) {
- try {
- return cls.getDeclaredMethod(VISIT_METHOD_IMPL, new
Class[] {clauseClass});
-
- } catch (NoSuchMethodException e) {
- LOG.trace(TRACE_KEEP_LOOKING);
- }
- } else {
- return null;
- }
- }
- }
-
-// /**
-// * Add some debug function to the interpreter.
-// */
-// static {
-// Interpreter.addFunction("visitor-methods", new
Interpreter.Function() {
-// public String execute(Context ctx) {
-// String res = "";
-// for (Class<? extends Visitor> cv : CACHE.keySet()) {
-// res += cv.getName() + "\n";
-// for (Class<? extends Clause> cc :
CACHE.get(cv).keySet()) {
-// res += " " + cc.getName() + " - " +
CACHE.get(cv).get(cc).toGenericString() + "\n";
-// }
-// }
-// res += "Total: " + CACHE.size();
-// return res;
-// }
-//
-// public String describe() {
-// return "Print out the methods in the cach used by the
visitors.";
-// }
-//
-// });
-// }
-}
Modified:
branches/2.18/query-api/src/test/java/no/sesat/search/query/parser/TestVisitor.java
===================================================================
---
branches/2.18/query-api/src/test/java/no/sesat/search/query/parser/TestVisitor.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-api/src/test/java/no/sesat/search/query/parser/TestVisitor.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -20,6 +20,7 @@
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.site.SiteTestCase;
import no.sesat.search.query.token.TokenEvaluationEngineTestContext;
import no.sesat.search.query.AndNotClause;
Modified:
branches/2.18/query-transform-control-spi/src/main/java/no/sesat/search/query/transform/AbstractQueryTransformer.java
===================================================================
---
branches/2.18/query-transform-control-spi/src/main/java/no/sesat/search/query/transform/AbstractQueryTransformer.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-transform-control-spi/src/main/java/no/sesat/search/query/transform/AbstractQueryTransformer.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -19,7 +19,7 @@
import no.sesat.search.query.XorClause;
-import no.sesat.search.query.parser.AbstractReflectionVisitor;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import org.apache.log4j.Logger;
import org.w3c.dom.Element;
Modified:
branches/2.18/query-transform-control-spi/src/main/java/no/sesat/search/query/transform/QueryTransformer.java
===================================================================
---
branches/2.18/query-transform-control-spi/src/main/java/no/sesat/search/query/transform/QueryTransformer.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-transform-control-spi/src/main/java/no/sesat/search/query/transform/QueryTransformer.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -22,7 +22,7 @@
import no.sesat.search.query.Clause;
import no.sesat.search.query.LeafClause;
import no.sesat.search.query.QueryContext;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.XorClause;
import no.sesat.search.query.token.TokenEvaluationEngine;
import no.sesat.search.site.SiteContext;
Modified:
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/AbstractTransformerTestCase.java
===================================================================
---
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/AbstractTransformerTestCase.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/AbstractTransformerTestCase.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -38,10 +38,10 @@
import no.sesat.search.query.UnaryClause;
import no.sesat.search.query.OrClause;
import no.sesat.search.query.Query;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.XorClause;
import no.sesat.search.query.parser.AbstractQueryParserContext;
-import no.sesat.search.query.parser.AbstractReflectionVisitor;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.query.parser.ParseException;
import no.sesat.search.query.parser.QueryParser;
import no.sesat.search.query.parser.QueryParserImpl;
Modified:
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/QueryTransformerTestContext.java
===================================================================
---
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/QueryTransformerTestContext.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/QueryTransformerTestContext.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -31,7 +31,7 @@
import no.sesat.search.query.Clause;
import no.sesat.search.query.LeafClause;
import no.sesat.search.query.Query;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.XorClause;
import no.sesat.search.query.token.TokenEvaluationEngine;
import no.sesat.search.query.token.TokenEvaluationEngineImpl;
Modified:
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/SynonymQueryTransformerTest.java
===================================================================
---
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/SynonymQueryTransformerTest.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/query-transform-control-spi/src/test/java/no/sesat/search/query/transform/SynonymQueryTransformerTest.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -34,7 +34,7 @@
import no.sesat.search.query.OrClause;
import no.sesat.search.query.Query;
import no.sesat.search.query.XorClause;
-import no.sesat.search.query.parser.AbstractReflectionVisitor;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.query.parser.ParseException;
import no.sesat.search.query.token.Categories;
import no.sesat.search.query.token.TokenEvaluationEngineTestContext;
Modified:
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/AbstractSearchCommand.java
===================================================================
---
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/AbstractSearchCommand.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/AbstractSearchCommand.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -33,10 +33,10 @@
import no.sesat.search.query.Clause;
import no.sesat.search.query.LeafClause;
import no.sesat.search.query.Query;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.XorClause;
import no.sesat.search.query.parser.AbstractQueryParserContext;
-import no.sesat.search.query.parser.AbstractReflectionVisitor;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
import no.sesat.search.query.parser.QueryParser;
import no.sesat.search.query.parser.QueryParserImpl;
import no.sesat.search.query.parser.TokenMgrError;
Modified:
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
===================================================================
---
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -27,7 +27,7 @@
import no.sesat.search.query.UnaryClause;
import no.sesat.search.query.Query;
import no.sesat.search.query.XorClause;
-import no.sesat.search.query.parser.AbstractReflectionVisitor;
+import no.sesat.commons.visitor.AbstractReflectionVisitor;
/** Abstract QueryBuilder providing basic support for mantaining context and
stringBuilder fields (and related methods).
*
Modified:
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/QueryBuilder.java
===================================================================
---
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/QueryBuilder.java
2008-11-27 19:22:27 UTC (rev 6998)
+++
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/QueryBuilder.java
2008-11-28 09:05:20 UTC (rev 6999)
@@ -19,7 +19,7 @@
import java.util.Collection;
import no.sesat.search.query.Clause;
import no.sesat.search.query.Query;
-import no.sesat.search.query.Visitor;
+import no.sesat.commons.visitor.Visitor;
import no.sesat.search.query.transform.QueryTransformer;
/** QueryBuilder provides a string representation of a Query Tree against of
map of "transformed terms".
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits