Coverage report

  %line %branch
org.apache.jetspeed.profiler.rules.impl.RoleFallbackProfilingRule
0% 
0% 

 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  
 import java.util.StringTokenizer;
 21  
 
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 import org.apache.jetspeed.profiler.ProfileLocator;
 25  
 import org.apache.jetspeed.profiler.Profiler;
 26  
 import org.apache.jetspeed.profiler.rules.ProfileResolvers;
 27  
 import org.apache.jetspeed.profiler.rules.ProfilingRule;
 28  
 import org.apache.jetspeed.profiler.rules.RuleCriterion;
 29  
 import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
 30  
 import org.apache.jetspeed.request.RequestContext;
 31  
 
 32  
 /**
 33  
  * RoleFallbackProfilingRule
 34  
  *
 35  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
 36  
  * @version $Id: RoleFallbackProfilingRule.java 517121 2007-03-12 07:45:49Z ate $
 37  
  */
 38  
 public class RoleFallbackProfilingRule
 39  
     extends AbstractProfilingRule
 40  
     implements ProfilingRule
 41  
 {
 42  0
     protected final static Log log = LogFactory.getLog(RoleFallbackProfilingRule.class);
 43  
     private final static long serialVersionUID = 1L;
 44  
     
 45  
     public RoleFallbackProfilingRule()
 46  0
     {     
 47  0
         this.setClassname(class="keyword">this.getClass().getName());
 48  
 
 49  0
     }
 50  
     
 51  
     public RoleFallbackProfilingRule(ProfileResolvers resolvers) 
 52  
     {
 53  0
         super(resolvers);
 54  0
         this.setClassname(class="keyword">this.getClass().getName());
 55  0
     }
 56  
     
 57  
     
 58  
     /* (non-Javadoc)
 59  
      * @see org.apache.jetspeed.profiler.rules.ProfilingRule#apply(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.profiler.Profiler)
 60  
      */
 61  
     public ProfileLocator apply(RequestContext context, Profiler service)
 62  
     {
 63  0
         StringBuffer key = new StringBuffer();
 64  0
         int count = 0;
 65  
         
 66  
         // first pass, build the key
 67  0
         Iterator criteria = this.getRuleCriteria().iterator();
 68  0
         while (criteria.hasNext())
 69  
         {
 70  0
             RuleCriterion criterion = (RuleCriterion)criteria.next();
 71  0
             if (criterion.getType() == null)
 72  
             {
 73  0
                 log.warn("Invalid criterion provided - type null on rule " + this);
 74  
             }
 75  0
             RuleCriterionResolver resolver = getResolver(criterion.getType());
 76  0
             if (resolver == null)
 77  
             {
 78  0
                 resolver = getDefaultResolver();
 79  
             }
 80  0
             String value = resolver.resolve(context, criterion);
 81  0
             if (value != null && (resolver instanceof RoleCriterionResolver ||
 82  
                 resolver instanceof GroupCriterionResolver))
 83  
             {
 84  0
                 StringTokenizer tokenizer = new StringTokenizer(value, StandardResolver.VALUE_DELIMITER);
 85  0
                 while (tokenizer.hasMoreTokens())
 86  
                 {
 87  0
                     String token = tokenizer.nextToken();
 88  0
                     key.append(criterion.getName());
 89  0
                     key.append(ProfileLocator.PATH_SEPARATOR);
 90  0
                     key.append(token);
 91  0
                     if (tokenizer.hasMoreTokens())
 92  
                     {
 93  0
                         key.append(ProfileLocator.PATH_SEPARATOR);
 94  
                     }
 95  0
                 }
 96  0
             }
 97  
             else
 98  
             {
 99  0
                 key.append(criterion.getName());
 100  0
                 key.append(ProfileLocator.PATH_SEPARATOR);
 101  0
                 key.append(value);
 102  
             }
 103  0
             if (criteria.hasNext())
 104  
             {
 105  0
                 key.append(ProfileLocator.PATH_SEPARATOR);
 106  
             }
 107  0
             count++;                                                                                                    
 108  0
         }
 109  
         // try to get the profile locator from the cache,
 110  
         // request path and key sufficient to generate unique key
 111  0
         String requestPath = context.getPath();
 112  0
         String locatorKey = ((requestPath != null) ? requestPath : "/") + ProfileLocator.PATH_SEPARATOR + key.toString();
 113  0
         ProfileLocator locator = getLocatorFromCache(locatorKey); 
 114  0
         if (locator != null)
 115  
         {
 116  0
             return locator;
 117  
         }
 118  
         
 119  
         // second pass, build the locator object         
 120  0
         locator = service.createLocator(context);
 121  0
         criteria = this.getRuleCriteria().iterator();
 122  0
         while (criteria.hasNext())
 123  
         {
 124  0
             RuleCriterion criterion = (RuleCriterion)criteria.next();
 125  0
             if (criterion.getType() == null)
 126  
             {
 127  0
                 log.warn("Invalid criterion provided - name or type null on rule " + this);
 128  
             }
 129  0
             RuleCriterionResolver resolver = getResolver(criterion.getType());
 130  0
             if (resolver != null)
 131  
             {
 132  0
                 String value = resolver.resolve(context, criterion);
 133  0
                 boolean isControl = resolver.isControl(criterion);
 134  0
                 boolean isNavigation = resolver.isNavigation(criterion);
 135  0
                 if (value != null && (resolver instanceof RoleCriterionResolver ||
 136  
                         resolver instanceof GroupCriterionResolver))
 137  
                     {
 138  0
                         StringTokenizer tokenizer = new StringTokenizer(value, StandardResolver.VALUE_DELIMITER);
 139  0
                         while (tokenizer.hasMoreTokens())
 140  
                         {
 141  0
                             String token = tokenizer.nextToken();
 142  0
                             locator.add(criterion, isControl, isNavigation, token);
 143  0
                         }
 144  0
                     }
 145  
                     else
 146  
                     {
 147  0
                         locator.add(criterion, isControl, isNavigation, value);
 148  
                     }
 149  
             }                
 150  0
         }               
 151  
              
 152  0
         addLocatorToCache(locatorKey, locator);
 153  0
         return locator; 
 154  
         
 155  
     }
 156  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.