blob: 6ba1ca1297531fce930dbe0e2e6f71babb992888 [file] [log] [blame]
Felix Meschberger6a698df2009-08-16 18:38:46 +00001/*
Carsten Ziegeler47b825b2008-01-29 09:01:39 +00002 * 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 Meschbergeradd2b4a2007-04-11 18:12:33 +00009 *
Carsten Ziegeler47b825b2008-01-29 09:01:39 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000011 *
Carsten Ziegeler47b825b2008-01-29 09:01:39 +000012 * 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 Meschbergeradd2b4a2007-04-11 18:12:33 +000018 */
19package org.apache.felix.cm.impl;
20
21
22import java.io.IOException;
23import java.util.Dictionary;
24
25import org.osgi.service.cm.Configuration;
Felix Meschbergerf0c5a3d2011-11-04 10:47:58 +000026import org.osgi.service.log.LogService;
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000027
28
29/**
Felix Meschberger93c409a2009-01-19 10:47:59 +000030 * 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 Meschbergeradd2b4a2007-04-11 18:12:33 +000034 */
35public class ConfigurationAdapter implements Configuration
36{
37
Felix Meschbergerdf26ae82009-08-14 19:50:43 +000038 private final ConfigurationAdminImpl configurationAdmin;
39 private final ConfigurationImpl delegatee;
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000040
41
42 ConfigurationAdapter( ConfigurationAdminImpl configurationAdmin, ConfigurationImpl delegatee )
43 {
44 this.configurationAdmin = configurationAdmin;
45 this.delegatee = delegatee;
46 }
47
48
49 /**
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000050 * @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 Meschbergeradd2b4a2007-04-11 18:12:33 +000060 * @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 Meschbergeradd2b4a2007-04-11 18:12:33 +000070 * @see org.apache.felix.cm.impl.ConfigurationImpl#getBundleLocation()
71 */
72 public String getBundleLocation()
73 {
Felix Meschbergerf0c5a3d2011-11-04 10:47:58 +000074 delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "getBundleLocation()", ( Throwable ) null );
75
Felix Meschberger007c50e2011-10-20 12:39:38 +000076 // CM 1.4 / 104.13.2.4
Felix Meschbergerfa6f0132011-11-16 09:51:23 +000077 final String bundleLocation = delegatee.getBundleLocation();
78 configurationAdmin.checkPermission( ( bundleLocation == null ) ? "*" : bundleLocation );
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000079 checkDeleted();
Felix Meschbergerfa6f0132011-11-16 09:51:23 +000080 return bundleLocation;
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000081 }
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 Meschbergerf0c5a3d2011-11-04 10:47:58 +000090 delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "setBundleLocation(bundleLocation={0})",
91 new Object[]
92 { bundleLocation } );
93
Felix Meschberger007c50e2011-10-20 12:39:38 +000094 // CM 1.4 / 104.13.2.4
95 configurationAdmin.checkPermission( delegatee.getBundleLocation() );
Felix Meschbergerfb833e72011-10-27 06:12:37 +000096 configurationAdmin.checkPermission( ( bundleLocation == null ) ? "*" : bundleLocation );
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000097 checkDeleted();
Felix Meschbergeref470042009-08-19 05:52:41 +000098 delegatee.setStaticBundleLocation( bundleLocation );
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000099 }
100
101
102 /**
103 * @throws IOException
104 * @see org.apache.felix.cm.impl.ConfigurationImpl#update()
105 */
106 public void update() throws IOException
107 {
Felix Meschbergerf0c5a3d2011-11-04 10:47:58 +0000108 delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "update()", ( Throwable ) null );
109
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +0000110 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 Meschbergerf0c5a3d2011-11-04 10:47:58 +0000122 delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "update(properties={0})", new Object[]
123 { properties } );
124
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +0000125 checkDeleted();
126 delegatee.update( properties );
127 }
128
129
130 /**
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +0000131 * @see org.apache.felix.cm.impl.ConfigurationImpl#getProperties()
132 */
133 public Dictionary getProperties()
134 {
Felix Meschbergerf0c5a3d2011-11-04 10:47:58 +0000135 delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "getProperties()", ( Throwable ) null );
136
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +0000137 checkDeleted();
Felix Meschberger6a698df2009-08-16 18:38:46 +0000138
Felix Meschbergera0903df2009-01-19 10:40:28 +0000139 // 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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000142 }
143
144
145 /**
146 * @throws IOException
147 * @see org.apache.felix.cm.impl.ConfigurationImpl#delete()
148 */
149 public void delete() throws IOException
150 {
Felix Meschbergerf0c5a3d2011-11-04 10:47:58 +0000151 delegatee.getConfigurationManager().log( LogService.LOG_DEBUG, "delete()", ( Throwable ) null );
152
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +0000153 checkDeleted();
154 delegatee.delete();
155 }
156
157
158 /**
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +0000159 * @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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000169 * @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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000178 * @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 Ziegeler7853b9a2008-01-11 16:30:24 +0000187 *
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +0000188 * @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}