KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > event > UserMgmtEvent


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.event;
25
26 import com.sun.enterprise.admin.event.AdminEvent;
27
28 //i18n import
29
import com.sun.enterprise.util.i18n.StringManager;
30
31 /**
32  * UserMgmtEvent - emitted by DAS upon changes
33  * user/group relationship content refered by AuthRealm element
34  * (this event is not about changes of realm element itself)
35  * This event does not cover the case of changes in realm content
36  * for this realm (It is the subject for another event - UserMgmtEvent)
37  * Attibutes: actionType, realmName, userName, groupList
38  */

39 public class UserMgmtEvent extends AdminEvent {
40
41     /**
42      * Constant denoting action code
43      */

44     public static final int ACTION_USERADD = 1;
45     public static final int ACTION_USERUPDATE = 2;
46     public static final int ACTION_USERREMOVE = 3;
47
48     /**
49      * Event type
50      */

51     static final String JavaDoc eventType = UserMgmtEvent.class.getName();
52
53     /**
54      * Attributes
55      */

56     private int actionType;
57     private String JavaDoc realmName;
58     private String JavaDoc userName;
59     private String JavaDoc[] groupList;
60
61     // i18n StringManager
62
private static StringManager localStrings = StringManager.getManager( UserMgmtEvent.class );
63
64     /**
65      * Create a new UserMgmtEvent.
66      * @param instance name of the instance to which the event applies
67      * @param realm name of the AuthRealm on which event happened.
68      * @param action type of action - one of UserMgmtEvent.ACTION_USERADD,
69      * UserMgmtEvent.ACTION_USERUPDATE, UserMgmtEvent.ACTION_USERREMOVE
70      * @param user name of user.
71      * @param groups list of groups for the user.
72      * @throws IllegalArgumentException if specified action is not valid
73      */

74     public UserMgmtEvent(String JavaDoc instance, String JavaDoc realm, int action, String JavaDoc user, String JavaDoc[] groups) {
75         this(eventType, instance, realm, action, user, groups);
76     }
77
78     /**
79      * Create a new UserMgmtEvent.
80      * @param type event type, a string representation for the event
81      * @param instance name of the instance to which the event applies
82      * @param realm name of the AuthRealm on which event happened.
83      * @param action type of action - one of UserMgmtEvent.ACTION_USERADD,
84      * UserMgmtEvent.ACTION_USERUPDATE, UserMgmtEvent.ACTION_USERREMOVE
85      * @param user name of user.
86      * @param groups list of groups for the user.
87      * @throws IllegalArgumentException if specified action is not valid
88      */

89     public UserMgmtEvent(String JavaDoc type, String JavaDoc instance, String JavaDoc realm, int action, String JavaDoc user, String JavaDoc[] groups) {
90         super(type, instance);
91         realmName = realm;
92         userName = user;
93         groupList = groups;
94         setAction(action);
95     }
96
97     /**
98      * Get name of the AuthRealm on which event happened
99      */

100     public String JavaDoc getAuthRealmName() {
101         return realmName;
102     }
103
104     /**
105      * Get name of the user
106      */

107     public String JavaDoc getUserName() {
108         return userName;
109     }
110
111     /**
112      * Get groups list for user
113      */

114     public String JavaDoc[] getGroupList() {
115         return groupList;
116     }
117
118     /**
119      * Get action type for this event.
120      */

121     public int getActionType() {
122         return actionType;
123     }
124
125     /**
126      * Set action to specified value. If action is not one of allowed,
127      * then IllegalArgumentException is thrown.
128      * @throws IllegalArgumentException if action is invalid
129      */

130     private void setAction(int action) {
131         boolean valid = false;
132         if (action==ACTION_USERADD ||
133             action==ACTION_USERUPDATE ||
134             action==ACTION_USERREMOVE )
135             valid = true;
136         if (!valid) {
137             String JavaDoc msg = localStrings.getString( "admin.event.invalid_action", ""+action );
138             throw new IllegalArgumentException JavaDoc( msg );
139         }
140         this.actionType = action;
141     }
142
143 }
144
Popular Tags