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 | { |
| 33 | super( cm, ManagedServiceFactory.class ); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | @Override |
| 38 | protected boolean isFactory() |
| 39 | { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | |
| 44 | @Override |
Felix Meschberger | accd901 | 2012-07-02 15:18:08 +0000 | [diff] [blame^] | 45 | 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] | 46 | { |
| 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 Meschberger | accd901 | 2012-07-02 15:18:08 +0000 | [diff] [blame^] | 68 | public void removeConfiguration( ServiceReference<ManagedServiceFactory> reference, final ConfigurationImpl config ) |
Felix Meschberger | e7f513f | 2012-07-02 14:00:02 +0000 | [diff] [blame] | 69 | { |
| 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 | } |