Felix Meschberger | e7f513f | 2012-07-02 14:00:02 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 19 | package org.apache.felix.cm.impl.helper; |
| 20 | |
| 21 | import java.util.Dictionary; |
| 22 | |
| 23 | import org.apache.felix.cm.impl.ConfigurationImpl; |
| 24 | import org.apache.felix.cm.impl.ConfigurationManager; |
| 25 | import org.osgi.framework.ServiceReference; |
| 26 | import org.osgi.service.cm.ManagedServiceFactory; |
| 27 | |
| 28 | public class ManagedServiceFactoryTracker extends BaseTracker<ManagedServiceFactory> |
| 29 | { |
| 30 | |
| 31 | public ManagedServiceFactoryTracker( ConfigurationManager cm ) |
| 32 | { |
Felix Meschberger | 382a19b | 2012-07-03 09:45:14 +0000 | [diff] [blame^] | 33 | super( cm, true ); |
Felix Meschberger | e7f513f | 2012-07-02 14:00:02 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | |
| 37 | @Override |
Felix Meschberger | accd901 | 2012-07-02 15:18:08 +0000 | [diff] [blame] | 38 | public void provideConfiguration( ServiceReference<ManagedServiceFactory> reference, final ConfigurationImpl config, final Dictionary<String, ?> rawProps ) |
Felix Meschberger | e7f513f | 2012-07-02 14:00:02 +0000 | [diff] [blame] | 39 | { |
| 40 | ManagedServiceFactory service = getRealService( reference ); |
| 41 | if ( service != null ) |
| 42 | { |
| 43 | try |
| 44 | { |
| 45 | Dictionary props = getProperties( rawProps, config.getFactoryPid(), reference ); |
| 46 | service.updated( config.getPid(), props ); |
| 47 | } |
| 48 | catch ( Throwable t ) |
| 49 | { |
Felix Meschberger | 382a19b | 2012-07-03 09:45:14 +0000 | [diff] [blame^] | 50 | this.handleCallBackError( t, reference, config ); |
Felix Meschberger | e7f513f | 2012-07-02 14:00:02 +0000 | [diff] [blame] | 51 | } |
| 52 | finally |
| 53 | { |
| 54 | this.ungetRealService( reference ); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | |
| 60 | @Override |
Felix Meschberger | accd901 | 2012-07-02 15:18:08 +0000 | [diff] [blame] | 61 | public void removeConfiguration( ServiceReference<ManagedServiceFactory> reference, final ConfigurationImpl config ) |
Felix Meschberger | e7f513f | 2012-07-02 14:00:02 +0000 | [diff] [blame] | 62 | { |
| 63 | ManagedServiceFactory service = this.getRealService( reference ); |
| 64 | if ( service != null ) |
| 65 | { |
| 66 | try |
| 67 | { |
| 68 | service.deleted( config.getPid() ); |
| 69 | } |
| 70 | catch ( Throwable t ) |
| 71 | { |
Felix Meschberger | 382a19b | 2012-07-03 09:45:14 +0000 | [diff] [blame^] | 72 | this.handleCallBackError( t, reference, config ); |
Felix Meschberger | e7f513f | 2012-07-02 14:00:02 +0000 | [diff] [blame] | 73 | } |
| 74 | finally |
| 75 | { |
| 76 | this.ungetRealService( reference ); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |