KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > interceptor > LuceneIndexerInterceptor


1 /*
2  * Copyright 2004 JavaFree.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.javabb.interceptor;
17
18 import org.aopalliance.intercept.MethodInterceptor;
19 import org.aopalliance.intercept.MethodInvocation;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import org.javabb.lucene.index.Indexer;
25
26 import org.javabb.vo.Post;
27
28 /**
29  * @author <a HREF="mailto:jackganzha@dev.java.net">Marcos Silva Pereira</a>
30  *
31  * $Id: LuceneIndexerInterceptor.java,v 1.3 2005/04/08 20:19:42 daltoncamargo
32  * Exp $
33  */

34 public class LuceneIndexerInterceptor implements MethodInterceptor {
35
36     protected static final Log logger = LogFactory
37             .getLog(LuceneIndexerInterceptor.class);
38
39     private Indexer indexer;
40
41     /**
42      *
43      */

44     public LuceneIndexerInterceptor() {
45
46         // TODO Auto-generated constructor stub
47
}
48
49     /**
50      * @param index
51      */

52     public LuceneIndexerInterceptor(Indexer index) {
53
54         this.indexer = index;
55
56     }
57
58     /**
59      * @return Returns the indexer.
60      */

61     public Indexer getIndexer() {
62
63         return indexer;
64
65     }
66
67     /**
68      * @param indexer
69      * The indexer to set.
70      */

71     public void setIndexer(Indexer indexer) {
72
73         this.indexer = indexer;
74
75     }
76
77     /**
78      * Works only for Post objects.
79      *
80      * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
81      */

82     public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc {
83
84         Object JavaDoc[] params = invocation.getArguments();
85         Object JavaDoc post = params[0];
86
87         Object JavaDoc result = post;
88
89         if (post instanceof Post) {
90
91             Post postObj = (Post) post;
92             indexer.index(postObj);
93
94             result = invocation.proceed();
95
96         } else {
97
98             // TODO logger...
99
}
100
101         return result;
102
103     }
104
105 }
Popular Tags