blob: 37831db446b0c6e88b16051aeba1f4a47fe94570 [file] [log] [blame]
Felix Meschbergeref470042009-08-19 05:52:41 +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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
18 */
19package org.apache.felix.cm.impl;
20
21
22import java.io.IOException;
23import java.util.Dictionary;
24import org.apache.felix.cm.PersistenceManager;
Felix Meschbergeref470042009-08-19 05:52:41 +000025import org.osgi.service.log.LogService;
26
27
28abstract class ConfigurationBase
29{
30
31 /**
32 * The {@link ConfigurationManager configuration manager} instance which
33 * caused this configuration object to be created.
34 */
35 private final ConfigurationManager configurationManager;
36
37 // the persistence manager storing this factory mapping
38 private final PersistenceManager persistenceManager;
39
40 // the basic ID of this instance
41 private final String baseId;
42
Felix Meschbergeref470042009-08-19 05:52:41 +000043 protected ConfigurationBase( final ConfigurationManager configurationManager,
Felix Meschberger007c50e2011-10-20 12:39:38 +000044 final PersistenceManager persistenceManager, final String baseId )
Felix Meschbergeref470042009-08-19 05:52:41 +000045 {
46 if ( configurationManager == null )
47 {
48 throw new IllegalArgumentException( "ConfigurationManager must not be null" );
49 }
50
51 if ( persistenceManager == null )
52 {
53 throw new IllegalArgumentException( "PersistenceManager must not be null" );
54 }
55
56 this.configurationManager = configurationManager;
57 this.persistenceManager = persistenceManager;
58 this.baseId = baseId;
Felix Meschbergeref470042009-08-19 05:52:41 +000059 }
60
61
62 ConfigurationManager getConfigurationManager()
63 {
64 return configurationManager;
65 }
66
67
68 PersistenceManager getPersistenceManager()
69 {
70 return persistenceManager;
71 }
72
73
74 String getBaseId()
75 {
76 return baseId;
77 }
78
79
Felix Meschbergeref470042009-08-19 05:52:41 +000080 abstract void store() throws IOException;
81
82
83 void storeSilently()
84 {
85 try
86 {
87 this.store();
88 }
89 catch ( IOException ioe )
90 {
Felix Meschberger4f269292011-10-21 13:52:31 +000091 configurationManager.log( LogService.LOG_ERROR, "Persisting ID {0} failed", new Object[]
92 { getBaseId(), ioe } );
Felix Meschbergeref470042009-08-19 05:52:41 +000093 }
94 }
95
96
97 static protected void replaceProperty( Dictionary properties, String key, String value )
98 {
99 if ( value == null )
100 {
101 properties.remove( key );
102 }
103 else
104 {
105 properties.put( key, value );
106 }
107 }
108
109}