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; |
| 26 | |
| 27 | |
| 28 | /** |
Felix Meschberger | 93c409a | 2009-01-19 10:47:59 +0000 | [diff] [blame] | 29 | * The <code>ConfigurationAdapter</code> is just an adapter to the internal |
| 30 | * configuration object. Instances of this class are returned as Configuration |
| 31 | * objects to the client, where each caller gets a fresh instance of this |
| 32 | * class while internal Configuration objects are shared. |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 33 | */ |
| 34 | public class ConfigurationAdapter implements Configuration |
| 35 | { |
| 36 | |
Felix Meschberger | df26ae8 | 2009-08-14 19:50:43 +0000 | [diff] [blame] | 37 | private final ConfigurationAdminImpl configurationAdmin; |
| 38 | private final ConfigurationImpl delegatee; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 39 | |
| 40 | |
| 41 | ConfigurationAdapter( ConfigurationAdminImpl configurationAdmin, ConfigurationImpl delegatee ) |
| 42 | { |
| 43 | this.configurationAdmin = configurationAdmin; |
| 44 | this.delegatee = delegatee; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 49 | * @see org.apache.felix.cm.impl.ConfigurationImpl#getPid() |
| 50 | */ |
| 51 | public String getPid() |
| 52 | { |
| 53 | checkDeleted(); |
| 54 | return delegatee.getPid(); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 59 | * @see org.apache.felix.cm.impl.ConfigurationImpl#getFactoryPid() |
| 60 | */ |
| 61 | public String getFactoryPid() |
| 62 | { |
| 63 | checkDeleted(); |
| 64 | return delegatee.getFactoryPid(); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 69 | * @see org.apache.felix.cm.impl.ConfigurationImpl#getBundleLocation() |
| 70 | */ |
| 71 | public String getBundleLocation() |
| 72 | { |
Felix Meschberger | 007c50e | 2011-10-20 12:39:38 +0000 | [diff] [blame^] | 73 | // CM 1.4 / 104.13.2.4 |
| 74 | configurationAdmin.checkPermission( delegatee.getBundleLocation() ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 75 | checkDeleted(); |
| 76 | return delegatee.getBundleLocation(); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /** |
| 81 | * @param bundleLocation |
| 82 | * @see org.apache.felix.cm.impl.ConfigurationImpl#setBundleLocation(java.lang.String) |
| 83 | */ |
| 84 | public void setBundleLocation( String bundleLocation ) |
| 85 | { |
Felix Meschberger | 007c50e | 2011-10-20 12:39:38 +0000 | [diff] [blame^] | 86 | // CM 1.4 / 104.13.2.4 |
| 87 | configurationAdmin.checkPermission( delegatee.getBundleLocation() ); |
| 88 | configurationAdmin.checkPermission( bundleLocation ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 89 | checkDeleted(); |
Felix Meschberger | ef47004 | 2009-08-19 05:52:41 +0000 | [diff] [blame] | 90 | delegatee.setStaticBundleLocation( bundleLocation ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | |
| 94 | /** |
| 95 | * @throws IOException |
| 96 | * @see org.apache.felix.cm.impl.ConfigurationImpl#update() |
| 97 | */ |
| 98 | public void update() throws IOException |
| 99 | { |
| 100 | checkDeleted(); |
| 101 | delegatee.update(); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | /** |
| 106 | * @param properties |
| 107 | * @throws IOException |
| 108 | * @see org.apache.felix.cm.impl.ConfigurationImpl#update(java.util.Dictionary) |
| 109 | */ |
| 110 | public void update( Dictionary properties ) throws IOException |
| 111 | { |
| 112 | checkDeleted(); |
| 113 | delegatee.update( properties ); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 118 | * @see org.apache.felix.cm.impl.ConfigurationImpl#getProperties() |
| 119 | */ |
| 120 | public Dictionary getProperties() |
| 121 | { |
| 122 | checkDeleted(); |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 123 | |
Felix Meschberger | a0903df | 2009-01-19 10:40:28 +0000 | [diff] [blame] | 124 | // return a deep copy since the spec says, that modification of |
| 125 | // any value should not modify the internal, stored value |
| 126 | return delegatee.getProperties( true ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | |
| 130 | /** |
| 131 | * @throws IOException |
| 132 | * @see org.apache.felix.cm.impl.ConfigurationImpl#delete() |
| 133 | */ |
| 134 | public void delete() throws IOException |
| 135 | { |
| 136 | checkDeleted(); |
| 137 | delegatee.delete(); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 142 | * @see org.apache.felix.cm.impl.ConfigurationImpl#hashCode() |
| 143 | */ |
| 144 | public int hashCode() |
| 145 | { |
| 146 | return delegatee.hashCode(); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | /** |
| 151 | * @param obj |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 152 | * @see org.apache.felix.cm.impl.ConfigurationImpl#equals(java.lang.Object) |
| 153 | */ |
| 154 | public boolean equals( Object obj ) |
| 155 | { |
| 156 | return delegatee.equals( obj ); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 161 | * @see org.apache.felix.cm.impl.ConfigurationImpl#toString() |
| 162 | */ |
| 163 | public String toString() |
| 164 | { |
| 165 | return delegatee.toString(); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Checks whether this configuration object has already been deleted. |
Carsten Ziegeler | 7853b9a | 2008-01-11 16:30:24 +0000 | [diff] [blame] | 170 | * |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 171 | * @throws IllegalStateException If this configuration object has been |
| 172 | * deleted. |
| 173 | */ |
| 174 | private void checkDeleted() { |
| 175 | if (delegatee.isDeleted()) { |
| 176 | throw new IllegalStateException( "Configuration " + delegatee.getPid() + " deleted" ); |
| 177 | } |
| 178 | } |
| 179 | } |