Carsten Ziegeler | 47b825b | 2008-01-29 09:01:39 +0000 | [diff] [blame] | 1 | /* |
| 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 | /** |
| 29 | * The <code>ConfigurationAdapter</code> TODO |
| 30 | * |
| 31 | * @author fmeschbe |
Felix Meschberger | a0903df | 2009-01-19 10:40:28 +0000 | [diff] [blame^] | 32 | * @version $Rev:616219 $, $Date$ |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 33 | */ |
| 34 | public class ConfigurationAdapter implements Configuration |
| 35 | { |
| 36 | |
| 37 | private ConfigurationAdminImpl configurationAdmin; |
| 38 | private ConfigurationImpl delegatee; |
| 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 | { |
| 73 | configurationAdmin.checkPermission(); |
| 74 | checkDeleted(); |
| 75 | return delegatee.getBundleLocation(); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | /** |
| 80 | * @param bundleLocation |
| 81 | * @see org.apache.felix.cm.impl.ConfigurationImpl#setBundleLocation(java.lang.String) |
| 82 | */ |
| 83 | public void setBundleLocation( String bundleLocation ) |
| 84 | { |
| 85 | configurationAdmin.checkPermission(); |
| 86 | checkDeleted(); |
| 87 | delegatee.setBundleLocation( bundleLocation ); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | /** |
| 92 | * @throws IOException |
| 93 | * @see org.apache.felix.cm.impl.ConfigurationImpl#update() |
| 94 | */ |
| 95 | public void update() throws IOException |
| 96 | { |
| 97 | checkDeleted(); |
| 98 | delegatee.update(); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | /** |
| 103 | * @param properties |
| 104 | * @throws IOException |
| 105 | * @see org.apache.felix.cm.impl.ConfigurationImpl#update(java.util.Dictionary) |
| 106 | */ |
| 107 | public void update( Dictionary properties ) throws IOException |
| 108 | { |
| 109 | checkDeleted(); |
| 110 | delegatee.update( properties ); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 115 | * @see org.apache.felix.cm.impl.ConfigurationImpl#getProperties() |
| 116 | */ |
| 117 | public Dictionary getProperties() |
| 118 | { |
| 119 | checkDeleted(); |
Felix Meschberger | a0903df | 2009-01-19 10:40:28 +0000 | [diff] [blame^] | 120 | |
| 121 | // return a deep copy since the spec says, that modification of |
| 122 | // any value should not modify the internal, stored value |
| 123 | return delegatee.getProperties( true ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | |
| 127 | /** |
| 128 | * @throws IOException |
| 129 | * @see org.apache.felix.cm.impl.ConfigurationImpl#delete() |
| 130 | */ |
| 131 | public void delete() throws IOException |
| 132 | { |
| 133 | checkDeleted(); |
| 134 | delegatee.delete(); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 139 | * @see org.apache.felix.cm.impl.ConfigurationImpl#hashCode() |
| 140 | */ |
| 141 | public int hashCode() |
| 142 | { |
| 143 | return delegatee.hashCode(); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | /** |
| 148 | * @param obj |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 149 | * @see org.apache.felix.cm.impl.ConfigurationImpl#equals(java.lang.Object) |
| 150 | */ |
| 151 | public boolean equals( Object obj ) |
| 152 | { |
| 153 | return delegatee.equals( obj ); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | /** |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 158 | * @see org.apache.felix.cm.impl.ConfigurationImpl#toString() |
| 159 | */ |
| 160 | public String toString() |
| 161 | { |
| 162 | return delegatee.toString(); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Checks whether this configuration object has already been deleted. |
Carsten Ziegeler | 7853b9a | 2008-01-11 16:30:24 +0000 | [diff] [blame] | 167 | * |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 168 | * @throws IllegalStateException If this configuration object has been |
| 169 | * deleted. |
| 170 | */ |
| 171 | private void checkDeleted() { |
| 172 | if (delegatee.isDeleted()) { |
| 173 | throw new IllegalStateException( "Configuration " + delegatee.getPid() + " deleted" ); |
| 174 | } |
| 175 | } |
| 176 | } |