Richard S. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 1 | /* |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 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 | */ |
Richard S. Hall | 44002cf | 2009-02-11 21:47:26 +0000 | [diff] [blame] | 19 | package org.apache.felix.log; |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 20 | |
| 21 | import org.osgi.framework.Bundle; |
| 22 | import org.osgi.framework.ServiceFactory; |
| 23 | import org.osgi.framework.ServiceRegistration; |
| 24 | |
| 25 | /** |
| 26 | * {@link ServiceFactory} implementation for {@link LogReaderService}. Associates |
| 27 | * an individual {@link LogReaderService} with a {@link Bundle}. |
| 28 | */ |
Richard S. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 29 | final class LogReaderServiceFactory implements ServiceFactory |
| 30 | { |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 31 | /** The log to associate the service implementations with. */ |
| 32 | private final Log m_log; |
| 33 | |
| 34 | /** |
| 35 | * Create a new instance. |
| 36 | * @param log the log to associate the service implementations with., |
| 37 | */ |
Richard S. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 38 | LogReaderServiceFactory(final Log log) |
| 39 | { |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 40 | m_log = log; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get the service to use for the specified bundle. |
| 45 | * @param bundle the bundle requesting the service |
| 46 | * @param registration the service registration |
| 47 | * @return the log reader service implementation for the specified bundle |
| 48 | */ |
| 49 | public Object getService(final Bundle bundle, |
Richard S. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 50 | final ServiceRegistration registration) |
| 51 | { |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 52 | return new LogReaderServiceImpl(m_log); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Release the service previously obtained through |
| 57 | * {@link #getService(Bundle, ServiceRegistration)}. |
| 58 | * @param bundle the bundle that originally requested the service |
| 59 | * @param registration the service registration |
| 60 | * @param service the service to release |
| 61 | */ |
| 62 | public void ungetService(final Bundle bundle, |
Richard S. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 63 | final ServiceRegistration registration, |
| 64 | final Object service) |
| 65 | { |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 66 | ((LogReaderServiceImpl) service).removeAllLogListeners(); |
| 67 | } |
Richard S. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 68 | } |