portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r320995 - in /portals/jetspeed-2/trunk/components/profiler/src: java/org/apache/jetspeed/profiler/impl/ java/org/apache/jetspeed/profiler/rules/impl/ test/org/apache/jetspeed/profiler/
Date Fri, 14 Oct 2005 04:14:25 GMT
Author: taylor
Date: Thu Oct 13 21:14:21 2005
New Revision: 320995

URL: http://svn.apache.org/viewcvs?rev=320995&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-379

move initialization of criterion resolvers into a spring component (ProfileResolversImpl)


Added:
    portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/ProfileResolversImpl.java
Modified:
    portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfilerImpl.java
    portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/AbstractProfilingRule.java
    portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java
    portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/StandardProfilingRule.java
    portals/jetspeed-2/trunk/components/profiler/src/test/org/apache/jetspeed/profiler/TestProfiler.java

Modified: portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfilerImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfilerImpl.java?rev=320995&r1=320994&r2=320995&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfilerImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfilerImpl.java
Thu Oct 13 21:14:21 2005
@@ -31,6 +31,7 @@
 import org.apache.jetspeed.profiler.Profiler;
 import org.apache.jetspeed.profiler.ProfilerException;
 import org.apache.jetspeed.profiler.rules.PrincipalRule;
+import org.apache.jetspeed.profiler.rules.ProfileResolvers;
 import org.apache.jetspeed.profiler.rules.ProfilingRule;
 import org.apache.jetspeed.profiler.rules.impl.AbstractProfilingRule;
 import org.apache.jetspeed.profiler.rules.impl.PrincipalRuleImpl;
@@ -76,9 +77,12 @@
 
     private Map rulesPerPrincipal = new HashMap();
 
-    public JetspeedProfilerImpl(String repositoryPath)
+    private ProfileResolvers resolvers;
+    
+    public JetspeedProfilerImpl(String repositoryPath, ProfileResolvers resolvers)
     {
         super(repositoryPath);
+        this.resolvers = resolvers;
     }
 
     /**
@@ -93,17 +97,17 @@
      *             if any the implementation classes defined within the <code>properties</code>
argument could not be
      *             found.
      */
-    public JetspeedProfilerImpl(String repositoryPath, String defaultRule) throws ClassNotFoundException
+    public JetspeedProfilerImpl(String repositoryPath, String defaultRule, ProfileResolvers
resolvers) 
+    throws ClassNotFoundException
     {
-        this(repositoryPath);
+        this(repositoryPath, resolvers);
         this.defaultRule = defaultRule;
-        // start()
     }
 
-    public JetspeedProfilerImpl(String repositoryPath, String defaultRule, Properties properties)
+    public JetspeedProfilerImpl(String repositoryPath, String defaultRule, Properties properties,
ProfileResolvers resolvers)
             throws ClassNotFoundException
     {
-        this(repositoryPath, defaultRule);
+        this(repositoryPath, defaultRule, resolvers);
         initModelClasses(properties); // TODO: move this to
         // start()
     }
@@ -279,6 +283,7 @@
             pr.setLocatorName(locatorName);
             pr.setProfilingRule(rule);
         }
+        rule.setResolvers(resolvers);        
         pr.setProfilingRule(rule);
         getPersistenceBrokerTemplate().store(pr);
         principalRules.put(makePrincipalRuleKey(principal.getName(), locatorName), pr);
@@ -310,8 +315,10 @@
 
         pr = (PrincipalRule) getPersistenceBrokerTemplate().getObjectByQuery(
                 QueryFactory.newQuery(principalRuleClass, c));
-
+        
         principalRules.put(makePrincipalRuleKey(principal, locatorName), pr);
+        if (pr != null)
+            pr.getProfilingRule().setResolvers(resolvers);
         return pr;
     }
 
@@ -332,8 +339,15 @@
      */
     public Collection getRules()
     {
-        return getPersistenceBrokerTemplate().getCollectionByQuery(
+        Collection rules = getPersistenceBrokerTemplate().getCollectionByQuery(
                 QueryFactory.newQuery(profilingRuleClass, new Criteria()));
+        Iterator r = rules.iterator();
+        while (r.hasNext())
+        {
+            ProfilingRule rule = (ProfilingRule)r.next();
+            rule.setResolvers(resolvers);
+        }
+        return rules;
     }
 
     /*
@@ -343,12 +357,16 @@
      */
     public ProfilingRule getRule(String id)
     {
-        // TODO: implement caching
         Criteria c = new Criteria();
         c.addEqualTo("id", id);
 
-        return (ProfilingRule) getPersistenceBrokerTemplate().getObjectByQuery(
+        ProfilingRule rule = (ProfilingRule)getPersistenceBrokerTemplate().getObjectByQuery(
                 QueryFactory.newQuery(profilingRuleClass, c));
+        if (rule != null)
+        {
+            rule.setResolvers(resolvers);
+        }
+        return rule;
     }
 
     /*
@@ -375,6 +393,7 @@
         {
             PrincipalRule pr = (PrincipalRule) it.next();
             names[ix] = pr.getLocatorName();
+            pr.getProfilingRule().setResolvers(resolvers);
             ix++;
         }
         return names;
@@ -393,6 +412,14 @@
         Criteria c = new Criteria();
         c.addEqualTo("principalName", principal.getName());
         rules = getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(principalRuleClass,
c));
+        Iterator r = rules.iterator();
+        while (r.hasNext())
+        {
+            PrincipalRule pr = (PrincipalRule)r.next();
+            ProfilingRule rule = pr.getProfilingRule();
+            if (rule != null)
+                rule.setResolvers(resolvers);
+        }        
         this.rulesPerPrincipal.put(principal.getName(), rules);
         return rules;
     }

Modified: portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/AbstractProfilingRule.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/AbstractProfilingRule.java?rev=320995&r1=320994&r2=320995&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/AbstractProfilingRule.java
(original)
+++ portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/AbstractProfilingRule.java
Thu Oct 13 21:14:21 2005
@@ -22,6 +22,7 @@
 
 import org.apache.jetspeed.profiler.ProfileLocator;
 import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.profiler.rules.ProfileResolvers;
 import org.apache.jetspeed.profiler.rules.ProfilingRule;
 import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
 import org.apache.jetspeed.request.RequestContext;
@@ -34,36 +35,28 @@
  */
 public abstract class AbstractProfilingRule implements ProfilingRule
 {
+    private static final long serialVersionUID = 1;    
     protected Collection criteria = new Vector();
     protected String id;
     protected String title;
     protected String ojbConcreteClass;
     
     /** Map of profile locators kept around for reuse TODO: evict entries after max size
reached */    
-    static Map locators = new HashMap();
+    protected Map locators = new HashMap();
     
     /** Map of resolver rules for criteria. The map goes from criterion name to resolver
class */
-    static Map resolvers = new HashMap();
+    protected ProfileResolvers resolvers;
+
+    public AbstractProfilingRule()
+    {        
+    }
     
-    static 
+    public AbstractProfilingRule(ProfileResolvers resolvers) 
     {
-        resolvers.put(RuleCriterionResolver.REQUEST, new StandardResolver());
-        resolvers.put(RuleCriterionResolver.REQUEST_SESSION, new RequestSessionResolver());
-        resolvers.put(RuleCriterionResolver.PATH, new PathResolver());        
-        resolvers.put(RuleCriterionResolver.PATH_SESSION, new PathSessionResolver());   
            
-        resolvers.put(RuleCriterionResolver.HARD_CODED, new HardCodedResolver());
-        resolvers.put(RuleCriterionResolver.USER, new UserCriterionResolver());
-        resolvers.put(RuleCriterionResolver.ROLE, new RoleCriterionResolver()); 
-        resolvers.put(RuleCriterionResolver.GROUP, new GroupCriterionResolver());       
  
-        resolvers.put(RuleCriterionResolver.MEDIATYPE, new MediatypeCriterionResolver());
-        resolvers.put(RuleCriterionResolver.LANGUAGE, new LanguageCriterionResolver());
-        resolvers.put(RuleCriterionResolver.COUNTRY, new CountryCriterionResolver());
-        resolvers.put(RuleCriterionResolver.GROUP_ROLE_USER, new GroupRoleUserCriterionResolver());
-        resolvers.put(RuleCriterionResolver.USER_ATTRIBUTE, new UserAttributeResolver());
-        resolvers.put(RuleCriterionResolver.NAVIGATION, new NavigationCriterionResolver());
-        resolvers.put(RuleCriterionResolver.USER_AGENT, new UserAgentCriterionResolver());
       
+        this.resolvers = resolvers;
     }
     
+     
     protected ProfileLocator getLocatorFromCache(String key)
     {
         return (ProfileLocator)locators.get(key);
@@ -162,4 +155,18 @@
         return this.getClass().toString();
     }
     
+    /**
+     * @return Returns the resolvers.
+     */
+    public ProfileResolvers getResolvers()
+    {
+        return resolvers;
+    }
+    /**
+     * @param resolvers The resolvers to set.
+     */
+    public void setResolvers(ProfileResolvers resolvers)
+    {
+        this.resolvers = resolvers;
+    }
 }

Added: portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/ProfileResolversImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/ProfileResolversImpl.java?rev=320995&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/ProfileResolversImpl.java
(added)
+++ portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/ProfileResolversImpl.java
Thu Oct 13 21:14:21 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.profiler.rules.impl;
+
+import java.util.Map;
+
+import org.apache.jetspeed.profiler.rules.ProfileResolvers;
+import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
+
+/**
+ * Profile Resolvers 
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class ProfileResolversImpl implements ProfileResolvers 
+{
+    private Map resolvers;
+    
+    public ProfileResolversImpl(Map resolvers)
+    {
+        this.resolvers = resolvers;
+    }
+    
+    public RuleCriterionResolver get(String resolverName)
+    {
+        return (RuleCriterionResolver)resolvers.get(resolverName);
+    }
+}

Modified: portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java?rev=320995&r1=320994&r2=320995&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java
(original)
+++ portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java
Thu Oct 13 21:14:21 2005
@@ -22,6 +22,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.profiler.ProfileLocator;
 import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.profiler.rules.ProfileResolvers;
 import org.apache.jetspeed.profiler.rules.ProfilingRule;
 import org.apache.jetspeed.profiler.rules.RuleCriterion;
 import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
@@ -38,6 +39,17 @@
     implements ProfilingRule
 {
     protected final static Log log = LogFactory.getLog(RoleFallbackProfilingRule.class);
+    private final static long serialVersionUID = 1L;
+    
+    public RoleFallbackProfilingRule()
+    {        
+    }
+    
+    public RoleFallbackProfilingRule(ProfileResolvers resolvers) 
+    {
+        super(resolvers);
+    }
+    
     
     /* (non-Javadoc)
      * @see org.apache.jetspeed.profiler.rules.ProfilingRule#apply(org.apache.jetspeed.request.RequestContext,
org.apache.jetspeed.profiler.Profiler)

Modified: portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/StandardProfilingRule.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/StandardProfilingRule.java?rev=320995&r1=320994&r2=320995&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/StandardProfilingRule.java
(original)
+++ portals/jetspeed-2/trunk/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/StandardProfilingRule.java
Thu Oct 13 21:14:21 2005
@@ -21,6 +21,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.profiler.ProfileLocator;
 import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.profiler.rules.ProfileResolvers;
 import org.apache.jetspeed.profiler.rules.ProfilingRule;
 import org.apache.jetspeed.profiler.rules.RuleCriterion;
 import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
@@ -37,9 +38,18 @@
     extends AbstractProfilingRule
     implements ProfilingRule
 {
-    protected final static Log log = LogFactory.getLog(StandardProfilingRule.class);
-        
+    protected final static Log log = LogFactory.getLog(StandardProfilingRule.class);    
       
+    private static final long serialVersionUID = 1;    
             
+    public StandardProfilingRule()
+    {        
+    }
+    
+    public StandardProfilingRule(ProfileResolvers resolvers) 
+    {
+        super(resolvers);
+    }
+    
     /* (non-Javadoc)
      * @see org.apache.jetspeed.profiler.rules.ProfilingRule#apply(org.apache.jetspeed.request.RequestContext,
org.apache.jetspeed.profiler.Profiler)
      */    

Modified: portals/jetspeed-2/trunk/components/profiler/src/test/org/apache/jetspeed/profiler/TestProfiler.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/profiler/src/test/org/apache/jetspeed/profiler/TestProfiler.java?rev=320995&r1=320994&r2=320995&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/profiler/src/test/org/apache/jetspeed/profiler/TestProfiler.java
(original)
+++ portals/jetspeed-2/trunk/components/profiler/src/test/org/apache/jetspeed/profiler/TestProfiler.java
Thu Oct 13 21:14:21 2005
@@ -27,6 +27,7 @@
 import org.apache.jetspeed.components.test.AbstractSpringTestCase;
 import org.apache.jetspeed.mockobjects.request.MockRequestContext;
 import org.apache.jetspeed.profiler.impl.JetspeedProfilerImpl;
+import org.apache.jetspeed.profiler.rules.ProfileResolvers;
 import org.apache.jetspeed.profiler.rules.ProfilingRule;
 import org.apache.jetspeed.profiler.rules.RuleCriterion;
 import org.apache.jetspeed.profiler.rules.impl.RoleFallbackProfilingRule;
@@ -44,7 +45,8 @@
 public class TestProfiler extends AbstractSpringTestCase
 {
     private Profiler profiler = null;
-
+    private ProfileResolvers resolvers = null;
+    
     protected static final Properties TEST_PROPS = new Properties();
 
     static
@@ -83,6 +85,9 @@
         super.setUp();
         this.profiler = (Profiler) ctx.getBean("profiler");
         JetspeedProfilerImpl profilerImpl = (JetspeedProfilerImpl) ctx.getBean("profilerImpl");
+        assertNotNull("profiler not found ", profiler);
+        ProfileResolvers resolvers = (ProfileResolvers) ctx.getBean("ProfileResolvers");
+        assertNotNull("resolvers not found ", resolvers);
         profilerImpl.setDefaultRule(JetspeedProfilerImpl.DEFAULT_RULE);
     }
 
@@ -373,7 +378,7 @@
     {
         System.out.println("Maintenance tests commencing....");
         assertNotNull("profiler service is null", profiler);
-        ProfilingRule rule = new StandardProfilingRule();
+        ProfilingRule rule = new StandardProfilingRule(resolvers);
         rule.setClassname("org.apache.jetspeed.profiler.rules.impl.StandardProfilingRule");
         rule.setId("testmo");
         rule.setTitle("The Grand Title");



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message