Carsten Ziegeler | 395a782 | 2013-01-28 19:01:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | * contributor license agreements. See the NOTICE file distributed with |
| 4 | * this work for additional information regarding copyright ownership. |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | * (the "License"); you may not use this file except in compliance with |
| 7 | * the License. You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | package org.apache.felix.status.impl; |
| 18 | |
| 19 | import java.util.Dictionary; |
| 20 | import java.util.Hashtable; |
| 21 | |
| 22 | import org.apache.felix.status.StatusPrinterManager; |
| 23 | import org.apache.felix.status.impl.webconsole.WebConsoleAdapter; |
| 24 | import org.osgi.framework.BundleActivator; |
| 25 | import org.osgi.framework.BundleContext; |
| 26 | import org.osgi.framework.Constants; |
| 27 | import org.osgi.framework.ServiceRegistration; |
| 28 | |
| 29 | /** |
| 30 | * Activate bridges and register manager. |
| 31 | */ |
| 32 | public class Activator implements BundleActivator { |
| 33 | |
| 34 | private StatusPrinterManagerImpl printerManager; |
| 35 | |
| 36 | private ServiceRegistration managerRegistration; |
| 37 | |
| 38 | private WebConsoleAdapter webAdapter; |
| 39 | |
| 40 | /** |
| 41 | * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) |
| 42 | */ |
| 43 | public void start(final BundleContext context) throws Exception { |
| 44 | this.webAdapter = new WebConsoleAdapter(context); |
| 45 | this.printerManager = new StatusPrinterManagerImpl(context); |
| 46 | final Dictionary<String, Object> props = new Hashtable<String, Object>(); |
| 47 | props.put(Constants.SERVICE_DESCRIPTION, "Apache Felix Status Printer Manager"); |
| 48 | props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation"); |
| 49 | this.managerRegistration = context.registerService( |
| 50 | StatusPrinterManager.class.getName(), |
| 51 | this.printerManager, props); |
Carsten Ziegeler | e21a047 | 2013-01-29 17:42:46 +0000 | [diff] [blame] | 52 | } |
Carsten Ziegeler | 395a782 | 2013-01-28 19:01:22 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) |
| 56 | */ |
| 57 | public void stop(final BundleContext context) throws Exception { |
| 58 | if( this.managerRegistration != null ) { |
| 59 | this.managerRegistration.unregister(); |
| 60 | this.managerRegistration = null; |
| 61 | } |
| 62 | if ( this.printerManager != null ) { |
| 63 | this.printerManager.dispose(); |
| 64 | this.printerManager = null; |
| 65 | } |
| 66 | if ( this.webAdapter != null ) { |
| 67 | this.webAdapter.dispose(); |
| 68 | this.webAdapter = null; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | } |