use of org.apache.felix.scr.impl.helper.ReadOnlyDictionary in project felix by apache.
the class BindMethod method getParameters.
@Override
protected Object[] getParameters(Method method, BindParameters bp) {
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);
}
}
return result;
}
use of org.apache.felix.scr.impl.helper.ReadOnlyDictionary in project felix by apache.
the class ValueUtils method getValue.
/**
* Get the value for the value type
* @param componentType The class of the component
* @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 String componentType, 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 // note: getProperties() returns a ReadOnlyDictionary which is a Map
config_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;
case ref_logger:
case ref_formatterLogger:
value = getLogger(componentType, targetType, componentContext, refPair);
break;
default:
value = null;
}
return value;
}
use of org.apache.felix.scr.impl.helper.ReadOnlyDictionary in project felix by apache.
the class FieldHandler method getValue.
private Object getValue(final ComponentContextImpl key, final RefPair<?, ?> refPair) {
final Object obj;
switch(this.valueType) {
case serviceType:
obj = refPair.getServiceObject(key);
break;
case serviceReference:
obj = refPair.getRef();
break;
case serviceObjects:
obj = key.getComponentServiceObjectsHelper().getServiceObjects(refPair.getRef());
break;
case map:
obj = new ReadOnlyDictionary(refPair.getRef());
break;
case tuple:
final Object tupleKey = new ReadOnlyDictionary(refPair.getRef());
final Object tupleValue = refPair.getServiceObject(key);
obj = new MapEntryImpl(tupleKey, tupleValue, refPair.getRef());
break;
default:
obj = null;
}
return obj;
}
Aggregations