View Javadoc

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.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      /* (non-Javadoc)
72       * @see org.apache.jetspeed.profiler.rules.ProfilingRule#getResolver(java.lang.String)
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      /* (non-Javadoc)
85       * @see org.apache.jetspeed.profiler.rules.ProfilingRule#apply(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.profiler.Profiler)
86       */
87      public abstract ProfileLocator apply(RequestContext context, Profiler service);
88      
89      /* (non-Javadoc)
90       * @see org.apache.jetspeed.profiler.rules.ProfilingRule#getRuleCriterion()
91       */
92      public Collection getRuleCriteria()
93      {
94          return criteria;
95      }
96      
97      /* (non-Javadoc)
98       * @see org.apache.jetspeed.profiler.rules.ProfilingRule#getId()
99       */
100     public String getId()
101     {
102         return this.id;    
103     }
104     
105     /* (non-Javadoc)
106      * @see org.apache.jetspeed.profiler.rules.ProfilingRule#setId(java.lang.String)
107      */
108     public void setId(String id)
109     {
110         this.id = id;
111     }
112         
113     /* (non-Javadoc)
114      * @see org.apache.jetspeed.profiler.rules.ProfilingRule#getTitle()
115      */
116     public String getTitle()
117     {
118         return this.title;
119     }
120     
121     /* (non-Javadoc)
122      * @see org.apache.jetspeed.profiler.rules.ProfilingRule#setTitle(java.lang.String)
123      */
124     public void setTitle(String title)
125     {
126         this.title = title;                        
127     }
128 
129     /* (non-Javadoc)
130      * @see org.apache.jetspeed.profiler.rules.ProfilingRule#getClassname()
131      */
132     public String getClassname()
133     {
134         return this.ojbConcreteClass;
135     }
136     
137     /* (non-Javadoc)
138      * @see org.apache.jetspeed.profiler.rules.ProfilingRule#setClassname(java.lang.String)
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 }