Created interfaces for all kind of dependencies. Implementation classes are now in org.apache.felix.dm.impl.dependencies package

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@887383 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/BundleDependency.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/BundleDependency.java
new file mode 100644
index 0000000..3466606
--- /dev/null
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/BundleDependency.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless
+ * required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dm.dependencies;
+
+import org.apache.felix.dm.management.ServiceComponentDependency;
+import org.osgi.framework.Bundle;
+
+public interface BundleDependency extends Dependency, ServiceComponentDependency
+{
+  /**
+   * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+   * dependency is added or removed. When you specify callbacks, the auto configuration feature
+   * is automatically turned off, because we're assuming you don't need it in this case.
+   * 
+   * @param added the method to call when a service was added
+   * @param removed the method to call when a service was removed
+   * @return this service dependency
+   */
+  BundleDependency setCallbacks(String added, String removed);
+
+  /**
+   * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+   * dependency is added, changed or removed. When you specify callbacks, the auto configuration
+   * feature is automatically turned off, because we're assuming you don't need it in this case.
+   * 
+   * @param added the method to call when a service was added
+   * @param changed the method to call when a service was changed
+   * @param removed the method to call when a service was removed
+   * @return this service dependency
+   */
+  BundleDependency setCallbacks(String added, String changed, String removed);
+
+  /**
+   * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+   * dependency is added or removed. They are called on the instance you provide. When you
+   * specify callbacks, the auto configuration feature is automatically turned off, because
+   * we're assuming you don't need it in this case.
+   * 
+   * @param instance the instance to call the callbacks on
+   * @param added the method to call when a service was added
+   * @param removed the method to call when a service was removed
+   * @return this service dependency
+   */
+  BundleDependency setCallbacks(Object instance, String added, String removed);
+
+  /**
+   * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+   * dependency is added, changed or removed. They are called on the instance you provide. When
+   * you specify callbacks, the auto configuration feature is automatically turned off, because
+   * we're assuming you don't need it in this case.
+   * 
+   * @param instance the instance to call the callbacks on
+   * @param added the method to call when a service was added
+   * @param changed the method to call when a service was changed
+   * @param removed the method to call when a service was removed
+   * @return this service dependency
+   */
+  BundleDependency setCallbacks(Object instance, String added, String changed, String removed);
+
+  BundleDependency setAutoConfig(boolean autoConfig);
+
+  BundleDependency setRequired(boolean required);
+
+  BundleDependency setBundle(Bundle bundle);
+
+  BundleDependency setFilter(String filter) throws IllegalArgumentException;
+
+  BundleDependency setStateMask(int mask);
+}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ConfigurationDependency.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ConfigurationDependency.java
new file mode 100644
index 0000000..bd165c3
--- /dev/null
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ConfigurationDependency.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless
+ * required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dm.dependencies;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.felix.dm.dependencies.Dependency;
+import org.apache.felix.dm.impl.Logger;
+import org.apache.felix.dm.management.ServiceComponentDependency;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+/**
+ * Configuration dependency that can track the availability of a (valid) configuration. To use
+ * it, specify a PID for the configuration. The dependency is always required, because if it is
+ * not, it does not make sense to use the dependency manager. In that scenario, simply register
+ * your service as a <code>ManagedService(Factory)</code> and handle everything yourself. Also,
+ * only managed services are supported, not factories. There are a couple of things you need to
+ * be aware of when implementing the <code>updated(Dictionary)</code> method:
+ * <ul>
+ * <li>Make sure it throws a <code>ConfigurationException</code> when you get a configuration
+ * that is invalid. In this case, the dependency will not change: if it was not available, it
+ * will still not be. If it was available, it will remain available and implicitly assume you
+ * keep working with your old configuration.</li>
+ * <li>This method will be called before all required dependencies are available. Make sure you
+ * do not depend on these to parse your settings.</li>
+ * </ul>
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface ConfigurationDependency extends Dependency, ServiceComponentDependency
+{
+  ConfigurationDependency setCallback(String callback);
+
+  /**
+   * Sets the <code>service.pid</code> of the configuration you are depending on.
+   */
+  ConfigurationDependency setPid(String pid);
+
+  /**
+   * Sets propagation of the configuration properties to the service properties. Any additional
+   * service properties specified directly are merged with these.
+   */
+  ConfigurationDependency setPropagate(boolean propagate);
+}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ResourceDependency.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ResourceDependency.java
new file mode 100644
index 0000000..fb59e88
--- /dev/null
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ResourceDependency.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dm.dependencies;
+
+import org.apache.felix.dm.resources.Resource;
+import org.apache.felix.dm.resources.ResourceHandler;
+
+public interface ResourceDependency extends Dependency, ResourceHandler {
+    /**
+     * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+     * dependency is added or removed. When you specify callbacks, the auto configuration 
+     * feature is automatically turned off, because we're assuming you don't need it in this 
+     * case.
+     * 
+     * @param added the method to call when a service was added
+     * @param removed the method to call when a service was removed
+     * @return this service dependency
+     */
+     ResourceDependency setCallbacks(String added, String removed) ;
+
+    /**
+     * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+     * dependency is added, changed or removed. When you specify callbacks, the auto 
+     * configuration feature is automatically turned off, because we're assuming you don't 
+     * need it in this case.
+     * 
+     * @param added the method to call when a service was added
+     * @param changed the method to call when a service was changed
+     * @param removed the method to call when a service was removed
+     * @return this service dependency
+     */
+     ResourceDependency setCallbacks(String added, String changed, String removed);
+
+    /**
+     * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+     * dependency is added or removed. They are called on the instance you provide. When you
+     * specify callbacks, the auto configuration feature is automatically turned off, because
+     * we're assuming you don't need it in this case.
+     * 
+     * @param instance the instance to call the callbacks on
+     * @param added the method to call when a service was added
+     * @param removed the method to call when a service was removed
+     * @return this service dependency
+     */
+     ResourceDependency setCallbacks(Object instance, String added, String removed);
+    
+    /**
+     * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+     * dependency is added, changed or removed. They are called on the instance you provide. When you
+     * specify callbacks, the auto configuration feature is automatically turned off, because
+     * we're assuming you don't need it in this case.
+     * 
+     * @param instance the instance to call the callbacks on
+     * @param added the method to call when a service was added
+     * @param changed the method to call when a service was changed
+     * @param removed the method to call when a service was removed
+     * @return this service dependency
+     */
+     ResourceDependency setCallbacks(Object instance, String added, String changed, String removed);
+        
+    /**
+     * Sets auto configuration for this service. Auto configuration allows the
+     * dependency to fill in any attributes in the service implementation that
+     * are of the same type as this dependency. Default is on.
+     * 
+     * @param autoConfig the value of auto config
+     * @return this service dependency
+     */
+     ResourceDependency setAutoConfig(boolean autoConfig);
+    
+    /**
+     * Sets auto configuration for this service. Auto configuration allows the
+     * dependency to fill in the attribute in the service implementation that
+     * has the same type and instance name.
+     * 
+     * @param instanceName the name of attribute to auto config
+     * @return this service dependency
+     */
+     ResourceDependency setAutoConfig(String instanceName);
+    
+     ResourceDependency setResource(Resource resource);
+	
+     ResourceDependency setRequired(boolean required);
+
+     ResourceDependency setFilter(String resourceFilter);
+}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ServiceDependency.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ServiceDependency.java
new file mode 100644
index 0000000..3fdee98
--- /dev/null
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/ServiceDependency.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dm.dependencies;
+
+import org.apache.felix.dm.management.ServiceComponentDependency;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Service dependency that can track an OSGi service.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface ServiceDependency extends Dependency, ServiceComponentDependency {
+    /**
+     * Sets the name of the service that should be tracked. 
+     * 
+     * @param serviceName the name of the service
+     * @return this service dependency
+     */
+    ServiceDependency setService(Class serviceName);
+    
+    /**
+     * Sets the name of the service that should be tracked. You can either specify
+     * only the name, or the name and a filter. In the latter case, the filter is used
+     * to track the service and should only return services of the type that was specified
+     * in the name. To make sure of this, the filter is actually extended internally to
+     * filter on the correct name.
+     * 
+     * @param serviceName the name of the service
+     * @param serviceFilter the filter condition
+     * @return this service dependency
+     */
+    ServiceDependency setService(Class serviceName, String serviceFilter);
+
+    /**
+     * Sets the name of the service that should be tracked. You can either specify
+     * only the name, or the name and a reference. In the latter case, the service reference
+     * is used to track the service and should only return services of the type that was 
+     * specified in the name.
+     * 
+     * @param serviceName the name of the service
+     * @param serviceReference the service reference to track
+     * @return this service dependency
+     */
+    ServiceDependency setService(Class serviceName, ServiceReference serviceReference);
+    
+    /**
+     * Sets the default implementation for this service dependency. You can use this to supply
+     * your own implementation that will be used instead of a Null Object when the dependency is
+     * not available. This is also convenient if the service dependency is not an interface
+     * (which would cause the Null Object creation to fail) but a class.
+     * 
+     * @param implementation the instance to use or the class to instantiate if you want to lazily
+     *     instantiate this implementation
+     * @return this service dependency
+     */
+    ServiceDependency setDefaultImplementation(Object implementation);
+
+    /**
+     * Sets the required flag which determines if this service is required or not.
+     * 
+     * @param required the required flag
+     * @return this service dependency
+     */
+    ServiceDependency setRequired(boolean required);
+    
+    /**
+     * Sets auto configuration for this service. Auto configuration allows the
+     * dependency to fill in any attributes in the service implementation that
+     * are of the same type as this dependency. Default is on.
+     * 
+     * @param autoConfig the value of auto config
+     * @return this service dependency
+     */
+    ServiceDependency setAutoConfig(boolean autoConfig);
+    
+    /**
+     * Sets auto configuration for this service. Auto configuration allows the
+     * dependency to fill in the attribute in the service implementation that
+     * has the same type and instance name.
+     * 
+     * @param instanceName the name of attribute to auto config
+     * @return this service dependency
+     */
+    ServiceDependency setAutoConfig(String instanceName);
+    
+    /**
+     * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+     * dependency is added or removed. When you specify callbacks, the auto configuration 
+     * feature is automatically turned off, because we're assuming you don't need it in this 
+     * case.
+     * 
+     * @param added the method to call when a service was added
+     * @param removed the method to call when a service was removed
+     * @return this service dependency
+     */
+    ServiceDependency setCallbacks(String added, String removed);
+    
+    /**
+     * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+     * dependency is added, changed or removed. When you specify callbacks, the auto 
+     * configuration feature is automatically turned off, because we're assuming you don't 
+     * need it in this case.
+     * 
+     * @param added the method to call when a service was added
+     * @param changed the method to call when a service was changed
+     * @param removed the method to call when a service was removed
+     * @return this service dependency
+     */
+    ServiceDependency setCallbacks(String added, String changed, String removed);
+
+    /**
+     * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+     * dependency is added or removed. They are called on the instance you provide. When you
+     * specify callbacks, the auto configuration feature is automatically turned off, because
+     * we're assuming you don't need it in this case.
+     * 
+     * @param instance the instance to call the callbacks on
+     * @param added the method to call when a service was added
+     * @param removed the method to call when a service was removed
+     * @return this service dependency
+     */
+    ServiceDependency setCallbacks(Object instance, String added, String removed);
+    
+    /**
+     * Sets the callbacks for this service. These callbacks can be used as hooks whenever a
+     * dependency is added, changed or removed. They are called on the instance you provide. When you
+     * specify callbacks, the auto configuration feature is automatically turned off, because
+     * we're assuming you don't need it in this case.
+     * 
+     * @param instance the instance to call the callbacks on
+     * @param added the method to call when a service was added
+     * @param changed the method to call when a service was changed
+     * @param removed the method to call when a service was removed
+     * @return this service dependency
+     */
+    ServiceDependency setCallbacks(Object instance, String added, String changed, String removed);
+}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/TemporalServiceDependency.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/TemporalServiceDependency.java
new file mode 100644
index 0000000..0e2455e
--- /dev/null
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/TemporalServiceDependency.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless
+ * required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dm.dependencies;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.impl.Logger;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+* A Temporal Service dependency that can block the caller thread between service updates. Only
+* useful for required stateless dependencies that can be replaced transparently.
+* A Dynamic Proxy is used to wrap the actual service dependency. When the dependency goes 
+* away, an attempt is made to replace it with another one which satisfies the service dependency 
+* criteria. If no service replacement is available, then any method invocation (through the 
+* dynamic proxy) will block during a configurable timeout. On timeout, an unchecked ServiceUnavailable 
+* exception is raised (but the service is not deactivated).<p>
+* 
+* <b>This class only supports required dependencies, and temporal dependencies must be accessed outside
+* the Activator (OSGi) thread, because method invocations may block the caller thread when dependencies
+* are not satisfied.
+* </b>
+*
+* <p> Sample Code:<p>
+* <blockquote>
+* 
+* <pre>
+* import org.apache.felix.dependencymanager.*;
+* 
+* public class Activator extends DependencyActivatorBase {
+*   public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+*     dm.add(createService()
+*            .setImplementation(MyServer.class)
+*        .add(createTemporalServiceDependency()
+*            .setService(MyDependency.class)
+*            .setTimeout(15000)));
+*   }
+* 
+*   public void destroy(BundleContext ctx, DependencyManager dm) throws Exception {
+*   }
+* }
+* 
+* class MyServer implements Runnable {
+*   MyDependency _dependency; // Auto-Injected by reflection.
+*   void start() {
+*     (new Thread(this)).start();
+*   }
+*   
+*   public void run() {
+*     try {
+*       _dependency.doWork();
+*     } catch (ServiceUnavailableException e) {
+*       t.printStackTrace();
+*     }
+*   }   
+* </pre>
+* 
+* </blockquote>
+*/
+public interface TemporalServiceDependency extends ServiceDependency {
+    /**
+     * Sets the timeout for this temporal dependency. Specifying a timeout value of zero means that there is no timeout period,
+     * and an invocation on a missing service will fail immediately.
+     * 
+     * @param timeout the dependency timeout value greater or equals to 0
+     * @throws IllegalArgumentException if the timeout is negative
+     * @return this temporal dependency
+     */
+    TemporalServiceDependency setTimeout(long timeout);
+}