FELIX-4011 genericize stuff, fix a bug in ReadOnlyDictionary
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1463770 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java b/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
index cb802f1..47aad82 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
@@ -35,28 +35,28 @@
* a <code>Map</code> whose modificaiton methods (like {@link #put(Object, Object)},
* {@link #remove(Object)}, etc.) have no effect.
*/
-public class ReadOnlyDictionary extends Dictionary implements Map
+public class ReadOnlyDictionary<S, T> extends Dictionary<S, T> implements Map<S, T>
{
- private final Hashtable m_delegatee;
+ private final Hashtable<S, T> m_delegatee;
/**
* Creates a wrapper for the given delegatee dictionary providing read
* only access to the data.
*/
- public ReadOnlyDictionary( final Dictionary delegatee )
+ public ReadOnlyDictionary( final Dictionary<S, T> delegatee )
{
if ( delegatee instanceof Hashtable )
{
- this.m_delegatee = ( Hashtable ) delegatee;
+ this.m_delegatee = ( Hashtable<S, T> ) delegatee;
}
else
{
- this.m_delegatee = new Hashtable();
- for ( Enumeration ke = delegatee.elements(); ke.hasMoreElements(); )
+ this.m_delegatee = new Hashtable<S, T>();
+ for ( Enumeration<S> ke = delegatee.keys(); ke.hasMoreElements(); )
{
- Object key = ke.nextElement();
+ S key = ke.nextElement();
this.m_delegatee.put( key, delegatee.get( key ) );
}
}
@@ -85,13 +85,12 @@
//---------- Dictionary API
- public Enumeration elements()
+ public Enumeration<T> elements()
{
return m_delegatee.elements();
}
-
- public Object get( final Object key )
+ public T get( final Object key )
{
return m_delegatee.get( key );
}
@@ -103,7 +102,7 @@
}
- public Enumeration keys()
+ public Enumeration<S> keys()
{
return m_delegatee.keys();
}
@@ -113,7 +112,7 @@
* This method has no effect and always returns <code>null</code> as this
* instance is read-only and cannot modify and properties.
*/
- public Object put( final Object key, final Object value )
+ public T put( final S key, final T value )
{
return null;
}
@@ -123,7 +122,7 @@
* This method has no effect and always returns <code>null</code> as this
* instance is read-only and cannot modify and properties.
*/
- public Object remove( final Object key )
+ public T remove( final Object key )
{
return null;
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
index e214400..d629b4a 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
@@ -87,7 +87,7 @@
private final ComponentMethods m_componentMethods;
// The dependency managers that manage every dependency
- private final List<DependencyManager> m_dependencyManagers;
+ private final List<DependencyManager<S, ?>> m_dependencyManagers;
private volatile boolean m_dependencyManagersInitialized;
@@ -669,9 +669,9 @@
}
- final ServiceReference getServiceReference()
+ final ServiceReference<S> getServiceReference()
{
- ServiceRegistration reg = getServiceRegistration();
+ ServiceRegistration<S> reg = getServiceRegistration();
if (reg != null)
{
return reg.getReference();
@@ -961,9 +961,9 @@
}
- private List<DependencyManager> loadDependencyManagers( ComponentMetadata metadata )
+ private List<DependencyManager<S, ?>> loadDependencyManagers( ComponentMetadata metadata )
{
- List<DependencyManager> depMgrList = new ArrayList<DependencyManager>(metadata.getDependencies().size());
+ List<DependencyManager<S, ?>> depMgrList = new ArrayList<DependencyManager<S, ?>>(metadata.getDependencies().size());
// If this component has got dependencies, create dependency managers for each one of them.
if ( metadata.getDependencies().size() != 0 )
@@ -971,7 +971,7 @@
int index = 0;
for ( ReferenceMetadata currentdependency: metadata.getDependencies() )
{
- DependencyManager depmanager = new DependencyManager( this, currentdependency, index++ );
+ DependencyManager<S, ?> depmanager = new DependencyManager( this, currentdependency, index++ );
depMgrList.add( depmanager );
}
@@ -1040,7 +1040,7 @@
* Returns an iterator over the {@link DependencyManager} objects
* representing the declared references in declaration order
*/
- List<DependencyManager> getDependencyManagers()
+ List<DependencyManager<S, ?>> getDependencyManagers()
{
return m_dependencyManagers;
}
@@ -1049,17 +1049,17 @@
* Returns an iterator over the {@link DependencyManager} objects
* representing the declared references in reversed declaration order
*/
- List<DependencyManager> getReversedDependencyManagers()
+ List<DependencyManager<S, ?>> getReversedDependencyManagers()
{
- List list = new ArrayList( m_dependencyManagers );
+ List<DependencyManager<S, ?>> list = new ArrayList<DependencyManager<S, ?>>( m_dependencyManagers );
Collections.reverse( list );
return list;
}
- DependencyManager getDependencyManager(String name)
+ DependencyManager<S, ?> getDependencyManager(String name)
{
- for ( DependencyManager dm: getDependencyManagers() )
+ for ( DependencyManager<S, ?> dm: getDependencyManagers() )
{
if ( name.equals(dm.getName()) )
{
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
index fe1c5ea..34fad5e 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
@@ -34,21 +34,21 @@
* Implementation for the ComponentContext interface
*
*/
-public class ComponentContextImpl implements ExtComponentContext {
+public class ComponentContextImpl<S> implements ExtComponentContext {
- private final AbstractComponentManager m_componentManager;
+ private final AbstractComponentManager<S> m_componentManager;
private final EdgeInfo[] edgeInfos;
private volatile ComponentInstance m_componentInstance;
- ComponentContextImpl( AbstractComponentManager componentManager )
+ ComponentContextImpl( AbstractComponentManager<S> componentManager )
{
m_componentManager = componentManager;
edgeInfos = new EdgeInfo[componentManager.getComponentMetadata().getDependencies().size()];
}
- EdgeInfo getEdgeInfo(DependencyManager dm)
+ EdgeInfo getEdgeInfo(DependencyManager<S, ?> dm)
{
int index = dm.getIndex();
if (edgeInfos[index] == null)
@@ -63,29 +63,29 @@
Arrays.fill( edgeInfos, null );
}
- protected AbstractComponentManager getComponentManager()
+ protected AbstractComponentManager<S> getComponentManager()
{
return m_componentManager;
}
- public final Dictionary getProperties()
+ public final Dictionary<String, Object> getProperties()
{
// 112.12.3.5 The Dictionary is read-only and cannot be modified
- Dictionary ctxProperties = m_componentManager.getProperties();
- return new ReadOnlyDictionary( ctxProperties );
+ Dictionary<String, Object> ctxProperties = m_componentManager.getProperties();
+ return new ReadOnlyDictionary<String, Object>( ctxProperties );
}
public Object locateService( String name )
{
- DependencyManager dm = m_componentManager.getDependencyManager( name );
+ DependencyManager<S, ?> dm = m_componentManager.getDependencyManager( name );
return ( dm != null ) ? dm.getService() : null;
}
public Object locateService( String name, ServiceReference ref )
{
- DependencyManager dm = m_componentManager.getDependencyManager( name );
+ DependencyManager<S, ?> dm = m_componentManager.getDependencyManager( name );
return ( dm != null ) ? dm.getService( ref ) : null;
}
@@ -127,7 +127,7 @@
}
- public ServiceReference getServiceReference()
+ public ServiceReference<S> getServiceReference()
{
return m_componentManager.getServiceReference();
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
index 57c7af7..54b60bf 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
@@ -59,7 +59,7 @@
private final AtomicInteger m_useCount = new AtomicInteger( );
// The context that will be passed to the implementationObject
- private final ComponentContextImpl m_componentContext = new ComponentContextImpl(this);
+ private final ComponentContextImpl<S> m_componentContext = new ComponentContextImpl<S>(this);
// the component holder responsible for managing this component
private ComponentHolder m_componentHolder;