You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2017/02/01 14:26:32 UTC
svn commit: r1781251 - in
/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject:
BindParameters.java ValueUtils.java methods/BindMethod.java
Author: cziegeler
Date: Wed Feb 1 14:26:32 2017
New Revision: 1781251
URL: http://svn.apache.org/viewvc?rev=1781251&view=rev
Log:
FELIX--5457 : Logger Support. Refactor bind methods to use ValueUtils
Modified:
felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/BindParameters.java
felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/ValueUtils.java
felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/methods/BindMethod.java
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/BindParameters.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/BindParameters.java?rev=1781251&r1=1781250&r2=1781251&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/BindParameters.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/BindParameters.java Wed Feb 1 14:26:32 2017
@@ -25,7 +25,7 @@ import org.osgi.framework.BundleContext;
public class BindParameters
{
-
+
private final ComponentContextImpl<?> componentContext;
private final RefPair<?, ?> refPair;
public BindParameters(ComponentContextImpl<?> componentContext, RefPair<?, ?> refPair)
@@ -33,17 +33,17 @@ public class BindParameters
this.componentContext = componentContext;
this.refPair = refPair;
}
-
- public ComponentContextImpl getComponentContext()
+
+ public ComponentContextImpl<?> getComponentContext()
{
return componentContext;
}
-
+
public RefPair getRefPair()
{
return refPair;
}
-
+
public Object getServiceObject() {
return refPair.getServiceObject((ComponentContextImpl) componentContext);
}
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/ValueUtils.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/ValueUtils.java?rev=1781251&r1=1781250&r2=1781251&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/ValueUtils.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/ValueUtils.java Wed Feb 1 14:26:32 2017
@@ -35,28 +35,35 @@ import org.osgi.service.log.LogService;
*/
public class ValueUtils {
- /**
- * The value type of the field, activation field or constructor parameter
- */
- public enum ValueType
+ private static final String LOGGER_CLASS = "org.osgi.service.log.Logger";
+ private static final String FORMATTER_LOGGER_CLASS = "org.osgi.service.log.FormatterLogger";
+
+ /**
+ * The value type of the field, activation field or constructor parameter
+ */
+ public enum ValueType
{
ignore,
- componentContext,
- bundleContext,
- config_map,
- config_annotation,
- ref_serviceReference,
- ref_serviceObjects,
- ref_serviceType,
- ref_map,
- ref_tuple
+ componentContext, // field activation, constructor
+ bundleContext, // field activation, constructor
+ config_map, // field activation, constructor
+ config_annotation, // field activation, constructor
+ logger, // TODO
+ formatterLogger, // TODO
+ ref_serviceReference, // reference (field, constructor, method)
+ ref_serviceObjects, // reference (field, constructor, method)
+ ref_serviceType, // reference (field, constructor, method)
+ ref_map, // reference (field, constructor, method)
+ ref_tuple // reference (field, constructor ??)
}
-
+
/** Empty array. */
- public static final ValueType[] EMPTY_VALUE_TYPES = new ValueType[0];
+ public static final ValueType[] EMPTY_VALUE_TYPES = new ValueType[0];
/**
* Get the value type for the parameter class.
+ * This method is used for field activation and constructor injection.
+ *
* @param typeClass The class of the parameter
* @return The value type
*/
@@ -64,24 +71,32 @@ public class ValueUtils {
{
if ( typeClass == ClassUtils.COMPONENT_CONTEXT_CLASS )
{
- return ValueType.componentContext;
+ return ValueType.componentContext;
}
else if ( typeClass == ClassUtils.BUNDLE_CONTEXT_CLASS )
{
- return ValueType.bundleContext;
+ return ValueType.bundleContext;
}
else if ( typeClass == ClassUtils.MAP_CLASS )
{
- return ValueType.config_map;
+ return ValueType.config_map;
+ }
+ else if ( typeClass.getName().equals(LOGGER_CLASS) )
+ {
+ return ValueType.logger;
+ }
+ else if ( typeClass.getName().equals(FORMATTER_LOGGER_CLASS) )
+ {
+ return ValueType.formatterLogger;
}
else
{
- return ValueType.config_annotation;
+ return ValueType.config_annotation;
}
}
/**
- * Get the value type of the reference
+ * Get the value type of the reference for a field/constructor
* @param componentClass The component class declaring the reference
* @param metadata The reference metadata
* @param typeClass The type of the field/parameter
@@ -89,18 +104,18 @@ public class ValueUtils {
* @param logger The logger
* @return The value type for the field. If invalid, {@code ValueType#ignore}
*/
- public static ValueType getReferenceValueType(
- final Class<?> componentClass,
- final ReferenceMetadata metadata,
- final Class<?> typeClass,
- final Field field,
- final SimpleLogger logger )
+ public static ValueType getReferenceValueType(
+ final Class<?> componentClass,
+ final ReferenceMetadata metadata,
+ final Class<?> typeClass,
+ final Field field,
+ final SimpleLogger logger )
{
final Class<?> referenceType = ClassUtils.getClassFromComponentClassLoader(
componentClass, metadata.getInterface(), logger);
ValueType valueType = ValueType.ignore;
-
+
// unary reference
if ( !metadata.isMultiple() )
{
@@ -126,16 +141,16 @@ public class ValueUtils {
}
else
{
- if ( field != null )
- {
- logger.log( LogService.LOG_ERROR, "Field {0} in component {1} has unsupported type {2}", new Object[]
- {metadata.getField(), componentClass, typeClass.getName()}, null );
- }
- else
- {
- logger.log( LogService.LOG_ERROR, "Constructor argument {0} in component {1} has unsupported type {2}", new Object[]
- {metadata.getParameterIndex(), componentClass, typeClass.getName()}, null );
- }
+ if ( field != null )
+ {
+ logger.log( LogService.LOG_ERROR, "Field {0} in component {1} has unsupported type {2}", new Object[]
+ {metadata.getField(), componentClass, typeClass.getName()}, null );
+ }
+ else
+ {
+ logger.log( LogService.LOG_ERROR, "Constructor argument {0} in component {1} has unsupported type {2}", new Object[]
+ {metadata.getParameterIndex(), componentClass, typeClass.getName()}, null );
+ }
valueType = ValueType.ignore;
}
@@ -180,16 +195,16 @@ public class ValueUtils {
// multiple cardinality, field type must be collection or subtype
if ( !ClassUtils.COLLECTION_CLASS.isAssignableFrom(typeClass) )
{
- if ( field != null )
- {
- logger.log( LogService.LOG_ERROR, "Field {0} in component {1} has unsupported type {2}", new Object[]
- {metadata.getField(), componentClass, typeClass.getName()}, null );
- }
- else
- {
+ if ( field != null )
+ {
+ logger.log( LogService.LOG_ERROR, "Field {0} in component {1} has unsupported type {2}", new Object[]
+ {metadata.getField(), componentClass, typeClass.getName()}, null );
+ }
+ else
+ {
logger.log( LogService.LOG_ERROR, "Constructor argument {0} in component {1} has unsupported type {2}", new Object[]
- {metadata.getParameterIndex(), componentClass, typeClass.getName()}, null );
- }
+ {metadata.getParameterIndex(), componentClass, typeClass.getName()}, null );
+ }
valueType = ValueType.ignore;
}
@@ -209,8 +224,8 @@ public class ValueUtils {
if ( typeClass != ClassUtils.LIST_CLASS && typeClass != ClassUtils.COLLECTION_CLASS )
{
logger.log( LogService.LOG_ERROR, "Field {0} in component {1} has unsupported type {2}."+
- " It must be one of java.util.Collection or java.util.List.",
- new Object[] {metadata.getField(), componentClass, typeClass.getName()}, null );
+ " It must be one of java.util.Collection or java.util.List.",
+ new Object[] {metadata.getField(), componentClass, typeClass.getName()}, null );
valueType = ValueType.ignore;
}
@@ -233,38 +248,42 @@ public class ValueUtils {
}
/**
- * Get the value for the parameter type
- * @param type The parameter type
+ * Get the value for the value type
+ * @param type The value type
+ * @param targetType Optional target type, only required for type {@code ValueType#config_annotation}.
* @param componentContext The component context
+ * @param refPair The ref pair
+ * @return The value or {@code null}.
*/
@SuppressWarnings("unchecked")
- public static Object getValue( final ValueType type,
- final Class<?> targetType,
- @SuppressWarnings("rawtypes") final ComponentContextImpl componentContext,
- final RefPair<?, ?> refPair)
+ public static Object getValue( final ValueType type,
+ final Class<?> targetType,
+ @SuppressWarnings("rawtypes") final ComponentContextImpl componentContext,
+ final RefPair<?, ?> refPair)
{
- final Object value;
- switch ( type ) {
- case ignore : value = null; break;
- case componentContext : value = componentContext; break;
- case bundleContext : value = componentContext.getBundleContext(); break;
- case config_map : // note: getProperties() returns a ReadOnlyDictionary which is a Map
- value = componentContext.getProperties(); break;
- case config_annotation : value = Annotations.toObject(targetType,
- (Map<String, Object>) componentContext.getProperties(),
- componentContext.getBundleContext().getBundle(), componentContext.getComponentMetadata().isConfigureWithInterfaces());
- break;
- case ref_serviceType : value = refPair.getServiceObject(componentContext); break;
- case ref_serviceReference : value = refPair.getRef(); break;
- case ref_serviceObjects : value = componentContext.getComponentServiceObjectsHelper().getServiceObjects(refPair.getRef()); break;
- case ref_map : value = new ReadOnlyDictionary( refPair.getRef() ); break;
- case ref_tuple : final Object tupleKey = new ReadOnlyDictionary( refPair.getRef() );
- final Object tupleValue = refPair.getServiceObject(componentContext);
- value = new MapEntryImpl(tupleKey, tupleValue, refPair.getRef());
- break;
+ final Object value;
+ switch ( type )
+ {
+ case ignore : value = null; break;
+ case componentContext : value = componentContext; break;
+ case bundleContext : value = componentContext.getBundleContext(); break;
+ case config_map : // note: getProperties() returns a ReadOnlyDictionary which is a Map
+ value = componentContext.getProperties(); break;
+ case config_annotation : value = Annotations.toObject(targetType,
+ (Map<String, Object>) componentContext.getProperties(),
+ componentContext.getBundleContext().getBundle(), componentContext.getComponentMetadata().isConfigureWithInterfaces());
+ break;
+ case ref_serviceType : value = refPair.getServiceObject(componentContext); break;
+ case ref_serviceReference : value = refPair.getRef(); break;
+ case ref_serviceObjects : value = componentContext.getComponentServiceObjectsHelper().getServiceObjects(refPair.getRef()); break;
+ case ref_map : value = new ReadOnlyDictionary( refPair.getRef() ); break;
+ case ref_tuple : final Object tupleKey = new ReadOnlyDictionary( refPair.getRef() );
+ final Object tupleValue = refPair.getServiceObject(componentContext);
+ value = new MapEntryImpl(tupleKey, tupleValue, refPair.getRef());
+ break;
default: value = null;
- }
- return value;
+ }
+ return value;
}
/**
@@ -287,21 +306,25 @@ public class ValueUtils {
this.ref = ref;
}
+ @Override
public Object getKey()
{
return this.key;
}
+ @Override
public Object getValue()
{
return this.value;
}
+ @Override
public Object setValue(final Object value)
{
throw new UnsupportedOperationException();
}
+ @Override
public int compareTo(final Map.Entry<?, ?> o)
{
if ( o == null )
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/methods/BindMethod.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/methods/BindMethod.java?rev=1781251&r1=1781250&r2=1781251&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/methods/BindMethod.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/methods/BindMethod.java Wed Feb 1 14:26:32 2017
@@ -26,10 +26,10 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
-import org.apache.felix.scr.impl.helper.ReadOnlyDictionary;
import org.apache.felix.scr.impl.helper.SimpleLogger;
import org.apache.felix.scr.impl.inject.BindParameters;
import org.apache.felix.scr.impl.inject.ClassUtils;
+import org.apache.felix.scr.impl.inject.ValueUtils;
import org.apache.felix.scr.impl.manager.ComponentContextImpl;
import org.apache.felix.scr.impl.manager.RefPair;
import org.apache.felix.scr.impl.metadata.DSVersion;
@@ -46,15 +46,8 @@ implements org.apache.felix.scr.impl.inj
{
private final String m_referenceClassName;
- private enum ParamType {
- serviceReference,
- serviceObjects,
- serviceType,
- map
- }
-
//initialized for cases where there is no method.
- private volatile List<ParamType> m_paramTypes = Collections.emptyList();
+ private volatile List<ValueUtils.ValueType> m_paramTypes = Collections.emptyList();
public BindMethod( final String methodName,
@@ -85,10 +78,10 @@ implements org.apache.felix.scr.impl.inj
*/
@Override
protected Method doFindMethod( final Class<?> targetClass,
- final boolean acceptPrivate,
- final boolean acceptPackage,
- final SimpleLogger logger )
- throws SuitableMethodNotAccessibleException, InvocationTargetException
+ final boolean acceptPrivate,
+ final boolean acceptPackage,
+ final SimpleLogger logger )
+ throws SuitableMethodNotAccessibleException, InvocationTargetException
{
// 112.3.1 The method is searched for using the following priority
// 1 - ServiceReference single parameter
@@ -98,15 +91,15 @@ implements org.apache.felix.scr.impl.inj
// 5 - DS 1.3+ : Single argument with Map
// 6 - DS 1.1/DS 1.2 : two parameters, first the type of or assignment compatible with the service, the second Map
// 7 - DS 1.3+ : one or more parameters of types ServiceReference, ServiceObjects, interface type,
- // or assignment compatible to interface type, in any order.
+ // or assignment compatible to interface type, in any order.
- // flag indicating a suitable but inaccessible method has been found
+ // flag indicating a suitable but inaccessible method has been found
boolean suitableMethodNotAccessible = false;
if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
{
logger.log( LogService.LOG_DEBUG,
- "doFindMethod: Looking for method " + targetClass.getName() + "." + getMethodName(), null );
+ "doFindMethod: Looking for method " + targetClass.getName() + "." + getMethodName(), null );
}
// Case 1 - Service reference parameter
@@ -120,7 +113,7 @@ implements org.apache.felix.scr.impl.inj
{
logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
}
- m_paramTypes = Collections.singletonList(ParamType.serviceReference);
+ m_paramTypes = Collections.singletonList(ValueUtils.ValueType.ref_serviceReference);
return method;
}
}
@@ -132,23 +125,23 @@ implements org.apache.felix.scr.impl.inj
// Case 2 - ComponentServiceObjects parameter
if ( getDSVersion().isDS13() )
{
- try
- {
- method = getComponentObjectsMethod( targetClass, acceptPrivate, acceptPackage, logger );
- if ( method != null )
- {
- if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
- {
- logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
- }
- m_paramTypes = Collections.singletonList(ParamType.serviceObjects);
- return method;
- }
- }
- catch ( SuitableMethodNotAccessibleException ex )
- {
- suitableMethodNotAccessible = true;
- }
+ try
+ {
+ method = getComponentObjectsMethod( targetClass, acceptPrivate, acceptPackage, logger );
+ if ( method != null )
+ {
+ if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
+ {
+ logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
+ }
+ m_paramTypes = Collections.singletonList(ValueUtils.ValueType.ref_serviceObjects);
+ return method;
+ }
+ }
+ catch ( SuitableMethodNotAccessibleException ex )
+ {
+ suitableMethodNotAccessible = true;
+ }
}
// for further methods we need the class of the service object
@@ -159,9 +152,9 @@ implements org.apache.felix.scr.impl.inj
if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
{
logger.log(
- LogService.LOG_DEBUG,
- "doFindMethod: No method taking ServiceReference found, checking method taking "
- + parameterClass.getName(), null );
+ LogService.LOG_DEBUG,
+ "doFindMethod: No method taking ServiceReference found, checking method taking "
+ + parameterClass.getName(), null );
}
// Case 3 - Service object parameter
@@ -170,11 +163,11 @@ implements org.apache.felix.scr.impl.inj
method = getServiceObjectMethod( targetClass, parameterClass, acceptPrivate, acceptPackage, logger );
if ( method != null )
{
- if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
- {
- logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
- }
- m_paramTypes = Collections.singletonList(ParamType.serviceType);
+ if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
+ {
+ logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
+ }
+ m_paramTypes = Collections.singletonList(ValueUtils.ValueType.ref_serviceType);
return method;
}
}
@@ -189,11 +182,11 @@ implements org.apache.felix.scr.impl.inj
method = getServiceObjectAssignableMethod( targetClass, parameterClass, acceptPrivate, acceptPackage, logger );
if ( method != null )
{
- if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
- {
- logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
- }
- m_paramTypes = Collections.singletonList(ParamType.serviceType);
+ if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
+ {
+ logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
+ }
+ m_paramTypes = Collections.singletonList(ValueUtils.ValueType.ref_serviceType);
return method;
}
}
@@ -210,11 +203,11 @@ implements org.apache.felix.scr.impl.inj
method = getMapMethod( targetClass, parameterClass, acceptPrivate, acceptPackage, logger );
if ( method != null )
{
- if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
- {
- logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
- }
- m_paramTypes = Collections.singletonList(ParamType.map);
+ if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
+ {
+ logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
+ }
+ m_paramTypes = Collections.singletonList(ValueUtils.ValueType.ref_map);
return method;
}
}
@@ -234,13 +227,13 @@ implements org.apache.felix.scr.impl.inj
method = getServiceObjectWithMapMethod( targetClass, parameterClass, acceptPrivate, acceptPackage, logger );
if ( method != null )
{
- if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
- {
- logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
- }
- List<ParamType> paramTypes = new ArrayList<ParamType>(2);
- paramTypes.add(ParamType.serviceType);
- paramTypes.add(ParamType.map);
+ if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
+ {
+ logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
+ }
+ List<ValueUtils.ValueType> paramTypes = new ArrayList<ValueUtils.ValueType>(2);
+ paramTypes.add(ValueUtils.ValueType.ref_serviceType);
+ paramTypes.add(ValueUtils.ValueType.ref_map);
m_paramTypes = paramTypes;
return method;
}
@@ -254,16 +247,16 @@ implements org.apache.felix.scr.impl.inj
try
{
method = getServiceObjectAssignableWithMapMethod( targetClass, parameterClass, acceptPrivate,
- acceptPackage );
+ acceptPackage );
if ( method != null )
{
- if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
- {
- logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
- }
- List<ParamType> paramTypes = new ArrayList<ParamType>(2);
- paramTypes.add(ParamType.serviceType);
- paramTypes.add(ParamType.map);
+ if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
+ {
+ logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + method, null );
+ }
+ List<ValueUtils.ValueType> paramTypes = new ArrayList<ValueUtils.ValueType>(2);
+ paramTypes.add(ValueUtils.ValueType.ref_serviceType);
+ paramTypes.add(ValueUtils.ValueType.ref_map);
m_paramTypes = paramTypes;
return method;
}
@@ -283,18 +276,18 @@ implements org.apache.felix.scr.impl.inj
Class<?>[] parameterTypes = m.getParameterTypes();
boolean matches = true;
boolean specialMatch = true;
- List<ParamType> paramTypes = new ArrayList<ParamType>(parameterTypes.length);
+ List<ValueUtils.ValueType> paramTypes = new ArrayList<ValueUtils.ValueType>(parameterTypes.length);
for (Class<?> paramType: parameterTypes) {
if (paramType == ClassUtils.SERVICE_REFERENCE_CLASS)
{
if (specialMatch && parameterClass == ClassUtils.SERVICE_REFERENCE_CLASS)
{
specialMatch = false;
- paramTypes.add(ParamType.serviceType);
+ paramTypes.add(ValueUtils.ValueType.ref_serviceType);
}
else
{
- paramTypes.add(ParamType.serviceReference);
+ paramTypes.add(ValueUtils.ValueType.ref_serviceReference);
}
}
else if (paramType == ClassUtils.COMPONENTS_SERVICE_OBJECTS_CLASS)
@@ -302,11 +295,11 @@ implements org.apache.felix.scr.impl.inj
if (specialMatch && parameterClass == ClassUtils.COMPONENTS_SERVICE_OBJECTS_CLASS)
{
specialMatch = false;
- paramTypes.add(ParamType.serviceType);
+ paramTypes.add(ValueUtils.ValueType.ref_serviceType);
}
else
{
- paramTypes.add(ParamType.serviceObjects);
+ paramTypes.add(ValueUtils.ValueType.ref_serviceObjects);
}
}
else if (paramType == Map.class)
@@ -314,16 +307,16 @@ implements org.apache.felix.scr.impl.inj
if (specialMatch && parameterClass == Map.class)
{
specialMatch = false;
- paramTypes.add(ParamType.serviceType);
+ paramTypes.add(ValueUtils.ValueType.ref_serviceType);
}
else
{
- paramTypes.add(ParamType.map);
+ paramTypes.add(ValueUtils.ValueType.ref_map);
}
}
else if (paramType.isAssignableFrom( parameterClass ) )
{
- paramTypes.add(ParamType.serviceType);
+ paramTypes.add(ValueUtils.ValueType.ref_serviceType);
}
else
{
@@ -335,10 +328,10 @@ implements org.apache.felix.scr.impl.inj
{
if ( accept( m, acceptPrivate, acceptPackage, returnValue() ) )
{
- if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
- {
- logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + m, null );
- }
+ if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
+ {
+ logger.log( LogService.LOG_DEBUG, "doFindMethod: Found Method " + m, null );
+ }
m_paramTypes = paramTypes;
return m;
}
@@ -351,9 +344,9 @@ implements org.apache.felix.scr.impl.inj
else if ( logger.isLogEnabled( LogService.LOG_WARNING ) )
{
logger.log(
- LogService.LOG_WARNING,
- "doFindMethod: Cannot check for methods taking parameter class " + m_referenceClassName + ": "
- + targetClass.getName() + " does not see it", null );
+ LogService.LOG_WARNING,
+ "doFindMethod: Cannot check for methods taking parameter class " + m_referenceClassName + ": "
+ + targetClass.getName() + " does not see it", null );
}
// if at least one suitable method could be found but none of
@@ -361,8 +354,8 @@ implements org.apache.felix.scr.impl.inj
if ( suitableMethodNotAccessible )
{
logger.log( LogService.LOG_ERROR,
- "doFindMethod: Suitable but non-accessible method found in class {0}", new Object[]
- { targetClass.getName() }, null );
+ "doFindMethod: Suitable but non-accessible method found in class {0}", new Object[]
+ { targetClass.getName() }, null );
throw new SuitableMethodNotAccessibleException();
}
@@ -390,18 +383,18 @@ implements org.apache.felix.scr.impl.inj
* trying to find the requested method.
*/
private Method getServiceReferenceMethod( final Class<?> targetClass, boolean acceptPrivate, boolean acceptPackage, SimpleLogger logger )
- throws SuitableMethodNotAccessibleException, InvocationTargetException
+ throws SuitableMethodNotAccessibleException, InvocationTargetException
{
return getMethod( targetClass, getMethodName(), new Class[]
- { ClassUtils.SERVICE_REFERENCE_CLASS }, acceptPrivate, acceptPackage, logger );
+ { ClassUtils.SERVICE_REFERENCE_CLASS }, acceptPrivate, acceptPackage, logger );
}
private Method getComponentObjectsMethod( final Class<?> targetClass, boolean acceptPrivate, boolean acceptPackage, SimpleLogger logger )
- throws SuitableMethodNotAccessibleException, InvocationTargetException
+ throws SuitableMethodNotAccessibleException, InvocationTargetException
{
return getMethod(targetClass, getMethodName(),
- new Class[] { ClassUtils.COMPONENTS_SERVICE_OBJECTS_CLASS }, acceptPrivate, acceptPackage,
- logger);
+ new Class[] { ClassUtils.COMPONENTS_SERVICE_OBJECTS_CLASS }, acceptPrivate, acceptPackage,
+ logger);
}
@@ -428,7 +421,7 @@ implements org.apache.felix.scr.impl.inj
boolean acceptPackage, SimpleLogger logger ) throws SuitableMethodNotAccessibleException, InvocationTargetException
{
return getMethod( targetClass, getMethodName(), new Class[]
- { parameterClass }, acceptPrivate, acceptPackage, logger );
+ { parameterClass }, acceptPrivate, acceptPackage, logger );
}
@@ -460,8 +453,8 @@ implements org.apache.felix.scr.impl.inj
if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
{
logger.log(
- LogService.LOG_DEBUG,
- "getServiceObjectAssignableMethod: Checking " + candidateBindMethods.length
+ LogService.LOG_DEBUG,
+ "getServiceObjectAssignableMethod: Checking " + candidateBindMethods.length
+ " declared method in class " + targetClass.getName(), null );
}
@@ -507,9 +500,9 @@ implements org.apache.felix.scr.impl.inj
else if ( logger.isLogEnabled( LogService.LOG_DEBUG ) )
{
logger.log(
- LogService.LOG_DEBUG,
- "getServiceObjectAssignableMethod: Parameter failure: Required " + theParameter + "; actual "
- + parameterClass.getName(), null );
+ LogService.LOG_DEBUG,
+ "getServiceObjectAssignableMethod: Parameter failure: Required " + theParameter + "; actual "
+ + parameterClass.getName(), null );
}
}
@@ -549,10 +542,10 @@ implements org.apache.felix.scr.impl.inj
*/
private Method getServiceObjectWithMapMethod( final Class<?> targetClass, final Class<?> parameterClass,
boolean acceptPrivate, boolean acceptPackage, SimpleLogger logger ) throws SuitableMethodNotAccessibleException,
- InvocationTargetException
+ InvocationTargetException
{
return getMethod( targetClass, getMethodName(), new Class[]
- { parameterClass, ClassUtils.MAP_CLASS }, acceptPrivate, acceptPackage, logger );
+ { parameterClass, ClassUtils.MAP_CLASS }, acceptPrivate, acceptPackage, logger );
}
@@ -574,7 +567,7 @@ implements org.apache.felix.scr.impl.inj
* found which is not accessible
*/
private Method getServiceObjectAssignableWithMapMethod( final Class<?> targetClass, final Class<?> parameterClass,
- boolean acceptPrivate, boolean acceptPackage ) throws SuitableMethodNotAccessibleException
+ boolean acceptPrivate, boolean acceptPackage ) throws SuitableMethodNotAccessibleException
{
// Get all potential bind methods
Method candidateBindMethods[] = targetClass.getDeclaredMethods();
@@ -634,18 +627,19 @@ implements org.apache.felix.scr.impl.inj
*/
private Method getMapMethod( final Class<?> targetClass, final Class<?> parameterClass,
boolean acceptPrivate, boolean acceptPackage, SimpleLogger logger ) throws SuitableMethodNotAccessibleException,
- InvocationTargetException
+ InvocationTargetException
{
return getMethod( targetClass, getMethodName(), new Class[]
- { ClassUtils.MAP_CLASS }, acceptPrivate, acceptPackage, logger );
+ { ClassUtils.MAP_CLASS }, acceptPrivate, acceptPackage, logger );
}
+ @Override
public <S, T> boolean getServiceObject( final BindParameters parameters, BundleContext context, SimpleLogger logger )
{
//??? this resolves which we need.... better way?
if ( parameters.getServiceObject() == null && methodExists( logger ) )
{
- if ( m_paramTypes.contains(ParamType.serviceType) ) {
+ if ( m_paramTypes.contains(ValueUtils.ValueType.ref_serviceType) ) {
return parameters.getServiceObject(context, logger);
}
}
@@ -655,31 +649,13 @@ implements org.apache.felix.scr.impl.inj
@Override
protected Object[] getParameters( Method method, BindParameters bp )
{
- ComponentContextImpl key = bp.getComponentContext();
+ ComponentContextImpl<?> key = bp.getComponentContext();
Object[] result = new Object[ m_paramTypes.size()];
RefPair<?, ?> refPair = bp.getRefPair();
int i = 0;
- for ( ParamType pt: m_paramTypes ) {
- switch (pt) {
- case serviceReference:
- result[i++] = refPair.getRef();
- break;
-
- case serviceObjects:
- result[i++] = bp.getComponentContext().getComponentServiceObjectsHelper().getServiceObjects(refPair.getRef());
- break;
-
- case map:
- result[i++] = new ReadOnlyDictionary( refPair.getRef() );
- break;
-
- case serviceType:
- result[i++] = refPair.getServiceObject(key);
- break;
-
- default: throw new IllegalStateException("unexpected ParamType: " + pt);
-
- }
+ for ( ValueUtils.ValueType pt: m_paramTypes )
+ {
+ result[i++] = ValueUtils.getValue(pt, null, key, refPair);
}
return result;
}