KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > NamespacePermission


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package org.jboss.test;
8
9 import java.security.BasicPermission JavaDoc;
10 import java.security.Permission JavaDoc;
11 import java.security.PermissionCollection JavaDoc;
12 import javax.naming.Name JavaDoc;
13
14 /** A path like heirarchical permission.
15
16 @author Scott.Stark@jboss.org
17 @version $Revsiion:$
18 */

19 public class NamespacePermission extends BasicPermission JavaDoc
20 {
21     private PermissionName fullName;
22     private String JavaDoc actions;
23
24     /** Creates new NamespacePermission */
25     public NamespacePermission(String JavaDoc name, String JavaDoc actions)
26     {
27         super(name, actions);
28         this.actions = actions;
29         fullName = new PermissionName(name);
30     }
31     public NamespacePermission(Name JavaDoc name, String JavaDoc actions)
32     {
33         super(name.toString(), actions);
34         this.actions = actions;
35         fullName = new PermissionName(name);
36     }
37
38     public String JavaDoc getActions()
39     {
40         return actions;
41     }
42
43     public PermissionName getFullName()
44     {
45         return fullName;
46     }
47
48     public boolean implies(Permission JavaDoc p)
49     {
50         String JavaDoc pactions = p.getActions();
51         boolean implied = true;
52         for(int n = 0; n < actions.length(); n ++)
53         {
54             char a = actions.charAt(n);
55             char pa = pactions.charAt(n);
56             if( (a != '-' && pa != '-' && pa != a) )
57             {
58                 implied = false;
59                 break;
60             }
61             else if( a == '-' && pa != '-' )
62             {
63                 implied = false;
64                 break;
65             }
66         }
67         return implied;
68     }
69
70     public PermissionCollection JavaDoc newPermissionCollection()
71     {
72         return new NamespacePermissionCollection();
73     }
74 }
75
Popular Tags