/** {@inheritDoc} */ public void uninject() { final ThreadLocalValue<Object> injectedValue = Values.injectedValue(); final ThreadLocalValue<Object> thisValue = Values.thisValue(); final Value<?> oldTarget = injectedValue.getAndSetValue(this.injectedValue); try { final Value<?> oldThis = thisValue.getAndSetValue(targetValue); try { method.invoke(targetValue.getValue(), Values.getValues(parameterList)); } catch (Throwable t) { InjectorLogger.INSTANCE.uninjectFailed(t, method); } finally { thisValue.setValue(oldThis); } } finally { injectedValue.setValue(oldTarget); } } }
/** {@inheritDoc} */ public void uninject() { final ThreadLocalValue<Object> injectedValue = Values.injectedValue(); final ThreadLocalValue<Object> thisValue = Values.thisValue(); final Value<?> oldTarget = injectedValue.getAndSetValue(this.injectedValue); try { final Value<?> oldThis = thisValue.getAndSetValue(targetValue); try { method.invoke(targetValue.getValue(), Values.getValues(parameterList)); } catch (Throwable t) { InjectorLogger.INSTANCE.uninjectFailed(t, method); } finally { thisValue.setValue(oldThis); } } finally { injectedValue.setValue(oldTarget); } } }
/** {@inheritDoc} */ @SuppressWarnings({ "unchecked" }) public T getValue() throws IllegalStateException { final ThreadLocalValue<Object> thisValue = Values.thisValue(); final Value<?> targetValue = this.targetValue; try { final Value<?> old = thisValue.getAndSetValue(targetValue); try { return (T) methodValue.getValue().invoke(targetValue.getValue(), Values.getValues(parameters)); } finally { thisValue.setValue(old); } } catch (IllegalAccessException e) { throw new IllegalStateException("Method is not accessible", e); } catch (InvocationTargetException e) { throw new IllegalStateException("Failed to invoke method", e); } } }
/** {@inheritDoc} */ @SuppressWarnings({ "unchecked" }) public T getValue() throws IllegalStateException { final ThreadLocalValue<Object> thisValue = Values.thisValue(); final Value<?> targetValue = this.targetValue; try { final Value<?> old = thisValue.getAndSetValue(targetValue); try { return (T) methodValue.getValue().invoke(targetValue.getValue(), Values.getValues(parameters)); } finally { thisValue.setValue(old); } } catch (IllegalAccessException e) { throw new IllegalStateException("Method is not accessible", e); } catch (InvocationTargetException e) { throw new IllegalStateException("Failed to invoke method", e); } } }
/** {@inheritDoc} */ public void inject(final T value) throws InjectionException { final ThreadLocalValue<Object> injectedValue = Values.injectedValue(); final ThreadLocalValue<Object> tlsThisValue = Values.thisValue(); final Value<?> thisValue = targetValue; final Value<?> oldInjectedValue = injectedValue.getAndSetValue((Value<?>) new ImmediateValue<T>(value)); try { final Value<?> oldThis = tlsThisValue.getAndSetValue(thisValue); try { method.invoke(thisValue.getValue(), Values.getValues(parameterList)); } catch (InvocationTargetException e) { try { throw e.getCause(); } catch (InjectionException e2) { throw e2; } catch (Throwable throwable) { throw new InjectionException("Injection failed", e); } } catch (Exception e) { throw new InjectionException("Injection failed", e); } finally { tlsThisValue.setValue(oldThis); } } finally { injectedValue.setValue(oldInjectedValue); } }
/** {@inheritDoc} */ public void inject(final T value) throws InjectionException { final ThreadLocalValue<Object> injectedValue = Values.injectedValue(); final ThreadLocalValue<Object> tlsThisValue = Values.thisValue(); final Value<?> thisValue = targetValue; final Value<?> oldInjectedValue = injectedValue.getAndSetValue((Value<?>) new ImmediateValue<T>(value)); try { final Value<?> oldThis = tlsThisValue.getAndSetValue(thisValue); try { method.invoke(thisValue.getValue(), Values.getValues(parameterList)); } catch (InvocationTargetException e) { try { throw e.getCause(); } catch (InjectionException e2) { throw e2; } catch (Throwable throwable) { throw new InjectionException("Injection failed", e); } } catch (Exception e) { throw new InjectionException("Injection failed", e); } finally { tlsThisValue.setValue(oldThis); } } finally { injectedValue.setValue(oldInjectedValue); } }