taylor 2004/10/08 14:45:53
Modified: components/profiler/src/test/org/apache/jetspeed/profiler
TestProfiler.java
components/profiler/src/java/org/apache/jetspeed/profiler/impl
JetspeedProfiler.java
Log:
added api getLocatorNamesForPrincipal
Revision Changes Path
1.5 +12 -2
jakarta-jetspeed-2/components/profiler/src/test/org/apache/jetspeed/profiler/TestProfiler.java
Index: TestProfiler.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/profiler/src/test/org/apache/jetspeed/profiler/TestProfiler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestProfiler.java 8 Oct 2004 06:49:37 -0000 1.4
+++ TestProfiler.java 8 Oct 2004 21:45:53 -0000 1.5
@@ -361,5 +361,15 @@
System.out.println("locator = " + path);
assertTrue("locator path: " + path,
path.equals("path:/football/nfl/chiefs"));
}
-
+
+ public void testGetLocatorNames() throws Exception
+ {
+ assertNotNull("profiler service is null", profiler);
+ String[] result = profiler.getLocatorNamesForPrincipal(new
UserPrincipalImpl("guest"));
+ for (int ix = 0; ix < result.length; ix++)
+ {
+ System.out.println("$$$ result = " + result[ix]);
+ assertTrue("locator name = " + result[ix], result[ix].equals("page"));
+ }
+ }
}
1.6 +32 -4
jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfiler.java
Index: JetspeedProfiler.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfiler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JetspeedProfiler.java 8 Oct 2004 06:49:38 -0000 1.5
+++ JetspeedProfiler.java 8 Oct 2004 21:45:53 -0000 1.6
@@ -18,6 +18,7 @@
import java.security.Principal;
import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
@@ -231,9 +232,14 @@
// TODO: throw appropriate exception
}
persistentStore.getTransaction().commit();
- principalRules.put(principal.getName(), pr);
+ principalRules.put(makePrincipalRuleKey(principal.getName(), locatorName),
pr);
}
+ private String makePrincipalRuleKey(String principal, String locator)
+ {
+ return principal + ":" + locator;
+ }
+
/**
* Helper function to lookup principal rule associations by principal
*
@@ -244,7 +250,7 @@
*/
private PrincipalRule lookupPrincipalRule(String principal, String locatorName)
{
- PrincipalRule pr = (PrincipalRule) principalRules.get(principal);
+ PrincipalRule pr = (PrincipalRule)
principalRules.get(makePrincipalRuleKey(principal, locatorName));
if (pr != null)
{
return pr;
@@ -254,7 +260,7 @@
filter.addEqualTo("locatorName", locatorName);
Object query = persistentStore.newQuery(principalRuleClass, filter);
pr = (PrincipalRule) persistentStore.getObjectByQuery(query);
- principalRules.put(principal, pr);
+ principalRules.put(makePrincipalRuleKey(principal, locatorName), pr);
return pr;
}
@@ -349,4 +355,26 @@
return this.anonymousUser;
}
+ public String[] getLocatorNamesForPrincipal(Principal principal)
+ {
+ Filter filter = persistentStore.newFilter();
+ filter.addEqualTo("principalName", principal);
+ Object query = persistentStore.newQuery(principalRuleClass, filter);
+ Collection result = persistentStore.getCollectionByQuery(query);
+ if (result.size() == 0)
+ {
+ return new String[]{};
+ }
+ String [] names = new String[result.size()];
+ Iterator it = result.iterator();
+ int ix = 0;
+ while (it.hasNext())
+ {
+ PrincipalRule pr = (PrincipalRule)it.next();
+ names[ix] = pr.getLocatorName();
+ ix++;
+ }
+ return names;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]