Felix Meschberger | 007c50e | 2011-10-20 12:39:38 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) OSGi Alliance (2004, 2011). All Rights Reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.osgi.service.cm; |
| 17 | |
| 18 | import org.osgi.framework.ServiceReference; |
| 19 | |
| 20 | /** |
| 21 | * A Configuration Event. |
| 22 | * |
| 23 | * <p> |
| 24 | * {@code ConfigurationEvent} objects are delivered to all registered |
| 25 | * {@code ConfigurationListener} service objects. ConfigurationEvents must be |
| 26 | * asynchronously delivered in chronological order with respect to each |
| 27 | * listener. |
| 28 | * |
| 29 | * <p> |
| 30 | * A type code is used to identify the type of event. The following event types |
| 31 | * are defined: |
| 32 | * <ul> |
| 33 | * <li>{@link #CM_UPDATED}</li> |
| 34 | * <li>{@link #CM_DELETED}</li> |
| 35 | * <li>{@link #CM_LOCATION_CHANGED}</li> |
| 36 | * </ul> |
| 37 | * Additional event types may be defined in the future. |
| 38 | * |
| 39 | * <p> |
| 40 | * Security Considerations. {@code ConfigurationEvent} objects do not provide |
| 41 | * {@code Configuration} objects, so no sensitive configuration information is |
| 42 | * available from the event. If the listener wants to locate the |
| 43 | * {@code Configuration} object for the specified pid, it must use |
| 44 | * {@code ConfigurationAdmin}. |
| 45 | * |
| 46 | * @see ConfigurationListener |
| 47 | * @Immutable |
| 48 | * @version $Id: 1493c281dfd9387837e6399b9b815cdc8dc43453 $ |
| 49 | * @since 1.2 |
| 50 | */ |
| 51 | public class ConfigurationEvent { |
| 52 | /** |
| 53 | * A {@code Configuration} has been updated. |
| 54 | * |
| 55 | * <p> |
| 56 | * This {@code ConfigurationEvent} type that indicates that a |
| 57 | * {@code Configuration} object has been updated with new properties. |
| 58 | * |
| 59 | * An event is fired when a call to {@link Configuration#update(Dictionary)} |
| 60 | * successfully changes a configuration. |
| 61 | */ |
| 62 | public static final int CM_UPDATED = 1; |
| 63 | /** |
| 64 | * A {@code Configuration} has been deleted. |
| 65 | * |
| 66 | * <p> |
| 67 | * This {@code ConfigurationEvent} type that indicates that a |
| 68 | * {@code Configuration} object has been deleted. |
| 69 | * |
| 70 | * An event is fired when a call to {@link Configuration#delete()} |
| 71 | * successfully deletes a configuration. |
| 72 | */ |
| 73 | public static final int CM_DELETED = 2; |
| 74 | |
| 75 | /** |
| 76 | * The location of a {@code Configuration} has been changed. |
| 77 | * |
| 78 | * <p> |
| 79 | * This {@code ConfigurationEvent} type that indicates that the location of |
| 80 | * a {@code Configuration} object has been changed. |
| 81 | * |
| 82 | * An event is fired when a call to |
| 83 | * {@link Configuration#setBundleLocation(String)} successfully changes the |
| 84 | * location. |
| 85 | * |
| 86 | * @since 1.4 |
| 87 | */ |
| 88 | public static final int CM_LOCATION_CHANGED = 3; |
| 89 | /** |
| 90 | * Type of this event. |
| 91 | * |
| 92 | * @see #getType() |
| 93 | */ |
| 94 | private final int type; |
| 95 | /** |
| 96 | * The factory pid associated with this event. |
| 97 | */ |
| 98 | private final String factoryPid; |
| 99 | /** |
| 100 | * The pid associated with this event. |
| 101 | */ |
| 102 | private final String pid; |
| 103 | /** |
| 104 | * The ConfigurationAdmin service which created this event. |
| 105 | */ |
| 106 | private final ServiceReference reference; |
| 107 | |
| 108 | /** |
| 109 | * Constructs a {@code ConfigurationEvent} object from the given |
| 110 | * {@code ServiceReference} object, event type, and pids. |
| 111 | * |
| 112 | * @param reference The {@code ServiceReference} object of the Configuration |
| 113 | * Admin service that created this event. |
| 114 | * @param type The event type. See {@link #getType()}. |
| 115 | * @param factoryPid The factory pid of the associated configuration if the |
| 116 | * target of the configuration is a ManagedServiceFactory. Otherwise |
| 117 | * {@code null} if the target of the configuration is a |
| 118 | * ManagedService. |
| 119 | * @param pid The pid of the associated configuration. |
| 120 | */ |
| 121 | public ConfigurationEvent(ServiceReference reference, |
| 122 | int type, |
| 123 | String factoryPid, String pid) { |
| 124 | this.reference = reference; |
| 125 | this.type = type; |
| 126 | this.factoryPid = factoryPid; |
| 127 | this.pid = pid; |
| 128 | if ((reference == null) || (pid == null)) { |
| 129 | throw new NullPointerException("reference and pid must not be null"); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Returns the factory pid of the associated configuration. |
| 135 | * |
| 136 | * @return Returns the factory pid of the associated configuration if the |
| 137 | * target of the configuration is a ManagedServiceFactory. Otherwise |
| 138 | * {@code null} if the target of the configuration is a |
| 139 | * ManagedService. |
| 140 | */ |
| 141 | public String getFactoryPid() { |
| 142 | return factoryPid; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Returns the pid of the associated configuration. |
| 147 | * |
| 148 | * @return Returns the pid of the associated configuration. |
| 149 | */ |
| 150 | public String getPid() { |
| 151 | return pid; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Return the type of this event. |
| 156 | * <p> |
| 157 | * The type values are: |
| 158 | * <ul> |
| 159 | * <li>{@link #CM_UPDATED}</li> |
| 160 | * <li>{@link #CM_DELETED}</li> |
| 161 | * <li>{@link #CM_LOCATION_CHANGED}</li> |
| 162 | * </ul> |
| 163 | * |
| 164 | * @return The type of this event. |
| 165 | */ |
| 166 | public int getType() { |
| 167 | return type; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Return the {@code ServiceReference} object of the Configuration |
| 172 | * Admin service that created this event. |
| 173 | * |
| 174 | * @return The {@code ServiceReference} object for the Configuration |
| 175 | * Admin service that created this event. |
| 176 | */ |
| 177 | public ServiceReference getReference() { |
| 178 | return reference; |
| 179 | } |
| 180 | } |