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.interceptors;
021
022import org.apache.felix.ipojo.Factory;
023import org.osgi.framework.Bundle;
024import org.osgi.framework.Constants;
025import org.osgi.framework.ServiceReference;
026
027import java.util.*;
028
029/**
030 * Transformed service reference is an interface letting updating the properties of a service reference.
031 *
032 * Transformed service reference wraps a <i>real</i> service reference and has all its properties.
033 */
034public interface TransformedServiceReference<S> extends ServiceReference<S> {
035
036    /**
037     * These properties are cannot be removed, added or updated.
038     */
039    public static final List<String> FORBIDDEN_KEYS = Arrays.asList(
040            Constants.SERVICE_ID,
041            Constants.SERVICE_PID,
042            Factory.INSTANCE_NAME_PROPERTY
043    );
044
045
046    /**
047     * Adds a property to the reference
048     * @param name the property name
049     * @param value the value (must not be null)
050     * @return the current transformed service reference
051     */
052    public TransformedServiceReference<S> addProperty(String name, Object value);
053
054    /**
055     * Adds a property to the service reference if this property is not already set on the reference.
056     * @param name the property name
057     * @param value the value
058     * @return the current transformed service reference
059     */
060    public TransformedServiceReference<S> addPropertyIfAbsent(String name, Object value);
061
062    /**
063     * Gets the current value of a property.
064     * @param name the property name
065     * @return the current value of the property, {@literal null} if not in the properties.
066     */
067    public Object get(String name);
068
069    /**
070     * Removes a property from the reference.
071     * @param name the property name
072     * @return the current transformed service reference
073     */
074    public TransformedServiceReference<S> removeProperty(String name);
075
076    /**
077     * Does the service reference contains the given property ?
078     * @param name the property name
079     * @return whether the current reference contains a property with the given name
080     */
081    public boolean contains(String name);
082
083    /**
084     * Gets the wrapped service reference
085     * @return the wrapped service reference
086     */
087    public ServiceReference<S> getWrappedReference();
088}