use of org.apache.felix.scr.impl.manager.ComponentContextImpl in project felix by apache.
the class FieldHandler method updateField.
private MethodResult updateField(final METHOD_TYPE mType, final Object componentInstance, final BindParameters bp, final SimpleLogger logger) throws InvocationTargetException {
final ComponentContextImpl key = bp.getComponentContext();
final RefPair<?, ?> refPair = bp.getRefPair();
if (!this.metadata.isMultiple()) {
// unbind needs only be done, if reference is dynamic and optional
if (mType == METHOD_TYPE.UNBIND) {
if (this.metadata.isOptional() && !this.metadata.isStatic()) {
// we only reset if it was previously set with this value
if (bp.getComponentContext().getBoundValues(metadata.getName()).size() == 1) {
this.setFieldValue(componentInstance, null);
}
}
bp.getComponentContext().getBoundValues(metadata.getName()).remove(refPair);
} else // for a static reference we need a reactivation
if (mType == METHOD_TYPE.UPDATED) {
if (this.valueType == ParamType.map || this.valueType == ParamType.tuple) {
if (this.metadata.isStatic()) {
return MethodResult.REACTIVATE;
}
final Object obj = getValue(key, refPair);
this.setFieldValue(componentInstance, obj);
bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair, obj);
}
} else // bind needs always be done
{
final Object obj = getValue(key, refPair);
this.setFieldValue(componentInstance, obj);
bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair, obj);
}
} else {
// bind: replace or update the field
if (mType == METHOD_TYPE.BIND) {
final Object obj = getValue(key, refPair);
bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair, obj);
if (metadata.isReplace()) {
this.setFieldValue(componentInstance, getReplaceCollection(bp));
} else {
@SuppressWarnings("unchecked") final Collection<Object> col = (Collection<Object>) this.getFieldValue(componentInstance);
col.add(obj);
}
} else // unbind needs only be done, if reference is dynamic
if (mType == METHOD_TYPE.UNBIND) {
if (!metadata.isStatic()) {
final Object obj = bp.getComponentContext().getBoundValues(metadata.getName()).remove(refPair);
if (metadata.isReplace()) {
this.setFieldValue(componentInstance, getReplaceCollection(bp));
} else {
@SuppressWarnings("unchecked") final Collection<Object> col = (Collection<Object>) this.getFieldValue(componentInstance);
col.remove(obj);
}
}
} else // updated needs only be done, if the value type is map or tuple
if (mType == METHOD_TYPE.UPDATED) {
if (this.valueType == ParamType.map || this.valueType == ParamType.tuple) {
if (!this.metadata.isStatic()) {
final Object obj = getValue(key, refPair);
final Object oldObj = bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair, obj);
if (metadata.isReplace()) {
this.setFieldValue(componentInstance, getReplaceCollection(bp));
} else {
@SuppressWarnings("unchecked") final Collection<Object> col = (Collection<Object>) this.getFieldValue(componentInstance);
col.add(obj);
col.remove(oldObj);
}
} else {
// if it's static we need to reactivate
return MethodResult.REACTIVATE;
}
}
}
}
return MethodResult.VOID;
}
Aggregations