KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > DefaultPolicy


1 package com.sslexplorer.policyframework;
2
3 import java.util.Calendar JavaDoc;
4 import java.util.List JavaDoc;
5
6 import com.sslexplorer.core.UserDatabaseManager;
7 import com.sslexplorer.realms.Realm;
8 import com.sslexplorer.security.Role;
9 import com.sslexplorer.security.User;
10
11 public class DefaultPolicy extends AbstractResource implements Policy {
12
13     private int type;
14     private boolean addToFavorite = false;
15     private int attachedUsers = 0;
16     private int attachedGroups = 0;
17
18     /**
19      * Create a new empty policy of the specified type, ID and name.
20      * @param realmID
21      * @param uniqueId policy id
22      * @param name name of policy
23      * @param description description
24      * @param type type
25      * @param dateCreated the date / time this policy was created
26      * @param dateAmended the date / time this policy was last amended
27      */

28     public DefaultPolicy(int uniqueId, String JavaDoc name, String JavaDoc description, int type,
29                     Calendar JavaDoc dateCreated, Calendar JavaDoc dateAmended, int realmID) {
30         super(realmID, PolicyConstants.POLICY_RESOURCE_TYPE, uniqueId, name, description, dateCreated, dateAmended);
31         try {
32             List JavaDoc<Principal> principalsGrantedPolicy = PolicyDatabaseFactory.getInstance().getPrincipalsGrantedPolicy(this, UserDatabaseManager.getInstance().getRealm(realmID));
33             for (Principal principal : principalsGrantedPolicy) {
34                 if (principal instanceof User){
35                     attachedUsers ++;
36                 }
37                 else if (principal instanceof Role){
38                     attachedGroups ++;
39                 }
40             }
41         } catch (Exception JavaDoc e) {
42             // TODO Auto-generated catch block
43
e.printStackTrace();
44         }
45     }
46
47     /*
48      * (non-Javadoc)
49      *
50      * @see com.sslexplorer.policyframework.Policy#getType()
51      */

52     public int getType() {
53         return type;
54     }
55     
56     /* (non-Javadoc)
57      * @see com.sslexplorer.policyframework.Policy#setType(int)
58      */

59     public void setType(int type) {
60         this.type = type;
61     }
62
63     public boolean isAddToFavorite() {
64         return addToFavorite;
65     }
66
67     public void setAddToFavorite(boolean addToFavorite) {
68         this.addToFavorite = addToFavorite;
69     }
70
71     public int getAttachedGroups() {
72         return attachedGroups;
73     }
74
75     public int getAttachedUsers() {
76         return attachedUsers;
77     }
78 }
79
Popular Tags