You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2014/01/15 14:03:58 UTC
svn commit: r1558370 - in
/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender:
./ internal/ internal/declaration/ internal/linker/
Author: clement
Date: Wed Jan 15 13:03:57 2014
New Revision: 1558370
URL: http://svn.apache.org/r1558370
Log:
Extend declaration to handle the bundle context
Added:
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/InstanceBundleContextAware.java
Modified:
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/InstanceDeclaration.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/AbstractService.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultInstanceDeclaration.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/InstanceDeclaration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/InstanceDeclaration.java?rev=1558370&r1=1558369&r2=1558370&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/InstanceDeclaration.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/InstanceDeclaration.java Wed Jan 15 13:03:57 2014
@@ -19,6 +19,8 @@
package org.apache.felix.ipojo.extender;
+import org.osgi.framework.Bundle;
+
import java.util.Dictionary;
/**
@@ -68,4 +70,11 @@ public interface InstanceDeclaration ext
* @return the instance name, {@literal unnamed} if not specified.
*/
String getInstanceName();
+
+ /**
+ * Gets the bundle that is declaring this instance.
+ * @return the bundle object
+ * @since 1.11.2
+ */
+ Bundle getBundle();
}
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/AbstractService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/AbstractService.java?rev=1558370&r1=1558369&r2=1558370&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/AbstractService.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/AbstractService.java Wed Jan 15 13:03:57 2014
@@ -31,8 +31,9 @@ public abstract class AbstractService im
/**
* The bundle context.
+ * To let sub-classes retrieve the used bundle context, this member is {@literal protected}.
*/
- private final BundleContext m_bundleContext;
+ protected final BundleContext m_bundleContext;
/**
* The service specification.
*/
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultInstanceDeclaration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultInstanceDeclaration.java?rev=1558370&r1=1558369&r2=1558370&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultInstanceDeclaration.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/declaration/DefaultInstanceDeclaration.java Wed Jan 15 13:03:57 2014
@@ -21,6 +21,7 @@ package org.apache.felix.ipojo.extender.
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.extender.InstanceDeclaration;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import java.util.Dictionary;
@@ -78,6 +79,16 @@ public class DefaultInstanceDeclaration
return m_instanceName;
}
+ /**
+ * Gets the bundle that is declaring this instance.
+ *
+ * @return the bundle object
+ * @since 1.11.2
+ */
+ public Bundle getBundle() {
+ return m_bundleContext.getBundle();
+ }
+
@Override
protected Dictionary<String, ?> getServiceProperties() {
Hashtable<String, Object> properties = new Hashtable<String, Object>();
Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/InstanceBundleContextAware.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/InstanceBundleContextAware.java?rev=1558370&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/InstanceBundleContextAware.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/InstanceBundleContextAware.java Wed Jan 15 13:03:57 2014
@@ -0,0 +1,44 @@
+/*
+ * 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.ipojo.extender.internal.linker;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * Instance containers that can handle the bundle context from the instance declaration implement this interface,
+ * letting handlers and other entities to retrieve this bundle context.
+ * @since 1.11.2
+ */
+public interface InstanceBundleContextAware {
+
+ /**
+ * Sets the instance bundle context.
+ * @param context the context of the instance
+ * @since 1.11.2
+ */
+ public void setInstanceBundleContext(BundleContext context);
+
+ /**
+ * Gets the bundle context of the instance, i.e. the bundle context of the bundle having declared this instance.
+ * @return the bundle context of the instance.
+ * @since 1.11.2
+ */
+ public BundleContext getInstanceContext();
+}
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java?rev=1558370&r1=1558369&r2=1558370&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java Wed Jan 15 13:03:57 2014
@@ -310,6 +310,10 @@ public class ManagedType implements Fact
// It is automatically started
// Future.get should never be null since this tracker is started when the factory has been created
ComponentInstance instance = m_future.get().createComponentInstance(instanceDeclaration.getConfiguration());
+ if (instance instanceof InstanceBundleContextAware) {
+ ((InstanceBundleContextAware) instance).setInstanceBundleContext(instanceDeclaration
+ .getBundle().getBundleContext());
+ }
// Notify the declaration that everything is fine
instanceDeclaration.bind();