blob: 4f6fc81d369c230d807058e6d5e2c07269fcc40d [file] [log] [blame]
Felix Meschbergere7f513f2012-07-02 14:00:02 +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.helper;
20
21import java.util.Dictionary;
22
23import org.apache.felix.cm.impl.ConfigurationImpl;
24import org.apache.felix.cm.impl.ConfigurationManager;
25import org.osgi.framework.ServiceReference;
26import org.osgi.service.cm.ManagedServiceFactory;
27
28public class ManagedServiceFactoryTracker extends BaseTracker<ManagedServiceFactory>
29{
30
31 public ManagedServiceFactoryTracker( ConfigurationManager cm )
32 {
33 super( cm, ManagedServiceFactory.class );
34 }
35
36
37 @Override
38 protected boolean isFactory()
39 {
40 return true;
41 }
42
43
44 @Override
Felix Meschbergeraccd9012012-07-02 15:18:08 +000045 public void provideConfiguration( ServiceReference<ManagedServiceFactory> reference, final ConfigurationImpl config, final Dictionary<String, ?> rawProps )
Felix Meschbergere7f513f2012-07-02 14:00:02 +000046 {
47 ManagedServiceFactory service = getRealService( reference );
48 if ( service != null )
49 {
50 try
51 {
52 Dictionary props = getProperties( rawProps, config.getFactoryPid(), reference );
53 service.updated( config.getPid(), props );
54 }
55 catch ( Throwable t )
56 {
57 this.cm.handleCallBackError( t, reference, config );
58 }
59 finally
60 {
61 this.ungetRealService( reference );
62 }
63 }
64 }
65
66
67 @Override
Felix Meschbergeraccd9012012-07-02 15:18:08 +000068 public void removeConfiguration( ServiceReference<ManagedServiceFactory> reference, final ConfigurationImpl config )
Felix Meschbergere7f513f2012-07-02 14:00:02 +000069 {
70 ManagedServiceFactory service = this.getRealService( reference );
71 if ( service != null )
72 {
73 try
74 {
75 service.deleted( config.getPid() );
76 }
77 catch ( Throwable t )
78 {
79 this.cm.handleCallBackError( t, reference, config );
80 }
81 finally
82 {
83 this.ungetRealService( reference );
84 }
85 }
86 }
87}