KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > filter > AbstractFilterUsageDecorator


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21
22 package org.jacorb.notification.filter;
23
24 import java.lang.reflect.InvocationHandler JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.util.Date JavaDoc;
27
28 /**
29  * @author Alphonse Bendt
30  * @version $Id: AbstractFilterUsageDecorator.java,v 1.1 2005/03/31 20:15:36 alphonse.bendt Exp $
31  */

32 public abstract class AbstractFilterUsageDecorator
33 {
34     private final Date JavaDoc created_ = new Date JavaDoc();
35
36     protected final FilterInvocationHandler invocationHandler_;
37     
38     protected class FilterInvocationHandler implements InvocationHandler JavaDoc
39     {
40         private long lastUsage_;
41
42         private final Object JavaDoc delegate_;
43
44         private long matchCount_ = 0;
45
46         private long matchStructuredCount_ = 0;
47
48         private long matchTypedCount_ = 0;
49
50         public FilterInvocationHandler(Object JavaDoc delegate)
51         {
52             delegate_ = delegate;
53         }
54
55         public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc
56         {
57             updateUsage(method);
58
59             return method.invoke(delegate_, args);
60         }
61
62         
63         private void updateUsage(Method JavaDoc method)
64         {
65             lastUsage_ = System.currentTimeMillis();
66
67             // this will work for MappingFilters and Filters as methods have the same names.
68
if (method.getName().equals("match"))
69             {
70                 ++matchCount_;
71             }
72             else if (method.getName().equals("match_structured"))
73             {
74                 ++matchStructuredCount_;
75             }
76             else if (method.getName().equals("match_typed"))
77             {
78                 ++matchTypedCount_;
79             }
80         }
81
82         public long getLastUsage()
83         {
84             return lastUsage_;
85         }
86     }
87
88     /**
89      *
90      */

91     public AbstractFilterUsageDecorator(Object JavaDoc delegate)
92     {
93         super();
94
95         invocationHandler_ = new FilterInvocationHandler(delegate);
96     }
97
98     public Date JavaDoc getLastUsage()
99     {
100         return new Date JavaDoc(invocationHandler_.getLastUsage());
101     }
102
103     public Date JavaDoc getCreationDate()
104     {
105         return created_;
106     }
107 }
108
Popular Tags