/** * Get an object array from the result of an iterable series of values. * * @param i the iterable series * @return the values array */ public static Object[] getValues(Iterable<? extends Value<?>> i) { return getValues(i.iterator(), 0); }
/** * Get a typed object array from the result of an iterable series of values. * * @param i the iterable series * @param clazz the resultant array type * @return the values array */ public static <T> T[] getValues(Iterable<? extends Value<? extends T>> i, Class<T> clazz) { return getValues(i.iterator(), clazz, 0); }
/** * Get a typed object array from the result of an iterable series of values. * * @param i the iterable series * @param clazz the resultant array type * @return the values array */ public static <T> T[] getValues(Iterable<? extends Value<? extends T>> i, Class<T> clazz) { return getValues(i.iterator(), clazz, 0); }
/** * Get an object array from the result of an iterable series of values. * * @param i the iterable series * @return the values array */ public static Object[] getValues(Iterable<? extends Value<?>> i) { return getValues(i.iterator(), 0); }
/** {@inheritDoc} */ public T getValue() throws IllegalStateException { try { return constructor.newInstance(Values.getValues(parameters)); } catch (IllegalAccessException e) { throw new IllegalStateException("Field is not accessible", e); } catch (InvocationTargetException e) { throw new IllegalStateException("Failed to invoke constructor", e); } catch (InstantiationException e) { throw new IllegalStateException("Failed to construct instance", e); } } }
/** {@inheritDoc} */ public T getValue() throws IllegalStateException { try { return constructor.newInstance(Values.getValues(parameters)); } catch (IllegalAccessException e) { throw new IllegalStateException("Field is not accessible", e); } catch (InvocationTargetException e) { throw new IllegalStateException("Failed to invoke constructor", e); } catch (InstantiationException e) { throw new IllegalStateException("Failed to construct instance", e); } } }
private static Object[] getValues(Iterator<? extends Value<?>> i, int idx) { if (i.hasNext()) { final Value<?> v = i.next(); final Object[] params = getValues(i, idx + 1); params[idx] = v.getValue(); return params; } else { return idx == 0 ? NONE : new Object[idx]; } }
private static Object[] getValues(Iterator<? extends Value<?>> i, int idx) { if (i.hasNext()) { final Value<?> v = i.next(); final Object[] params = getValues(i, idx + 1); params[idx] = v.getValue(); return params; } else { return idx == 0 ? NONE : new Object[idx]; } }
private static <T> T[] getValues(Iterator<? extends Value<? extends T>> i, Class<T> clazz, int idx) { if (i.hasNext()) { final Value<? extends T> v = i.next(); final T[] params = getValues(i, clazz, idx + 1); params[idx] = v.getValue(); return params; } else { return arrayOf(clazz, idx); } }
private static <T> T[] getValues(Iterator<? extends Value<? extends T>> i, Class<T> clazz, int idx) { if (i.hasNext()) { final Value<? extends T> v = i.next(); final T[] params = getValues(i, clazz, idx + 1); params[idx] = v.getValue(); return params; } else { return arrayOf(clazz, idx); } }
/** {@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 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 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 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 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); } }