portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r735797 [1/3] - in /portals/jetspeed-2/portal/branches/JPA_BRANCH: components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/ components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/jpa/ components/je...
Date Mon, 19 Jan 2009 20:39:40 GMT
Author: rwatler
Date: Mon Jan 19 12:39:38 2009
New Revision: 735797

URL: http://svn.apache.org/viewvc?rev=735797&view=rev
Log:
JPA Profiler Component Integration
-------------------------------------
- add JPA support for profiler component
- move common ProfilerRule algorithms to abstract base class to facilitate reuse between OJB and JPA implementations
- schema modifications required: add JPA_VERSION to persistent object mappings and replace RuleCriterion autoincrement string/VARCHAR id with integer
- TODO: separate persistent ProfilerRule objects from ProfilerRule algorithmic logic which needs to be Spring injectable
 

Added:
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/JetspeedProfilerImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/ProfilerManager.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/ProfilerManagerContext.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/AbstractBaseProfilingRule.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/AbstractProfilingRule.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/PrincipalRuleImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/RoleFallbackProfilingRule.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/RuleCriterionImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/RuleCriterionList.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/StandardProfilingRule.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/resources/
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/resources/META-INF/
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/resources/META-INF/persistence.xml
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/test/java/org/apache/jetspeed/profiler/TestOpenJPAProfiler.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/test/resources/jndi.properties
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/test/resources/jpa-profiler.xml
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/test/resources/log4j.properties
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/test/resources/openjpa-profiler.xml
Modified:
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/jpa/DatabasePageManagerImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/pom.xml
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/JETSPEED-INF/ojb/profiler_repository.xml
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/AbstractProfilingRule.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/RuleCriterionImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/StandardProfilingRule.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/serializer/JetspeedProfilerSerializer.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/test/java/org/apache/jetspeed/profiler/TestProfiler.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/NamingJavaJNDIComponent.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletregistry/jpa/RegistryManager.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletregistry/jpa/RegistryManagerImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/jpa/CustomWindowStateImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/jpa/InitParamImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/jpa/PortletApplicationDefinitionImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/jpa/PortletDefinitionImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/jpa/SecurityRoleImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/jpa/SecurityRoleRefImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/jpa/UserAttributeImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/jpa/UserAttributeRefImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-api/src/main/java/org/apache/jetspeed/profiler/rules/ProfilingRule.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-api/src/main/java/org/apache/jetspeed/profiler/rules/RuleCriterion.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-portal-resources/src/main/ddl-schema/phase2-schema.xml
    portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-portal-resources/src/main/resources/ddl/mssql/create-schema.sql

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/jpa/DatabasePageManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/jpa/DatabasePageManagerImpl.java?rev=735797&r1=735796&r2=735797&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/jpa/DatabasePageManagerImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/jpa/DatabasePageManagerImpl.java Mon Jan 19 12:39:38 2009
@@ -152,8 +152,8 @@
      */
     public DatabasePageManagerImpl(boolean isPermissionsSecurity, boolean isConstraintsSecurity)
     {
-        delegator = new DelegatingPageManager(isPermissionsSecurity, isConstraintsSecurity, modelClasses);
-        contexts = new ThreadLocal();
+        this.delegator = new DelegatingPageManager(isPermissionsSecurity, isConstraintsSecurity, modelClasses);
+        this.contexts = new ThreadLocal();
     }
 
     /**
@@ -749,10 +749,7 @@
             synchronized (folderImpl.accessCacheLock())
             {
                 folderImpl.accessFolders().clear();
-                if (folders != null)
-                {
-                    folderImpl.accessFolders().addAll(folders);
-                }
+                folderImpl.accessFolders().addAll(folders);
                 folderImpl.resetFolders(true);
             }
         }
@@ -819,10 +816,7 @@
             synchronized (folderImpl.accessCacheLock())
             {
                 folderImpl.accessPages().clear();
-                if (pages != null)
-                {
-                    folderImpl.accessPages().addAll(pages);
-                }
+                folderImpl.accessPages().addAll(pages);
                 folderImpl.resetPages(true);
             }
         }
@@ -889,10 +883,7 @@
             synchronized (folderImpl.accessCacheLock())
             {
                 folderImpl.accessLinks().clear();
-                if (links != null)
-                {
-                    folderImpl.accessLinks().addAll(links);
-                }
+                folderImpl.accessLinks().addAll(links);
                 folderImpl.resetLinks(true);
             }
         }
@@ -1008,28 +999,22 @@
             foldersQuery.setParameter("folder", folder);
             Collection folders = foldersQuery.getResultList();
             infuseElements(folders);
-            if (folders != null)
-            {
-                all.addAll(folders);
-            }
+            all.addAll(folders);
+
             // query for pages by parent
             Query pagesQuery = entityManager.createNamedQuery("FOLDER_PAGES");
             pagesQuery.setParameter("folder", folder);
             Collection pages = pagesQuery.getResultList();
             infuseElements(pages);
-            if (pages != null)
-            {
-                all.addAll(pages);
-            }
+            all.addAll(pages);
+
             // query for links by parent
             Query linksQuery = entityManager.createNamedQuery("FOLDER_LINKS");
             linksQuery.setParameter("folder", folder);
             Collection links = linksQuery.getResultList();
             infuseElements(links);
-            if (links != null)
-            {
-                all.addAll(links);
-            }
+            all.addAll(links);
+
             // query for page security by parent
             Query pageSecurityQuery = entityManager.createNamedQuery("FOLDER_PAGE_SECURITY");
             pageSecurityQuery.setParameter("folder", folder);
@@ -1334,13 +1319,10 @@
             pagesQuery.setParameter("folder", folder);
             Collection pages = pagesQuery.getResultList();
             infuseElements(pages);
-            if (pages != null)
+            Iterator pagesIter = pages.iterator();
+            while (pagesIter.hasNext())
             {
-                Iterator pagesIter = pages.iterator();
-                while (pagesIter.hasNext())
-                {
-                    updatePage((Page)pagesIter.next());
-                }
+                updatePage((Page)pagesIter.next());
             }
 
             // update links, query for links by parent
@@ -1348,13 +1330,10 @@
             linksQuery.setParameter("folder", folder);
             Collection links = linksQuery.getResultList();
             infuseElements(links);
-            if (links != null)
+            Iterator linksIter = links.iterator();
+            while (linksIter.hasNext())
             {
-                Iterator linksIter = links.iterator();
-                while (linksIter.hasNext())
-                {
-                    updateLink((Link)linksIter.next());
-                }
+                updateLink((Link)linksIter.next());
             }
 
             // update page security, query for page security by parent
@@ -1376,13 +1355,10 @@
             foldersQuery.setParameter("folder", folder);
             Collection folders = foldersQuery.getResultList();
             infuseElements(folders);
-            if (folders != null)
+            Iterator foldersIter = folders.iterator();
+            while (foldersIter.hasNext())
             {
-                Iterator foldersIter = folders.iterator();
-                while (foldersIter.hasNext())
-                {
-                    updateFolder((Folder)foldersIter.next(), true);
-                }
+                updateFolder((Folder)foldersIter.next(), true);
             }
         }
         catch (FolderNotUpdatedException fnue)
@@ -1467,13 +1443,10 @@
             foldersQuery.setParameter("folder", folder);
             Collection folders = foldersQuery.getResultList();
             infuseElements(folders);
-            if (folders != null)
+            Iterator foldersIter = folders.iterator();
+            while (foldersIter.hasNext())
             {
-                Iterator foldersIter = folders.iterator();
-                while (foldersIter.hasNext())
-                {
-                    removeFolder((Folder)foldersIter.next());
-                }
+                removeFolder((Folder)foldersIter.next());
             }
 
             // remove pages, query for pages by parent
@@ -1481,13 +1454,10 @@
             pagesQuery.setParameter("folder", folder);
             Collection pages = pagesQuery.getResultList();
             infuseElements(pages);
-            if (pages != null)
+            Iterator pagesIter = pages.iterator();
+            while (pagesIter.hasNext())
             {
-                Iterator pagesIter = pages.iterator();
-                while (pagesIter.hasNext())
-                {
-                    removePage((Page)pagesIter.next());
-                }
+                removePage((Page)pagesIter.next());
             }
 
             // remove links, query for links by parent
@@ -1495,13 +1465,10 @@
             linksQuery.setParameter("folder", folder);
             Collection links = linksQuery.getResultList();
             infuseElements(links);
-            if (links != null)
+            Iterator linksIter = links.iterator();
+            while (linksIter.hasNext())
             {
-                Iterator linksIter = links.iterator();
-                while (linksIter.hasNext())
-                {
-                    removeLink((Link)linksIter.next());
-                }
+                removeLink((Link)linksIter.next());
             }
 
             // remove page security, query for page security by parent

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/pom.xml?rev=735797&r1=735796&r2=735797&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/pom.xml (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/pom.xml Mon Jan 19 12:39:38 2009
@@ -141,6 +141,68 @@
                     </execution>
                 </executions>
             </plugin>
+ 	        <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>openjpa-maven-plugin</artifactId>
+                <version>1.0-alpha</version>
+                <executions>
+                    <execution>
+                        <id>org.apache.jetspeed.profiler.rules.jpa</id>
+                        <phase>process-classes</phase>
+                        <goals>
+                            <goal>enhance</goal>
+                        </goals>
+                        <configuration>
+                            <classes>${project.build.directory}/classes/org/apache/jetspeed/profiler/rules/jpa</classes>                   	  
+                            <toolProperties>                      	 
+                                <property>
+                                    <name>addDefaultConstructor</name>
+                                    <value>true</value>
+                                </property>
+                                <property>
+                                    <name>enforcePropertyRestrictions</name>
+                                    <value>true</value>
+                                </property>
+                            </toolProperties>
+                        </configuration>                  
+                    </execution>
+                    <execution>
+                        <id>org.apache.jetspeed.profiler.jpa</id>
+                        <phase>process-classes</phase>
+                        <goals>
+                            <goal>enhance</goal>
+                        </goals>
+                        <configuration>
+                            <classes>${project.build.directory}/classes/org/apache/jetspeed/profiler/jpa</classes>                   	  
+                            <toolProperties>                      	 
+                                <property>
+                                    <name>addDefaultConstructor</name>
+                                    <value>true</value>
+                                </property>
+                                <property>
+                                    <name>enforcePropertyRestrictions</name>
+                                    <value>true</value>
+                                </property>
+                            </toolProperties>
+                        </configuration>                  
+                    </execution>
+                </executions>
+                <dependencies>
+                    <!-- rule objects implement Jetspeed APIs -->
+                    <dependency>
+                        <groupId>${pom.groupId}</groupId>
+                        <artifactId>jetspeed-api</artifactId>
+                        <version>${pom.version}</version>
+                    </dependency>
+                    <!-- force upgrade of JPA for plugin -->
+                    <dependency>
+                        <groupId>org.apache.openjpa</groupId>
+                        <artifactId>openjpa-persistence-jdbc</artifactId>
+                        <version>${openjpa.version}</version>
+                        <scope>runtime</scope>
+                    </dependency>
+                </dependencies>
+            </plugin>
         </plugins>
         <testResources>
             <testResource>

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/JETSPEED-INF/ojb/profiler_repository.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/JETSPEED-INF/ojb/profiler_repository.xml?rev=735797&r1=735796&r2=735797&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/JETSPEED-INF/ojb/profiler_repository.xml (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/JETSPEED-INF/ojb/profiler_repository.xml Mon Jan 19 12:39:38 2009
@@ -103,7 +103,7 @@
     <field-descriptor
      name="id"
      column="CRITERION_ID"
-     jdbc-type="VARCHAR"
+     jdbc-type="INTEGER"
      primarykey="true"
      autoincrement="true"         
     />
@@ -111,6 +111,7 @@
      name="ruleId"
      column="RULE_ID"
      jdbc-type="VARCHAR"
+     access="anonymous"
     />
     <field-descriptor
      name="fallbackOrder"
@@ -183,4 +184,4 @@
    
       
       
-  
\ No newline at end of file
+  

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/JetspeedProfilerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/JetspeedProfilerImpl.java?rev=735797&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/JetspeedProfilerImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/JetspeedProfilerImpl.java Mon Jan 19 12:39:38 2009
@@ -0,0 +1,745 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jpa;
+
+import java.security.Principal;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.persistence.Query;
+
+import javax.security.auth.Subject;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.profiler.ProfileLocator;
+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.RuleCriterion;
+import org.apache.jetspeed.profiler.rules.jpa.AbstractProfilingRule;
+import org.apache.jetspeed.profiler.rules.jpa.PrincipalRuleImpl;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.security.SubjectHelper;
+import org.apache.jetspeed.security.UserSubjectPrincipal;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * JetspeedProfilerImpl
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: JetspeedProfilerImpl.java 702093 2008-10-06 11:05:52Z ate $
+ */
+@Repository
+public class JetspeedProfilerImpl implements Profiler, BeanFactoryAware, ProfilerManager
+{
+    /** The default rule. */
+    public final static String DEFAULT_RULE = "j1";
+    
+    /** Commons logging */
+    protected final static Log log = LogFactory.getLog(JetspeedProfilerImpl.class);
+
+    /**
+     * This is the principal that is used if there are no principal to rule associations for the current principal
+     */
+    public final static Principal DEFAULT_RULE_PRINCIPAL = new Principal() {
+        public String getName()
+        {
+            return "*";
+        }
+    };
+
+    /** The default locator class implementation */
+    private String locatorBean = "ProfileLocator";
+
+    /** The default principalRule association class implementation */
+    private Class prRuleClass;
+    
+    private String principalRuleBean = "PrincipalRule";
+    
+    /** The base (abstract) profilingRule class implementation */
+    private String profilingRuleStandardBean = "StandardProfilingRule";
+    
+    /** The base (abstract) profilingRule class implementation */
+    private String profilingRuleFallbackBean = "RoleFallbackProfilingRule";    
+    
+    /** The base (abstract) profilingRule class implementation */
+    private Class profilingRuleClass = AbstractProfilingRule.class;
+
+    /** The configured default rule for this portal */
+    private String defaultRule = DEFAULT_RULE;
+
+    private ProfileResolvers resolvers;
+
+    /** the default criterion bean name */
+    private String ruleCriterionBean = "RuleCriterion";
+
+    /**
+     * added support for bean factory to create profile rules
+     */
+    private BeanFactory beanFactory;
+
+    private EntityManager entityManager;
+    private ThreadLocal contexts;
+
+    /**
+     * Create profiler implementation with default rule, resolvers map,
+     * rule bean name map, and criterion bean name.
+     * 
+     * @param defaultRule name of default rule.
+     * @param resolvers map of profile resolvers.
+     * @param ruleConstructors rule bean name map.
+     * @param ruleCriterionBean criterion bean name.
+     */
+    public JetspeedProfilerImpl(String defaultRule, ProfileResolvers resolvers, Map ruleConstructors, String ruleCriterionBean)
+    {
+        this.defaultRule = defaultRule;
+        this.resolvers = resolvers;
+        initRuleClasses(ruleConstructors);
+        this.ruleCriterionBean = ruleCriterionBean;
+        this.contexts = new ThreadLocal();        
+    }
+
+    /**
+     * Inject shared entity manager from assembly; this entity
+     * manager is expected to honor existing entity manager
+     * context attached to current thread, (otherwise, a new
+     * temporary entity manager is created).
+     * 
+     * @param entityManager injected shared entity manager
+     */
+    @PersistenceContext (type=PersistenceContextType.TRANSACTION, unitName="jetspeed-profiler")
+    public void setEntityManager(EntityManager entityManager) 
+    {
+        this.entityManager = entityManager;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.jpa.ProfilerManager#registerContext(java.lang.Object)
+     */
+    public void registerContext(Object context)
+    {
+        ProfilerManagerContext registeredContext = (ProfilerManagerContext)contexts.get();
+        if ((registeredContext == null) && (context instanceof ProfilerManagerContext))
+        {
+            contexts.set(context);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.jpa.ProfilerManager#getContext()
+     */
+    public Object getContext()
+    {
+        return (ProfilerManagerContext)contexts.get();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.jpa.ProfilerManager#unregisterContext(java.lang.Object)
+     */
+    public void unregisterContext(Object context)
+    {
+        ProfilerManagerContext registeredContext = (ProfilerManagerContext)contexts.get();
+        if (context == registeredContext)
+        {
+            contexts.remove();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.jpa.ProfilerManager#getEntityManager()
+     */
+    public EntityManager getEntityManager()
+    {
+        ProfilerManagerContext context = (ProfilerManagerContext)getContext();
+        return ((context != null) ? context.getExtendedEntityManager() : entityManager);
+    }    
+    
+    /**
+     * @param defaultRule
+     *            The default rule to set.
+     */
+    public void setDefaultRule(String defaultRule)
+    {
+        this.defaultRule = defaultRule;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getProfile(org.apache.jetspeed.request.RequestContext, java.lang.String)
+     */
+    @Transactional (readOnly=true)
+    public ProfileLocator getProfile(RequestContext context, String locatorName) throws ProfilerException
+    {
+        // get the principal representing the currently logged on user
+        Subject subject = context.getSubject();
+        if (subject == null)
+        {
+            String msg = "Invalid (null) Subject in request pipeline";
+            log.error(msg);
+            throw new ProfilerException(msg);
+        }
+        // get the UserPrincipal, finding the first UserPrincipal, or
+        // find the first principal if no UserPrincipal isn't available
+        Principal principal = SubjectHelper.getBestPrincipal(subject, UserSubjectPrincipal.class);
+        if (principal == null)
+        {
+            String msg = "Could not find a principle for subject in request pipeline";
+            log.error(msg);
+            throw new ProfilerException(msg);
+        }
+
+        // find a profiling rule for this principal
+        ProfilingRule rule = getRuleForPrincipal(principal, locatorName);
+        if (null == rule)
+        {
+            log.warn("Could not find profiling rule for principal: " + principal);
+            rule = getDefaultRule();
+        }
+
+        if (null == rule)
+        {
+            String msg = "Couldn't find any profiling rules including default rule for principal " + principal;
+            log.error(msg);
+            throw new ProfilerException(msg);
+        }
+        // create a profile locator for given rule
+        return rule.apply(context, this);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getDefaultProfile(org.apache.jetspeed.request.RequestContext, java.lang.String)
+     */
+    @Transactional (readOnly=true)
+    public ProfileLocator getDefaultProfile(RequestContext context, String locatorName) throws ProfilerException
+    {
+        ProfilingRule rule = getRuleForPrincipal(DEFAULT_RULE_PRINCIPAL, locatorName);
+        if (null == rule)
+        {
+            log.warn("Could not find profiling rule for principal: " + DEFAULT_RULE_PRINCIPAL);
+            rule = getDefaultRule();
+        }
+        if (null == rule)
+        {
+            String msg = "Couldn't find any profiling rules including default rule for principal " + DEFAULT_RULE_PRINCIPAL;
+            log.error(msg);
+            throw new ProfilerException(msg);
+        }
+        // create a profile locator for given rule
+        return rule.apply(context, this);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getProfile(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.profiler.rules.ProfilingRule)
+     */
+    public ProfileLocator getProfile(RequestContext context, ProfilingRule rule) throws ProfilerException
+    {
+        // create a profile locator for given rule
+        return rule.apply(context, this);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getRuleForPrincipal(java.security.Principal, java.lang.String)
+     */
+    @Transactional (readOnly=true)
+    public ProfilingRule getRuleForPrincipal(Principal principal, String locatorName)
+    {
+        ProfilingRule rule = null;
+        // lookup the rule for the given principal in our user/rule table
+        PrincipalRule pr = lookupPrincipalRule(principal.getName(), locatorName);
+
+        // if not found, fallback to the locator named rule or system wide rule
+        if (pr == null)
+        {
+            // find rule on locator name
+            rule = getRule(locatorName);
+
+            if (rule == null)
+            {
+                // if not found, fallback to the system wide rule
+                rule = getDefaultRule();
+            }
+            pr = new PrincipalRuleImpl();
+            pr.setLocatorName(locatorName);
+            pr.setPrincipalName(principal.getName());
+            pr.setProfilingRule(rule);
+        }
+        else
+        {
+            // Get the associated rule
+            rule = pr.getProfilingRule();
+        }
+
+        return rule;
+    }
+
+    /**
+     * Internal method to ensure we have a valid principalRule class for queries
+     * 
+     * @return the class object for the principalRule
+     */
+    private Class getPrincipalRuleClass()
+    {
+        if (prRuleClass == null)
+        {
+            try
+            {
+                PrincipalRule tempRule = createPrincipalRule();
+                prRuleClass = tempRule.getClass();
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+        return prRuleClass;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#setRuleForPrincipal(java.security.Principal, org.apache.jetspeed.profiler.rules.ProfilingRule, java.lang.String)
+     */
+    @Transactional (readOnly=false, rollbackFor=ProfilerException.class)
+    public void setRuleForPrincipal(Principal principal, ProfilingRule rule, String locatorName)
+    {
+        // query for principal rule by principal and locator names
+        EntityManager entityManager = getEntityManager();
+        Query principalRuleQuery = entityManager.createNamedQuery("PRINCIPAL_RULE");
+        principalRuleQuery.setParameter("principalName", principal.getName());
+        principalRuleQuery.setParameter("locatorName", locatorName);
+        PrincipalRule pr = null;
+        try
+        {
+            pr = (PrincipalRule)principalRuleQuery.getSingleResult();
+        }
+        catch (NoResultException nre)
+        {
+        }
+
+        // merge/set rule for principal
+        if (pr == null)
+        {
+            pr = new PrincipalRuleImpl(); // TODO: factory
+            pr.setPrincipalName(principal.getName());
+            pr.setLocatorName(locatorName);
+        }
+        rule.setResolvers(resolvers);
+        pr.setProfilingRule(rule);
+        
+        // update rule for principal
+        entityManager.persist(pr);
+        // explicitly flush entity manager after update
+        entityManager.flush();
+    }
+
+    /**
+     * Construct principal/locator rule key string.
+     * 
+     * @param principal principal key string.
+     * @param locator locator key string.
+     * @return principal/locator key string.
+     */
+    private String makePrincipalRuleKey(String principal, String locator)
+    {
+        return principal + ":" + locator;
+    }
+
+    /**
+     * Helper function to lookup principal rule associations by principal
+     * 
+     * @param principal
+     *            The string representation of the principal name.
+     * @return The found PrincipalRule associated with the principal key or null
+     *         if not found.
+     */
+    private PrincipalRule lookupPrincipalRule(String principal, String locatorName)
+    {
+        // query for principal rule by principal and locator names
+        EntityManager entityManager = getEntityManager();
+        Query principalRuleQuery = entityManager.createNamedQuery("PRINCIPAL_RULE");
+        principalRuleQuery.setParameter("principalName", principal);
+        principalRuleQuery.setParameter("locatorName", locatorName);
+        PrincipalRule pr = null;
+        try
+        {
+            pr = (PrincipalRule)principalRuleQuery.getSingleResult();
+            // set resolvers on loaded rules
+            pr.getProfilingRule().setResolvers(resolvers);
+        }
+        catch (NoResultException nre)
+        {
+        }
+        return pr;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getDefaultRule()
+     */
+    @Transactional (readOnly=true)
+    public ProfilingRule getDefaultRule()
+    {
+        return getRule(defaultRule);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getRules()
+     */
+    @Transactional (readOnly=true)
+    public Collection getRules()
+    {
+        // query for all profiling rules
+        Query profilerRulesQuery = entityManager.createNamedQuery("PROFILING_RULES");
+        Collection rules = profilerRulesQuery.getResultList();
+        Iterator r = rules.iterator();
+        while (r.hasNext())
+        {
+            ProfilingRule rule = (ProfilingRule) r.next();
+            // set resolvers on loaded rules
+            rule.setResolvers(resolvers);
+        }
+        return rules;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getRule(java.lang.String)
+     */
+    @Transactional (readOnly=true)
+    public ProfilingRule getRule(String id)
+    {
+        // query for profiling rule by id
+        Query profilerRuleQuery = entityManager.createNamedQuery("PROFILING_RULE");
+        profilerRuleQuery.setParameter("id", id);
+        ProfilingRule rule = null;
+        try
+        {
+            rule = (ProfilingRule)profilerRuleQuery.getSingleResult();
+            // set resolvers on loaded rules
+            rule.setResolvers(resolvers);
+        }
+        catch (NoResultException nre)
+        {
+        }
+        return rule;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getLocatorNamesForPrincipal(java.security.Principal)
+     */
+    @Transactional (readOnly=true)
+    public String[] getLocatorNamesForPrincipal(Principal principal)
+    {
+        // query for principal rules by principal name
+        EntityManager entityManager = getEntityManager();
+        Query principalRulesQuery = entityManager.createNamedQuery("PRINCIPAL_RULES");
+        principalRulesQuery.setParameter("principalName", principal.getName());
+        Collection result = principalRulesQuery.getResultList();
+
+        // extract locator names from rules
+        String[] names = new String[result.size()];
+        Iterator it = result.iterator();
+        int ix = 0;
+        while (it.hasNext())
+        {
+            // extract locator names
+            PrincipalRule pr = (PrincipalRule) it.next();
+            names[ix++] = pr.getLocatorName();
+            // set resolvers on loaded rules
+            pr.getProfilingRule().setResolvers(resolvers);
+        }
+        return names;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getRulesForPrincipal(java.security.Principal)
+     */
+    @Transactional (readOnly=true)
+    public Collection getRulesForPrincipal(Principal principal)
+    {
+        // query for principal rules by principal name
+        EntityManager entityManager = getEntityManager();
+        Query principalRulesQuery = entityManager.createNamedQuery("PRINCIPAL_RULES");
+        principalRulesQuery.setParameter("principalName", principal.getName());
+        Collection rules = principalRulesQuery.getResultList();
+        // set resolvers on loaded rules
+        Iterator r = rules.iterator();
+        while (r.hasNext())
+        {
+            PrincipalRule pr = (PrincipalRule) r.next();
+            ProfilingRule rule = pr.getProfilingRule();
+            if (rule != null)
+            {
+                rule.setResolvers(resolvers);
+            }
+        }
+        return rules;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getProfileLocators(org.apache.jetspeed.request.RequestContext, java.security.Principal)
+     */
+    @Transactional (readOnly=true)
+    public Map getProfileLocators(RequestContext context, Principal principal) throws ProfilerException
+    {
+        Map locators = new HashMap();
+        Collection rules = getRulesForPrincipal(principal);
+
+        Iterator it = rules.iterator();
+        while (it.hasNext())
+        {
+            PrincipalRule pr = (PrincipalRule) it.next();
+            locators.put(pr.getLocatorName(), getProfile(context, pr.getLocatorName()));
+        }
+        return locators;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#getDefaultProfileLocators(org.apache.jetspeed.request.RequestContext)
+     */
+    @Transactional (readOnly=true)
+    public Map getDefaultProfileLocators(RequestContext context) throws ProfilerException
+    {
+        Map locators = new HashMap();
+        Collection rules = getRulesForPrincipal(DEFAULT_RULE_PRINCIPAL);
+
+        Iterator it = rules.iterator();
+        while (it.hasNext())
+        {
+            PrincipalRule pr = (PrincipalRule) it.next();
+            locators.put(pr.getLocatorName(), getDefaultProfile(context, pr.getLocatorName()));
+        }
+        return locators;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#storeProfilingRule(org.apache.jetspeed.profiler.rules.ProfilingRule)
+     */
+    @Transactional (readOnly=false, rollbackFor=ProfilerException.class)
+    public void storeProfilingRule(ProfilingRule rule) throws ProfilerException
+    {
+        EntityManager entityManager = getEntityManager();
+        // update, (potentially detached), element
+        if (!((AbstractProfilingRule)rule).isNew())
+        {
+            rule = (ProfilingRule)entityManager.merge(rule);
+        }
+        entityManager.persist(rule);
+        // explicitly flush entity manager after remove
+        entityManager.flush();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#deleteProfilingRule(org.apache.jetspeed.profiler.rules.ProfilingRule)
+     */
+    @Transactional (readOnly=false, rollbackFor=ProfilerException.class)
+    public void deleteProfilingRule(ProfilingRule rule) throws ProfilerException
+    {
+        EntityManager entityManager = getEntityManager();
+        // remove, (potentially detached), element
+        if (!((AbstractProfilingRule)rule).isNew())
+        {
+            rule = (ProfilingRule)entityManager.merge(rule);
+        }
+        entityManager.remove(rule);
+        // explicitly flush entity manager after remove
+        entityManager.flush();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#storePrincipalRule(org.apache.jetspeed.profiler.rules.PrincipalRule)
+     */
+    @Transactional (readOnly=false, rollbackFor=ProfilerException.class)
+    public void storePrincipalRule(PrincipalRule rule) throws ProfilerException
+    {
+        EntityManager entityManager = getEntityManager();
+        // update, (potentially detached), element
+        if (!((PrincipalRuleImpl)rule).isNew())
+        {
+            rule = (PrincipalRule)entityManager.merge(rule);
+        }
+        entityManager.persist(rule);
+        // explicitly flush entity manager after remove
+        entityManager.flush();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#deletePrincipalRule(org.apache.jetspeed.profiler.rules.PrincipalRule)
+     */
+    @Transactional (readOnly=false, rollbackFor=ProfilerException.class)
+    public void deletePrincipalRule(PrincipalRule rule) throws ProfilerException
+    {
+        EntityManager entityManager = getEntityManager();
+        // remove, (potentially detached), element
+        if (!((PrincipalRuleImpl)rule).isNew())
+        {
+            rule = (PrincipalRule)entityManager.merge(rule);
+        }
+        entityManager.remove(rule);
+        // explicitly flush entity manager after remove
+        entityManager.flush();
+    }
+
+    /*
+     * Method called automatically by Spring container upon initialization
+     * 
+     * @param beanFactory automatically provided by framework @throws
+     * BeansException
+     */
+    public void setBeanFactory(BeanFactory beanFactory) throws BeansException
+    {
+        this.beanFactory = beanFactory;
+    }
+
+    /**
+     * added logic to get the settings for creating the various rule related
+     * instances
+     * 
+     * @param classes
+     */
+    private void initRuleClasses(Map beans)
+    {
+        String beanName = "";
+        try
+        {
+            if ((beanName = (String) beans.get("locator")) != null)
+            {
+                locatorBean = beanName;
+            }
+        }
+        catch (Exception e)
+        {
+            String msg = "Exception in setting locatorbeanName : " + e.getLocalizedMessage();
+            log.error(msg);
+        }
+        try
+        {
+            if ((beanName = (String) beans.get("principal")) != null)
+            {
+                principalRuleBean = beanName;
+            }
+        }
+        catch (Exception e)
+        {
+            String msg = "Exception in setting principalRulebeanName : " + e.getLocalizedMessage();
+            log.error(msg);
+        }
+        try
+        {
+            if ((beanName = (String) beans.get("standard")) != null)
+            {
+                profilingRuleStandardBean = beanName;
+            }
+        }
+        catch (Exception e)
+        {
+            String msg = "Exception in setting profilingRuleStandardbeanName : " + e.getLocalizedMessage();
+            log.error(msg);
+        }
+        try
+        {
+            if ((beanName = (String) beans.get("fallback")) != null)
+            {
+                profilingRuleFallbackBean = beanName;
+            }
+        }
+        catch (Exception e)
+        {
+            String msg = "Exception in setting profilingRuleFallback : " + e.getLocalizedMessage();
+            log.error(msg);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#createProfilingRule(boolean)
+     */
+    public ProfilingRule createProfilingRule(boolean standard) throws ClassNotFoundException
+    {
+        try
+        {
+            if (standard)
+            {
+                return (ProfilingRule) beanFactory.getBean(profilingRuleStandardBean, ProfilingRule.class);
+            }
+            return (ProfilingRule) beanFactory.getBean(profilingRuleFallbackBean, ProfilingRule.class);
+        }
+        catch (BeansException e)
+        {
+            throw new ClassNotFoundException("Spring failed to create the " + (standard ? "standard" : "fallback") + " profiling rule bean.", e);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#createLocator(org.apache.jetspeed.request.RequestContext)
+     */
+    public ProfileLocator createLocator(RequestContext context)
+    {
+        try
+        {
+            ProfileLocator locator = (ProfileLocator) beanFactory.getBean(locatorBean, ProfileLocator.class);
+            locator.init(this, context.getPath());
+            return locator;
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to create locator for " + locatorBean + " error : " + e.getLocalizedMessage());
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#createPrincipalRule()
+     */
+    public PrincipalRule createPrincipalRule() throws ClassNotFoundException
+    {
+        try
+        {
+            PrincipalRule principalRule = (PrincipalRule) beanFactory.getBean(principalRuleBean, PrincipalRule.class);
+            return principalRule;
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to create principalRule for " + principalRuleBean + " error : " + e.getLocalizedMessage());
+            throw new ClassNotFoundException("Spring failed to create the " + " principal rule bean.", e);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.Profiler#createRuleCriterion()
+     */
+    public RuleCriterion createRuleCriterion() throws ClassNotFoundException
+    {
+        try
+        {
+            RuleCriterion ruleCriterion = (RuleCriterion) beanFactory.getBean(ruleCriterionBean, RuleCriterion.class);
+            return ruleCriterion;
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to create principalRule for " + ruleCriterionBean + " error : " + e.getLocalizedMessage());
+            throw new ClassNotFoundException("Spring failed to create the " + " rule criterion bean.", e);
+        }
+    }
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/ProfilerManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/ProfilerManager.java?rev=735797&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/ProfilerManager.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/ProfilerManager.java Mon Jan 19 12:39:38 2009
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jpa;
+
+import javax.persistence.EntityManager;
+
+/**
+ * ProfilerManager
+ * 
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public interface ProfilerManager
+{
+    /**
+     * Return entity manager associated with current thread from
+     * registered context or default transactional entity manager
+     * created for this request.
+     * 
+     * @return entity manager.
+     */
+    public EntityManager getEntityManager();
+
+    /**
+     * Register profiler manager context with current thread.
+     * 
+     * @param context profiler manager context.
+     */
+    public void registerContext(Object context);
+
+    /**
+     * Get profiler manager context registered with current thread.
+     * 
+     * @return profiler manager context.
+     */
+    public Object getContext();
+
+    /**
+     * Unregister profiler manager context with current thread.
+     * 
+     * @param context profiler manager context.
+     */
+    public void unregisterContext(Object context);
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/ProfilerManagerContext.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/ProfilerManagerContext.java?rev=735797&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/ProfilerManagerContext.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/jpa/ProfilerManagerContext.java Mon Jan 19 12:39:38 2009
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jpa;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+
+/**
+ * ProfilerManagerContext
+ * 
+ * Stateful object uses to hold JPA extended entity manager.
+ * 
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class ProfilerManagerContext
+{
+    private EntityManager extendedEntityManager;
+    private ProfilerManager profilerManager;
+
+    /**
+     * Set extended conversational entity manager instance for context.
+     * 
+     * @param entityManager injected entity manager.
+     */
+    @PersistenceContext (type=PersistenceContextType.EXTENDED, unitName="jetspeed-profiler")
+    public void setExtendedEntityManager(EntityManager entityManager)
+    {
+        extendedEntityManager = entityManager;
+    }
+    
+    /**
+     * Get extended conversational entity manager instance for context.
+     * 
+     * @return entity manager.
+     */
+    public EntityManager getExtendedEntityManager()
+    {
+        return extendedEntityManager;
+    }
+    
+    /**
+     * Set profiler manager associated with context.
+     * 
+     * @param profilerManager
+     */
+    public void setProfilerManager(ProfilerManager profilerManager)
+    {
+        this.profilerManager = profilerManager;
+    }
+    
+    /**
+     * Initialize context by registering with profilerManager on creating thread.
+     */
+    public void initialize()
+    {
+        profilerManager.registerContext(this);
+    }
+
+    /**
+     * Terminate context by unregistering with profilerManager on creating thread.
+     */
+    public void terminate()
+    {
+        profilerManager.unregisterContext(this);
+    }
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/AbstractBaseProfilingRule.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/AbstractBaseProfilingRule.java?rev=735797&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/AbstractBaseProfilingRule.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/AbstractBaseProfilingRule.java Mon Jan 19 12:39:38 2009
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Collection;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.profiler.ProfileLocator;
+import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.profiler.rules.FallbackCriterionResolver;
+import org.apache.jetspeed.profiler.rules.ProfilingRule;
+import org.apache.jetspeed.profiler.rules.RuleCriterion;
+import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * AbstractBaseProfilingRule
+ * 
+ * Shared profiling rule algorithm implementations.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: AbstractProfilingRule.java 726976 2008-12-16 07:15:50Z taylor $
+ */
+public abstract class AbstractBaseProfilingRule implements ProfilingRule
+{
+    private final static long serialVersionUID = 1L;
+    protected final static Log log = LogFactory.getLog(AbstractBaseProfilingRule.class);
+
+    /**
+     * Get collection of rule criteria to use while applying rules.
+     * 
+     * @return rule criterion collection.
+     */
+    public abstract Collection<RuleCriterion> getRuleCriteria();
+
+    /**
+     * Get named rule criterion resolver.
+     * 
+     * @param name resolver name.
+     * @return resolver.
+     */
+    public abstract RuleCriterionResolver getResolver(String name);
+
+    /**
+     * Get default rule criterion resolver.
+     * 
+     * @return resolver.
+     */
+    public abstract RuleCriterionResolver getDefaultResolver();
+
+    /**
+     * Get cached profile locator.
+     * 
+     * @param key profile locator key.
+     * @return profile locator.
+     */
+    protected abstract ProfileLocator getLocatorFromCache(String key);
+    
+    /**
+     * Add profile locator to cache.
+     * 
+     * @param key profile locator key.
+     * @param locator profile locator.
+     */
+    protected abstract void addLocatorToCache(String key, ProfileLocator locator);
+    
+    /**
+     * Apply standard profiling rule based on criteria to
+     * create profile locator.
+     * 
+     * @param context request context.
+     * @param service profile service.
+     * @return profile locator for request.
+     */
+    protected ProfileLocator applyStandardProfilingRule(RequestContext context, Profiler service)
+    {
+        StringBuffer key = new StringBuffer();
+        int count = 0;
+        
+        // first pass, build the key
+        Iterator<RuleCriterion> criteria = getRuleCriteria().iterator();
+        while (criteria.hasNext())
+        {
+            RuleCriterion criterion = criteria.next();
+            if (criterion.getType() == null)
+            {
+                log.warn("Invalid criterion provided - type null on rule " + this);
+            }
+            RuleCriterionResolver resolver = getResolver(criterion.getType());
+            if (resolver == null)
+            {
+                resolver = getDefaultResolver();
+            }
+            String value = resolver.resolve(context, criterion);
+            key.append(criterion.getName());
+            key.append(ProfileLocator.PATH_SEPARATOR);
+            key.append(value);
+            if (criteria.hasNext())
+            {
+                key.append(ProfileLocator.PATH_SEPARATOR);
+            }
+            count++;                                                                                                    
+        }
+        
+        // try to get the profile locator from the cache,
+        // request path and key sufficient to generate unique key
+        String requestPath = context.getPath();
+        String locatorKey = ((requestPath != null) ? requestPath : "/") + ProfileLocator.PATH_SEPARATOR + key.toString();
+        ProfileLocator locator = getLocatorFromCache(locatorKey); 
+        if (locator != null)
+        {
+            return locator;
+        }
+        
+        // second pass, build the locator object         
+        locator = service.createLocator(context);
+        criteria = getRuleCriteria().iterator();
+        while (criteria.hasNext())
+        {
+            RuleCriterion criterion = (RuleCriterion)criteria.next();
+            if (criterion.getType() == null)
+            {
+                log.warn("Invalid criterion provided - type null on rule " + this);
+            }
+            RuleCriterionResolver resolver = getResolver(criterion.getType());
+            if (resolver != null)
+            {
+                String value = resolver.resolve(context, criterion);
+                boolean isControl = resolver.isControl(criterion);
+                boolean isNavigation = resolver.isNavigation(criterion);                
+                locator.add(criterion, isControl, isNavigation, value);
+            }                
+        }               
+             
+        addLocatorToCache(locatorKey, locator);
+        return locator; 
+    }
+    
+    /**
+     * Apply role fallback profiling rule based on criteria to
+     * create profile locator.
+     * 
+     * @param context request context.
+     * @param service profile service.
+     * @return profile locator for request.
+     */
+    protected ProfileLocator applyRoleFallbackProfilingRule(RequestContext context, Profiler service)
+    {
+        StringBuffer key = new StringBuffer();
+        int count = 0;
+        
+        // first pass, build the key
+        Iterator<RuleCriterion> criteria = getRuleCriteria().iterator();
+        while (criteria.hasNext())
+        {
+            RuleCriterion criterion = (RuleCriterion)criteria.next();
+            if (criterion.getType() == null)
+            {
+                log.warn("Invalid criterion provided - type null on rule " + this);
+            }
+            RuleCriterionResolver resolver = getResolver(criterion.getType());
+            if (resolver == null)
+            {
+                resolver = getDefaultResolver();
+            }
+            String value = resolver.resolve(context, criterion);
+            if (value != null && (resolver instanceof FallbackCriterionResolver))                    
+            {
+                StringTokenizer tokenizer = new StringTokenizer(value, StandardResolver.VALUE_DELIMITER);
+                while (tokenizer.hasMoreTokens())
+                {
+                    String token = tokenizer.nextToken();
+                    key.append(criterion.getName());
+                    key.append(ProfileLocator.PATH_SEPARATOR);
+                    key.append(token);
+                    if (tokenizer.hasMoreTokens())
+                    {
+                        key.append(ProfileLocator.PATH_SEPARATOR);
+                    }
+                }
+            }
+            else
+            {
+                key.append(criterion.getName());
+                key.append(ProfileLocator.PATH_SEPARATOR);
+                key.append(value);
+            }
+            if (criteria.hasNext())
+            {
+                key.append(ProfileLocator.PATH_SEPARATOR);
+            }
+            count++;                                                                                                    
+        }
+        // try to get the profile locator from the cache,
+        // request path and key sufficient to generate unique key
+        String requestPath = context.getPath();
+        String locatorKey = ((requestPath != null) ? requestPath : "/") + ProfileLocator.PATH_SEPARATOR + key.toString();
+        ProfileLocator locator = getLocatorFromCache(locatorKey); 
+        if (locator != null)
+        {
+            return locator;
+        }
+        
+        // second pass, build the locator object         
+        locator = service.createLocator(context);
+        criteria = getRuleCriteria().iterator();
+        while (criteria.hasNext())
+        {
+            RuleCriterion criterion = (RuleCriterion)criteria.next();
+            if (criterion.getType() == null)
+            {
+                log.warn("Invalid criterion provided - name or type null on rule " + this);
+            }
+            RuleCriterionResolver resolver = getResolver(criterion.getType());
+            if (resolver != null)
+            {
+                String value = resolver.resolve(context, criterion);
+                boolean isControl = resolver.isControl(criterion);
+                boolean isNavigation = resolver.isNavigation(criterion);
+                if (value != null && (resolver instanceof FallbackCriterionResolver)) 
+                {
+                    StringTokenizer tokenizer = new StringTokenizer(value, StandardResolver.VALUE_DELIMITER);
+                    while (tokenizer.hasMoreTokens())
+                    {
+                        String token = tokenizer.nextToken();
+                        locator.add(criterion, isControl, isNavigation, token);
+                    }
+                }
+                else
+                {
+                    locator.add(criterion, isControl, isNavigation, value);
+                }
+            }                
+        }               
+             
+        addLocatorToCache(locatorKey, locator);
+        return locator;         
+    }    
+}

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/AbstractProfilingRule.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/AbstractProfilingRule.java?rev=735797&r1=735796&r2=735797&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/AbstractProfilingRule.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/AbstractProfilingRule.java Mon Jan 19 12:39:38 2009
@@ -36,7 +36,7 @@
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id$
  */
-public abstract class AbstractProfilingRule implements ProfilingRule
+public abstract class AbstractProfilingRule extends AbstractBaseProfilingRule implements ProfilingRule
 {
     private static final long serialVersionUID = 1;    
     protected Collection<RuleCriterion> criteria = new RemovalAwareCollection();

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java?rev=735797&r1=735796&r2=735797&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java Mon Jan 19 12:39:38 2009
@@ -16,18 +16,10 @@
  */
 package org.apache.jetspeed.profiler.rules.impl;
 
-import java.util.Iterator;
-import java.util.StringTokenizer;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.profiler.ProfileLocator;
 import org.apache.jetspeed.profiler.Profiler;
-import org.apache.jetspeed.profiler.rules.FallbackCriterionResolver;
 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;
 import org.apache.jetspeed.request.RequestContext;
 
 /**
@@ -40,7 +32,6 @@
     extends AbstractProfilingRule
     implements ProfilingRule
 {
-    protected final static Log log = LogFactory.getLog(RoleFallbackProfilingRule.class);
     private final static long serialVersionUID = 1L;
     
     public RoleFallbackProfilingRule()
@@ -61,95 +52,6 @@
      */
     public ProfileLocator apply(RequestContext context, Profiler service)
     {
-        StringBuffer key = new StringBuffer();
-        int count = 0;
-        
-        // first pass, build the key
-        Iterator<RuleCriterion> criteria = this.getRuleCriteria().iterator();
-        while (criteria.hasNext())
-        {
-            RuleCriterion criterion = (RuleCriterion)criteria.next();
-            if (criterion.getType() == null)
-            {
-                log.warn("Invalid criterion provided - type null on rule " + this);
-            }
-            RuleCriterionResolver resolver = getResolver(criterion.getType());
-            if (resolver == null)
-            {
-                resolver = getDefaultResolver();
-            }
-            String value = resolver.resolve(context, criterion);
-            if (value != null && (resolver instanceof FallbackCriterionResolver))                    
-            {
-                StringTokenizer tokenizer = new StringTokenizer(value, StandardResolver.VALUE_DELIMITER);
-                while (tokenizer.hasMoreTokens())
-                {
-                    String token = tokenizer.nextToken();
-                    key.append(criterion.getName());
-                    key.append(ProfileLocator.PATH_SEPARATOR);
-                    key.append(token);
-                    if (tokenizer.hasMoreTokens())
-                    {
-                        key.append(ProfileLocator.PATH_SEPARATOR);
-                    }
-                }
-            }
-            else
-            {
-                key.append(criterion.getName());
-                key.append(ProfileLocator.PATH_SEPARATOR);
-                key.append(value);
-            }
-            if (criteria.hasNext())
-            {
-                key.append(ProfileLocator.PATH_SEPARATOR);
-            }
-            count++;                                                                                                    
-        }
-        // try to get the profile locator from the cache,
-        // request path and key sufficient to generate unique key
-        String requestPath = context.getPath();
-        String locatorKey = ((requestPath != null) ? requestPath : "/") + ProfileLocator.PATH_SEPARATOR + key.toString();
-        ProfileLocator locator = getLocatorFromCache(locatorKey); 
-        if (locator != null)
-        {
-            return locator;
-        }
-        
-        // second pass, build the locator object         
-        locator = service.createLocator(context);
-        criteria = this.getRuleCriteria().iterator();
-        while (criteria.hasNext())
-        {
-            RuleCriterion criterion = (RuleCriterion)criteria.next();
-            if (criterion.getType() == null)
-            {
-                log.warn("Invalid criterion provided - name or type null on rule " + this);
-            }
-            RuleCriterionResolver resolver = getResolver(criterion.getType());
-            if (resolver != null)
-            {
-                String value = resolver.resolve(context, criterion);
-                boolean isControl = resolver.isControl(criterion);
-                boolean isNavigation = resolver.isNavigation(criterion);
-                if (value != null && (resolver instanceof FallbackCriterionResolver)) 
-                {
-                    StringTokenizer tokenizer = new StringTokenizer(value, StandardResolver.VALUE_DELIMITER);
-                    while (tokenizer.hasMoreTokens())
-                    {
-                        String token = tokenizer.nextToken();
-                        locator.add(criterion, isControl, isNavigation, token);
-                    }
-                }
-                else
-                {
-                    locator.add(criterion, isControl, isNavigation, value);
-                }
-            }                
-        }               
-             
-        addLocatorToCache(locatorKey, locator);
-        return locator; 
-        
+        return applyRoleFallbackProfilingRule(context, service);
     }
 }

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/RuleCriterionImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/RuleCriterionImpl.java?rev=735797&r1=735796&r2=735797&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/RuleCriterionImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/RuleCriterionImpl.java Mon Jan 19 12:39:38 2009
@@ -26,8 +26,7 @@
  */
 public class RuleCriterionImpl implements RuleCriterion
 {
-    private String id;
-    private String ruleId;
+    private int id;
     private String type;
     private String name = null;
     private String value;
@@ -41,7 +40,6 @@
     public RuleCriterionImpl(RuleCriterion master)
     {
         this.name = master.getName();
-        this.ruleId = master.getRuleId();
         this.type = master.getType();
         this.value = master.getValue();
         this.fallbackOrder = master.getFallbackOrder();
@@ -109,22 +107,6 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.jetspeed.profiler.rules.RuleCriterion#getRuleId()
-     */
-    public String getRuleId()
-    {
-        return ruleId;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.jetspeed.profiler.rules.RuleCriterion#setRuleId(java.lang.String)
-     */
-    public void setRuleId(String ruleId)
-    {
-        this.ruleId = ruleId;
-    }
-
-    /* (non-Javadoc)
      * @see org.apache.jetspeed.profiler.rules.RuleCriterion#getFallbackOrder()
      */
     public int getFallbackOrder()

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/StandardProfilingRule.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/StandardProfilingRule.java?rev=735797&r1=735796&r2=735797&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/StandardProfilingRule.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/impl/StandardProfilingRule.java Mon Jan 19 12:39:38 2009
@@ -16,16 +16,10 @@
  */
 package org.apache.jetspeed.profiler.rules.impl;
 
-import java.util.Iterator;
-
-import org.apache.commons.logging.Log;
-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;
 import org.apache.jetspeed.request.RequestContext;
 
 /**
@@ -39,7 +33,6 @@
     extends AbstractProfilingRule
     implements ProfilingRule
 {
-    protected final static Log log = LogFactory.getLog(StandardProfilingRule.class);            
     private static final long serialVersionUID = 1;    
             
     public StandardProfilingRule()
@@ -58,66 +51,7 @@
      */    
     public ProfileLocator apply(RequestContext context, Profiler service)
     {
-        StringBuffer key = new StringBuffer();
-        int count = 0;
-        
-        // first pass, build the key
-        Iterator criteria = this.getRuleCriteria().iterator();
-        while (criteria.hasNext())
-        {
-            RuleCriterion criterion = (RuleCriterion)criteria.next();
-            if (criterion.getType() == null)
-            {
-                log.warn("Invalid criterion provided - type null on rule " + this);
-            }
-            RuleCriterionResolver resolver = getResolver(criterion.getType());
-            if (resolver == null)
-            {
-                resolver = getDefaultResolver();
-            }
-            String value = resolver.resolve(context, criterion);
-            key.append(criterion.getName());
-            key.append(ProfileLocator.PATH_SEPARATOR);
-            key.append(value);
-            if (criteria.hasNext())
-            {
-                key.append(ProfileLocator.PATH_SEPARATOR);
-            }
-            count++;                                                                                                    
-        }
-        
-        // try to get the profile locator from the cache,
-        // request path and key sufficient to generate unique key
-        String requestPath = context.getPath();
-        String locatorKey = ((requestPath != null) ? requestPath : "/") + ProfileLocator.PATH_SEPARATOR + key.toString();
-        ProfileLocator locator = getLocatorFromCache(locatorKey); 
-        if (locator != null)
-        {
-            return locator;
-        }
-        
-        // second pass, build the locator object         
-        locator = service.createLocator(context);
-        criteria = this.getRuleCriteria().iterator();
-        while (criteria.hasNext())
-        {
-            RuleCriterion criterion = (RuleCriterion)criteria.next();
-            if (criterion.getType() == null)
-            {
-                log.warn("Invalid criterion provided - type null on rule " + this);
-            }
-            RuleCriterionResolver resolver = getResolver(criterion.getType());
-            if (resolver != null)
-            {
-                String value = resolver.resolve(context, criterion);
-                boolean isControl = resolver.isControl(criterion);
-                boolean isNavigation = resolver.isNavigation(criterion);                
-                locator.add(criterion, isControl, isNavigation, value);
-            }                
-        }               
-             
-        addLocatorToCache(locatorKey, locator);
-        return locator; 
+        return applyStandardProfilingRule(context, service);
     }
         
 }

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/AbstractProfilingRule.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/AbstractProfilingRule.java?rev=735797&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/AbstractProfilingRule.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/AbstractProfilingRule.java Mon Jan 19 12:39:38 2009
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jpa;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.NamedQuery;
+import javax.persistence.NamedQueries;
+import javax.persistence.OneToMany;
+import javax.persistence.OrderBy;
+import javax.persistence.PostLoad;
+import javax.persistence.PrePersist;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import javax.persistence.Version;
+
+import org.apache.jetspeed.components.rdbms.jpa.JPAUtils;
+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;
+import org.apache.jetspeed.profiler.rules.impl.AbstractBaseProfilingRule;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * AbstractProfilingRule
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: AbstractProfilingRule.java 726976 2008-12-16 07:15:50Z taylor $
+ */
+@Entity (name="ProfilingRule")
+@Inheritance (strategy=InheritanceType.SINGLE_TABLE)
+@Table (name="PROFILING_RULE")
+@DiscriminatorColumn (name="CLASS_NAME")
+@NamedQueries({@NamedQuery(name="PROFILING_RULES", query="select pr from ProfilingRule pr"),
+               @NamedQuery(name="PROFILING_RULE", query="select pr from ProfilingRule pr where pr.id = :id")})
+public abstract class AbstractProfilingRule extends AbstractBaseProfilingRule implements ProfilingRule
+{
+    private static final long serialVersionUID = 1; 
+
+    // Members
+    
+    @Id
+    @Column (name="RULE_ID")
+    private String id;
+    @Version
+    @Column (name="JPA_VERSION")
+    private int jpaVersion;
+    @Basic
+    @Column (name="TITLE")
+    private String title;    
+    @OneToMany (targetEntity=RuleCriterionImpl.class, mappedBy="rule", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
+    @OrderBy (value="fallbackOrder ASC")
+    private List<RuleCriterion> criteria;
+
+    @PostLoad
+    private void postLoad()
+    {
+        if (criteria != null)
+        {
+            criteria.size();
+        }
+
+        isNew = false;        
+    }    
+    @PrePersist
+    private void prePersist()
+    {
+        isNew = false;
+    }
+    
+    @Transient
+    private RuleCriterionList criteriaList;
+    @Transient
+    private boolean isNew = true;
+    
+    /** Map of profile locators kept around for reuse TODO: evict entries after max size reached */
+    @Transient
+    private Map<String, ProfileLocator> locators = Collections.synchronizedMap(new HashMap<String, ProfileLocator>());
+    
+    /** Map of resolver rules for criteria. The map goes from criterion name to resolver class */
+    @Transient
+    private ProfileResolvers resolvers;
+
+    // Constructors
+    
+    public AbstractProfilingRule()
+    {
+    }
+    
+    public AbstractProfilingRule(ProfileResolvers resolvers) 
+    {
+        this();
+        this.resolvers = resolvers;
+    }
+
+    // Implementation
+    
+    protected ProfileLocator getLocatorFromCache(String key)
+    {
+        return (ProfileLocator)locators.get(key);
+    }
+    
+    
+    protected void addLocatorToCache(String key, ProfileLocator locator)
+    {
+        locators.put(key, locator);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.rules.ProfilingRule#getResolver(java.lang.String)
+     */
+    public RuleCriterionResolver getResolver(String name)
+    {
+        return resolvers.get(name);
+    }
+
+    public RuleCriterionResolver getDefaultResolver()
+    {
+        return resolvers.get(RuleCriterionResolver.REQUEST);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.rules.ProfilingRule#apply(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.profiler.Profiler)
+     */
+    public abstract ProfileLocator apply(RequestContext context, Profiler service);
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.rules.ProfilingRule#getRuleCriterion()
+     */
+    public Collection<RuleCriterion> getRuleCriteria()
+    {
+        if (criteria == null)
+        {
+            criteria = (List<RuleCriterion>)JPAUtils.createList();
+        }
+        if (criteriaList == null)
+        {
+            criteriaList = new RuleCriterionList(this, criteria);
+        }
+        return criteriaList;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.rules.ProfilingRule#getId()
+     */
+    public String getId()
+    {
+        return this.id;    
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.rules.ProfilingRule#setId(java.lang.String)
+     */
+    public void setId(String id)
+    {
+        this.id = id;
+    }
+        
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.rules.ProfilingRule#getTitle()
+     */
+    public String getTitle()
+    {
+        return this.title;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.rules.ProfilingRule#setTitle(java.lang.String)
+     */
+    public void setTitle(String title)
+    {
+        this.title = title;                        
+    }
+
+    public String toString()
+    {
+        if (id != null)
+        {
+            return id;
+        }
+        else if (title != null)
+        {
+            return title;
+        }
+        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;
+    }
+
+    /**
+     * Get new persistent status.
+     * 
+     * @return whether object is new.
+     */
+    public boolean isNew()
+    {
+        return isNew;
+    }    
+}



---------------------------------------------------------------------
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