protected void error_InjectMethodIsNotVoid(Method method) { throw new MultiException(new IllegalStateException("Injection failed on " + method.getName() + " : setter method is not declared with a void return type")); }
@Override public Object resolve(Injectee injectee, ServiceHandle<?> root) { ActiveDescriptor<?> descriptor = locator.getInjecteeDescriptor(injectee); if (descriptor == null) { // Is it OK to return null? if (isNullable(injectee)) { return null; } throw new MultiException(new UnsatisfiedDependencyException(injectee)); } return locator.getService(descriptor, root, injectee); } }
/** * {@inheritDoc} */ @Override public ServiceLocator create(String name, ServiceLocator parent) { ServiceLocator retVal = super.create(name, parent); DynamicConfigurationService dcs = retVal.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); try { populator.populate(); } catch (IOException e) { throw new MultiException(e); } return retVal; } }
/** * Get the class by contract or create and inject a new instance. * * @param <T> instance type. * @param serviceLocator HK2 service locator. * @param clazz class of the instance to be provider. * @return instance of the class either provided as a service or created and injected by HK2. */ public static <T> T getOrCreate(final ServiceLocator serviceLocator, final Class<T> clazz) { try { final T component = serviceLocator.getService(clazz); return component == null ? serviceLocator.createAndInitialize(clazz) : component; } catch (final MultiException e) { // Look for WebApplicationException and return it if found. MultiException is thrown when *Param field is // annotated and value cannot be provided (for example fromString(String) method can throw unchecked // exception. // // see InvalidParamTest // see JERSEY-1117 for (final Throwable t : e.getErrors()) { if (WebApplicationException.class.isAssignableFrom(t.getClass())) { throw (WebApplicationException) t; } } throw e; } }
checkState(); Type requiredType = injectee.getRequiredType(); Class<?> rawType = ReflectionHelper.getRawClass(requiredType); if (rawType == null) { throw new MultiException(new IllegalArgumentException( "Invalid injectee with required type of " + injectee.getRequiredType() + " passed to getInjecteeDescriptor")); (ReflectionHelper.getFirstTypeArgument(requiredType)), injectee.getRequiredQualifiers(), injectee.getUnqualified(), injectee, ReflectionHelper.getFirstTypeArgument(requiredType), injectee.getRequiredQualifiers());
if (!root.isReified()) { root = (ActiveDescriptor<T>) locator.reifyDescriptor(root, injectee); context = locator.resolveContext(root.getScopeAnnotation()); if (injectee != null && injectee.isOptional()) return null; " in scope " + root.getScope() + " an error occured while locating the context"); me.addError(addMe); MultiException me = new MultiException(th); me.addError(addMe); throw me; throw new MultiException(th); throw new MultiException(new IllegalStateException("Context " + context + " findOrCreate returned a null for descriptor " + root + " and handle " + handle));
@SuppressWarnings("unchecked") private ServiceHandle<Factory<T>> getFactoryHandle() { try { return (ServiceHandle<Factory<T>>) locator.getServiceHandle(factoryDescriptor); } catch (Throwable th) { throw new MultiException(th); } }
ClassLoader loader; if (injectee != null) { AnnotatedElement parent = injectee.getParent(); MultiException me = new MultiException(th); me.addError(th2); throw new MultiException(th);
proxyClass = Utilities.getFactoryAwareImplementationClass(root); iFaces = Utilities.getInterfacesForProxy(root.getContractTypes()); " in scope " + root.getScope() + " an error occured while creating the proxy"); me.addError(addMe); MultiException me = new MultiException(th); me.addError(addMe); throw me;
private void fail(Throwable th, Descriptor descriptor) { synchronized (lock) { if (hardCancelled) return; ErrorInformation info = invokeOnError(currentTaskFuture, th, ErrorInformation.ErrorAction.GO_TO_NEXT_LOWER_LEVEL_AND_STOP, listeners, descriptor); if (ErrorInformation.ErrorAction.IGNORE.equals(info.getAction())) return; if (accumulatedExceptions == null) { accumulatedExceptions = new MultiException(); } accumulatedExceptions.addError(th); } }
/** * Post constructs the given object * * @param postMe post constructs the thing * @param locator The non-null service locator associated with the operation (for finding the strategy) * @param strategy The strategy to use for analyzing the class */ public static void justPostConstruct(Object postMe, ServiceLocatorImpl locator, String strategy) { if (postMe == null) throw new IllegalArgumentException(); Collector collector = new Collector(); ClassAnalyzer analyzer = getClassAnalyzer(locator, strategy, collector); collector.throwIfErrors(); Class<?> baseClass = postMe.getClass(); Method postConstruct = getPostConstruct(baseClass, analyzer, collector); collector.throwIfErrors(); if (postConstruct == null) return; try { ReflectionHelper.invoke(postMe, postConstruct, new Object[0], locator.getNeutralContextClassLoader()); } catch (Throwable e) { throw new MultiException(e); } }
@Override public Object resolve(Injectee injectee, ServiceHandle<?> root) { ActiveDescriptor<?> ad = locator.getInjecteeDescriptor(injectee); if (ad == null) { if (injectee.isOptional()) return null; throw new MultiException(new UnsatisfiedDependencyException(injectee)); } return locator.getService(ad, root, injectee); }
private Object internalInvoke(Object target, Method method, Method proceed, Object[] params) throws Throwable { Context<?> context; Object service; context = locator.resolveContext(descriptor.getScopeAnnotation()); service = context.findOrCreate(descriptor, root); if (service == null) { throw new MultiException(new IllegalStateException("Proxiable context " + context + " findOrCreate returned a null for descriptor " + descriptor + " and handle " + root)); } if (method.getName().equals(PROXY_MORE_METHOD_NAME)) { // We did what we came here to do return service; } if (isEquals(method) && (params.length == 1) && (params[0] != null) && (params[0] instanceof ProxyCtl)) { ProxyCtl equalsProxy = (ProxyCtl) params[0]; params = new Object[1]; params[0] = equalsProxy.__make(); } return ReflectionHelper.invoke(service, method, params, locator.getNeutralContextClassLoader()); }
activeDescriptor.dispose(instance); return; re = new MultiException(re); if (!reported.getReportToErrorService()) {
/** * This method returns the class associated with the type of the factory. * * @param descriptor The descriptor (reified and not null) that will be used to find the implementation. * @return the CLASS version of what the factory produces. Will not be null. * @throws MultiException if there was an error analyzing the class. */ private static Class<?> getFactoryProductionClass(ActiveDescriptor<?> descriptor) { Class<?> factoryClass = descriptor.getImplementationClass(); Type factoryProvidedType = getFactoryProductionType(factoryClass); Class<?> retVal = ReflectionHelper.getRawClass(factoryProvidedType); if (retVal == null && descriptor.getContractTypes().size() == 1) { // If the type was not resolved from a generic type, try to use // contract type if only one was registered. Type contract = descriptor.getContractTypes().iterator().next(); retVal = ReflectionHelper.getRawClass(contract); } if (retVal == null) { throw new MultiException(new AssertionError("Could not find true produced type of factory " + factoryClass.getName())); } return retVal; }
null, ReflectionHelper.<Map<Injectee,Object>>cast(allResolved), eventThrower)); retVal, ReflectionHelper.<Map<Injectee, Object>>cast(allResolved), eventThrower)); MultiException me = (MultiException) th; me.addError(new IllegalStateException("Unable to perform operation: " + failureLocation + " on " + implClass.getName())); MultiException me = new MultiException(th); me.addError(new IllegalStateException("Unable to perform operation: " + failureLocation + " on " + implClass.getName()));
/** * This method returns the class associated with the type of the * factory * * @param factoryClass The non-null factory class. May not be null * @return the CLASS version of what the factory produces. Will * not be null * @throws MultiException if there was an error analyzing the class */ private static Class<?> getFactoryProductionClass(Class<?> factoryClass) { Type factoryProvidedType = getFactoryProductionType(factoryClass); Class<?> retVal = ReflectionHelper.getRawClass(factoryProvidedType); if (retVal != null) return retVal; throw new MultiException(new AssertionError("Could not find true produced type of factory " + factoryClass.getName())); }
retVal = activeDescriptor.create(root); re = new MultiException(re); if (!reported.getReportToErrorService()) {
protected Class<?> loadClass(String type) throws ClassNotFoundException { HK2Loader loader = myself.getLoader(); if (loader == null) { return getClass().getClassLoader().loadClass(type); } try { return loader.loadClass(type); } catch (MultiException me) { for (Throwable th : me.getErrors()) { if (th instanceof ClassNotFoundException) { throw (ClassNotFoundException) th; } } throw new ClassNotFoundException(me.getMessage()); } }