Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 1 | /* |
Carsten Ziegeler | 47b825b | 2008-01-29 09:01:39 +0000 | [diff] [blame] | 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 9 | * |
Carsten Ziegeler | 47b825b | 2008-01-29 09:01:39 +0000 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 11 | * |
Carsten Ziegeler | 47b825b | 2008-01-29 09:01:39 +0000 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 18 | */ |
| 19 | package org.apache.felix.cm.impl; |
| 20 | |
| 21 | |
| 22 | import java.io.IOException; |
| 23 | import java.util.Dictionary; |
| 24 | |
| 25 | import org.osgi.service.cm.Configuration; |
Felix Meschberger | f0c5a3d | 2011-11-04 10:47:58 +0000 | [diff] [blame] | 26 | import org.osgi.service.log.LogService; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | /** |
Felix Meschberger | 93c409a | 2009-01-19 10:47:59 +0000 | [diff] [blame] | 30 | * The <code>ConfigurationAdapter</code> is just an adapter to the internal |
| 31 | * configuration object. Instances of this class are returned as Configuration |
| 32 | * objects to the client, where each caller gets a fresh instance of this |
| 33 | * class while internal Configuration objects are shared. |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 34 | */ |
| 35 | public class ConfigurationAdapter implements Configuration |
| 36 | { |
| 37 | |
Felix Meschberger | df26ae8 | 2009-08-14 19:50:43 +0000 | [diff] [blame] | 38 | private final ConfigurationAdminImpl configurationAdmin; |
| 39 | private final ConfigurationImpl delegatee; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 40 | |
| 41 | |
| 42 | ConfigurationAdapter( ConfigurationAdminImpl configurationAdmin, ConfigurationImpl delegatee ) |
| 43 | { |
| 44 | this.configurationAdmin = configurationAdmin; |
| 45 | this.delegatee = delegatee; |
| 46 | } |
| 47 | |
| 48 | |
| 49 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 50 | * @see org.apache.felix.cm.impl.ConfigurationImpl#getPid() |
| 51 | */ |
| 52 | public String getPid() |
| 53 | { |
| 54 | checkDeleted(); |
| 55 | return delegatee.getPid(); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 60 | * @see org.apache.felix.cm.impl.ConfigurationImpl#getFactoryPid() |
| 61 | */ |
| 62 | public String getFactoryPid() |
| 63 | { |
| 64 | checkDeleted(); |
| 65 | return delegatee.getFactoryPid(); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 70 | * @see org.apache.felix.cm.impl.ConfigurationImpl#getBundleLocation() |
| 71 | */ |
| 72 | public String getBundleLocation() |
| 73 | { |
Felix Meschberger | f0c5a3d | 2011-11-04 10:47:58 +0000 | [diff] [blame] | 74 | delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "getBundleLocation()", ( Throwable ) null ); |
| 75 | |
Felix Meschberger | 007c50e | 2011-10-20 12:39:38 +0000 | [diff] [blame] | 76 | // CM 1.4 / 104.13.2.4 |
Felix Meschberger | fa6f013 | 2011-11-16 09:51:23 +0000 | [diff] [blame^] | 77 | final String bundleLocation = delegatee.getBundleLocation(); |
| 78 | configurationAdmin.checkPermission( ( bundleLocation == null ) ? "*" : bundleLocation ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 79 | checkDeleted(); |
Felix Meschberger | fa6f013 | 2011-11-16 09:51:23 +0000 | [diff] [blame^] | 80 | return bundleLocation; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | |
| 84 | /** |
| 85 | * @param bundleLocation |
| 86 | * @see org.apache.felix.cm.impl.ConfigurationImpl#setBundleLocation(java.lang.String) |
| 87 | */ |
| 88 | public void setBundleLocation( String bundleLocation ) |
| 89 | { |
Felix Meschberger | f0c5a3d | 2011-11-04 10:47:58 +0000 | [diff] [blame] | 90 | delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "setBundleLocation(bundleLocation={0})", |
| 91 | new Object[] |
| 92 | { bundleLocation } ); |
| 93 | |
Felix Meschberger | 007c50e | 2011-10-20 12:39:38 +0000 | [diff] [blame] | 94 | // CM 1.4 / 104.13.2.4 |
| 95 | configurationAdmin.checkPermission( delegatee.getBundleLocation() ); |
Felix Meschberger | fb833e7 | 2011-10-27 06:12:37 +0000 | [diff] [blame] | 96 | configurationAdmin.checkPermission( ( bundleLocation == null ) ? "*" : bundleLocation ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 97 | checkDeleted(); |
Felix Meschberger | ef47004 | 2009-08-19 05:52:41 +0000 | [diff] [blame] | 98 | delegatee.setStaticBundleLocation( bundleLocation ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
| 102 | /** |
| 103 | * @throws IOException |
| 104 | * @see org.apache.felix.cm.impl.ConfigurationImpl#update() |
| 105 | */ |
| 106 | public void update() throws IOException |
| 107 | { |
Felix Meschberger | f0c5a3d | 2011-11-04 10:47:58 +0000 | [diff] [blame] | 108 | delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "update()", ( Throwable ) null ); |
| 109 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 110 | checkDeleted(); |
| 111 | delegatee.update(); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | /** |
| 116 | * @param properties |
| 117 | * @throws IOException |
| 118 | * @see org.apache.felix.cm.impl.ConfigurationImpl#update(java.util.Dictionary) |
| 119 | */ |
| 120 | public void update( Dictionary properties ) throws IOException |
| 121 | { |
Felix Meschberger | f0c5a3d | 2011-11-04 10:47:58 +0000 | [diff] [blame] | 122 | delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "update(properties={0})", new Object[] |
| 123 | { properties } ); |
| 124 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 125 | checkDeleted(); |
| 126 | delegatee.update( properties ); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 131 | * @see org.apache.felix.cm.impl.ConfigurationImpl#getProperties() |
| 132 | */ |
| 133 | public Dictionary getProperties() |
| 134 | { |
Felix Meschberger | f0c5a3d | 2011-11-04 10:47:58 +0000 | [diff] [blame] | 135 | delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "getProperties()", ( Throwable ) null ); |
| 136 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 137 | checkDeleted(); |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 138 | |
Felix Meschberger | a0903df | 2009-01-19 10:40:28 +0000 | [diff] [blame] | 139 | // return a deep copy since the spec says, that modification of |
| 140 | // any value should not modify the internal, stored value |
| 141 | return delegatee.getProperties( true ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | |
| 145 | /** |
| 146 | * @throws IOException |
| 147 | * @see org.apache.felix.cm.impl.ConfigurationImpl#delete() |
| 148 | */ |
| 149 | public void delete() throws IOException |
| 150 | { |
Felix Meschberger | f0c5a3d | 2011-11-04 10:47:58 +0000 | [diff] [blame] | 151 | delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "delete()", ( Throwable ) null ); |
| 152 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 153 | checkDeleted(); |
| 154 | delegatee.delete(); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 159 | * @see org.apache.felix.cm.impl.ConfigurationImpl#hashCode() |
| 160 | */ |
| 161 | public int hashCode() |
| 162 | { |
| 163 | return delegatee.hashCode(); |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /** |
| 168 | * @param obj |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 169 | * @see org.apache.felix.cm.impl.ConfigurationImpl#equals(java.lang.Object) |
| 170 | */ |
| 171 | public boolean equals( Object obj ) |
| 172 | { |
| 173 | return delegatee.equals( obj ); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 178 | * @see org.apache.felix.cm.impl.ConfigurationImpl#toString() |
| 179 | */ |
| 180 | public String toString() |
| 181 | { |
| 182 | return delegatee.toString(); |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Checks whether this configuration object has already been deleted. |
Carsten Ziegeler | 7853b9a | 2008-01-11 16:30:24 +0000 | [diff] [blame] | 187 | * |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 188 | * @throws IllegalStateException If this configuration object has been |
| 189 | * deleted. |
| 190 | */ |
| 191 | private void checkDeleted() { |
| 192 | if (delegatee.isDeleted()) { |
| 193 | throw new IllegalStateException( "Configuration " + delegatee.getPid() + " deleted" ); |
| 194 | } |
| 195 | } |
| 196 | } |