Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +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.integration.helper; |
| 20 | |
| 21 | |
Felix Meschberger | 05d89e1 | 2011-11-03 23:37:10 +0000 | [diff] [blame] | 22 | import java.util.Dictionary; |
| 23 | |
Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame] | 24 | import org.osgi.framework.BundleContext; |
Guillaume Nodet | 3473093 | 2012-12-14 16:40:08 +0000 | [diff] [blame^] | 25 | import org.osgi.framework.Constants; |
Felix Meschberger | 05d89e1 | 2011-11-03 23:37:10 +0000 | [diff] [blame] | 26 | import org.osgi.framework.ServiceRegistration; |
Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame] | 27 | import org.osgi.service.cm.ManagedService; |
| 28 | |
| 29 | |
| 30 | public class ManagedServiceTestActivator extends BaseTestActivator |
| 31 | { |
| 32 | |
| 33 | public static ManagedServiceTestActivator INSTANCE; |
| 34 | |
Felix Meschberger | 05d89e1 | 2011-11-03 23:37:10 +0000 | [diff] [blame] | 35 | private Dictionary registrationProps; |
| 36 | private ServiceRegistration registration; |
Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame] | 37 | |
| 38 | public void start( BundleContext context ) throws Exception |
| 39 | { |
Felix Meschberger | 05d89e1 | 2011-11-03 23:37:10 +0000 | [diff] [blame] | 40 | this.registrationProps = getServiceProperties( context ); |
| 41 | this.registration = context.registerService( ManagedService.class.getName(), this, this.registrationProps ); |
Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame] | 42 | INSTANCE = this; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | public void stop( BundleContext arg0 ) throws Exception |
| 47 | { |
| 48 | INSTANCE = null; |
| 49 | } |
Felix Meschberger | 05d89e1 | 2011-11-03 23:37:10 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | public void changePid( final String newPid ) |
| 53 | { |
| 54 | this.registrationProps.put( Constants.SERVICE_PID, newPid ); |
| 55 | this.registration.setProperties( this.registrationProps ); |
| 56 | } |
Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame] | 57 | } |