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  
18  package org.apache.commons.monitoring.servlet.jsp;
19  
20  import static org.apache.commons.monitoring.servlet.jsp.TagUtils.*;
21  
22  import javax.servlet.jsp.JspException;
23  import javax.servlet.jsp.tagext.TagSupport;
24  
25  import org.apache.commons.monitoring.Monitoring;
26  import org.apache.commons.monitoring.Repository;
27  import org.apache.commons.monitoring.StopWatch;
28  import org.apache.commons.monitoring.servlet.ServletContextUtil;
29  
30  /**
31   * A JSP tag to monitor JSP rendering performances
32   *
33   * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
34   */
35  public class StartTag
36      extends TagSupport
37  {
38      private String id;
39  
40      private String scope;
41  
42      private String name;
43  
44      private String category;
45  
46      private String subsystem;
47  
48      protected String repository;
49  
50  
51      /**
52       * @param id the id to set
53       */
54      public void setId( String id )
55      {
56          this.id = id;
57      }
58  
59      /**
60       * {@inheritDoc}
61       *
62       * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
63       */
64      @Override
65      public int doStartTag()
66          throws JspException
67      {
68          Repository repo = TagUtils.getRepository( pageContext, repository );
69  
70          StopWatch stopWatch = repo.start( repo.getMonitor( name, category, subsystem ) );
71          if (scope != null)
72          {
73              pageContext.setAttribute( id, stopWatch, getScope( scope ) );
74          }
75          else
76          {
77              pageContext.setAttribute( id, stopWatch );
78          }
79          return EVAL_PAGE;
80      }
81  
82      /**
83       * @param scope the scope to set
84       */
85      public void setScope( String scope )
86      {
87          this.scope = scope;
88      }
89  
90      /**
91       * @param name the name to set
92       */
93      public void setName( String name )
94      {
95          this.name = name;
96      }
97  
98      /**
99       * @param category the category to set
100      */
101     public void setCategory( String category )
102     {
103         this.category = category;
104     }
105 
106     /**
107      * @param subsystem the subsystem to set
108      */
109     public void setSubsystem( String subsystem )
110     {
111         this.subsystem = subsystem;
112     }
113 
114     public void setRepository( String repository )
115     {
116         this.repository = repository;
117     }
118 }