%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.profiler.rules.impl.StandardProfilingRule |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.profiler.rules.impl; |
|
18 | ||
19 | import java.util.Iterator; |
|
20 | ||
21 | import org.apache.commons.logging.Log; |
|
22 | import org.apache.commons.logging.LogFactory; |
|
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.RuleCriterion; |
|
28 | import org.apache.jetspeed.profiler.rules.RuleCriterionResolver; |
|
29 | import org.apache.jetspeed.request.RequestContext; |
|
30 | ||
31 | /** |
|
32 | * StandardProfilingRule applies the standard Jetspeed-1 profiling rules. |
|
33 | * The result is an ordered list of Profile Locator name/value pairs. |
|
34 | * |
|
35 | * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a> |
|
36 | * @version $Id: StandardProfilingRule.java 516448 2007-03-09 16:25:47Z ate $ |
|
37 | */ |
|
38 | public class StandardProfilingRule |
|
39 | extends AbstractProfilingRule |
|
40 | implements ProfilingRule |
|
41 | { |
|
42 | 0 | protected final static Log log = LogFactory.getLog(StandardProfilingRule.class); |
43 | private static final long serialVersionUID = 1; |
|
44 | ||
45 | public StandardProfilingRule() |
|
46 | 0 | { |
47 | 0 | this.setClassname(class="keyword">this.getClass().getName()); |
48 | 0 | } |
49 | ||
50 | public StandardProfilingRule(ProfileResolvers resolvers) |
|
51 | { |
|
52 | 0 | super(resolvers); |
53 | 0 | this.setClassname(class="keyword">this.getClass().getName()); |
54 | 0 | } |
55 | ||
56 | /* (non-Javadoc) |
|
57 | * @see org.apache.jetspeed.profiler.rules.ProfilingRule#apply(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.profiler.Profiler) |
|
58 | */ |
|
59 | public ProfileLocator apply(RequestContext context, Profiler service) |
|
60 | { |
|
61 | 0 | StringBuffer key = new StringBuffer(); |
62 | 0 | int count = 0; |
63 | ||
64 | // first pass, build the key |
|
65 | 0 | Iterator criteria = this.getRuleCriteria().iterator(); |
66 | 0 | while (criteria.hasNext()) |
67 | { |
|
68 | 0 | RuleCriterion criterion = (RuleCriterion)criteria.next(); |
69 | 0 | if (criterion.getType() == null) |
70 | { |
|
71 | 0 | log.warn("Invalid criterion provided - type null on rule " + this); |
72 | } |
|
73 | 0 | RuleCriterionResolver resolver = getResolver(criterion.getType()); |
74 | 0 | if (resolver == null) |
75 | { |
|
76 | 0 | resolver = getDefaultResolver(); |
77 | } |
|
78 | 0 | String value = resolver.resolve(context, criterion); |
79 | 0 | key.append(criterion.getName()); |
80 | 0 | key.append(ProfileLocator.PATH_SEPARATOR); |
81 | 0 | key.append(value); |
82 | 0 | if (criteria.hasNext()) |
83 | { |
|
84 | 0 | key.append(ProfileLocator.PATH_SEPARATOR); |
85 | } |
|
86 | 0 | count++; |
87 | 0 | } |
88 | ||
89 | // try to get the profile locator from the cache, |
|
90 | // request path and key sufficient to generate unique key |
|
91 | 0 | String requestPath = context.getPath(); |
92 | 0 | String locatorKey = ((requestPath != null) ? requestPath : "/") + ProfileLocator.PATH_SEPARATOR + key.toString(); |
93 | 0 | ProfileLocator locator = getLocatorFromCache(locatorKey); |
94 | 0 | if (locator != null) |
95 | { |
|
96 | 0 | return locator; |
97 | } |
|
98 | ||
99 | // second pass, build the locator object |
|
100 | 0 | locator = service.createLocator(context); |
101 | 0 | criteria = this.getRuleCriteria().iterator(); |
102 | 0 | while (criteria.hasNext()) |
103 | { |
|
104 | 0 | RuleCriterion criterion = (RuleCriterion)criteria.next(); |
105 | 0 | if (criterion.getType() == null) |
106 | { |
|
107 | 0 | log.warn("Invalid criterion provided - type null on rule " + this); |
108 | } |
|
109 | 0 | RuleCriterionResolver resolver = getResolver(criterion.getType()); |
110 | 0 | if (resolver != null) |
111 | { |
|
112 | 0 | String value = resolver.resolve(context, criterion); |
113 | 0 | boolean isControl = resolver.isControl(criterion); |
114 | 0 | boolean isNavigation = resolver.isNavigation(criterion); |
115 | 0 | locator.add(criterion, isControl, isNavigation, value); |
116 | } |
|
117 | 0 | } |
118 | ||
119 | 0 | addLocatorToCache(locatorKey, locator); |
120 | 0 | return locator; |
121 | } |
|
122 | ||
123 | } |
|
124 | ||
125 |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |