blob: 396f564184a1dae2b8dc78def4c4f4836dbc5832 [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;
26
27
28/**
Felix Meschberger93c409a2009-01-19 10:47:59 +000029 * 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 Meschbergeradd2b4a2007-04-11 18:12:33 +000033 */
34public class ConfigurationAdapter implements Configuration
35{
36
Felix Meschbergerdf26ae82009-08-14 19:50:43 +000037 private final ConfigurationAdminImpl configurationAdmin;
38 private final ConfigurationImpl delegatee;
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000039
40
41 ConfigurationAdapter( ConfigurationAdminImpl configurationAdmin, ConfigurationImpl delegatee )
42 {
43 this.configurationAdmin = configurationAdmin;
44 this.delegatee = delegatee;
45 }
46
47
48 /**
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000049 * @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 Meschbergeradd2b4a2007-04-11 18:12:33 +000059 * @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 Meschbergeradd2b4a2007-04-11 18:12:33 +000069 * @see org.apache.felix.cm.impl.ConfigurationImpl#getBundleLocation()
70 */
71 public String getBundleLocation()
72 {
Felix Meschberger007c50e2011-10-20 12:39:38 +000073 // CM 1.4 / 104.13.2.4
74 configurationAdmin.checkPermission( delegatee.getBundleLocation() );
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000075 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 Meschberger007c50e2011-10-20 12:39:38 +000086 // CM 1.4 / 104.13.2.4
87 configurationAdmin.checkPermission( delegatee.getBundleLocation() );
88 configurationAdmin.checkPermission( bundleLocation );
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000089 checkDeleted();
Felix Meschbergeref470042009-08-19 05:52:41 +000090 delegatee.setStaticBundleLocation( bundleLocation );
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000091 }
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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000118 * @see org.apache.felix.cm.impl.ConfigurationImpl#getProperties()
119 */
120 public Dictionary getProperties()
121 {
122 checkDeleted();
Felix Meschberger6a698df2009-08-16 18:38:46 +0000123
Felix Meschbergera0903df2009-01-19 10:40:28 +0000124 // 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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000127 }
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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000142 * @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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000152 * @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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000161 * @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 Ziegeler7853b9a2008-01-11 16:30:24 +0000170 *
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +0000171 * @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}