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