blob: 7a4ae55a16a6a3639e2c67eb64e55be998fe8aee [file] [log] [blame]
Carsten Ziegeler47b825b2008-01-29 09:01:39 +00001/*
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 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/**
29 * The <code>ConfigurationAdapter</code> TODO
30 *
31 * @author fmeschbe
Felix Meschbergera0903df2009-01-19 10:40:28 +000032 * @version $Rev:616219 $, $Date$
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +000033 */
34public 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 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 {
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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000115 * @see org.apache.felix.cm.impl.ConfigurationImpl#getProperties()
116 */
117 public Dictionary getProperties()
118 {
119 checkDeleted();
Felix Meschbergera0903df2009-01-19 10:40:28 +0000120
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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000124 }
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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000139 * @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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000149 * @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 Meschbergeradd2b4a2007-04-11 18:12:33 +0000158 * @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 Ziegeler7853b9a2008-01-11 16:30:24 +0000167 *
Felix Meschbergeradd2b4a2007-04-11 18:12:33 +0000168 * @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}