protected void error_injectionException(InjectionResolver target, Annotation inject, AnnotatedElement injectionPoint, Throwable e) { Logger.getAnonymousLogger().log(Level.FINE, "** Injection failure **", e); if (UnsatisfiedDependencyException.class.isInstance(e)) { if (injectionPoint == ((UnsatisfiedDependencyException)e).getUnsatisfiedElement()) { // no need to wrap again throw (UnsatisfiedDependencyException)e; } if (target.isOptional(injectionPoint, inject)) { return; } else { throw new UnsatisfiedDependencyException(injectionPoint, inject, e); } } if (null != e.getCause() && InvocationTargetException.class.isInstance(e)) { e = e.getCause(); } throw new MultiException(e); }
public UnsatisfiedDependencyException(Type target, Class<?> targetClass, Annotation inject, Throwable cause) { super(injection_failed_msg(target, inject, null), inject, cause); this.member = targetClass; }
public String getUnsatisfiedName() { String name = (member instanceof Member) ? ((Member)member).getName() : member.toString(); if (isMethod()) { return name.substring(3).toLowerCase(Locale.ENGLISH); } return name; }
@Override public void run() { Type genericType = field.getGenericType(); Class fieldType = field.getType(); try { Object value = target.getValue(ic.component, field, genericType, fieldType); if (value != null) { AccessController.doPrivileged(new PrivilegedAction<Field>() { @Override public Field run() { field.setAccessible(true); return field; } }); field.set(ic.component, value); } else { if (!target.isOptional(field, inject)) { throw new UnsatisfiedDependencyException(field, inject); } } } catch (MultiException e) { error_injectionException(target, inject, field, e); } catch (IllegalAccessException e) { error_injectionException(target, inject, field, e); } catch (RuntimeException e) { error_injectionException(target, inject, field, e); } } }
injectionMgr.inject(injectionTarget, injector); } catch (UnsatisfiedDependencyException e) { Param param = e.getAnnotation(Param.class); CommandModel.ParamModel paramModel = null; for (CommandModel.ParamModel pModel : model.getParameters()) { errorMsg = adminStrings.getLocalString("admin.param.missing.nofound", "Cannot find {1} in {0} command model, file a bug", model.getCommandName(), e.getUnsatisfiedName());
public <T extends Annotation> T getAnnotation(Class<T> annotationType) { AnnotatedElement annotated = getUnsatisfiedElement(); if (annotated!=null) { return annotated.getAnnotation(annotationType); } else { return null; } } }
/** * Inject this instance with the final values of all the command * parameters. * * @throws CommandException if execution of the command fails * @throws CommandValidationException if there's something wrong * with the options or arguments */ protected void inject() throws CommandException { // injector expects operands to be in the ParameterMap with the key // "DEFAULT" options.set("DEFAULT", operands); // if command has a "terse" option, set it from ProgramOptions if (commandModel.getModelFor("terse") != null) options.set("terse", Boolean.toString(programOpts.isTerse())); // initialize the injector. InjectionResolver<Param> injector = new MapInjectionResolver(commandModel, options); // inject try { injectionMgr.inject(this, injector); } catch (UnsatisfiedDependencyException e) { throw new CommandValidationException(e.getMessage(), e); } }
} else { if (!target.isOptional(method, inject)) { throw new UnsatisfiedDependencyException(method, inject); } else { if (!target.isOptional(method, inject)) { throw new UnsatisfiedDependencyException(method, inject);
injectionMgr.inject(injectionTarget, injector); } catch (UnsatisfiedDependencyException e) { Param param = e.getAnnotation(Param.class); CommandModel.ParamModel paramModel = null; for (CommandModel.ParamModel pModel : model.getParameters()) { errorMsg = adminStrings.getLocalString("admin.param.missing.nofound", "Cannot find {1} in {0} command model, file a bug", model.getCommandName(), e.getUnsatisfiedName());
public <T extends Annotation> T getAnnotation(Class<T> annotationType) { AnnotatedElement annotated = getUnsatisfiedElement(); if (annotated!=null) { return annotated.getAnnotation(annotationType); } else { return null; } } }
protected void error_injectionException(InjectionResolver target, Annotation inject, AnnotatedElement injectionPoint, Throwable e) { Logger.getAnonymousLogger().log(Level.FINE, "** Injection failure **", e); if (UnsatisfiedDependencyException.class.isInstance(e)) { if (injectionPoint == ((UnsatisfiedDependencyException)e).getUnsatisfiedElement()) { // no need to wrap again throw (UnsatisfiedDependencyException)e; } if (target.isOptional(injectionPoint, inject)) { return; } else { throw new UnsatisfiedDependencyException(injectionPoint, inject, e); } } if (null != e.getCause() && InvocationTargetException.class.isInstance(e)) { e = e.getCause(); } throw new MultiException(e); }
throw new UnsatisfiedDependencyException(field, nonOptionalAnnotation); } else { if (!target.isOptional(method, inject)) { throw new UnsatisfiedDependencyException(method, inject); } else { if (!target.isOptional(method, inject)) { throw new UnsatisfiedDependencyException(method, inject);
public UnsatisfiedDependencyException(AnnotatedElement target, Annotation inject, Throwable cause) { super(injection_failed_msg(target, inject, cause), cause); this.member = target; }
public <T extends Annotation> T getAnnotation(Class<T> annotationType) { AnnotatedElement annotated = getUnsatisfiedElement(); if (annotated!=null) { return annotated.getAnnotation(annotationType); } else { return null; } } }
public String getUnsatisfiedName() { String name = (member instanceof Member) ? ((Member)member).getName() : member.toString(); if (isMethod()) { return name.substring(3).toLowerCase(); } return name; }
protected void error_injectionException(InjectionResolver target, Annotation inject, AnnotatedElement injectionPoint, Throwable e) { Logger.getAnonymousLogger().log(Level.FINE, "** Injection failure **", e); if (UnsatisfiedDependencyException.class.isInstance(e)) { if (injectionPoint == ((UnsatisfiedDependencyException)e).getUnsatisfiedElement()) { // no need to wrap again throw (UnsatisfiedDependencyException)e; } if (target.isOptional(injectionPoint, inject)) { return; } else { throw new UnsatisfiedDependencyException(injectionPoint, inject, e); } } if (null != e.getCause() && InvocationTargetException.class.isInstance(e)) { e = e.getCause(); } throw new MultiException(e); }
@Override public void run() { Type genericType = field.getGenericType(); Class fieldType = field.getType(); try { Object value = target.getValue(ic.component, field, genericType, fieldType); if (value != null) { field.setAccessible(true); field.set(ic.component, value); } else { if (!target.isOptional(field, inject)) { throw new UnsatisfiedDependencyException(field, inject); } } } catch (MultiException e) { error_injectionException(target, inject, field, e); } catch (IllegalAccessException e) { error_injectionException(target, inject, field, e); } catch (RuntimeException e) { error_injectionException(target, inject, field, e); } } }
public UnsatisfiedDependencyException(AnnotatedElement target, Annotation inject, Throwable cause) { super(injection_failed_msg(target, inject, cause), cause); this.member = target; }
public String getUnsatisfiedName() { String name = (member instanceof Member) ? ((Member)member).getName() : member.toString(); if (isMethod()) { return name.substring(3).toLowerCase(Locale.ENGLISH); } return name; }
@Override public void run() { Type genericType = field.getGenericType(); Class fieldType = field.getType(); try { Object value = target.getValue(ic.component, field, genericType, fieldType); if (value != null) { AccessController.doPrivileged(new PrivilegedAction<Field>() { @Override public Field run() { field.setAccessible(true); return field; } }); field.set(ic.component, value); } else { if (!target.isOptional(field, inject)) { throw new UnsatisfiedDependencyException(field, inject); } } } catch (MultiException e) { error_injectionException(target, inject, field, e); } catch (IllegalAccessException e) { error_injectionException(target, inject, field, e); } catch (RuntimeException e) { error_injectionException(target, inject, field, e); } } }