Package org.glassfish.hk2.api

Examples of org.glassfish.hk2.api.MultiException


       
        try {
            future.get();
        }
        catch (InterruptedException e) {
            throw new MultiException(e);
        }
        catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            }
           
            throw new MultiException(cause);
        }
    }
View Full Code Here


                    break;
                }     
            }
           
            if (!validOption) {
                throw new MultiException(new IllegalArgumentException(" Invalid option: " + key));
            }
        }
        parameters.mergeAll(adds);
    }
View Full Code Here

                    break;
                }     
            }
           
            if (!validOption) {
                throw new MultiException(new IllegalArgumentException(" Invalid option: " + key));
            }
        }
        parameters.mergeAll(adds);
    }
View Full Code Here

                    break;
                }     
            }
           
            if (!validOption) {
                throw new MultiException(new IllegalArgumentException(" Invalid option: " + key));
            }
        }
        parameters.mergeAll(adds);
    }
View Full Code Here

  @Override
  public Class<?> loadClass(final String className) throws MultiException {
    try {
      bundle.start();
    } catch (BundleException e1) {
      throw new MultiException(e1);
    }
    return (Class<?>) AccessController
        .doPrivileged(new PrivilegedAction() {
          public java.lang.Object run() {
            try {
              return bundle.loadClass(className);
            } catch (Throwable e) {
              logger.logp(
                  Level.SEVERE,
                  "OSGiModuleImpl",
                  "loadClass",
                  "Exception in module "
                      + bundle.toString() + " : "
                      + e.toString());
              throw new MultiException(e);
            }
          }
        });

  }
View Full Code Here

                        } catch (Throwable e) {
                            logger.logp(Level.SEVERE, "OSGiModuleImpl",
                                    "loadClass",
                                    "Exception in module " + osgiModule.getBundle().toString(), e);

                            throw new MultiException(e);
                        }
                    }
                });

            }
View Full Code Here

                                    "GenericCrudCommand.invalid_type",
                                    "Invalid annotated type {0} passed to InjectionResolver:getValue()",
                                    annotated.getClass().toString());
                            Object[] params = new Object[] { annotated.getClass().toString()};
                            logger.log(Level.SEVERE, "GenericCrudCommand.invalid_type", params);
                            throw new MultiException(new IllegalArgumentException(msg));
                        }
                    } catch (IllegalAccessException e) {
                        String msg = localStrings.getLocalString(GenericCrudCommand.class,
                                "GenericCrudCommand.invocation_failure",
                                "Failure {0} while getting List<?> values from component",
                                e.getMessage());
                        Object[] params = new Object[] { e.getMessage()};
                        logger.log(Level.SEVERE, "GenericCrudCommand.invocation_failure", params);
                        throw new MultiException(new IllegalStateException(msg, e));
                    } catch (InvocationTargetException e) {
                        String msg = localStrings.getLocalString(GenericCrudCommand.class,
                                "GenericCrudCommand.invocation_failure",
                                "Failure {0} while getting List<?> values from component",
                                e.getMessage());
                        Object[] params = new Object[] { e.getMessage()};
                        logger.log(Level.SEVERE, "GenericCrudCommand.invocation_failure", params);
                        throw new MultiException(new IllegalStateException(msg, e));
                    }
                    Object value = delegate.getValue(component, annotated, genericType, type);
                    if (value==null) {
                        if (logger.isLoggable(level)) {
                            logger.log(level, "Value of " + annotated.toString() + " is null");
                        }
                        return null;
                    }
                    Type genericReturnType=null;
                    if (annotated instanceof Method) {
                        genericReturnType = ((Method) annotated).getGenericReturnType();
                    } else if (annotated instanceof Field) {
                        genericReturnType = ((Field) annotated).getGenericType();
                    }
                    if (genericReturnType==null) {
                        throw new MultiException(new IllegalArgumentException(
                                "Cannot determine parametized type from " + annotated.toString()));
                    }

                    final Class<? extends ConfigBeanProxy> itemType = Types.erasure(Types.getTypeArgument(genericReturnType, 0));
                    if (logger.isLoggable(level)) {
                        logger.log(level, "Found that List<?> really is a List<" + itemType.toString() + ">");
                    }
                    if (itemType==null) {
                            String msg = localStrings.getLocalString(GenericCrudCommand.class,
                                    "GenericCrudCommand.nongeneric_type",
                                    "The List type returned by {0} must be a generic type",
                                    annotated.toString());
                            Object[] params = new Object[] {annotated.toString()};
                            logger.log(Level.SEVERE, "GenericCrudCommand.nongeneric_type", params);
                            throw new MultiException(new IllegalArgumentException(msg));
                    }
                    if (!ConfigBeanProxy.class.isAssignableFrom(itemType)) {
                        String msg = localStrings.getLocalString(GenericCrudCommand.class,
                                "GenericCrudCommand.wrong_type",
                                "The generic type {0} is not supported, only List<? extends ConfigBeanProxy> is",
                                annotated.toString());
                        Object[] params = new Object[] { annotated.toString()};
                        logger.log(Level.SEVERE, "GenericCrudCommand.wrong_type", params);
                        throw new MultiException(new IllegalArgumentException(msg));
                       
                    }
                    Properties props = convertStringToProperties(value.toString(), ':');
                    if (logger.isLoggable(level)) {
                        for (Map.Entry<Object, Object> entry : props.entrySet()) {
                            logger.log(level, "Subtype " + itemType + " key:" + entry.getKey() + " value:" + entry.getValue());
                        }
                    }
                    final BeanInfo beanInfo;
                    try {
                        beanInfo = Introspector.getBeanInfo(itemType);
                    } catch (IntrospectionException e) {
                        String msg = localStrings.getLocalString(GenericCrudCommand.class,
                                "GenericCrudCommand.introspection_failure",
                                "Failure {0} while instrospecting {1} to find all getters and setters",
                                e.getMessage(), itemType.getName());
                        Object[] params = new Object[] { e.getMessage(), itemType.getName()};
                        logger.log(Level.SEVERE, "GenericCrudCommand.introspection_failure", params);
                        throw new MultiException(new IllegalStateException(msg, e));
                    }
                    for (final Map.Entry<Object, Object> entry : props.entrySet()) {
                        ConfigBeanProxy child = (ConfigBeanProxy) component;
                        try {
                            ConfigBeanProxy cc = child.createChild(itemType);
                            new InjectionManager().inject(cc, itemType, new InjectionResolver<Attribute>(Attribute.class) {

                                @Override
                                public boolean isOptional(AnnotatedElement annotated, Attribute annotation) {
                                    return true;   
                                }

                                @Override
                                public Method getSetterMethod(Method annotated, Attribute annotation) {
                                    // Attribute annotation are always annotated on the getter, we need to find the setter
                                    // variant.
                                    for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
                                        if (pd.getReadMethod().equals(annotated)) {
                                            return pd.getWriteMethod();
                                        }
                                    }
                                    return annotated;
                                }

                                @Override
                                public <V> V getValue(Object component, AnnotatedElement annotated, Type genericType, Class<V> type) throws MultiException {
                                    String name = annotated.getAnnotation(Attribute.class).value();
                                    if ((name==null || name.length()==0) && annotated instanceof Method) {

                                        // maybe there is a better way to do this...
                                        name = ((Method) annotated).getName().substring(3);

                                        if (name.equalsIgnoreCase("name") || name.equalsIgnoreCase("key")) {
                                            return type.cast(entry.getKey());
                                        }
                                        if (name.equalsIgnoreCase("value")) {
                                            return type.cast(entry.getValue());
                                        }
                                    }
                                    return null;
                                }
                            });
                            values.add(cc);
                        } catch (TransactionFailure transactionFailure) {
                            String msg = localStrings.getLocalString(GenericCrudCommand.class,
                                "GenericCrudCommand.transactionException",
                                "Transaction exception {0} while injecting {1}",
                                transactionFailure.getMessage(), itemType);
                            Object[] params = new Object[] { transactionFailure.getMessage(), itemType};
                            logger.log(Level.SEVERE, "GenericCrudCommand.transactionException", params);
                            throw new MultiException(new IllegalStateException(msg, transactionFailure));
                        }

                    }
                    return null;
                }
View Full Code Here

        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"));
        }
       
        if (Provider.class.equals(rawType) || IterableProvider.class.equals(rawType) ) {
            IterableProviderImpl<?> value = new IterableProviderImpl<Object>(this,
View Full Code Here

        if (contractOrImpl == null) throw new IllegalArgumentException();
        checkState();
       
        Class<?> rawClass = ReflectionHelper.getRawClass(contractOrImpl);
        if (rawClass == null) {
            throw new MultiException(new IllegalArgumentException("Type must be a class or parameterized type, it was " + contractOrImpl));
        }
       
        boolean useCache = false;
        Filter filter;
        if (unqualified == null) {
View Full Code Here

                if (retVal.contains(candidate)) continue;
               
                for (ValidationService vs : getAllValidators()) {
                    if (!vs.getValidator().validate(new ValidationInformationImpl(
                            Operation.UNBIND, candidate))) {
                        throw new MultiException(new IllegalArgumentException("Descriptor " +
                            candidate + " did not pass the UNBIND validation"));
                    }
                }
               
                if (candidate.getAdvertisedContracts().contains(InstanceLifecycleListener.class.getName())) {
                    addOrRemoveOfInstanceListener = true;
                }
                if (candidate.getAdvertisedContracts().contains(InjectionResolver.class.getName())) {
                    addOrRemoveOfInjectionResolver = true;
                }
                if (candidate.getAdvertisedContracts().contains(ErrorService.class.getName())) {
                    addOrRemoveOfErrorHandler = true;
                }
                if (candidate.getAdvertisedContracts().contains(ClassAnalyzer.class.getName())) {
                    addOrRemoveOfClazzAnalyzer = true;
                }
               
                retVal.add(candidate);
            }
        }
       
        for (SystemDescriptor<?> sd : dci.getAllDescriptors()) {
            affectedContracts.addAll(getAllContracts(sd));
           
            boolean checkScope = false;
            if (sd.getAdvertisedContracts().contains(ValidationService.class.getName()) ||
                sd.getAdvertisedContracts().contains(ErrorService.class.getName()) ||
                sd.getAdvertisedContracts().contains(InstanceLifecycleListener.class.getName())) {
                // These gets reified right away
                reifyDescriptor(sd);
               
                checkScope = true;
               
                if (sd.getAdvertisedContracts().contains(ErrorService.class.getName())) {
                    addOrRemoveOfErrorHandler = true;
                }
                if (sd.getAdvertisedContracts().contains(InstanceLifecycleListener.class.getName())) {
                    addOrRemoveOfInstanceListener = true;
                }
            }
           
            if (sd.getAdvertisedContracts().contains(InjectionResolver.class.getName())) {
                // This gets reified right away
                reifyDescriptor(sd);
               
                checkScope = true;
               
                if (Utilities.getInjectionResolverType(sd) == null) {
                    throw new MultiException(new IllegalArgumentException(
                            "An implementation of InjectionResolver must be a parameterized type and the actual type" +
                            " must be an annotation"));
                }
               
                addOrRemoveOfInjectionResolver = true;
            }
           
            if (sd.getAdvertisedContracts().contains(Context.class.getName())) {
                // This one need not be reified, it will get checked later
                checkScope = true;
            }
           
            if (sd.getAdvertisedContracts().contains(ClassAnalyzer.class.getName())) {
                addOrRemoveOfClazzAnalyzer = true;
            }
           
            if (checkScope) {
                String scope = (sd.getScope() == null) ? PerLookup.class.getName() : sd.getScope() ;
               
                if (!scope.equals(Singleton.class.getName())) {
                    throw new MultiException(new IllegalArgumentException(
                            "The implementation class " +  sd.getImplementation() + " must be in the Singleton scope"));
                }
            }
           
            for (ValidationService vs : getAllValidators()) {
                Validator validator = vs.getValidator();
                if (validator == null) {
                    throw new MultiException(new IllegalArgumentException("Validator was null from validation service" + vs));
                }
               
                if (!vs.getValidator().validate(new ValidationInformationImpl(
                        Operation.BIND, sd))) {
                    throw new MultiException(new IllegalArgumentException("Descriptor " + sd + " did not pass the BIND validation"));
                }
            }
        }
       
        return new CheckConfigurationData(retVal,
View Full Code Here

TOP

Related Classes of org.glassfish.hk2.api.MultiException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.