blob: 632704458c57e072b7c87970d7bb079f328a1ebf [file] [log] [blame]
Richard S. Hallddf2e142009-09-30 17:03:45 +00001/*
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +00002 * 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. Hall44002cf2009-02-11 21:47:26 +000019package org.apache.felix.log;
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000020
21import org.osgi.framework.Bundle;
22import org.osgi.framework.ServiceFactory;
23import 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. Hallddf2e142009-09-30 17:03:45 +000029final class LogReaderServiceFactory implements ServiceFactory
30{
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000031 /** 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. Hallddf2e142009-09-30 17:03:45 +000038 LogReaderServiceFactory(final Log log)
39 {
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000040 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. Hallddf2e142009-09-30 17:03:45 +000050 final ServiceRegistration registration)
51 {
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000052 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. Hallddf2e142009-09-30 17:03:45 +000063 final ServiceRegistration registration,
64 final Object service)
65 {
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000066 ((LogReaderServiceImpl) service).removeAllLogListeners();
67 }
Richard S. Hallddf2e142009-09-30 17:03:45 +000068}