Francesco Furfari | d1072b5 | 2006-05-03 07:44:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 The Apache Software Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | package org.apache.felix.upnp.sample.clock; |
| 19 | |
| 20 | import java.util.Dictionary; |
| 21 | |
| 22 | import org.osgi.framework.BundleActivator; |
| 23 | import org.osgi.framework.BundleContext; |
| 24 | import org.osgi.framework.ServiceRegistration; |
| 25 | import org.osgi.service.upnp.UPnPDevice; |
| 26 | |
| 27 | /* |
| 28 | * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a> |
| 29 | */ |
| 30 | public class Activator implements BundleActivator { |
| 31 | |
| 32 | private ServiceRegistration serviceRegistration; |
| 33 | private BundleContext context; |
| 34 | private ClockFrame clockFrame; |
| 35 | |
| 36 | /** |
| 37 | * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) |
| 38 | */ |
| 39 | public void start(BundleContext context) throws Exception { |
| 40 | this.context = context; |
| 41 | doServiceRegistration(); |
| 42 | } |
| 43 | |
| 44 | private void doServiceRegistration() { |
| 45 | clockFrame = new ClockFrame(context); |
| 46 | Dictionary dict = clockFrame.getClockDevice().getDescriptions(null); |
| 47 | |
| 48 | serviceRegistration = context.registerService( |
| 49 | UPnPDevice.class.getName(), |
| 50 | clockFrame.getClockDevice(), |
| 51 | dict |
| 52 | ); |
| 53 | |
| 54 | clockFrame.start(); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) |
| 60 | */ |
| 61 | public void stop(BundleContext context) throws Exception { |
| 62 | serviceRegistration.unregister(); |
| 63 | clockFrame.stop(); |
| 64 | } |
| 65 | } |