001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020package org.apache.felix.ipojo.dependency.impl;
021
022import org.apache.felix.ipojo.dependency.interceptors.ServiceTrackingInterceptor;
023import org.apache.felix.ipojo.dependency.interceptors.TransformedServiceReference;
024import org.apache.felix.ipojo.util.DependencyModel;
025import org.osgi.framework.BundleContext;
026import org.osgi.framework.Filter;
027import org.osgi.framework.ServiceReference;
028
029/**
030 * An implementation of the service tracking interceptor using a filter.
031 */
032public class FilterBasedServiceTrackingInterceptor implements ServiceTrackingInterceptor {
033
034    private final Filter m_filter;
035
036    public FilterBasedServiceTrackingInterceptor(Filter filter) {
037        m_filter = filter;
038    }
039
040    public void open(DependencyModel dependency) {
041
042    }
043
044    public <S> TransformedServiceReference<S> accept(DependencyModel dependency, BundleContext context, TransformedServiceReference<S> ref) {
045        if (ServiceReferenceUtils.match(m_filter, ref) && dependency.match(ref)) {
046            return ref;
047        } else {
048            return null;
049        }
050    }
051
052    public void close(DependencyModel dependency) {
053
054    }
055
056    public <S> S getService(DependencyModel dependency, S service, ServiceReference<S> reference) {
057        return service;
058    }
059
060    public void ungetService(DependencyModel dependency, boolean noMoreUsage, ServiceReference reference) {
061
062    }
063}