Clean up imports.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@566081 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/AbstractComponentManager.java b/scr/src/main/java/org/apache/felix/scr/AbstractComponentManager.java
index 9e6a869..9590d69 100644
--- a/scr/src/main/java/org/apache/felix/scr/AbstractComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/AbstractComponentManager.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -18,75 +18,61 @@
*/
package org.apache.felix.scr;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
-import java.util.HashSet;
import java.util.Hashtable;
-import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.component.ComponentConstants;
-import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.ComponentInstance;
/**
* The default ComponentManager. Objects of this class are responsible for managing
- * implementation object's lifecycle.
+ * implementation object's lifecycle.
*
*/
abstract class AbstractComponentManager implements ComponentManager, ComponentInstance
{
// manager has been newly created or disabled
static final int STATE_DISABLED = 1;
-
+
// manager has just been enabled and is going to be activated
static final int STATE_ENABLED = 2;
-
+
// manager has been enabled but not satisfied
static final int STATE_UNSATISFIED = 4;
-
+
// manager is currently activating
static final int STATE_ACTIVATING = 8;
-
+
// manager is now active
static final int STATE_ACTIVE = 16;
// manager for a delayed component has been registered (not active yet)
static final int STATE_REGISTERED = 32;
-
+
// manager for a component factory has been registered
static final int STATE_FACTORY = 64;
-
+
// manager is current deactivating
static final int STATE_DEACTIVATING = 128;
// manager has been destroyed and may not be used anymore
static final int STATE_DESTROYED = 256;
-
+
// The state of this instance manager
private int m_state;
// The metadata
private ComponentMetadata m_componentMetadata;
-
+
// The dependency managers that manage every dependency
private List m_dependencyManagers;
@@ -98,23 +84,23 @@
/**
* The constructor receives both the activator and the metadata
- *
+ *
* @param activator
* @param metadata
*/
protected AbstractComponentManager(BundleComponentActivator activator, ComponentMetadata metadata)
{
- m_activator = activator;
- m_componentMetadata = metadata;
-
- m_state = STATE_DISABLED;
- m_dependencyManagers = new ArrayList();
+ this.m_activator = activator;
+ this.m_componentMetadata = metadata;
- Activator.trace("Component created", m_componentMetadata);
+ this.m_state = STATE_DISABLED;
+ this.m_dependencyManagers = new ArrayList();
+
+ Activator.trace("Component created", this.m_componentMetadata);
}
-
+
//---------- Asynchronous frontend to state change methods ----------------
-
+
/**
* Enables this component and - if satisfied - also activates it. If
* enabling the component fails for any reason, the component ends up
@@ -126,15 +112,15 @@
* This method schedules the enablement for asynchronous execution.
*/
public final void enable() {
- getActivator().schedule( new Runnable()
+ this.getActivator().schedule( new Runnable()
{
public void run()
{
- enableInternal();
+ AbstractComponentManager.this.enableInternal();
}
} );
}
-
+
/**
* Activates this component if satisfied. If any of the dependencies is
* not met, the component is not activated and remains unsatisifed.
@@ -142,15 +128,15 @@
* This method schedules the activation for asynchronous execution.
*/
public final void activate() {
- getActivator().schedule( new Runnable()
+ this.getActivator().schedule( new Runnable()
{
public void run()
{
- activateInternal();
+ AbstractComponentManager.this.activateInternal();
}
} );
}
-
+
/**
* Reconfigures this component by deactivating and activating it. During
* activation the new configuration data is retrieved from the Configuration
@@ -158,10 +144,10 @@
*/
public final void reconfigure()
{
- Activator.trace( "Deactivating and Activating to reconfigure", m_componentMetadata );
- reactivate();
+ Activator.trace( "Deactivating and Activating to reconfigure", this.m_componentMetadata );
+ this.reactivate();
}
-
+
/**
* Cycles this component by deactivating it and - if still satisfied -
* activating it again.
@@ -169,32 +155,32 @@
* This method schedules the reactivation for asynchronous execution.
*/
public final void reactivate() {
- getActivator().schedule( new Runnable()
+ this.getActivator().schedule( new Runnable()
{
public void run()
{
- deactivateInternal();
- Activator.trace( "Dependency Manager: RECREATING", m_componentMetadata );
- activateInternal();
+ AbstractComponentManager.this.deactivateInternal();
+ Activator.trace( "Dependency Manager: RECREATING", AbstractComponentManager.this.m_componentMetadata );
+ AbstractComponentManager.this.activateInternal();
}
} );
}
-
+
/**
* Deactivates the component.
* <p>
* This method schedules the deactivation for asynchronous execution.
*/
public final void deactivate() {
- getActivator().schedule( new Runnable()
+ this.getActivator().schedule( new Runnable()
{
public void run()
{
- deactivateInternal();
+ AbstractComponentManager.this.deactivateInternal();
}
} );
}
-
+
/**
* Disables this component and - if active - first deactivates it. The
* component may be reenabled by calling the {@link #enable()} method.
@@ -202,15 +188,15 @@
* This method schedules the disablement for asynchronous execution.
*/
public final void disable() {
- getActivator().schedule( new Runnable()
+ this.getActivator().schedule( new Runnable()
{
public void run()
{
- disableInternal();
+ AbstractComponentManager.this.disableInternal();
}
} );
}
-
+
/**
* Disposes off this component deactivating and disabling it first as
* required. After disposing off the component, it may not be used anymore.
@@ -221,71 +207,71 @@
* may continue.
*/
public final void dispose() {
- disposeInternal();
+ this.disposeInternal();
}
//---------- internal immediate state change methods ----------------------
// these methods must only be called from a separate thread by calling
// the respective asynchronous (public) method
-
+
/**
* Enable this component
- *
+ *
* @return true if enabling was successful
*/
private void enableInternal() {
-
- if (getState() == STATE_DESTROYED)
+
+ if (this.getState() == STATE_DESTROYED)
{
- Activator.error( "Destroyed Component cannot be enabled", m_componentMetadata );
+ Activator.error( "Destroyed Component cannot be enabled", this.m_componentMetadata );
return;
}
- else if (getState() != STATE_DISABLED)
+ else if (this.getState() != STATE_DISABLED)
{
- Activator.trace( "Component is already enabled", m_componentMetadata );
+ Activator.trace( "Component is already enabled", this.m_componentMetadata );
return;
}
-
- Activator.trace("Enabling component", m_componentMetadata);
-
+
+ Activator.trace("Enabling component", this.m_componentMetadata);
+
try
{
// If this component has got dependencies, create dependency managers for each one of them.
- if (m_componentMetadata.getDependencies().size() != 0)
+ if (this.m_componentMetadata.getDependencies().size() != 0)
{
- Iterator dependencyit = m_componentMetadata.getDependencies().iterator();
-
+ Iterator dependencyit = this.m_componentMetadata.getDependencies().iterator();
+
while(dependencyit.hasNext())
{
ReferenceMetadata currentdependency = (ReferenceMetadata)dependencyit.next();
-
+
DependencyManager depmanager = new DependencyManager(this, currentdependency);
-
- m_dependencyManagers.add(depmanager);
+
+ this.m_dependencyManagers.add(depmanager);
}
}
-
+
// enter enabled state before trying to activate
- setState( STATE_ENABLED );
-
- Activator.trace("Component enabled", m_componentMetadata);
+ this.setState( STATE_ENABLED );
+
+ Activator.trace("Component enabled", this.m_componentMetadata);
// immediately activate the compopnent, no need to schedule again
- activateInternal();
+ this.activateInternal();
}
catch(Exception ex)
{
- Activator.exception( "Failed enabling Component", m_componentMetadata, ex );
+ Activator.exception( "Failed enabling Component", this.m_componentMetadata, ex );
- // ensure we get back to DISABLED state
+ // ensure we get back to DISABLED state
// immediately disable, no need to schedule again
- disableInternal();
+ this.disableInternal();
}
}
/**
* Activate this Instance manager.
- *
+ *
* 112.5.6 Activating a component configuration consists of the following steps
* 1. Load the component implementation class
* 2. Create the component instance and component context
@@ -297,7 +283,7 @@
{
// CONCURRENCY NOTE: This method is called either by the enable()
// method or by the dependency managers or the reconfigure() method
- if ( (getState() & (STATE_ENABLED|STATE_UNSATISFIED)) == 0)
+ if ( (this.getState() & (STATE_ENABLED|STATE_UNSATISFIED)) == 0)
{
// This state can only be entered from the ENABLED (in the enable()
// method) or UNSATISFIED (missing references) states
@@ -305,55 +291,55 @@
}
// go to the activating state
- setState(STATE_ACTIVATING);
+ this.setState(STATE_ACTIVATING);
- Activator.trace("Activating component", m_componentMetadata);
+ Activator.trace("Activating component", this.m_componentMetadata);
// Before creating the implementation object, we are going to
// test if all the mandatory dependencies are satisfied
- Iterator it = m_dependencyManagers.iterator();
+ Iterator it = this.m_dependencyManagers.iterator();
while (it.hasNext())
{
DependencyManager dm = (DependencyManager)it.next();
if (!dm.isValid())
{
// at least one dependency is not satisfied
- Activator.trace( "Dependency not satisfied: " + dm.getName(), m_componentMetadata );
- setState(STATE_UNSATISFIED);
+ Activator.trace( "Dependency not satisfied: " + dm.getName(), this.m_componentMetadata );
+ this.setState(STATE_UNSATISFIED);
return;
}
}
-
+
// 1. Load the component implementation class
// 2. Create the component instance and component context
// 3. Bind the target services
// 4. Call the activate method, if present
- createComponent();
-
+ this.createComponent();
+
// Validation occurs before the services are provided, otherwhise the
// service provider's service may be called by a service requester
// while it is still ACTIVATING
- setState(getSatisfiedState());
-
+ this.setState(this.getSatisfiedState());
+
// 5. Register provided services
- m_serviceRegistration = registerComponentService();
-
- Activator.trace("Component activated", m_componentMetadata);
+ this.m_serviceRegistration = this.registerComponentService();
+
+ Activator.trace("Component activated", this.m_componentMetadata);
}
/**
* This method deactivates the manager, performing the following steps
- *
+ *
* [0. Remove published services from the registry]
* 1. Call the deactivate() method, if present
* 2. Unbind any bound services
- * 3. Release references to the component instance and component context
+ * 3. Release references to the component instance and component context
**/
private void deactivateInternal()
{
// CONCURRENCY NOTE: This method may be called either from application
// code or by the dependency managers or reconfiguration
- if ((getState() & (STATE_ACTIVATING|STATE_ACTIVE|STATE_REGISTERED|STATE_FACTORY)) == 0)
+ if ((this.getState() & (STATE_ACTIVATING|STATE_ACTIVE|STATE_REGISTERED|STATE_FACTORY)) == 0)
{
// This state can only be entered from the ACTIVATING (if activation
// fails), ACTIVE, REGISTERED or FACTORY states
@@ -361,24 +347,24 @@
}
// start deactivation by resetting the state
- setState( STATE_DEACTIVATING );
-
- Activator.trace("Deactivating component", m_componentMetadata);
+ this.setState( STATE_DEACTIVATING );
+
+ Activator.trace("Deactivating component", this.m_componentMetadata);
// 0.- Remove published services from the registry
- unregisterComponentService();
+ this.unregisterComponentService();
- // 1.- Call the deactivate method, if present
+ // 1.- Call the deactivate method, if present
// 2. Unbind any bound services
// 3. Release references to the component instance and component context
- deleteComponent();
+ this.deleteComponent();
//Activator.trace("InstanceManager from bundle ["+ m_activator.getBundleContext().getBundle().getBundleId() + "] was invalidated.");
// reset to state UNSATISFIED
- setState( STATE_UNSATISFIED );
-
- Activator.trace("Component deactivated", m_componentMetadata);
+ this.setState( STATE_UNSATISFIED );
+
+ Activator.trace("Component deactivated", this.m_componentMetadata);
}
private void disableInternal()
@@ -387,28 +373,28 @@
// but not by the dependency managers
// deactivate first, this does nothing if not active/registered/factory
- deactivateInternal();
-
- Activator.trace("Disabling component", m_componentMetadata);
+ this.deactivateInternal();
+
+ Activator.trace("Disabling component", this.m_componentMetadata);
// close all service listeners now, they are recreated on enable
// Stop the dependency managers to listen to events...
- Iterator it = m_dependencyManagers.iterator();
+ Iterator it = this.m_dependencyManagers.iterator();
while (it.hasNext())
{
DependencyManager dm = (DependencyManager)it.next();
dm.close();
}
- m_dependencyManagers.clear();
+ this.m_dependencyManagers.clear();
// we are now disabled, ready for re-enablement or complete destroyal
- setState( STATE_DISABLED );
-
- Activator.trace("Component disabled", m_componentMetadata);
+ this.setState( STATE_DISABLED );
+
+ Activator.trace("Component disabled", this.m_componentMetadata);
}
-
+
/**
- *
+ *
*/
private void disposeInternal()
{
@@ -416,60 +402,60 @@
// but not by the dependency managers
// disable first to clean up correctly
- disableInternal();
-
+ this.disableInternal();
+
// this component must not be used any more
- setState( STATE_DESTROYED );
+ this.setState( STATE_DESTROYED );
// release references (except component metadata for logging purposes)
- m_activator = null;
- m_dependencyManagers = null;
+ this.m_activator = null;
+ this.m_dependencyManagers = null;
- Activator.trace("Component disposed", m_componentMetadata);
+ Activator.trace("Component disposed", this.m_componentMetadata);
}
//---------- Component handling methods ----------------------------------
-
+
/**
* Method is called by {@link #activate()} in STATE_ACTIVATING or by
* {@link DelayedComponentManager#getService(Bundle, ServiceRegistration)}
* in STATE_REGISTERED.
*/
protected abstract void createComponent();
-
+
/**
* Method is called by {@link #deactivate()} in STATE_DEACTIVATING
*
*/
protected abstract void deleteComponent();
-
+
/**
* Returns the service object to be registered if the service element is
* specified.
* <p>
* Extensions of this class may overwrite this method to return a
* ServiceFactory to register in the case of a delayed or a service
- * factory component.
+ * factory component.
*/
protected abstract Object getService();
-
+
/**
* Returns the state value to set, when the component is satisfied. The
* return value depends on the kind of the component:
* <dl>
- * <dt>Immediate</dt><dd><code>STATE_ACTIVE</code></dd>
- * <dt>Delayed</dt><dd><code>STATE_REGISTERED</code></dd>
+ * <dt>Immediate</dt><dd><code>STATE_ACTIVE</code></dd>
+ * <dt>Delayed</dt><dd><code>STATE_REGISTERED</code></dd>
* <dt>Component Factory</dt><dd><code>STATE_FACTORY</code></dd>
* </dl>
- *
+ *
* @return
*/
private int getSatisfiedState() {
- if (m_componentMetadata.isFactory())
+ if (this.m_componentMetadata.isFactory())
{
return STATE_FACTORY;
}
- else if (m_componentMetadata.isImmediate())
+ else if (this.m_componentMetadata.isImmediate())
{
return STATE_ACTIVE;
}
@@ -478,54 +464,54 @@
return STATE_REGISTERED;
}
}
-
+
// 5. Register provided services
protected ServiceRegistration registerComponentService()
{
- if ( getComponentMetadata().getServiceMetadata() != null )
+ if ( this.getComponentMetadata().getServiceMetadata() != null )
{
- Activator.trace( "registering services", getComponentMetadata() );
+ Activator.trace( "registering services", this.getComponentMetadata() );
// get a copy of the component properties as service properties
- Dictionary serviceProperties = copyTo( null, getProperties() );
+ Dictionary serviceProperties = this.copyTo( null, this.getProperties() );
- return getActivator().getBundleContext().registerService(
- getComponentMetadata().getServiceMetadata().getProvides(), getService(), serviceProperties );
+ return this.getActivator().getBundleContext().registerService(
+ this.getComponentMetadata().getServiceMetadata().getProvides(), this.getService(), serviceProperties );
}
-
+
return null;
}
-
+
protected void unregisterComponentService()
{
- if ( m_serviceRegistration != null )
+ if ( this.m_serviceRegistration != null )
{
- m_serviceRegistration.unregister();
- m_serviceRegistration = null;
+ this.m_serviceRegistration.unregister();
+ this.m_serviceRegistration = null;
- Activator.trace( "unregistering the services", getComponentMetadata() );
+ Activator.trace( "unregistering the services", this.getComponentMetadata() );
}
}
-
+
//**********************************************************************************************************
-
+
BundleComponentActivator getActivator() {
- return m_activator;
+ return this.m_activator;
}
-
+
Iterator getDependencyManagers() {
- return m_dependencyManagers.iterator();
+ return this.m_dependencyManagers.iterator();
}
-
+
DependencyManager getDependencyManager( String name )
{
- Iterator it = getDependencyManagers();
+ Iterator it = this.getDependencyManagers();
while ( it.hasNext() )
{
DependencyManager dm = ( DependencyManager ) it.next();
if ( name.equals( dm.getName() ) )
{
- // only return the dm if it has service references
+ // only return the dm if it has service references
return ( dm.size() > 0 ) ? dm : null;
}
}
@@ -533,7 +519,7 @@
// not found
return null;
}
-
+
/**
* Get the object that is implementing this descriptor
*
@@ -545,13 +531,13 @@
/**
* Copies the properties from the <code>source</code> <code>Dictionary</code>
* into the <code>target</code> <code>Dictionary</code>.
- *
+ *
* @param target The <code>Dictionary</code> into which to copy the
* properties. If <code>null</code> a new <code>Hashtable</code> is
* created.
* @param source The <code>Dictionary</code> providing the properties to
* copy. If <code>null</code> or empty, nothing is copied.
- *
+ *
* @return The <code>target</code> is returned, which may be empty if
* <code>source</code> is <code>null</code> or empty and
* <code>target</code> was <code>null</code>.
@@ -576,28 +562,28 @@
}
ServiceReference getServiceReference() {
- return ( m_serviceRegistration != null ) ? m_serviceRegistration.getReference() : null;
+ return ( this.m_serviceRegistration != null ) ? this.m_serviceRegistration.getReference() : null;
}
-
+
/**
- *
+ *
*/
public ComponentMetadata getComponentMetadata() {
- return m_componentMetadata;
+ return this.m_componentMetadata;
}
int getState() {
- return m_state;
+ return this.m_state;
}
-
+
/**
* sets the state of the manager
**/
protected synchronized void setState(int newState) {
- Activator.trace( "State transition : " + stateToString( m_state ) + " -> " + stateToString( newState ),
- m_componentMetadata );
-
- m_state = newState;
+ Activator.trace( "State transition : " + this.stateToString( this.m_state ) + " -> " + this.stateToString( newState ),
+ this.m_componentMetadata );
+
+ this.m_state = newState;
}
public String stateToString(int state) {
@@ -630,39 +616,39 @@
* calling the <code>Method.setAccessible</code> method if required and
* the method is returned. Enforcing accessibility is required to support
* invocation of protected methods.
- *
+ *
* @param clazz The <code>Class</code> which provides the method.
* @param name The name of the method.
* @param parameterTypes The parameters to the method. Passing
* <code>null</code> is equivalent to using an empty array.
- *
+ *
* @return The named method with enforced accessibility
- *
+ *
* @throws NoSuchMethodException If no public or protected method with
* the given name can be found in the class or any of its super classes.
*/
static Method getMethod(Class clazz, String name, Class[] parameterTypes)
- throws NoSuchMethodException
+ throws NoSuchMethodException
{
// try the default mechanism first, which only yields public methods
try
{
- return clazz.getMethod(name, parameterTypes);
+ return clazz.getMethod(name, parameterTypes);
}
catch (NoSuchMethodException nsme)
{
// it is ok to not find a public method, try to find a protected now
}
-
+
// now use method declarations, requiring walking up the class
// hierarchy manually. this algorithm also returns protected methods
// which is, what we need here
- for ( ; clazz != null; clazz = clazz.getSuperclass())
+ for ( ; clazz != null; clazz = clazz.getSuperclass())
{
- try
+ try
{
Method method = clazz.getDeclaredMethod(name, parameterTypes);
-
+
// only accept a protected method, a public method should
// have been found above and neither private nor package
// protected methods are acceptable here
@@ -676,10 +662,10 @@
// ignore for now
}
}
-
+
// walked up the complete super class hierarchy and still not found
// anything, sigh ...
throw new NoSuchMethodException(name);
}
-
+
}
diff --git a/scr/src/main/java/org/apache/felix/scr/ComponentFactoryImpl.java b/scr/src/main/java/org/apache/felix/scr/ComponentFactoryImpl.java
index a6f3c9f..4858c3b 100644
--- a/scr/src/main/java/org/apache/felix/scr/ComponentFactoryImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/ComponentFactoryImpl.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -24,12 +24,9 @@
import java.util.Hashtable;
import java.util.IdentityHashMap;
import java.util.Map;
-import java.util.Set;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedServiceFactory;
import org.osgi.service.component.ComponentConstants;
import org.osgi.service.component.ComponentFactory;
@@ -60,8 +57,8 @@
ComponentRegistry componentRegistry )
{
super( activator, metadata );
- m_componentRegistry = componentRegistry;
- m_createdComponents = new IdentityHashMap();
+ this.m_componentRegistry = componentRegistry;
+ this.m_createdComponents = new IdentityHashMap();
}
@@ -70,7 +67,7 @@
*/
public ComponentInstance newInstance( Dictionary dictionary )
{
- return ( ComponentInstance ) createComponentManager( dictionary );
+ return ( ComponentInstance ) this.createComponentManager( dictionary );
}
@@ -87,11 +84,11 @@
protected ServiceRegistration registerComponentService()
{
- Activator.trace( "registering component factory", getComponentMetadata() );
+ Activator.trace( "registering component factory", this.getComponentMetadata() );
- Dictionary serviceProperties = getProperties();
- return getActivator().getBundleContext().registerService( new String[]
- { ComponentFactory.class.getName(), ManagedServiceFactory.class.getName() }, getService(),
+ Dictionary serviceProperties = this.getProperties();
+ return this.getActivator().getBundleContext().registerService( new String[]
+ { ComponentFactory.class.getName(), ManagedServiceFactory.class.getName() }, this.getService(),
serviceProperties );
}
@@ -106,14 +103,14 @@
protected Dictionary getProperties()
{
Dictionary props = new Hashtable();
-
+
// 112.5.5 The Component Factory service must register with the following properties
- props.put( ComponentConstants.COMPONENT_NAME, getComponentMetadata().getName() );
- props.put( ComponentConstants.COMPONENT_FACTORY, getComponentMetadata().getFactoryIdentifier() );
-
+ props.put( ComponentConstants.COMPONENT_NAME, this.getComponentMetadata().getName() );
+ props.put( ComponentConstants.COMPONENT_FACTORY, this.getComponentMetadata().getFactoryIdentifier() );
+
// also register with the factory PID
- props.put( Constants.SERVICE_PID, getComponentMetadata().getName() );
-
+ props.put( Constants.SERVICE_PID, this.getComponentMetadata().getName() );
+
return props;
}
@@ -129,23 +126,23 @@
public void updated( String pid, Dictionary configuration )
{
ComponentManager cm;
- if ( m_configuredServices != null )
+ if ( this.m_configuredServices != null )
{
- cm = ( ComponentManager ) m_configuredServices.get( pid );
+ cm = ( ComponentManager ) this.m_configuredServices.get( pid );
}
else
{
- m_configuredServices = new HashMap();
+ this.m_configuredServices = new HashMap();
cm = null;
}
if ( cm == null )
{
// create a new instance with the current configuration
- cm = createComponentManager( configuration );
+ cm = this.createComponentManager( configuration );
// keep a reference for future updates
- m_configuredServices.put( pid, cm );
+ this.m_configuredServices.put( pid, cm );
}
else
{
@@ -163,12 +160,12 @@
public void deleted( String pid )
{
- if ( m_configuredServices != null )
+ if ( this.m_configuredServices != null )
{
- ComponentManager cm = ( ComponentManager ) m_configuredServices.remove( pid );
+ ComponentManager cm = ( ComponentManager ) this.m_configuredServices.remove( pid );
if ( cm != null )
{
- disposeComponentManager( cm );
+ this.disposeComponentManager( cm );
}
}
@@ -177,7 +174,7 @@
public String getName()
{
- return "Component Factory " + getComponentMetadata().getName();
+ return "Component Factory " + this.getComponentMetadata().getName();
}
@@ -190,15 +187,15 @@
*/
private ComponentManager createComponentManager( Dictionary configuration )
{
- long componentId = m_componentRegistry.createComponentId();
- ComponentManager cm = ManagerFactory.createManager( getActivator(), getComponentMetadata(), componentId );
+ long componentId = this.m_componentRegistry.createComponentId();
+ ComponentManager cm = ManagerFactory.createManager( this.getActivator(), this.getComponentMetadata(), componentId );
// add the new component to the activators instances
- getActivator().getInstanceReferences().add( cm );
+ this.getActivator().getInstanceReferences().add( cm );
// register with the internal set of created components
- m_createdComponents.put(cm, cm);
-
+ this.m_createdComponents.put(cm, cm);
+
// inject configuration if possible
if ( cm instanceof ImmediateComponentManager )
{
@@ -207,37 +204,18 @@
// immediately enable this ComponentManager
cm.enable();
-
+
return cm;
}
-
+
private void disposeComponentManager(ComponentManager cm) {
// remove from created components
- m_createdComponents.remove( cm );
-
+ this.m_createdComponents.remove( cm );
+
// remove from activators list
- getActivator().getInstanceReferences().remove( cm );
-
+ this.getActivator().getInstanceReferences().remove( cm );
+
// finally dispose it
cm.dispose();
}
-
- private class ComponentInstanceWrapper implements ComponentInstance {
-
- private ComponentManager m_component;
-
- ComponentInstanceWrapper(ComponentManager component) {
- m_component = component;
- }
-
- public Object getInstance()
- {
- return ((ComponentInstance) m_component).getInstance();
- }
-
- public void dispose()
- {
- disposeComponentManager( m_component );
- }
- }
}
diff --git a/scr/src/main/java/org/apache/felix/scr/ComponentManager.java b/scr/src/main/java/org/apache/felix/scr/ComponentManager.java
index 5ae0c7a..3a7a23ad 100644
--- a/scr/src/main/java/org/apache/felix/scr/ComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/ComponentManager.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -18,32 +18,31 @@
*/
package org.apache.felix.scr;
-import java.util.Dictionary;
/**
- * This interface is provided so that there can be multiple implementations of
- * managers that are responsible for managing component's lifecycle.
- *
+ * This interface is provided so that there can be multiple implementations of
+ * managers that are responsible for managing component's lifecycle.
+ *
*/
public interface ComponentManager {
-
+
/**
* Enable the component
*/
public void enable();
-
+
/**
* Reconfigure the component with configuration data newly retrieved from
* the Configuration Admin Service.
*/
public void reconfigure();
-
+
/**
* Disable the component. After disabling the component may be re-enabled
* by calling the {@link #enable()} method.
*/
public void disable();
-
+
/**
* Dispose the component. After disposing the component manager it must not
* be used anymore.
@@ -52,7 +51,7 @@
/**
* Get the component information
- *
+ *
* @return a ComponentMetadata object
*/
public ComponentMetadata getComponentMetadata();
diff --git a/scr/src/main/java/org/apache/felix/scr/ComponentRegistry.java b/scr/src/main/java/org/apache/felix/scr/ComponentRegistry.java
index 9460390..7e775ab 100644
--- a/scr/src/main/java/org/apache/felix/scr/ComponentRegistry.java
+++ b/scr/src/main/java/org/apache/felix/scr/ComponentRegistry.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -19,7 +19,6 @@
package org.apache.felix.scr;
-import java.awt.Component;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
@@ -53,22 +52,22 @@
ComponentRegistry( BundleContext context )
{
- m_componentNames = new HashMap();
- m_componentCounter = -1;
+ this.m_componentNames = new HashMap();
+ this.m_componentCounter = -1;
Dictionary props = new Hashtable();
props.put( Constants.SERVICE_DESCRIPTION, "Service Component Configuration Support" );
props.put( Constants.SERVICE_VENDOR, "Apache Software Foundation" );
- registration = context.registerService( ConfigurationListener.class.getName(), this, props );
+ this.registration = context.registerService( ConfigurationListener.class.getName(), this, props );
}
void dispose()
{
- if ( registration != null )
+ if ( this.registration != null )
{
- registration.unregister();
- registration = null;
+ this.registration.unregister();
+ this.registration = null;
}
}
@@ -78,7 +77,7 @@
public void configurationEvent( ConfigurationEvent configEvent )
{
String pid = configEvent.getPid();
- ComponentManager cm = getComponent( pid );
+ ComponentManager cm = this.getComponent( pid );
if ( cm != null )
{
cm.reconfigure();
@@ -90,39 +89,39 @@
long createComponentId()
{
- m_componentCounter++;
- return m_componentCounter;
+ this.m_componentCounter++;
+ return this.m_componentCounter;
}
void checkComponentName( String name )
{
- if ( m_componentNames.containsKey( name ) )
+ if ( this.m_componentNames.containsKey( name ) )
{
throw new ComponentException( "The component name '" + name + "' has already been registered." );
}
// reserve the name
- m_componentNames.put( name, name );
+ this.m_componentNames.put( name, name );
}
void registerComponent( String name, ComponentManager component )
{
// only register the component if there is a registration for it !
- if ( !name.equals( m_componentNames.get( name ) ) )
+ if ( !name.equals( this.m_componentNames.get( name ) ) )
{
// this is not expected if all works ok
throw new ComponentException( "The component name '" + name + "' has already been registered." );
}
- m_componentNames.put( name, component );
+ this.m_componentNames.put( name, component );
}
ComponentManager getComponent( String name )
{
- Object entry = m_componentNames.get( name );
+ Object entry = this.m_componentNames.get( name );
// only return the entry if non-null and not a reservation
if ( entry instanceof ComponentManager )
@@ -136,6 +135,6 @@
void unregisterComponent( String name )
{
- m_componentNames.remove( name );
+ this.m_componentNames.remove( name );
}
}
diff --git a/scr/src/main/java/org/apache/felix/scr/DelayedComponentManager.java b/scr/src/main/java/org/apache/felix/scr/DelayedComponentManager.java
index b073bb2..b305729 100644
--- a/scr/src/main/java/org/apache/felix/scr/DelayedComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/DelayedComponentManager.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -21,13 +21,12 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.component.ComponentContext;
/**
* The <code>DelayedComponentManager</code> TODO
*
* @author fmeschbe
- * @version $Rev$, $Date$
+ * @version $Rev: 538123 $, $Date$
*/
public class DelayedComponentManager extends ImmediateComponentManager implements ServiceFactory
{
@@ -51,42 +50,42 @@
protected void deleteComponent()
{
// only have to delete, if there is actually an instance
- if (getInstance() != null) {
+ if (this.getInstance() != null) {
super.deleteComponent();
}
}
-
+
protected Object getService()
{
return this;
}
-
+
//---------- ServiceFactory interface -------------------------------------
-
+
public Object getService( Bundle arg0, ServiceRegistration arg1 )
{
- Activator.trace("DelayedComponentServiceFactory.getService()", getComponentMetadata());
+ Activator.trace("DelayedComponentServiceFactory.getService()", this.getComponentMetadata());
// When the getServiceMethod is called, the implementation object must be created
// unless another bundle has already retrievd it
-
- if (getInstance() == null) {
+
+ if (this.getInstance() == null) {
super.createComponent();
-
+
// if component creation failed, we were deactivated and the state
// is not REGISTERED any more. Otherwise go to standard ACTIVE
// state now
- if (getState() == STATE_REGISTERED)
+ if (this.getState() == STATE_REGISTERED)
{
- setState( STATE_ACTIVE );
+ this.setState( STATE_ACTIVE );
}
}
-
- return getInstance();
+
+ return this.getInstance();
}
-
+
public void ungetService( Bundle arg0, ServiceRegistration arg1, Object arg2 )
{
// nothing to do here
}
-
+
}
diff --git a/scr/src/main/java/org/apache/felix/scr/DependencyManager.java b/scr/src/main/java/org/apache/felix/scr/DependencyManager.java
index 4f55702..128b7ac 100644
--- a/scr/src/main/java/org/apache/felix/scr/DependencyManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/DependencyManager.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -28,12 +28,10 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
/**
@@ -63,16 +61,16 @@
/**
* Constructor that receives several parameters.
- *
+ *
* @param dependency An object that contains data about the dependency
*/
DependencyManager( AbstractComponentManager componentManager, ReferenceMetadata dependency )
throws InvalidSyntaxException
{
- m_componentManager = componentManager;
- m_dependencyMetadata = dependency;
- m_bindUsesServiceReference = false;
- m_tracked = new HashMap();
+ this.m_componentManager = componentManager;
+ this.m_dependencyMetadata = dependency;
+ this.m_bindUsesServiceReference = false;
+ this.m_tracked = new HashMap();
// register the service listener
String filterString = "(" + Constants.OBJECTCLASS + "=" + dependency.getInterface() + ")";
@@ -87,7 +85,7 @@
filterString );
for ( int i = 0; refs != null && i < refs.length; i++ )
{
- addingService( refs[i] );
+ this.addingService( refs[i] );
}
}
@@ -99,14 +97,14 @@
switch ( event.getType() )
{
case ServiceEvent.REGISTERED:
- addingService( event.getServiceReference() );
+ this.addingService( event.getServiceReference() );
break;
case ServiceEvent.MODIFIED:
- removedService( event.getServiceReference() );
- addingService( event.getServiceReference() );
+ this.removedService( event.getServiceReference() );
+ this.addingService( event.getServiceReference() );
break;
case ServiceEvent.UNREGISTERING:
- removedService( event.getServiceReference() );
+ this.removedService( event.getServiceReference() );
break;
}
}
@@ -119,12 +117,12 @@
*/
void close()
{
- BundleContext context = m_componentManager.getActivator().getBundleContext();
+ BundleContext context = this.m_componentManager.getActivator().getBundleContext();
context.removeServiceListener( this );
- synchronized ( m_tracked )
+ synchronized ( this.m_tracked )
{
- for ( Iterator ri = m_tracked.keySet().iterator(); ri.hasNext(); )
+ for ( Iterator ri = this.m_tracked.keySet().iterator(); ri.hasNext(); )
{
ServiceReference sr = ( ServiceReference ) ri.next();
context.ungetService( sr );
@@ -139,9 +137,9 @@
*/
int size()
{
- synchronized ( m_tracked )
+ synchronized ( this.m_tracked )
{
- return m_tracked.size();
+ return this.m_tracked.size();
}
}
@@ -151,11 +149,11 @@
*/
ServiceReference getServiceReference()
{
- synchronized ( m_tracked )
+ synchronized ( this.m_tracked )
{
- if ( m_tracked.size() > 0 )
+ if ( this.m_tracked.size() > 0 )
{
- return ( ServiceReference ) m_tracked.keySet().iterator().next();
+ return ( ServiceReference ) this.m_tracked.keySet().iterator().next();
}
return null;
@@ -169,11 +167,11 @@
*/
ServiceReference[] getServiceReferences()
{
- synchronized ( m_tracked )
+ synchronized ( this.m_tracked )
{
- if ( m_tracked.size() > 0 )
+ if ( this.m_tracked.size() > 0 )
{
- return ( ServiceReference[] ) m_tracked.keySet().toArray( new ServiceReference[m_tracked.size()] );
+ return ( ServiceReference[] ) this.m_tracked.keySet().toArray( new ServiceReference[this.m_tracked.size()] );
}
return null;
@@ -186,9 +184,9 @@
*/
Object getService( ServiceReference serviceReference )
{
- synchronized ( m_tracked )
+ synchronized ( this.m_tracked )
{
- return m_tracked.get( serviceReference );
+ return this.m_tracked.get( serviceReference );
}
}
@@ -198,11 +196,11 @@
*/
Object getService()
{
- synchronized ( m_tracked )
+ synchronized ( this.m_tracked )
{
- if ( m_tracked.size() > 0 )
+ if ( this.m_tracked.size() > 0 )
{
- return m_tracked.values().iterator().next();
+ return this.m_tracked.values().iterator().next();
}
return null;
@@ -216,11 +214,11 @@
*/
Object[] getServices()
{
- synchronized ( m_tracked )
+ synchronized ( this.m_tracked )
{
- if ( m_tracked.size() > 0 )
+ if ( this.m_tracked.size() > 0 )
{
- return m_tracked.values().toArray( new ServiceReference[m_tracked.size()] );
+ return this.m_tracked.values().toArray( new ServiceReference[this.m_tracked.size()] );
}
return null;
@@ -235,7 +233,7 @@
*/
String getName()
{
- return m_dependencyMetadata.getName();
+ return this.m_dependencyMetadata.getName();
}
@@ -245,21 +243,21 @@
*/
boolean isValid()
{
- return size() > 0 || m_dependencyMetadata.isOptional();
+ return this.size() > 0 || this.m_dependencyMetadata.isOptional();
}
/**
* initializes a dependency. This method binds all of the service
* occurrences to the instance object
- *
+ *
* @return true if the operation was successful, false otherwise
*/
boolean bind( Object instance )
{
// If no references were received, we have to check if the dependency
// is optional, if it is not then the dependency is invalid
- if ( !isValid() )
+ if ( !this.isValid() )
{
return false;
}
@@ -272,7 +270,7 @@
}
// Get service references
- ServiceReference refs[] = getServiceReferences();
+ ServiceReference refs[] = this.getServiceReferences();
// refs can be null if the dependency is optional
if ( refs != null )
@@ -280,19 +278,19 @@
int max = 1;
boolean retval = true;
- if ( m_dependencyMetadata.isMultiple() == true )
+ if ( this.m_dependencyMetadata.isMultiple() == true )
{
max = refs.length;
}
for ( int index = 0; index < max; index++ )
{
- retval = invokeBindMethod( instance, refs[index], getService( refs[index] ) );
+ retval = this.invokeBindMethod( instance, refs[index], this.getService( refs[index] ) );
if ( retval == false && ( max == 1 ) )
{
// There was an exception when calling the bind method
Activator.error( "Dependency Manager: Possible exception in the bind method during initialize()",
- m_componentManager.getComponentMetadata() );
+ this.m_componentManager.getComponentMetadata() );
return false;
}
}
@@ -315,14 +313,14 @@
return;
}
- ServiceReference[] allrefs = getServiceReferences();
+ ServiceReference[] allrefs = this.getServiceReferences();
if ( allrefs == null )
return;
for ( int i = 0; i < allrefs.length; i++ )
{
- invokeUnbindMethod( instance, allrefs[i], getService( allrefs[i] ) );
+ this.invokeUnbindMethod( instance, allrefs[i], this.getService( allrefs[i] ) );
}
}
@@ -330,7 +328,7 @@
/**
* Gets a bind or unbind method according to the policies described in the
* specification
- *
+ *
* @param methodname The name of the method
* @param targetClass the class to which the method belongs to
* @param parameterClassName the name of the class of the parameter that is
@@ -357,7 +355,7 @@
method = AbstractComponentManager.getMethod( targetClass, methodname, new Class[]
{ ServiceReference.class } );
- m_bindUsesServiceReference = true;
+ this.m_bindUsesServiceReference = true;
}
catch ( NoSuchMethodException ex )
{
@@ -366,9 +364,9 @@
{
// Case2
- m_bindUsesServiceReference = false;
+ this.m_bindUsesServiceReference = false;
- parameterClass = m_componentManager.getActivator().getBundleContext().getBundle().loadClass(
+ parameterClass = this.m_componentManager.getActivator().getBundleContext().getBundle().loadClass(
parameterClassName );
method = AbstractComponentManager.getMethod( targetClass, methodname, new Class[]
@@ -427,7 +425,7 @@
}
catch ( ClassNotFoundException ex2 )
{
- Activator.exception( "Cannot load class used as parameter " + parameterClassName, m_componentManager
+ Activator.exception( "Cannot load class used as parameter " + parameterClassName, this.m_componentManager
.getComponentMetadata(), ex2 );
}
}
@@ -440,7 +438,7 @@
* Call the bind method. In case there is an exception while calling the
* bind method, the service is not considered to be bound to the instance
* object
- *
+ *
* @param implementationObject The object to which the service is bound
* @param ref A ServiceReference with the service that will be bound to the
* instance object
@@ -459,10 +457,10 @@
try
{
// Get the bind method
- Activator.trace( "getting bind: " + m_dependencyMetadata.getBind(), m_componentManager
+ Activator.trace( "getting bind: " + this.m_dependencyMetadata.getBind(), this.m_componentManager
.getComponentMetadata() );
- Method bindMethod = getBindingMethod( m_dependencyMetadata.getBind(), implementationObject.getClass(),
- m_dependencyMetadata.getInterface() );
+ Method bindMethod = this.getBindingMethod( this.m_dependencyMetadata.getBind(), implementationObject.getClass(),
+ this.m_dependencyMetadata.getInterface() );
if ( bindMethod == null )
{
@@ -470,14 +468,14 @@
// error
// message with the log service, if present, and ignore the
// method
- Activator.error( "bind() method not found", m_componentManager.getComponentMetadata() );
+ Activator.error( "bind() method not found", this.m_componentManager.getComponentMetadata() );
return false;
}
// Get the parameter
Object parameter;
- if ( m_bindUsesServiceReference == false )
+ if ( this.m_bindUsesServiceReference == false )
{
parameter = service;
}
@@ -490,7 +488,7 @@
bindMethod.invoke( implementationObject, new Object[]
{ parameter } );
- Activator.trace( "bound: " + getName(), m_componentManager.getComponentMetadata() );
+ Activator.trace( "bound: " + this.getName(), this.m_componentManager.getComponentMetadata() );
return true;
}
@@ -500,17 +498,17 @@
// public, SCR must log an error
// message with the log service, if present, and ignore the
// method
- Activator.exception( "bind() method cannot be called", m_componentManager.getComponentMetadata(), ex );
+ Activator.exception( "bind() method cannot be called", this.m_componentManager.getComponentMetadata(), ex );
return false;
}
catch ( InvocationTargetException ex )
{
- Activator.exception( "DependencyManager : exception while invoking " + m_dependencyMetadata.getBind()
- + "()", m_componentManager.getComponentMetadata(), ex );
+ Activator.exception( "DependencyManager : exception while invoking " + this.m_dependencyMetadata.getBind()
+ + "()", this.m_componentManager.getComponentMetadata(), ex );
return false;
}
}
- else if ( implementationObject == null && m_componentManager.getComponentMetadata().isImmediate() == false )
+ else if ( implementationObject == null && this.m_componentManager.getComponentMetadata().isImmediate() == false )
{
return true;
}
@@ -525,7 +523,7 @@
/**
* Call the unbind method
- *
+ *
* @param implementationObject The object from which the service is unbound
* @param ref A service reference corresponding to the service that will be
* unbound
@@ -539,16 +537,16 @@
{
try
{
- Activator.trace( "getting unbind: " + m_dependencyMetadata.getUnbind(), m_componentManager
+ Activator.trace( "getting unbind: " + this.m_dependencyMetadata.getUnbind(), this.m_componentManager
.getComponentMetadata() );
- Method unbindMethod = getBindingMethod( m_dependencyMetadata.getUnbind(), implementationObject
- .getClass(), m_dependencyMetadata.getInterface() );
+ Method unbindMethod = this.getBindingMethod( this.m_dependencyMetadata.getUnbind(), implementationObject
+ .getClass(), this.m_dependencyMetadata.getInterface() );
// Recover the object that is bound from the map.
// Object parameter = m_boundServices.get(ref);
Object parameter = null;
- if ( m_bindUsesServiceReference == true )
+ if ( this.m_bindUsesServiceReference == true )
{
parameter = ref;
}
@@ -563,14 +561,14 @@
// error
// message with the log service, if present, and ignore the
// method
- Activator.error( "unbind() method not found", m_componentManager.getComponentMetadata() );
+ Activator.error( "unbind() method not found", this.m_componentManager.getComponentMetadata() );
return false;
}
unbindMethod.invoke( implementationObject, new Object[]
{ parameter } );
- Activator.trace( "unbound: " + getName(), m_componentManager.getComponentMetadata() );
+ Activator.trace( "unbound: " + this.getName(), this.m_componentManager.getComponentMetadata() );
return true;
}
@@ -580,18 +578,18 @@
// public, SCR must log an error
// message with the log service, if present, and ignore the
// method
- Activator.exception( "unbind() method cannot be called", m_componentManager.getComponentMetadata(), ex );
+ Activator.exception( "unbind() method cannot be called", this.m_componentManager.getComponentMetadata(), ex );
return false;
}
catch ( InvocationTargetException ex )
{
- Activator.exception( "DependencyManager : exception while invoking " + m_dependencyMetadata.getUnbind()
- + "()", m_componentManager.getComponentMetadata(), ex );
+ Activator.exception( "DependencyManager : exception while invoking " + this.m_dependencyMetadata.getUnbind()
+ + "()", this.m_componentManager.getComponentMetadata(), ex );
return false;
}
}
- else if ( implementationObject == null && m_componentManager.getComponentMetadata().isImmediate() == false )
+ else if ( implementationObject == null && this.m_componentManager.getComponentMetadata().isImmediate() == false )
{
return true;
}
@@ -607,38 +605,38 @@
private void addingService( ServiceReference reference )
{
// get the service and keep it here (for now or later)
- Object service = m_componentManager.getActivator().getBundleContext().getService( reference );
- synchronized ( m_tracked )
+ Object service = this.m_componentManager.getActivator().getBundleContext().getService( reference );
+ synchronized ( this.m_tracked )
{
- m_tracked.put( reference, service );
+ this.m_tracked.put( reference, service );
}
// forward the event if in event handling state
- if ( handleServiceEvent() )
+ if ( this.handleServiceEvent() )
{
// the component is UNSATISFIED if enabled but any of the references
// have been missing when activate was running the last time or
// the component has been deactivated
- if ( m_componentManager.getState() == AbstractComponentManager.STATE_UNSATISFIED )
+ if ( this.m_componentManager.getState() == AbstractComponentManager.STATE_UNSATISFIED )
{
- m_componentManager.activate();
+ this.m_componentManager.activate();
}
// Otherwise, this checks for dynamic 0..1, 0..N, and 1..N
// it never
// checks for 1..1 dynamic which is done above by the
// validate()
- else if ( !m_dependencyMetadata.isStatic() )
+ else if ( !this.m_dependencyMetadata.isStatic() )
{
// For dependency that are aggregates, always bind the
// service
// Otherwise only bind if bind services is zero, which
// captures the 0..1 case
// (size is still zero as we are called for the first service)
- if ( m_dependencyMetadata.isMultiple() || size() == 0 )
+ if ( this.m_dependencyMetadata.isMultiple() || this.size() == 0 )
{
- invokeBindMethod( m_componentManager.getInstance(), reference, service );
+ this.invokeBindMethod( this.m_componentManager.getInstance(), reference, service );
}
}
}
@@ -649,9 +647,9 @@
{
// remove the service from the internal registry, ignore if not cached
Object service;
- synchronized ( m_tracked )
+ synchronized ( this.m_tracked )
{
- service = m_tracked.remove( reference );
+ service = this.m_tracked.remove( reference );
}
// do nothing in the unlikely case that we do not have it cached
@@ -660,22 +658,22 @@
return;
}
- if ( handleServiceEvent() )
+ if ( this.handleServiceEvent() )
{
// A static dependency is broken the instance manager will
// be invalidated
- if ( m_dependencyMetadata.isStatic() )
+ if ( this.m_dependencyMetadata.isStatic() )
{
// setStateDependency(DependencyChangeEvent.DEPENDENCY_INVALID);
try
{
- Activator.trace( "Dependency Manager: Static dependency is broken", m_componentManager
+ Activator.trace( "Dependency Manager: Static dependency is broken", this.m_componentManager
.getComponentMetadata() );
- m_componentManager.reactivate();
+ this.m_componentManager.reactivate();
}
catch ( Exception ex )
{
- Activator.exception( "Exception while recreating dependency ", m_componentManager
+ Activator.exception( "Exception while recreating dependency ", this.m_componentManager
.getComponentMetadata(), ex );
}
}
@@ -685,8 +683,8 @@
// Release references to the service, call unbinder
// method
// and eventually request service unregistration
- Object instance = m_componentManager.getInstance();
- invokeUnbindMethod( instance, reference, service );
+ Object instance = this.m_componentManager.getInstance();
+ this.invokeUnbindMethod( instance, reference, service );
// The only thing we need to do here is check if we can
// reinitialize
@@ -697,18 +695,18 @@
// In the case of aggregates, this will only invalidate
// them since they
// can't be repaired.
- if ( size() == 0 )
+ if ( this.size() == 0 )
{
// try to reinitialize
- if ( !bind( instance ) )
+ if ( !this.bind( instance ) )
{
- if ( !m_dependencyMetadata.isOptional() )
+ if ( !this.m_dependencyMetadata.isOptional() )
{
Activator
.trace(
"Dependency Manager: Mandatory dependency not fullfilled and no replacements available... unregistering service...",
- m_componentManager.getComponentMetadata() );
- m_componentManager.reactivate();
+ this.m_componentManager.getComponentMetadata() );
+ this.m_componentManager.reactivate();
}
}
}
@@ -716,16 +714,16 @@
}
// finally unget the service
- m_componentManager.getActivator().getBundleContext().ungetService( reference );
+ this.m_componentManager.getActivator().getBundleContext().ungetService( reference );
}
private boolean handleServiceEvent()
{
- return ( m_componentManager.getState() & STATE_MASK ) != 0;
+ return ( this.m_componentManager.getState() & STATE_MASK ) != 0;
// return state != AbstractComponentManager.INSTANCE_DESTROYING
// && state != AbstractComponentManager.INSTANCE_DESTROYED
- // && state != AbstractComponentManager.INSTANCE_CREATING
+ // && state != AbstractComponentManager.INSTANCE_CREATING
// && state != AbstractComponentManager.INSTANCE_CREATED;
}
}
diff --git a/scr/src/main/java/org/apache/felix/scr/ImmediateComponentManager.java b/scr/src/main/java/org/apache/felix/scr/ImmediateComponentManager.java
index a4db355..022fd1e 100644
--- a/scr/src/main/java/org/apache/felix/scr/ImmediateComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/ImmediateComponentManager.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -21,35 +21,18 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.IdentityHashMap;
import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.ComponentConstants;
import org.osgi.service.component.ComponentContext;
-import org.osgi.service.component.ComponentInstance;
/**
* The default ComponentManager. Objects of this class are responsible for managing
- * implementation object's lifecycle.
+ * implementation object's lifecycle.
*
*/
class ImmediateComponentManager extends AbstractComponentManager
@@ -62,26 +45,26 @@
// The context that will be passed to the implementationObject
private ComponentContext m_componentContext = null;
-
+
// optional properties provided in the ComponentFactory.newInstance method
- private Dictionary m_factoryProperties;
-
+ private Dictionary m_factoryProperties;
+
// the component properties, also used as service properties
- private Dictionary m_properties;
-
+ private Dictionary m_properties;
+
/**
* The constructor receives both the activator and the metadata
- *
+ *
* @param activator
* @param metadata
*/
ImmediateComponentManager(BundleComponentActivator activator, ComponentMetadata metadata, long componentId)
{
super(activator, metadata);
-
- m_componentId = componentId;
+
+ this.m_componentId = componentId;
}
-
+
// 1. Load the component implementation class
// 2. Create the component instance and component context
@@ -92,46 +75,46 @@
protected void createComponent()
{
ComponentContext tmpContext = new ComponentContextImpl( this );
- Object tmpComponent = createImplementationObject( tmpContext );
-
+ Object tmpComponent = this.createImplementationObject( tmpContext );
+
// if something failed craeating the object, we fell back to
// unsatisfied !!
if (tmpComponent != null) {
- m_componentContext = tmpContext;
- m_implementationObject = tmpComponent;
+ this.m_componentContext = tmpContext;
+ this.m_implementationObject = tmpComponent;
}
}
-
+
protected void deleteComponent() {
- disposeImplementationObject( m_implementationObject, m_componentContext );
- m_implementationObject = null;
- m_componentContext = null;
- m_properties = null;
+ this.disposeImplementationObject( this.m_implementationObject, this.m_componentContext );
+ this.m_implementationObject = null;
+ this.m_componentContext = null;
+ this.m_properties = null;
}
//**********************************************************************************************************
-
+
/**
* Get the object that is implementing this descriptor
*
* @return the object that implements the services
*/
public Object getInstance() {
- return m_implementationObject;
+ return this.m_implementationObject;
}
protected Object createImplementationObject(ComponentContext componentContext) {
Object implementationObject;
-
+
// 1. Load the component implementation class
// 2. Create the component instance and component context
// If the component is not immediate, this is not done at this moment
try
{
// 112.4.4 The class is retrieved with the loadClass method of the component's bundle
- Class c = getActivator().getBundleContext().getBundle().loadClass(getComponentMetadata().getImplementationClassName());
-
+ Class c = this.getActivator().getBundleContext().getBundle().loadClass(this.getComponentMetadata().getImplementationClassName());
+
// 112.4.4 The class must be public and have a public constructor without arguments so component instances
// may be created by the SCR with the newInstance method on Class
implementationObject = c.newInstance();
@@ -139,14 +122,14 @@
catch (Exception ex)
{
// failed to instantiate, deactivate the component and return null
- Activator.exception( "Error during instantiation of the implementation object", getComponentMetadata(), ex );
- deactivate();
+ Activator.exception( "Error during instantiation of the implementation object", this.getComponentMetadata(), ex );
+ this.deactivate();
return null;
}
-
-
+
+
// 3. Bind the target services
- Iterator it = getDependencyManagers();
+ Iterator it = this.getDependencyManagers();
while ( it.hasNext() )
{
// if a dependency turned unresolved since the validation check,
@@ -156,12 +139,12 @@
if ( !dm.bind( implementationObject ) )
{
Activator.error( "Cannot create component instance due to failure to bind reference " + dm.getName(),
- getComponentMetadata() );
- deactivate();
+ this.getComponentMetadata() );
+ this.deactivate();
return null;
}
}
-
+
// 4. Call the activate method, if present
// Search for the activate method
try
@@ -174,20 +157,20 @@
catch ( NoSuchMethodException ex )
{
// We can safely ignore this one
- Activator.trace( "activate() method is not implemented", getComponentMetadata() );
+ Activator.trace( "activate() method is not implemented", this.getComponentMetadata() );
}
catch ( IllegalAccessException ex )
{
// Ignored, but should it be logged?
- Activator.trace( "activate() method cannot be called", getComponentMetadata() );
+ Activator.trace( "activate() method cannot be called", this.getComponentMetadata() );
}
catch ( InvocationTargetException ex )
{
// 112.5.8 If the activate method throws an exception, SCR must log an error message
// containing the exception with the Log Service
- Activator.exception( "The activate method has thrown an exception", getComponentMetadata(), ex );
+ Activator.exception( "The activate method has thrown an exception", this.getComponentMetadata(), ex );
}
-
+
return implementationObject;
}
@@ -205,22 +188,22 @@
catch ( NoSuchMethodException ex )
{
// We can safely ignore this one
- Activator.trace( "deactivate() method is not implemented", getComponentMetadata() );
+ Activator.trace( "deactivate() method is not implemented", this.getComponentMetadata() );
}
catch ( IllegalAccessException ex )
{
// Ignored, but should it be logged?
- Activator.trace( "deactivate() method cannot be called", getComponentMetadata() );
+ Activator.trace( "deactivate() method cannot be called", this.getComponentMetadata() );
}
catch ( InvocationTargetException ex )
{
// 112.5.12 If the deactivate method throws an exception, SCR must log an error message
// containing the exception with the Log Service and continue
- Activator.exception( "The deactivate method has thrown an exception", getComponentMetadata(), ex );
+ Activator.exception( "The deactivate method has thrown an exception", this.getComponentMetadata(), ex );
}
// 2. Unbind any bound services
- Iterator it = getDependencyManagers();
+ Iterator it = this.getDependencyManagers();
while ( it.hasNext() )
{
@@ -231,30 +214,30 @@
// 3. Release all references
// nothing to do, we keep no references on per-Bundle services
}
-
+
/**
* Returns the service object to be registered if the service element is
* specified.
* <p>
* Extensions of this class may overwrite this method to return a
* ServiceFactory to register in the case of a delayed or a service
- * factory component.
+ * factory component.
*/
protected Object getService() {
- return m_implementationObject;
+ return this.m_implementationObject;
}
-
+
protected void setFactoryProperties(Dictionary dictionary) {
- m_factoryProperties = copyTo( null, dictionary );
+ this.m_factoryProperties = this.copyTo( null, dictionary );
}
-
+
/**
* Returns the (private copy) of the Component properties to be used
* for the ComponentContext as well as eventual service registration.
* <p>
* Method implements the Component Properties provisioning as described
* in 112.6, Component Properties.
- *
+ *
* @return a private Hashtable of component properties
*/
protected Dictionary getProperties()
@@ -262,40 +245,40 @@
// TODO: Currently on ManagedService style configuration is supported, ManagedServiceFactory style is missing
- if ( m_properties == null )
+ if ( this.m_properties == null )
{
// 1. the properties from the component descriptor
- Dictionary props = copyTo( null, getComponentMetadata().getProperties() );
+ Dictionary props = this.copyTo( null, this.getComponentMetadata().getProperties() );
// 2. overlay with Configuration Admin properties
- ConfigurationAdmin ca = getActivator().getConfigurationAdmin();
+ ConfigurationAdmin ca = this.getActivator().getConfigurationAdmin();
if ( ca != null )
{
try
{
- Configuration cfg = ca.getConfiguration( getComponentMetadata().getName() );
+ Configuration cfg = ca.getConfiguration( this.getComponentMetadata().getName() );
if (cfg != null) {
- copyTo( props, cfg.getProperties() );
+ this.copyTo( props, cfg.getProperties() );
}
}
catch ( IOException ioe )
{
- Activator.exception( "Problem getting Configuration", getComponentMetadata(), ioe );
+ Activator.exception( "Problem getting Configuration", this.getComponentMetadata(), ioe );
}
}
// 3. copy any component factory properties, not supported yet
- copyTo( props, m_factoryProperties );
-
+ this.copyTo( props, this.m_factoryProperties );
+
// 4. set component.name and component.id
- props.put( ComponentConstants.COMPONENT_NAME, getComponentMetadata().getName() );
- props.put( ComponentConstants.COMPONENT_ID, new Long( m_componentId ) );
-
- m_properties = props;
+ props.put( ComponentConstants.COMPONENT_NAME, this.getComponentMetadata().getName() );
+ props.put( ComponentConstants.COMPONENT_ID, new Long( this.m_componentId ) );
+
+ this.m_properties = props;
}
- return m_properties;
+ return this.m_properties;
}
-
+
}