weaver 2004/07/27 06:41:33
Modified: components/page-manager/src/java/org/apache/jetspeed/profiler/impl
JetspeedProfiler.java
Log:
Removed exception consumption.
Revision Changes Path
1.5 +151 -136
jakarta-jetspeed-2/components/page-manager/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfiler.java
Index: JetspeedProfiler.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/page-manager/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfiler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JetspeedProfiler.java 21 Jul 2004 13:38:21 -0000 1.4
+++ JetspeedProfiler.java 27 Jul 2004 13:41:33 -0000 1.5
@@ -44,27 +44,26 @@
import org.apache.jetspeed.security.SecurityHelper;
import org.apache.jetspeed.security.UserPrincipal;
-
/**
* JetspeedProfilerService
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a>
* @version $Id$
*/
-public class JetspeedProfiler implements Profiler
+public class JetspeedProfiler implements Profiler
{
/** Commons logging */
protected final static Log log = LogFactory.getLog(JetspeedProfiler.class);
-
- PageManager pageManager;
-
+
+ PageManager pageManager;
+
/** The default locator class implementation */
private Class locatorClass = JetspeedProfileLocator.class;
/** The default principalRule association class implementation */
private Class principalRuleClass = PrincipalRuleImpl.class;
/** The base (abstract) profilingRule class implementation */
- private Class profilingRuleClass = AbstractProfilingRule.class;
-
+ private Class profilingRuleClass = AbstractProfilingRule.class;
+
/** The configured default rule for this portal */
private String defaultRule = "j1";
@@ -72,69 +71,68 @@
PersistenceStore persistentStore;
- private Map principalRules = new HashMap();
-
- public JetspeedProfiler(PersistenceStore persistentStore, PageManager
pageManager)
- {
+ private Map principalRules = new HashMap();
+
+ public JetspeedProfiler( PersistenceStore persistentStore, PageManager
pageManager )
+ {
this.persistentStore = persistentStore;
- this.pageManager = pageManager;
+ this.pageManager = pageManager;
}
-
+
/**
* Create a JetspeedProfiler with properties. Expected properties are:
*
- * defaultRule = the default profiling rule
- * anonymousUser = the name of the anonymous user
- * storeName = The name of the persistence store component to connect to
- * services.profiler.locator.impl = the pluggable Profile Locator impl
- * services.profiler.principalRule.impl = the pluggable Principal Rule impl
- * services.profiler.profilingRule.impl = the pluggable Profiling Rule impl
- *
- * @param pContainer The persistence store container
- * @param properties Properties for this component described above
+ * defaultRule = the default profiling rule anonymousUser = the name of the
+ * anonymous user storeName = The name of the persistence store component to
+ * connect to services.profiler.locator.impl = the pluggable Profile Locator
+ * impl services.profiler.principalRule.impl = the pluggable Principal Rule
+ * impl services.profiler.profilingRule.impl = the pluggable Profiling Rule
+ * impl
+ *
+ * @param pContainer
+ * The persistence store container
+ * @param properties
+ * Properties for this component described above
+ * @throws ClassNotFoundException
+ * if any the implementation classes defined within the
+ * <code>properties</code> argument could not be found.
*/
- public JetspeedProfiler(PersistenceStore persistentStore, PageManager
pageManager, Properties properties)
- {
+ public JetspeedProfiler( PersistenceStore persistentStore, PageManager
pageManager, Properties properties )
+ throws ClassNotFoundException
+ {
this(persistentStore, pageManager);
this.defaultRule = properties.getProperty("defaultRule", "j1");
this.anonymousUser = properties.getProperty("anonymousUser", "anon");
initModelClasses(properties); // TODO: move this to start()
}
-
- private void initModelClasses(Properties properties)
- {
+ private void initModelClasses( Properties properties ) throws
ClassNotFoundException
+ {
String modelName = "";
- try
+
+ if ((modelName = properties.getProperty("locator.impl")) != null)
{
- if ((modelName = properties.getProperty("locator.impl")) != null)
- {
- locatorClass = Class.forName(modelName);
- }
- if ((modelName = properties.getProperty("principalRule.impl")) != null)
- {
- principalRuleClass = Class.forName(modelName);
- }
- if ((modelName = properties.getProperty("profilingRule.impl")) != null)
- {
- profilingRuleClass = Class.forName(modelName);
- }
- }
- catch (ClassNotFoundException e)
+ locatorClass = Class.forName(modelName);
+ }
+ if ((modelName = properties.getProperty("principalRule.impl")) != null)
+ {
+ principalRuleClass = Class.forName(modelName);
+ }
+ if ((modelName = properties.getProperty("profilingRule.impl")) != null)
{
- log.error("Model class not found: " + modelName);
+ profilingRuleClass = Class.forName(modelName);
}
+
}
-
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see
org.apache.jetspeed.profiler.ProfilerService#getProfile(org.apache.jetspeed.request.RequestContext)
*/
- public ProfileLocator getProfile(RequestContext context)
- throws ProfilerException
+ public ProfileLocator getProfile( RequestContext context ) throws
ProfilerException
{
- // get the principal representing the currently logged on user
+ // get the principal representing the currently logged on user
Subject subject = context.getSubject();
if (subject == null)
{
@@ -144,14 +142,14 @@
}
// get the UserPrincipal, finding the first UserPrincipal, or
// find the first principal if no UserPrincipal isn't available
- Principal principal = SecurityHelper.getBestPrincipal(subject,
UserPrincipal.class);
+ Principal principal = SecurityHelper.getBestPrincipal(subject,
UserPrincipal.class);
if (principal == null)
{
String msg = "Could not find a principle for subject in request
pipeline";
log.error(msg);
- throw new ProfilerException(msg);
+ throw new ProfilerException(msg);
}
-
+
// find a profiling rule for this principal
ProfilingRule rule = getRuleForPrincipal(principal);
if (null == rule)
@@ -159,92 +157,105 @@
log.warn("Could not find profiling rule for principal: " + principal);
rule = this.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);
+ throw new ProfilerException(msg);
}
// create a profile locator for given rule
return rule.apply(context, this);
}
- /* (non-Javadoc)
- * @see
org.apache.jetspeed.profiler.ProfilerService#getProfile(org.apache.jetspeed.request.RequestContext,
org.apache.jetspeed.profiler.rules.ProfilingRule)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.jetspeed.profiler.ProfilerService#getProfile(org.apache.jetspeed.request.RequestContext,
+ * org.apache.jetspeed.profiler.rules.ProfilingRule)
*/
- public ProfileLocator getProfile(RequestContext context, ProfilingRule rule)
- {
+ public ProfileLocator getProfile( RequestContext context, ProfilingRule rule )
+ {
// create a profile locator for given rule
- return rule.apply(context, this);
+ return rule.apply(context, this);
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.jetspeed.profiler.ProfilerService#getDefaultRule()
*/
public ProfilingRule getDefaultRule()
{
return lookupProfilingRule(this.defaultRule);
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see
org.apache.jetspeed.profiler.ProfilerService#getRuleForPrincipal(java.security.Principal)
*/
- public ProfilingRule getRuleForPrincipal(Principal principal)
+ public ProfilingRule getRuleForPrincipal( Principal principal )
{
// lookup the rule for the given principal in our user/rule table
PrincipalRule pr = lookupPrincipalRule(principal.getName());
-
- // if not found, fallback to the system wide rule
+
+ // if not found, fallback to the system wide rule
if (pr == null)
{
return getDefaultRule();
}
-
- // Now get the associated rule
+
+ // Now get the associated rule
return pr.getProfilingRule();
}
/**
* 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.
+ * @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)
+ private PrincipalRule lookupPrincipalRule( String principal )
{
- PrincipalRule pr = (PrincipalRule)principalRules.get(principal);
+ PrincipalRule pr = (PrincipalRule) principalRules.get(principal);
if (pr != null)
{
return pr;
}
- Filter filter = persistentStore.newFilter();
+ Filter filter = persistentStore.newFilter();
filter.addEqualTo("principalName", principal);
Object query = persistentStore.newQuery(principalRuleClass, filter);
pr = (PrincipalRule) persistentStore.getObjectByQuery(query);
principalRules.put(principal, pr);
- return pr;
+ return pr;
}
/**
- * Helper function to lookup a profiling rule by rule id
+ * Helper function to lookup a profiling rule by rule id
*
- * @param ruleid The unique identifier for a rule.
- * @return The found ProfilingRule associated with the rule id or null if not
found.
+ * @param ruleid
+ * The unique identifier for a rule.
+ * @return The found ProfilingRule associated with the rule id or null if
+ * not found.
*/
- private ProfilingRule lookupProfilingRule(String ruleid)
+ private ProfilingRule lookupProfilingRule( String ruleid )
{
// TODO: implement caching
- Filter filter = persistentStore.newFilter();
+ Filter filter = persistentStore.newFilter();
Object query = persistentStore.newQuery(profilingRuleClass, filter);
ProfilingRule rule = (ProfilingRule)
persistentStore.getObjectByQuery(query);
- return rule;
+ return rule;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see
org.apache.jetspeed.profiler.ProfilerService#getDesktop(org.apache.jetspeed.profiler.ProfileLocator)
*/
- public Desktop getDesktop(ProfileLocator locator)
+ public Desktop getDesktop( ProfileLocator locator )
{
Desktop desktop = null;
Iterator fallback = locator.iterator();
@@ -254,42 +265,39 @@
if (desktop != null)
{
break;
- }
- }
+ }
+ }
return desktop;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see
org.apache.jetspeed.profiler.ProfilerService#getPage(org.apache.jetspeed.profiler.ProfileLocator)
*/
- public Page getPage(ProfileLocator locator) throws PageNotFoundException
+ public Page getPage( ProfileLocator locator ) throws PageNotFoundException
{
// TODO: under construction, for now use the name
-
+
return pageManager.getPage(locator);
-
+
/*
- Page page = null;
- Iterator fallback = locator.iterator();
- while (fallback.hasNext())
- {
- page = PageManager.getPage((String)fallback.next());
- if (page != null)
- {
- break;
- }
- }
- return page;
- */
- }
-
- /* (non-Javadoc)
+ * Page page = null; Iterator fallback = locator.iterator(); while
+ * (fallback.hasNext()) { page =
+ * PageManager.getPage((String)fallback.next()); if (page != null) {
+ * break; } } return page;
+ */
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see
org.apache.jetspeed.profiler.ProfilerService#getFragment(org.apache.jetspeed.profiler.ProfileLocator)
*/
- public Fragment getFragment(ProfileLocator locator)
+ public Fragment getFragment( ProfileLocator locator )
{
Fragment fragment = null;
- Iterator fallback = locator.iterator();
+ Iterator fallback = locator.iterator();
while (fallback.hasNext())
{
// fragment = PageManager.getFragment((String)fallback.next());
@@ -300,50 +308,57 @@
}
return fragment;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.jetspeed.profiler.ProfilerService#createLocator()
*/
- public ProfileLocator createLocator()
- {
- try
- {
- return (ProfileLocator)locatorClass.newInstance();
- }
- catch (Exception e)
- {
- log.error("Failed to create locator for " + locatorClass);
- }
- return null;
- }
+ public ProfileLocator createLocator()
+ {
+ try
+ {
+ return (ProfileLocator) locatorClass.newInstance();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to create locator for " + locatorClass);
+ }
+ return null;
+ }
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.jetspeed.profiler.ProfilerService#getRules()
*/
public Collection getRules()
{
-
+
return persistentStore.getExtent(profilingRuleClass);
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.jetspeed.profiler.ProfilerService#getRule(java.lang.String)
*/
- public ProfilingRule getRule(String id)
- {
- Filter filter = persistentStore.newFilter();
+ public ProfilingRule getRule( String id )
+ {
+ Filter filter = persistentStore.newFilter();
filter.addEqualTo("id", id);
Object query = persistentStore.newQuery(profilingRuleClass, filter);
- return (ProfilingRule) persistentStore.getObjectByQuery(query);
+ return (ProfilingRule) persistentStore.getObjectByQuery(query);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.jetspeed.profiler.ProfilerService#getAnonymousUser()
*/
public String getAnonymousUser()
{
- return this.anonymousUser;
+ return this.anonymousUser;
}
-
-}
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]