001 /*
002 * Copyright (c) OSGi Alliance (2001, 2008). All Rights Reserved.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.osgi.service.useradmin;
017
018 import org.osgi.framework.ServiceReference;
019
020 /**
021 * <code>Role</code> change event.
022 * <p>
023 * <code>UserAdminEvent</code> objects are delivered asynchronously to any
024 * <code>UserAdminListener</code> objects when a change occurs in any of the
025 * <code>Role</code> objects managed by a User Admin service.
026 *
027 * <p>
028 * A type code is used to identify the event. The following event types are
029 * defined: {@link #ROLE_CREATED} type, {@link #ROLE_CHANGED} type, and
030 * {@link #ROLE_REMOVED} type. Additional event types may be defined in the
031 * future.
032 *
033 * @see UserAdmin
034 * @see UserAdminListener
035 *
036 * @version $Revision: 5673 $
037 */
038 public class UserAdminEvent {
039 private ServiceReference ref;
040 private int type;
041 private Role role;
042 /**
043 * A <code>Role</code> object has been created.
044 *
045 * <p>
046 * The value of <code>ROLE_CREATED</code> is 0x00000001.
047 */
048 public static final int ROLE_CREATED = 0x00000001;
049 /**
050 * A <code>Role</code> object has been modified.
051 *
052 * <p>
053 * The value of <code>ROLE_CHANGED</code> is 0x00000002.
054 */
055 public static final int ROLE_CHANGED = 0x00000002;
056 /**
057 * A <code>Role</code> object has been removed.
058 *
059 * <p>
060 * The value of <code>ROLE_REMOVED</code> is 0x00000004.
061 */
062 public static final int ROLE_REMOVED = 0x00000004;
063
064 /**
065 * Constructs a <code>UserAdminEvent</code> object from the given
066 * <code>ServiceReference</code> object, event type, and <code>Role</code>
067 * object.
068 *
069 * @param ref The <code>ServiceReference</code> object of the User Admin
070 * service that generated this event.
071 * @param type The event type.
072 * @param role The <code>Role</code> object on which this event occurred.
073 */
074 public UserAdminEvent(ServiceReference ref, int type, Role role) {
075 this.ref = ref;
076 this.type = type;
077 this.role = role;
078 }
079
080 /**
081 * Gets the <code>ServiceReference</code> object of the User Admin service
082 * that generated this event.
083 *
084 * @return The User Admin service's <code>ServiceReference</code> object.
085 */
086 public ServiceReference getServiceReference() {
087 return ref;
088 }
089
090 /**
091 * Returns the type of this event.
092 *
093 * <p>
094 * The type values are {@link #ROLE_CREATED} type, {@link #ROLE_CHANGED}
095 * type, and {@link #ROLE_REMOVED} type.
096 *
097 * @return The event type.
098 */
099 public int getType() {
100 return type;
101 }
102
103 /**
104 * Gets the <code>Role</code> object this event was generated for.
105 *
106 * @return The <code>Role</code> object this event was generated for.
107 */
108 public Role getRole() {
109 return role;
110 }
111 }