Coverage report

  %line %branch
org.apache.jetspeed.profiler.impl.JetspeedProfilerImpl
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.impl;
 18  
 
 19  
 import java.security.Principal;
 20  
 import java.util.Collection;
 21  
 import java.util.Collections;
 22  
 import java.util.HashMap;
 23  
 import java.util.Iterator;
 24  
 import java.util.Map;
 25  
 import java.util.Properties;
 26  
 
 27  
 import javax.security.auth.Subject;
 28  
 
 29  
 import org.apache.commons.logging.Log;
 30  
 import org.apache.commons.logging.LogFactory;
 31  
 import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport;
 32  
 import org.apache.jetspeed.profiler.ProfileLocator;
 33  
 import org.apache.jetspeed.profiler.Profiler;
 34  
 import org.apache.jetspeed.profiler.ProfilerException;
 35  
 import org.apache.jetspeed.profiler.rules.PrincipalRule;
 36  
 import org.apache.jetspeed.profiler.rules.ProfileResolvers;
 37  
 import org.apache.jetspeed.profiler.rules.ProfilingRule;
 38  
 import org.apache.jetspeed.profiler.rules.RuleCriterion;
 39  
 import org.apache.jetspeed.profiler.rules.impl.AbstractProfilingRule;
 40  
 import org.apache.jetspeed.profiler.rules.impl.PrincipalRuleImpl;
 41  
 import org.apache.jetspeed.request.RequestContext;
 42  
 import org.apache.jetspeed.security.SecurityHelper;
 43  
 import org.apache.jetspeed.security.UserPrincipal;
 44  
 import org.apache.jetspeed.security.impl.UserPrincipalImpl;
 45  
 import org.apache.ojb.broker.query.Criteria;
 46  
 import org.apache.ojb.broker.query.QueryFactory;
 47  
 import org.springframework.beans.BeansException;
 48  
 import org.springframework.beans.factory.BeanFactory;
 49  
 import org.springframework.beans.factory.BeanFactoryAware;
 50  
 
 51  
 /**
 52  
  * JetspeedTransactionalProfiler
 53  
  * 
 54  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
 55  
  * @version $Id: JetspeedProfilerImpl.java 553647 2007-07-05 21:42:04Z taylor $
 56  
  */
 57  
 public class JetspeedProfilerImpl extends InitablePersistenceBrokerDaoSupport 
 58  
         implements Profiler, BeanFactoryAware
 59  
 {
 60  
     /** The default rule. */
 61  
     public final static String DEFAULT_RULE = "j1";
 62  
     
 63  
     /** Commons logging */
 64  0
     protected final static Log log = LogFactory.getLog(JetspeedProfilerImpl.class);
 65  
 
 66  
     /**
 67  
      * This is the princapl that is used if there are no principal to rule associations for the current principal
 68  
      */
 69  0
     public final static Principal DEFAULT_RULE_PRINCIPAL = new UserPrincipalImpl("*");
 70  
 
 71  
     /** The default locator class implementation */
 72  0
     private String locatorBean = "ProfileLocator";
 73  
 
 74  
     /** The default principalRule association class implementation */
 75  
     private Class prRuleClass;
 76  
     
 77  0
     private String principalRuleBean = "PrincipalRule";
 78  
     
 79  
     /** The base (abstract) profilingRule class implementation */
 80  0
     private String profilingRuleStandardBean = "StandardProfilingRule";
 81  
     
 82  
     /** The base (abstract) profilingRule class implementation */
 83  0
     private String profilingRuleFallbackBean = "RoleFallbackProfilingRule";    
 84  
     
 85  
     /** The base (abstract) profilingRule class implementation */
 86  0
     private Class profilingRuleClass = AbstractProfilingRule.class;
 87  
 
 88  
     /** The configured default rule for this portal */
 89  0
     private String defaultRule = DEFAULT_RULE;
 90  
 
 91  0
     private Map principalRules = Collections.synchronizedMap(new HashMap());
 92  
 
 93  0
     private Map rulesPerPrincipal = Collections.synchronizedMap(new HashMap());
 94  
 
 95  
     private ProfileResolvers resolvers;
 96  
 
 97  
     /** the default criterion bean name */
 98  0
     private String ruleCriterionBean = "RuleCriterion";
 99  
 
 100  
     /**
 101  
      * added support for bean factory to create profile rules
 102  
      */
 103  
     private BeanFactory beanFactory;
 104  
 
 105  
     public JetspeedProfilerImpl(String repositoryPath,
 106  
             ProfileResolvers resolvers)
 107  
     {
 108  0
         super(repositoryPath);
 109  0
         this.resolvers = resolvers;
 110  0
     }
 111  
 
 112  
     /**
 113  
      * Create a JetspeedProfiler with properties. Expected properties are:
 114  
      * defaultRule = the default profiling rule anonymousUser = the name of the
 115  
      * anonymous user storeName = The name of the persistence store component to
 116  
      * connect to services.profiler.locator.impl = the pluggable Profile Locator
 117  
      * impl services.profiler.principalRule.impl = the pluggable Principal Rule
 118  
      * impl services.profiler.profilingRule.impl = the pluggable Profiling Rule
 119  
      * impl
 120  
      * 
 121  
      * @param properties
 122  
      *            Properties for this component described above
 123  
      * @throws ClassNotFoundException
 124  
      *             if any the implementation classes defined within the
 125  
      *             <code>properties</code> argument could not be found.
 126  
      */
 127  
     public JetspeedProfilerImpl(String repositoryPath, String defaultRule,
 128  
             ProfileResolvers resolvers) throws ClassNotFoundException
 129  
     {
 130  0
         this(repositoryPath, resolvers);
 131  0
         this.defaultRule = defaultRule;
 132  0
     }
 133  
 
 134  
     /**
 135  
      * @deprecated As of release 2.1, property-based class references replaced
 136  
      *             by container managed bean factory
 137  
      */
 138  
     public JetspeedProfilerImpl(String repositoryPath, String defaultRule,
 139  
             Properties properties, ProfileResolvers resolvers)
 140  
             throws ClassNotFoundException
 141  
     {
 142  0
         this(repositoryPath, defaultRule, resolvers);
 143  0
         initModelClasses(properties); // TODO: move this to
 144  
         // start()
 145  0
     }
 146  
 
 147  
     /**
 148  
      * support passing of rule creation classes
 149  
      */
 150  
     public JetspeedProfilerImpl(String repositoryPath, String defaultRule,
 151  
             ProfileResolvers resolvers, Map ruleConstructors,
 152  
             String ruleCriterionBean) throws ClassNotFoundException
 153  
     {
 154  0
         this(repositoryPath, defaultRule, resolvers);
 155  0
         this.ruleCriterionBean = ruleCriterionBean;
 156  0
         initRuleClasses(ruleConstructors);
 157  0
     }
 158  
 
 159  
     /**
 160  
      * @param defaultRule
 161  
      *            The default rule to set.
 162  
      */
 163  
     public void setDefaultRule(String defaultRule)
 164  
     {
 165  0
         this.defaultRule = defaultRule;
 166  0
     }
 167  
 
 168  
     /**
 169  
      * @deprecated As of release 2.1, property-based class references replaced
 170  
      *             by container managed bean factory
 171  
      */
 172  
     private void initModelClasses(Properties properties)
 173  
             throws ClassNotFoundException
 174  
     {
 175  
 
 176  
         /**
 177  
          * String modelName = "";
 178  
          * 
 179  
          * if ((modelName = properties.getProperty("locator.impl")) != null) { //
 180  
          * locatorClassName = modelName; } if ((modelName =
 181  
          * properties.getProperty("principalRule.impl")) != null) {
 182  
          * principalRuleClass = Class.forName(modelName); } if ((modelName =
 183  
          * properties.getProperty("profilingRule.impl")) != null) {
 184  
          * profilingRuleClass = Class.forName(modelName); }
 185  
          */
 186  0
     }
 187  
 
 188  
     public ProfileLocator getProfile(RequestContext context, String locatorName)
 189  
             throws ProfilerException
 190  
     {
 191  
         // get the principal representing the currently logged on user
 192  0
         Subject subject = context.getSubject();
 193  0
         if (subject == null)
 194  
         {
 195  0
             String msg = "Invalid (null) Subject in request pipeline";
 196  0
             log.error(msg);
 197  0
             throw new ProfilerException(msg);
 198  
         }
 199  
         // get the UserPrincipal, finding the first UserPrincipal, or
 200  
         // find the first principal if no UserPrincipal isn't available
 201  0
         Principal principal = SecurityHelper.getBestPrincipal(subject,
 202  
                 UserPrincipal.class);
 203  0
         if (principal == null)
 204  
         {
 205  0
             String msg = "Could not find a principle for subject in request pipeline";
 206  0
             log.error(msg);
 207  0
             throw new ProfilerException(msg);
 208  
         }
 209  
 
 210  
         // find a profiling rule for this principal
 211  0
         ProfilingRule rule = getRuleForPrincipal(principal, locatorName);
 212  0
         if (null == rule)
 213  
         {
 214  0
             log.warn("Could not find profiling rule for principal: "
 215  
                     + principal);
 216  0
             rule = this.getDefaultRule();
 217  
         }
 218  
 
 219  0
         if (null == rule)
 220  
         {
 221  0
             String msg = "Couldn't find any profiling rules including default rule for principal "
 222  
                     + principal;
 223  0
             log.error(msg);
 224  0
             throw new ProfilerException(msg);
 225  
         }
 226  
         // create a profile locator for given rule
 227  0
         return rule.apply(context, this);
 228  
     }
 229  
 
 230  
     public ProfileLocator getDefaultProfile(RequestContext context,
 231  
             String locatorName) throws ProfilerException
 232  
     {
 233  
 
 234  0
         ProfilingRule rule = getRuleForPrincipal(DEFAULT_RULE_PRINCIPAL,
 235  
                 locatorName);
 236  0
         if (null == rule)
 237  
         {
 238  0
             log.warn("Could not find profiling rule for principal: "
 239  
                     + DEFAULT_RULE_PRINCIPAL);
 240  0
             rule = this.getDefaultRule();
 241  
         }
 242  
 
 243  0
         if (null == rule)
 244  
         {
 245  0
             String msg = "Couldn't find any profiling rules including default rule for principal "
 246  
                     + DEFAULT_RULE_PRINCIPAL;
 247  0
             log.error(msg);
 248  0
             throw new ProfilerException(msg);
 249  
         }
 250  
         // create a profile locator for given rule
 251  0
         return rule.apply(context, this);
 252  
     }
 253  
 
 254  
     /*
 255  
      * (non-Javadoc)
 256  
      * 
 257  
      * @see org.apache.jetspeed.profiler.Profiler#getProfile(org.apache.jetspeed.request.RequestContext,
 258  
      *      org.apache.jetspeed.profiler.rules.ProfilingRule)
 259  
      */
 260  
     public ProfileLocator getProfile(RequestContext context, ProfilingRule rule)
 261  
             throws ProfilerException
 262  
     {
 263  
         // create a profile locator for given rule
 264  0
         return rule.apply(context, this);
 265  
     }
 266  
 
 267  
     /*
 268  
      * (non-Javadoc)
 269  
      * 
 270  
      * @see org.apache.jetspeed.profiler.Profiler#getRuleForPrincipal(java.security.Principal,
 271  
      *      java.lang.String)
 272  
      */
 273  
     public ProfilingRule getRuleForPrincipal(Principal principal,
 274  
             String locatorName)
 275  
     {
 276  0
         ProfilingRule rule = null;
 277  
         // lookup the rule for the given principal in our user/rule table
 278  0
         PrincipalRule pr = lookupPrincipalRule(principal.getName(), locatorName);
 279  
 
 280  
         // if not found, fallback to the locator named rule or system wide rule
 281  0
         if (pr == null)
 282  
         {
 283  
             // find rule on locator name
 284  0
             rule = getRule(locatorName);
 285  
 
 286  0
             if (rule == null)
 287  
             {
 288  
                 // if not found, fallback to the system wide rule
 289  0
                 rule = getDefaultRule();
 290  
             }
 291  0
             pr = new PrincipalRuleImpl();
 292  0
             pr.setLocatorName(locatorName);
 293  0
             pr.setPrincipalName(principal.getName());
 294  0
             pr.setProfilingRule(rule);
 295  0
             principalRules.put(makePrincipalRuleKey(principal.getName(),
 296  
                     locatorName), pr);
 297  
         } else
 298  
         {
 299  
             // Get the associated rule
 300  0
             rule = pr.getProfilingRule();
 301  
         }
 302  
 
 303  0
         return rule;
 304  
     }
 305  
 
 306  
     /**
 307  
      * Internal method to ensure we have a valid principalRule class for queries
 308  
      * 
 309  
      * @return the class object for the principalRule
 310  
      */
 311  
     private Class getPrincipalRuleClass()
 312  
     {
 313  0
         if (this.prRuleClass == null)
 314  
         {
 315  
             try
 316  
             {
 317  0
                 PrincipalRule tempRule = createPrincipalRule();
 318  0
                 this.prRuleClass = tempRule.getClass();
 319  0
             } catch (Exception e)
 320  
             {
 321  0
                 e.printStackTrace();
 322  0
             }
 323  
         }
 324  0
         return this.prRuleClass;
 325  
     }
 326  
 
 327  
     /*
 328  
      * (non-Javadoc)
 329  
      * 
 330  
      * @see org.apache.jetspeed.profiler.Profiler#setRuleForPrincipal(java.security.Principal,
 331  
      *      org.apache.jetspeed.profiler.rules.ProfilingRule, java.lang.String)
 332  
      */
 333  
     public void setRuleForPrincipal(Principal principal, ProfilingRule rule,
 334  
             String locatorName)
 335  
     {
 336  0
         Criteria c = new Criteria();
 337  0
         c.addEqualTo("principalName", principal.getName());
 338  0
         c.addEqualTo("locatorName", locatorName);
 339  0
         PrincipalRule pr = (PrincipalRule) getPersistenceBrokerTemplate()
 340  
                 .getObjectByQuery(
 341  
                         QueryFactory.newQuery(getPrincipalRuleClass(), c));
 342  
 
 343  0
         if (pr == null)
 344  
         {
 345  0
             pr = new PrincipalRuleImpl(); // TODO: factory
 346  0
             pr.setPrincipalName(principal.getName());
 347  0
             pr.setLocatorName(locatorName);
 348  0
             pr.setProfilingRule(rule);
 349  
         }
 350  0
         rule.setResolvers(resolvers);
 351  0
         pr.setProfilingRule(rule);
 352  0
         getPersistenceBrokerTemplate().store(pr);
 353  0
         principalRules.put(makePrincipalRuleKey(principal.getName(),
 354  
                 locatorName), pr);
 355  0
         this.rulesPerPrincipal.remove(principal.getName());
 356  0
     }
 357  
 
 358  
     private String makePrincipalRuleKey(String principal, String locator)
 359  
     {
 360  0
         return principal + ":" + locator;
 361  
     }
 362  
 
 363  
     /**
 364  
      * Helper function to lookup principal rule associations by principal
 365  
      * 
 366  
      * @param principal
 367  
      *            The string representation of the principal name.
 368  
      * @return The found PrincipalRule associated with the principal key or null
 369  
      *         if not found.
 370  
      */
 371  
     private PrincipalRule lookupPrincipalRule(String principal,
 372  
             String locatorName)
 373  
     {
 374  0
         PrincipalRule pr = (PrincipalRule) principalRules
 375  
                 .get(makePrincipalRuleKey(principal, locatorName));
 376  0
         if (pr != null) { return pr; }
 377  0
         Criteria c = new Criteria();
 378  0
         c.addEqualTo("principalName", principal);
 379  0
         c.addEqualTo("locatorName", locatorName);
 380  
 
 381  0
         pr = (PrincipalRule) getPersistenceBrokerTemplate().getObjectByQuery(
 382  
                 QueryFactory.newQuery(getPrincipalRuleClass(), c));
 383  
 
 384  0
         principalRules.put(makePrincipalRuleKey(principal, locatorName), pr);
 385  0
         if (pr != null) pr.getProfilingRule().setResolvers(resolvers);
 386  0
         return pr;
 387  
     }
 388  
 
 389  
     /*
 390  
      * (non-Javadoc)
 391  
      * 
 392  
      * @see org.apache.jetspeed.profiler.Profiler#getDefaultRule()
 393  
      */
 394  
     public ProfilingRule getDefaultRule()
 395  
     {
 396  0
         return getRule(this.defaultRule);
 397  
     }
 398  
 
 399  
     /*
 400  
      * (non-Javadoc)
 401  
      * 
 402  
      * @see org.apache.jetspeed.profiler.Profiler#getRules()
 403  
      */
 404  
     public Collection getRules()
 405  
     {
 406  0
         Collection rules = getPersistenceBrokerTemplate().getCollectionByQuery(
 407  
                 QueryFactory.newQuery(profilingRuleClass, new Criteria()));
 408  0
         Iterator r = rules.iterator();
 409  0
         while (r.hasNext())
 410  
         {
 411  0
             ProfilingRule rule = (ProfilingRule) r.next();
 412  0
             rule.setResolvers(resolvers);
 413  0
         }
 414  0
         return rules;
 415  
     }
 416  
 
 417  
     /*
 418  
      * (non-Javadoc)
 419  
      * 
 420  
      * @see org.apache.jetspeed.profiler.Profiler#getRule(java.lang.String)
 421  
      */
 422  
     public ProfilingRule getRule(String id)
 423  
     {
 424  0
         Criteria c = new Criteria();
 425  0
         c.addEqualTo("id", id);
 426  
 
 427  0
         ProfilingRule rule = (ProfilingRule) getPersistenceBrokerTemplate()
 428  
                 .getObjectByQuery(QueryFactory.newQuery(profilingRuleClass, c));
 429  0
         if (rule != null)
 430  
         {
 431  0
             rule.setResolvers(resolvers);
 432  
         }
 433  0
         return rule;
 434  
     }
 435  
 
 436  
     /*
 437  
      * (non-Javadoc)
 438  
      * 
 439  
      * @see org.apache.jetspeed.profiler.Profiler#getLocatorNamesForPrincipal(java.security.Principal)
 440  
      */
 441  
     public String[] getLocatorNamesForPrincipal(Principal principal)
 442  
     {
 443  0
         Criteria c = new Criteria();
 444  0
         c.addEqualTo("principalName", principal.getName());
 445  
 
 446  0
         Collection result = getPersistenceBrokerTemplate()
 447  
                 .getCollectionByQuery(
 448  
                         QueryFactory.newQuery(getPrincipalRuleClass(), c));
 449  0
         if (result.size() == 0) { return new String[]
 450  
         {}; }
 451  0
         String[] names = new String[result.size()];
 452  0
         Iterator it = result.iterator();
 453  0
         int ix = 0;
 454  0
         while (it.hasNext())
 455  
         {
 456  0
             PrincipalRule pr = (PrincipalRule) it.next();
 457  0
             names[ix] = pr.getLocatorName();
 458  0
             pr.getProfilingRule().setResolvers(resolvers);
 459  0
             ix++;
 460  0
         }
 461  0
         return names;
 462  
     }
 463  
 
 464  
     /*
 465  
      * (non-Javadoc)
 466  
      * 
 467  
      * @see org.apache.jetspeed.profiler.Profiler#getRulesForPrincipal(java.security.Principal)
 468  
      */
 469  
     public Collection getRulesForPrincipal(Principal principal)
 470  
     {
 471  
 
 472  0
         Collection rules = (Collection) this.rulesPerPrincipal.get(principal
 473  
                 .getName());
 474  0
         if (rules != null) return rules;
 475  0
         Criteria c = new Criteria();
 476  0
         c.addEqualTo("principalName", principal.getName());
 477  0
         rules = getPersistenceBrokerTemplate().getCollectionByQuery(
 478  
                 QueryFactory.newQuery(getPrincipalRuleClass(), c));
 479  0
         Iterator r = rules.iterator();
 480  0
         while (r.hasNext())
 481  
         {
 482  0
             PrincipalRule pr = (PrincipalRule) r.next();
 483  0
             ProfilingRule rule = pr.getProfilingRule();
 484  0
             if (rule != null) rule.setResolvers(resolvers);
 485  0
         }
 486  0
         this.rulesPerPrincipal.put(principal.getName(), rules);
 487  0
         return rules;
 488  
     }
 489  
 
 490  
     /*
 491  
      * (non-Javadoc)
 492  
      * 
 493  
      * @see org.apache.jetspeed.profiler.Profiler#getProfileLocators(org.apache.jetspeed.request.RequestContext,
 494  
      *      java.security.Principal)
 495  
      */
 496  
     public Map getProfileLocators(RequestContext context, Principal principal)
 497  
             throws ProfilerException
 498  
     {
 499  0
         Map locators = new HashMap();
 500  0
         Collection rules = getRulesForPrincipal(principal);
 501  
 
 502  0
         Iterator it = rules.iterator();
 503  0
         while (it.hasNext())
 504  
         {
 505  0
             PrincipalRule pr = (PrincipalRule) it.next();
 506  0
             locators.put(pr.getLocatorName(), getProfile(context, pr
 507  
                     .getLocatorName()));
 508  0
         }
 509  0
         return locators;
 510  
     }
 511  
 
 512  
     public Map getDefaultProfileLocators(RequestContext context)
 513  
             throws ProfilerException
 514  
     {
 515  0
         Map locators = new HashMap();
 516  
 
 517  0
         Collection rules = getRulesForPrincipal(DEFAULT_RULE_PRINCIPAL);
 518  
 
 519  0
         Iterator it = rules.iterator();
 520  0
         while (it.hasNext())
 521  
         {
 522  0
             PrincipalRule pr = (PrincipalRule) it.next();
 523  0
             locators.put(pr.getLocatorName(), getDefaultProfile(context, pr
 524  
                     .getLocatorName()));
 525  0
         }
 526  0
         return locators;
 527  
     }
 528  
 
 529  
     /*
 530  
      * (non-Javadoc)
 531  
      * 
 532  
      * @see org.apache.jetspeed.profiler.Profiler#storeProfilingRule(org.apache.jetspeed.profiler.rules.ProfilingRule)
 533  
      */
 534  
     public void storeProfilingRule(ProfilingRule rule) throws ProfilerException
 535  
     {
 536  0
         getPersistenceBrokerTemplate().store(rule);
 537  0
     }
 538  
 
 539  
     /*
 540  
      * (non-Javadoc)
 541  
      * 
 542  
      * @see org.apache.jetspeed.profiler.Profiler#deleteProfilingRule(org.apache.jetspeed.profiler.rules.ProfilingRule)
 543  
      */
 544  
     public void deleteProfilingRule(ProfilingRule rule)
 545  
             throws ProfilerException
 546  
     {
 547  0
         getPersistenceBrokerTemplate().delete(rule);
 548  0
     }
 549  
 
 550  
     /*
 551  
      * (non-Javadoc)
 552  
      * 
 553  
      * @see org.apache.jetspeed.profiler.Profiler#storePrincipalRule(org.apache.jetspeed.profiler.rules.PrincipalRule)
 554  
      */
 555  
     public void storePrincipalRule(PrincipalRule rule) throws ProfilerException
 556  
     {
 557  0
         getPersistenceBrokerTemplate().store(rule);
 558  0
     }
 559  
 
 560  
     /*
 561  
      * (non-Javadoc)
 562  
      * 
 563  
      * @see org.apache.jetspeed.profiler.Profiler#deletePrincipalRule(org.apache.jetspeed.profiler.rules.PrincipalRule)
 564  
      */
 565  
     public void deletePrincipalRule(PrincipalRule rule)
 566  
             throws ProfilerException
 567  
     {
 568  0
         getPersistenceBrokerTemplate().delete(rule);
 569  0
         rulesPerPrincipal.remove(rule.getPrincipalName());
 570  0
         String key = this.makePrincipalRuleKey(rule.getPrincipalName(), rule.getLocatorName());
 571  0
         principalRules.remove(key);                
 572  0
     }
 573  
 
 574  
     /*
 575  
      * Method called automatically by Spring container upon initialization
 576  
      * 
 577  
      * @param beanFactory automatically provided by framework @throws
 578  
      * BeansException
 579  
      */
 580  
     public void setBeanFactory(BeanFactory beanFactory) throws BeansException
 581  
     {
 582  0
         this.beanFactory = beanFactory;
 583  0
     }
 584  
 
 585  
     /**
 586  
      * added logic to get the settings for creating the various rule related
 587  
      * instances
 588  
      * 
 589  
      * @param classes
 590  
      * @throws ClassNotFoundException
 591  
      */
 592  
     private void initRuleClasses(Map beans) throws ClassNotFoundException
 593  
     {
 594  
 
 595  0
         String beanName = "";
 596  
         try
 597  
         {
 598  0
             if ((beanName = (String) beans.get("locator")) != null)
 599  
             {
 600  0
                 this.locatorBean = beanName;
 601  
             }
 602  0
         } catch (Exception e)
 603  
         {
 604  0
             String msg = "Exception in setting locatorbeanName : "
 605  
                     + e.getLocalizedMessage();
 606  0
             log.error(msg);
 607  0
         }
 608  
         try
 609  
         {
 610  0
             if ((beanName = (String) beans.get("principal")) != null)
 611  
             {
 612  0
                 this.principalRuleBean = beanName;
 613  
             }
 614  0
         } catch (Exception e)
 615  
         {
 616  0
             String msg = "Exception in setting principalRulebeanName : "
 617  
                     + e.getLocalizedMessage();
 618  0
             log.error(msg);
 619  0
         }
 620  
         try
 621  
         {
 622  0
             if ((beanName = (String) beans.get("standard")) != null)
 623  
             {
 624  0
                 this.profilingRuleStandardBean = beanName;
 625  
             }
 626  0
         } catch (Exception e)
 627  
         {
 628  0
             String msg = "Exception in setting profilingRuleStandardbeanName : "
 629  
                     + e.getLocalizedMessage();
 630  0
             log.error(msg);
 631  0
         }
 632  
         try
 633  
         {
 634  0
             if ((beanName = (String) beans.get("fallback")) != null)
 635  
             {
 636  0
                 this.profilingRuleFallbackBean = beanName;
 637  
             }
 638  0
         } catch (Exception e)
 639  
         {
 640  0
             String msg = "Exception in setting profilingRuleFallback : "
 641  
                     + e.getLocalizedMessage();
 642  0
             log.error(msg);
 643  0
         }
 644  
 
 645  0
     }
 646  
 
 647  
     /*
 648  
      * (non-Javadoc)
 649  
      * 
 650  
      * @see org.apache.jetspeed.profiler.Profiler#createProfilingRule(boolean)
 651  
      */
 652  
     public ProfilingRule createProfilingRule(boolean standard)
 653  
             throws ClassNotFoundException
 654  
     {
 655  
         try
 656  
         {
 657  0
             if (standard)
 658  0
                 return (ProfilingRule) beanFactory.getBean(
 659  
                         this.profilingRuleStandardBean, ProfilingRule.class);
 660  
             else
 661  0
                 return (ProfilingRule) beanFactory.getBean(
 662  
                         this.profilingRuleFallbackBean, ProfilingRule.class);
 663  
 
 664  0
         } catch (BeansException e)
 665  
         {
 666  0
             throw new ClassNotFoundException("Spring failed to create the "
 667  
                     + (standard ? "standard" : "fallback")
 668  
                     + " profiling rule bean.", e);
 669  
         }
 670  
     }
 671  
 
 672  
     /*
 673  
      * (non-Javadoc)
 674  
      * 
 675  
      * @see org.apache.jetspeed.profiler.Profiler#createLocator(RequestContext)
 676  
      */
 677  
     public ProfileLocator createLocator(RequestContext context)
 678  
     {
 679  
         try
 680  
         {
 681  0
             ProfileLocator locator = (ProfileLocator) beanFactory.getBean(
 682  
                     this.locatorBean, ProfileLocator.class);
 683  0
             locator.init(this, context.getPath());
 684  0
             return locator;
 685  0
         } catch (Exception e)
 686  
         {
 687  0
             log.error("Failed to create locator for " + this.locatorBean
 688  
                     + " error : " + e.getLocalizedMessage());
 689  
         }
 690  0
         return null;
 691  
     }
 692  
 
 693  
     /*
 694  
      * (non-Javadoc)
 695  
      * 
 696  
      * @see org.apache.jetspeed.profiler.Profiler#createPrincipalRule()
 697  
      */
 698  
     public PrincipalRule createPrincipalRule() throws ClassNotFoundException
 699  
     {
 700  
         try
 701  
         {
 702  0
             PrincipalRule principalRule = (PrincipalRule) beanFactory.getBean(
 703  
                     this.principalRuleBean, PrincipalRule.class);
 704  0
             return principalRule;
 705  0
         } catch (Exception e)
 706  
         {
 707  0
             log.error("Failed to create principalRule for " + principalRuleBean
 708  
                     + " error : " + e.getLocalizedMessage());
 709  0
             throw new ClassNotFoundException("Spring failed to create the "
 710  
                     + " principal rule bean.", e);
 711  
         }
 712  
 
 713  
     }
 714  
 
 715  
     /*
 716  
      * (non-Javadoc)
 717  
      * 
 718  
      * @see org.apache.jetspeed.profiler.Profiler#createRuleCriterion()
 719  
      */
 720  
     public RuleCriterion createRuleCriterion() throws ClassNotFoundException
 721  
     {
 722  
         try
 723  
         {
 724  0
             RuleCriterion ruleCriterion = (RuleCriterion) beanFactory.getBean(
 725  
                     this.ruleCriterionBean, RuleCriterion.class);
 726  0
             return ruleCriterion;
 727  0
         } catch (Exception e)
 728  
         {
 729  0
             log.error("Failed to create principalRule for " + ruleCriterionBean
 730  
                     + " error : " + e.getLocalizedMessage());
 731  0
             throw new ClassNotFoundException("Spring failed to create the "
 732  
                     + " rule criterion bean.", e);
 733  
         }
 734  
 
 735  
     }
 736  
 
 737  
 }

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