1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.profiler.rules.impl;
18
19 import java.util.Collection;
20 import java.util.HashMap;
21 import java.util.Map;
22 import org.apache.jetspeed.profiler.ProfileLocator;
23 import org.apache.jetspeed.profiler.Profiler;
24 import org.apache.jetspeed.profiler.rules.ProfileResolvers;
25 import org.apache.jetspeed.profiler.rules.ProfilingRule;
26 import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
27 import org.apache.jetspeed.request.RequestContext;
28 import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
29
30 /***
31 * ProfilingRuleImpl
32 *
33 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
34 * @version $Id: AbstractProfilingRule.java 517121 2007-03-12 07:45:49Z ate $
35 */
36 public abstract class AbstractProfilingRule implements ProfilingRule
37 {
38 private static final long serialVersionUID = 1;
39 protected Collection criteria = new RemovalAwareCollection();
40 protected String id;
41 protected String title;
42 protected String ojbConcreteClass;
43
44 /*** Map of profile locators kept around for reuse TODO: evict entries after max size reached */
45 protected Map locators = new HashMap();
46
47 /*** Map of resolver rules for criteria. The map goes from criterion name to resolver class */
48 protected ProfileResolvers resolvers;
49
50 public AbstractProfilingRule()
51 {
52 }
53
54 public AbstractProfilingRule(ProfileResolvers resolvers)
55 {
56 this.resolvers = resolvers;
57 }
58
59
60 protected ProfileLocator getLocatorFromCache(String key)
61 {
62 return (ProfileLocator)locators.get(key);
63 }
64
65
66 protected void addLocatorToCache(String key, ProfileLocator locator)
67 {
68 locators.put(key, locator);
69 }
70
71
72
73
74 public RuleCriterionResolver getResolver(String name)
75 {
76 return resolvers.get(name);
77 }
78
79 public RuleCriterionResolver getDefaultResolver()
80 {
81 return resolvers.get(RuleCriterionResolver.REQUEST);
82 }
83
84
85
86
87 public abstract ProfileLocator apply(RequestContext context, Profiler service);
88
89
90
91
92 public Collection getRuleCriteria()
93 {
94 return criteria;
95 }
96
97
98
99
100 public String getId()
101 {
102 return this.id;
103 }
104
105
106
107
108 public void setId(String id)
109 {
110 this.id = id;
111 }
112
113
114
115
116 public String getTitle()
117 {
118 return this.title;
119 }
120
121
122
123
124 public void setTitle(String title)
125 {
126 this.title = title;
127 }
128
129
130
131
132 public String getClassname()
133 {
134 return this.ojbConcreteClass;
135 }
136
137
138
139
140 public void setClassname(String classname)
141 {
142 this.ojbConcreteClass = classname;
143 }
144
145 public String toString()
146 {
147 if (id != null)
148 {
149 return id;
150 }
151 else if (title != null)
152 {
153 return title;
154 }
155 return this.getClass().toString();
156 }
157
158 /***
159 * @return Returns the resolvers.
160 */
161 public ProfileResolvers getResolvers()
162 {
163 return resolvers;
164 }
165 /***
166 * @param resolvers The resolvers to set.
167 */
168 public void setResolvers(ProfileResolvers resolvers)
169 {
170 this.resolvers = resolvers;
171 }
172
173
174
175
176 }