added some new adapters and a few fixes, work in progress
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@888294 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
index 755d661..a60c740 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
@@ -28,8 +28,11 @@
import org.apache.felix.dm.dependencies.ResourceDependency;
import org.apache.felix.dm.dependencies.ServiceDependency;
import org.apache.felix.dm.dependencies.TemporalServiceDependency;
+import org.apache.felix.dm.impl.AdapterImpl;
import org.apache.felix.dm.impl.AspectImpl;
+import org.apache.felix.dm.impl.BundleAdapterImpl;
import org.apache.felix.dm.impl.Logger;
+import org.apache.felix.dm.impl.ResourceAdapterImpl;
import org.apache.felix.dm.impl.ServiceImpl;
import org.apache.felix.dm.impl.dependencies.BundleDependencyImpl;
import org.apache.felix.dm.impl.dependencies.ConfigurationDependencyImpl;
@@ -165,6 +168,41 @@
.setCallbacks("added", "removed")
);
}
+
+ //TODO rename iface en iface2 to adaptor en adaptee o.i.d.
+ public Service createAdapterService(Class iface, Class iface2, Class impl) {
+ return createService()
+ .setImplementation(new AdapterImpl(iface, iface2, impl))
+ .add(createServiceDependency()
+ .setService(iface)
+ .setAutoConfig(false)
+ .setCallbacks("added", "removed")
+ );
+ }
+
+ // TODO note to self, there are Dependency's and DependencyCollections
+ // (being a dependency on more than one, fi ServiceDendency, ResourceDependency
+ public Service createResourceAdapterService(String resourceFilter, Class iface2, Object impl) {
+ return createService()
+ .setImplementation(new ResourceAdapterImpl(impl, iface2))
+ .add(createResourceDependency()
+ .setFilter(resourceFilter)
+ .setAutoConfig(false)
+ .setCallbacks("added", "removed")
+ )
+ ;
+ }
+
+ public Service createBundleAdapterService(int stateMask, String filter, Object impl, Class iface) {
+ return createService()
+ .setImplementation(new BundleAdapterImpl(stateMask, filter, impl, iface))
+ .add(createBundleDependency()
+ .setFilter(filter)
+ .setStateMask(stateMask)
+ .setCallbacks("added", "removed")
+ )
+ ;
+ }
/**
* Returns a list of services.
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/Dependency.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/Dependency.java
index e22bc1f..cd1c0af 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/Dependency.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/dependencies/Dependency.java
@@ -18,6 +18,8 @@
*/
package org.apache.felix.dm.dependencies;
+import org.apache.felix.dm.impl.dependencies.DependencyService;
+
/**
* Generic dependency for a service. A dependency can be required or not.
* A dependency will be activated by the service it belongs to. The service
@@ -55,4 +57,51 @@
* @return <code>true</code> if the dependency is instance bound
*/
public boolean isInstanceBound();
+
+ /**
+ * Returns <code>true>code> if auto configuration is enabled for this dependency.
+ * Auto configuration means that a dependency is injected in the service instance
+ * when it's available, and if it's unavailable, a "null object" will be inserted
+ * instead.
+ *
+ * @return <code>true>code> if auto configuration is enabled for this dependency
+ */
+ public boolean isAutoConfig();
+
+ /**
+ * Returns the type of the instance that is injected.
+ *
+ * @return the type of the instance that is injected
+ */
+ public Class getAutoConfigType();
+
+ /**
+ * Returns the instance that is injected.
+ *
+ * @return the instance that is injected
+ */
+ public Object getAutoConfigInstance();
+
+ /**
+ * Returns the name of the member in the class of the service instance
+ * to inject into. If you specify this, not all members of the right
+ * type will be injected, only the member whose name matches.
+ *
+ * @return
+ */
+ public String getAutoConfigName();
+
+ /**
+ * Invoke the "added" callback on a required dependency.
+ *
+ * @param service
+ */
+ public void invokeAdded(DependencyService service);
+
+ /**
+ * Invoke the "removed" callback on a required dependency.
+ *
+ * @param service
+ */
+ public void invokeRemoved(DependencyService service);
}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterImpl.java
new file mode 100644
index 0000000..6dcec23
--- /dev/null
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterImpl.java
@@ -0,0 +1,60 @@
+/*
+ * 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.impl;
+
+import java.util.List;
+
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.service.Service;
+import org.osgi.framework.ServiceReference;
+
+public class AdapterImpl {
+ private volatile DependencyManager m_manager;
+ private volatile Service m_service;
+ private final Class m_iface;
+ private final Class m_iface2;
+ private final Class m_impl;
+
+ // TODO adapts a "dependency" ... making it sort of a decorator factory
+ public AdapterImpl(Class iface, Class iface2, Class impl) {
+ m_iface = iface;
+ m_iface2 = iface2;
+ m_impl = impl;
+ }
+
+ public void added(ServiceReference ref, Object service) {
+ // TODO decorator be smarter:
+
+ // get any "global" dependencies
+ List dependencies = m_service.getDependencies();
+
+ m_manager.add(m_manager.createService()
+ .setInterface(m_iface2.getName(), null)
+ .setImplementation(m_impl)
+ .add(dependencies)
+ .add(m_manager.createServiceDependency()
+ .setService(m_iface, ref)
+ .setRequired(true)
+ )
+ );
+ }
+
+ public void removed(ServiceReference ref, Object service) {
+ }
+}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/BundleAdapterImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/BundleAdapterImpl.java
new file mode 100644
index 0000000..6fc4897
--- /dev/null
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/BundleAdapterImpl.java
@@ -0,0 +1,53 @@
+/*
+ * 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.impl;
+
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.Bundle;
+
+public class BundleAdapterImpl {
+ private final int m_stateMask;
+ private final String m_filter;
+ private final Object m_impl;
+ private volatile DependencyManager m_manager;
+ private final Class m_iface;
+
+ public BundleAdapterImpl(int stateMask, String filter, Object impl, Class iface) {
+ m_stateMask = stateMask;
+ m_filter = filter;
+ m_impl = impl;
+ m_iface = iface;
+ }
+
+ public void added(Bundle bundle) {
+ // TODO decorator be smarter:
+ m_manager.add(m_manager.createService()
+ .setInterface(m_iface.getName(), null)
+ .setImplementation(m_impl)
+ .add(m_manager.createBundleDependency()
+ .setBundle(bundle)
+ .setStateMask(m_stateMask)
+ .setRequired(true)
+ )
+ );
+ }
+
+ public void removed(Bundle bundle) {
+ }
+}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterImpl.java
new file mode 100644
index 0000000..53cfd6a
--- /dev/null
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterImpl.java
@@ -0,0 +1,49 @@
+/*
+ * 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.impl;
+
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.resources.Resource;
+
+public class ResourceAdapterImpl {
+ private volatile DependencyManager m_manager;
+ private final Object m_impl;
+ private final Class m_iface;
+
+ public ResourceAdapterImpl(Object impl, Class iface) {
+ m_impl = impl;
+ m_iface = iface;
+ }
+
+ public void added(Resource resource) {
+ System.out.println("ADDED " + resource);
+ m_manager.add(m_manager.createService()
+ .setInterface(m_iface.getName(), null)
+ .setImplementation(m_impl)
+ .add(m_manager.createResourceDependency()
+ .setResource(resource)
+ .setRequired(true)
+ )
+ );
+ }
+
+ public void removed(Resource resource) {
+ }
+
+}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ServiceImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ServiceImpl.java
index 4bbedef..f8637d6 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ServiceImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ServiceImpl.java
@@ -49,7 +49,6 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationException;
/**
* Service implementation.
@@ -923,72 +922,80 @@
Iterator i = state.getDependencies().iterator();
while (i.hasNext()) {
Dependency dependency = (Dependency) i.next();
- if (dependency instanceof ServiceDependencyImpl) {
- ServiceDependencyImpl sd = (ServiceDependencyImpl) dependency;
- if (sd.isAutoConfig()) {
- if (sd.isRequired()) {
- configureImplementation(sd.getInterface(), sd.getService(), sd.getAutoConfigName());
- }
- else {
- // for optional services, we do an "ad-hoc" lookup to inject the service if it is
- // already available even though the tracker has not yet been started
- configureImplementation(sd.getInterface(), sd.lookupService(), sd.getAutoConfigName());
- }
- }
- // for required dependencies, we invoke any callbacks here
- if (sd.isRequired()) {
- sd.invokeAdded(this, sd.lookupServiceReference(), sd.lookupService());
- }
+ if (dependency.isAutoConfig()) {
+ configureImplementation(dependency.getAutoConfigType(), dependency.getAutoConfigInstance(), dependency.getAutoConfigName());
}
- else if (dependency instanceof BundleDependencyImpl) {
- BundleDependencyImpl bd = (BundleDependencyImpl) dependency;
- if (bd.isAutoConfig()) {
- if (bd.isRequired()) {
- configureImplementation(Bundle.class, bd.getBundle()); // TODO AutoConfigName support
- }
- else {
- // for optional services, we do an "ad-hoc" lookup to inject the service if it is
- // already available even though the tracker has not yet been started
-
- // TODO !!! configureImplementation(sd.getInterface(), sd.lookupService(), sd.getAutoConfigName());
- }
- }
- // for required dependencies, we invoke any callbacks here
- if (bd.isRequired()) {
- bd.invokeAdded(this, bd.getBundle());
- }
+ if (dependency.isRequired()) {
+ dependency.invokeAdded(this);
}
- else if (dependency instanceof ResourceDependencyImpl) {
- ResourceDependencyImpl bd = (ResourceDependencyImpl) dependency;
- if (bd.isAutoConfig()) {
- if (bd.isRequired()) {
- configureImplementation(Resource.class, bd.getResource()); // TODO AutoConfigName support
- }
- else {
- // for optional services, we do an "ad-hoc" lookup to inject the service if it is
- // already available even though the tracker has not yet been started
-
- // TODO !!! configureImplementation(sd.getInterface(), sd.lookupService(), sd.getAutoConfigName());
- }
- }
- // for required dependencies, we invoke any callbacks here
- if (bd.isRequired()) {
- bd.invokeAdded(this, bd.getResource());
- }
- }
- else if (dependency instanceof ConfigurationDependencyImpl) {
- ConfigurationDependencyImpl cd = (ConfigurationDependencyImpl) dependency;
- // for configuration dependencies, we invoke updated
- try {
- cd.invokeUpdate(this, this.getService(), cd.getConfiguration());
- }
- catch (ConfigurationException e) {
- // if this happens, it's definitely an inconsistency
- // when sharing configuration dependencies between services, all implementations
- // should accept the same configurations
- e.printStackTrace();
- }
- }
+
+
+// if (dependency instanceof ServiceDependencyImpl) {
+// ServiceDependencyImpl sd = (ServiceDependencyImpl) dependency;
+// if (sd.isAutoConfig()) {
+// if (sd.isRequired()) {
+// configureImplementation(sd.getInterface(), sd.getService(), sd.getAutoConfigName());
+// }
+// else {
+// // for optional services, we do an "ad-hoc" lookup to inject the service if it is
+// // already available even though the tracker has not yet been started
+// configureImplementation(sd.getInterface(), sd.lookupService(), sd.getAutoConfigName());
+// }
+// }
+// // for required dependencies, we invoke any callbacks here
+// if (sd.isRequired()) {
+// sd.invokeAdded(this, sd.lookupServiceReference(), sd.lookupService());
+// }
+// }
+// else if (dependency instanceof BundleDependencyImpl) {
+// BundleDependencyImpl bd = (BundleDependencyImpl) dependency;
+// if (bd.isAutoConfig()) {
+// if (bd.isRequired()) {
+// configureImplementation(Bundle.class, bd.getBundle()); // TODO AutoConfigName support
+// }
+// else {
+// // for optional services, we do an "ad-hoc" lookup to inject the service if it is
+// // already available even though the tracker has not yet been started
+//
+// // TODO !!! configureImplementation(sd.getInterface(), sd.lookupService(), sd.getAutoConfigName());
+// }
+// }
+// // for required dependencies, we invoke any callbacks here
+// if (bd.isRequired()) {
+// bd.invokeAdded(this, bd.getBundle());
+// }
+// }
+// else if (dependency instanceof ResourceDependencyImpl) {
+// ResourceDependencyImpl bd = (ResourceDependencyImpl) dependency;
+// if (bd.isAutoConfig()) {
+// if (bd.isRequired()) {
+// configureImplementation(Resource.class, bd.getResource()); // TODO AutoConfigName support
+// }
+// else {
+// // for optional services, we do an "ad-hoc" lookup to inject the service if it is
+// // already available even though the tracker has not yet been started
+//
+// // TODO !!! configureImplementation(sd.getInterface(), sd.lookupService(), sd.getAutoConfigName());
+// }
+// }
+// // for required dependencies, we invoke any callbacks here
+// if (bd.isRequired()) {
+// bd.invokeAdded(this, bd.getResource());
+// }
+// }
+// else if (dependency instanceof ConfigurationDependencyImpl) {
+// ConfigurationDependencyImpl cd = (ConfigurationDependencyImpl) dependency;
+// // for configuration dependencies, we invoke updated
+// try {
+// cd.invokeUpdate(this, this.getService(), cd.getConfiguration());
+// }
+// catch (ConfigurationException e) {
+// // if this happens, it's definitely an inconsistency
+// // when sharing configuration dependencies between services, all implementations
+// // should accept the same configurations
+// e.printStackTrace();
+// }
+// }
}
}
@@ -996,13 +1003,16 @@
Iterator i = state.getDependencies().iterator();
while (i.hasNext()) {
Dependency dependency = (Dependency) i.next();
- if (dependency instanceof ServiceDependencyImpl) {
- ServiceDependencyImpl sd = (ServiceDependencyImpl) dependency;
- // for required dependencies, we invoke any callbacks here
- if (sd.isRequired()) {
- sd.invokeRemoved(this, sd.lookupServiceReference(), sd.lookupService());
- }
+ if (dependency.isRequired()) {
+ dependency.invokeRemoved(this);
}
+// if (dependency instanceof ServiceDependencyImpl) {
+// ServiceDependencyImpl sd = (ServiceDependencyImpl) dependency;
+// // for required dependencies, we invoke any callbacks here
+// if (sd.isRequired()) {
+// sd.invokeRemoved(this, sd.lookupServiceReference(), sd.lookupService());
+// }
+// }
}
}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/BundleDependencyImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/BundleDependencyImpl.java
index e48e06f..e67860a 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/BundleDependencyImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/BundleDependencyImpl.java
@@ -97,10 +97,12 @@
public String getName() {
StringBuilder sb = new StringBuilder();
- sb.append(m_bundleInstance.getSymbolicName());
- sb.append(' ');
- sb.append(m_bundleInstance.getVersion());
- sb.append(' ');
+ if (m_bundleInstance != null) {
+ sb.append(m_bundleInstance.getSymbolicName());
+ sb.append(' ');
+ sb.append(m_bundleInstance.getHeaders().get("Bundle-Version"));
+ sb.append(' ');
+ }
sb.append(Integer.toString(m_stateMask, 2));
if (m_filter != null) {
sb.append(' ');
@@ -120,7 +122,8 @@
public Object addingBundle(Bundle bundle, BundleEvent event) {
// if we don't like a bundle, we could reject it here by returning null
- if (m_bundleId >= 0 && m_bundleId != bundle.getBundleId()) {
+ long bundleId = bundle.getBundleId();
+ if (m_bundleId >= 0 && m_bundleId != bundleId) {
return null;
}
Filter filter = m_filter;
@@ -354,4 +357,36 @@
}
return null;
}
+
+ public Object getAutoConfigInstance() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getAutoConfigName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class getAutoConfigType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void invokeAdded(DependencyService service) {
+ // we remember these for future reference, needed for required service callbacks
+ if (m_isStarted) {
+ // use the tracker
+ }
+ else {
+ // do a manual lookup
+ }
+ m_bundleInstance = null; // TODO save what we looked up here
+ invokeAdded(service, m_bundleInstance);
+ }
+
+ public void invokeRemoved(DependencyService service) {
+ invokeRemoved(service, m_bundleInstance);
+ m_bundleInstance = null;
+ }
}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ConfigurationDependencyImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ConfigurationDependencyImpl.java
index 2ef00ac..cafb0ea 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ConfigurationDependencyImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ConfigurationDependencyImpl.java
@@ -28,8 +28,6 @@
import java.util.Set;
import org.apache.felix.dm.dependencies.ConfigurationDependency;
-import org.apache.felix.dm.dependencies.Dependency;
-import org.apache.felix.dm.dependencies.ServiceDependency;
import org.apache.felix.dm.impl.Logger;
import org.apache.felix.dm.management.ServiceComponentDependency;
import org.osgi.framework.BundleContext;
@@ -266,4 +264,38 @@
public String getType() {
return "configuration";
}
+
+ public Object getAutoConfigInstance() {
+ return getConfiguration();
+ }
+
+ public String getAutoConfigName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class getAutoConfigType() {
+ return Dictionary.class;
+ }
+
+ public void invokeAdded(DependencyService service) {
+ try {
+ invokeUpdate(service, service.getService(), getConfiguration());
+ }
+ catch (ConfigurationException e) {
+ // if this happens, it's definitely an inconsistency, since we
+ // asked the instance the same question before (if this is a
+ // valid configuration) and then it was
+ e.printStackTrace();
+ }
+ }
+
+ public void invokeRemoved(DependencyService service) {
+ // TODO Auto-generated method stub
+ }
+
+ public boolean isAutoConfig() {
+ // TODO Auto-generated method stub
+ return false;
+ }
}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
index 31768ff..c3ede77 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ResourceDependencyImpl.java
@@ -44,7 +44,6 @@
private boolean m_autoConfig;
private final Logger m_logger;
private String m_autoConfigInstance;
-// private DependencyService m_service;
protected List m_services = new ArrayList();
private boolean m_isRequired;
private String m_resourceFilter;
@@ -363,6 +362,7 @@
}
public ResourceDependency setFilter(String resourceFilter) {
+ ensureNotActive();
m_resourceFilter = resourceFilter;
return this;
}
@@ -374,4 +374,28 @@
System.out.println("Fetching resource");
return m_resource;
}
+
+ public Object getAutoConfigInstance() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getAutoConfigName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class getAutoConfigType() {
+ return Resource.class;
+ }
+
+ public void invokeAdded(DependencyService service) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void invokeRemoved(DependencyService service) {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java
index 60ad245..f337bd3 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/dependencies/ServiceDependencyImpl.java
@@ -28,7 +28,6 @@
import java.util.Map;
import java.util.Set;
-import org.apache.felix.dm.dependencies.Dependency;
import org.apache.felix.dm.dependencies.ServiceDependency;
import org.apache.felix.dm.impl.DefaultNullObject;
import org.apache.felix.dm.impl.Logger;
@@ -196,7 +195,7 @@
if (m_isStarted) {
service = m_tracker.getService();
}
- if (service == null) {
+ if (service == null && isAutoConfig()) {
service = getDefaultImplementation();
if (service == null) {
service = getNullObject();
@@ -208,7 +207,7 @@
public Object lookupService() {
Object service = null;
if (m_isStarted) {
- service = m_tracker.getService();
+ service = getService();
}
else {
ServiceReference[] refs = null;
@@ -240,7 +239,7 @@
throw new IllegalStateException("Could not lookup dependency, no service name specified.");
}
}
- if (service == null) {
+ if (service == null && isAutoConfig()) {
service = getDefaultImplementation();
if (service == null) {
service = getNullObject();
@@ -379,10 +378,6 @@
if (!m_trackedServiceName.isInstance(service)) {
return null;
}
-
- // we remember these for future reference, needed for required service callbacks
- m_reference = ref;
- m_serviceInstance = service;
return service;
}
@@ -419,9 +414,6 @@
}
public void modifiedService(ServiceReference ref, Object service) {
- m_reference = ref;
- m_serviceInstance = service;
-
Object[] services;
synchronized (this) {
services = m_services.toArray();
@@ -722,6 +714,14 @@
public String getAutoConfigName() {
return m_autoConfigInstance;
}
+
+ public Object getAutoConfigInstance() {
+ return lookupService();
+ }
+
+ public Class getAutoConfigType() {
+ return getInterface();
+ }
public String getName() {
StringBuilder sb = new StringBuilder();
@@ -740,4 +740,17 @@
public String getType() {
return "service";
}
+
+ public void invokeAdded(DependencyService service) {
+ // we remember these for future reference, needed for required service callbacks
+ m_reference = lookupServiceReference();
+ m_serviceInstance = lookupService();
+ invokeAdded(service, m_reference, m_serviceInstance);
+ }
+
+ public void invokeRemoved(DependencyService service) {
+ invokeRemoved(service, m_reference, m_serviceInstance);
+ m_reference = null;
+ m_serviceInstance = null;
+ }
}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/tracker/ServiceTracker.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/tracker/ServiceTracker.java
index 1c1fc2a..eb0f147 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/tracker/ServiceTracker.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/tracker/ServiceTracker.java
@@ -863,7 +863,7 @@
}
}
break;
- case ServiceEvent.MODIFIED_ENDMATCH :
+ case 8 /* ServiceEvent.MODIFIED_ENDMATCH */ :
case ServiceEvent.UNREGISTERING :
untrack(reference, event);
/*
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
index c1c64c0..06d9b49 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/resources/BundleResourceRepository.java
@@ -56,7 +56,7 @@
URL entry = (URL) entries.nextElement();
Properties props = new Properties();
- props.setProperty(Resource.REPOSITORY, bundle.getSymbolicName() + "_" + bundle.getVersion());
+ props.setProperty(Resource.REPOSITORY, bundle.getSymbolicName() + "_" + bundle.getHeaders().get("Bundle-Version"));
props.setProperty(Resource.PATH, entry.getPath());
props.setProperty(Resource.NAME, entry.getFile());
@@ -84,7 +84,7 @@
URL entry = (URL) entries.nextElement();
Properties props = new Properties();
- props.setProperty(Resource.REPOSITORY, bundle.getSymbolicName() + "_" + bundle.getVersion());
+ props.setProperty(Resource.REPOSITORY, bundle.getSymbolicName() + "_" + bundle.getHeaders().get("Bundle-Version"));
props.setProperty(Resource.PATH, entry.getPath());
props.setProperty(Resource.NAME, entry.getFile());
@@ -112,7 +112,7 @@
public String getRepository() {
- return bundle.getSymbolicName() + "_" + bundle.getVersion();
+ return bundle.getSymbolicName() + "_" + bundle.getHeaders().get("Bundle-Version");
}
public InputStream openStream() throws IOException {