parameterTypes[i] = args[i].getClass(); return invokeConstructor(klass, args, parameterTypes);
parameterTypes[i] = args[i].getClass(); return invokeConstructor(klass, args, parameterTypes);
/** * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor. * The formal parameter type is inferred from the actual values of <code>arg</code>. * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p> * * <p>The signatures should be assignment compatible.</p> * * @param <T> the type of the object to be constructed * @param klass the class to be constructed. * @param arg the actual argument. May be null (this will result in calling the default constructor). * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException If the constructor cannot be found * @throws IllegalAccessException If an error occurs accessing the constructor * @throws InvocationTargetException If an error occurs invoking the constructor * @throws InstantiationException If an error occurs instantiating the class * * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) */ public static <T> T invokeConstructor(final Class<T> klass, final Object arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { final Object[] args = toArray(arg); return invokeConstructor(klass, args); }
/** * <p>Convenience method returning new instance of <code>klazz</code> using a single argument constructor. * The formal parameter type is inferred from the actual values of <code>arg</code>. * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.</p> * * <p>The signatures should be assignment compatible.</p> * * @param <T> the type of the object to be constructed * @param klass the class to be constructed. * @param arg the actual argument. May be null (this will result in calling the default constructor). * @return new instance of <code>klazz</code> * * @throws NoSuchMethodException If the constructor cannot be found * @throws IllegalAccessException If an error occurs accessing the constructor * @throws InvocationTargetException If an error occurs invoking the constructor * @throws InstantiationException If an error occurs instantiating the class * * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) */ public static <T> T invokeConstructor(final Class<T> klass, final Object arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { final Object[] args = toArray(arg); return invokeConstructor(klass, args); }
returnValue = invokeEnumInit(mState, (String) args[0], vm.getClassLoader()); } else { returnValue = ConstructorUtils.invokeConstructor(klazz, args);
@Override public T invoke() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException { return ConstructorUtils.invokeConstructor(c, params); } });
@Override public T invoke() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException, InstantiationException { return ConstructorUtils.invokeConstructor(c, params, argTypes); } });
protected static Object loadObject(Class<?> objectClass, Object[] constructorParams, Class<?>[] constructorParamTypes) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { return ConstructorUtils.invokeConstructor(objectClass, constructorParams, constructorParamTypes); }
private static ResourceBundle getTobagoBundle() { // XXX This is ugly, can be removed after merging tobago-jsf-compat to tobago-core try { Class clazz = Class.forName("org.apache.myfaces.tobago.context.TobagoResourceBundle"); Object bundle = ConstructorUtils.invokeConstructor(clazz, new Object[0]); return (ResourceBundle) bundle; } catch (Exception e) { LOG.error("Can't create TobagoResourceBundle, but it should be in the core.", e); return null; // should not be possible. } }
public static <O> O newInstanceWithParams(Class<O> type, Object... constructorParams) { try { return ConstructorUtils.invokeConstructor(Objects.requireNonNull(type), constructorParams); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { throw new IllegalStateException("Can't instantiate " + type.getName(), e); } }
private Object createNewInstance(String clazzName) { Class<?> beanClass = null; Object beanInstance = null; try { beanClass = getClass().getClassLoader().loadClass(clazzName); beanInstance = ConstructorUtils.invokeConstructor(beanClass, null); } catch (Exception e) { logger.error("Error during creating class" + clazzName, e); } return beanInstance; }
private Object createNewInstance(String clazzName) { Class<?> beanClass = null; Object beanInstance = null; try { beanClass = getClass().getClassLoader().loadClass(clazzName); beanInstance = ConstructorUtils.invokeConstructor(beanClass, null); } catch (Exception e) { logger.error("Error during creating class" + clazzName, e); } return beanInstance; }
/** * Returns a factory instance for this component. * * @return The component factory. */ public ComponentFactory getFactory() { try { return ConstructorUtils.invokeConstructor(factoryClass, this); } catch (Exception e) { throw MiscUtil.toUnchecked(e); } }
public static <E> E createInstance(Class<E> clazz, Object... args) { try { return ConstructorUtils.invokeConstructor(clazz, args); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new ReflectionException(e); } }
public static <E> E createInstance(Class<E> clazz, Object... args) { try { return ConstructorUtils.invokeConstructor(clazz, args); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new ReflectionException(e); } }
/** * Returns a factory instance for this component. * * @return The component factory. */ public ComponentFactory getFactory() { try { return ConstructorUtils.invokeConstructor(factoryClass, this); } catch (Exception e) { throw MiscUtil.toUnchecked(e); } }
private DataSource invokeDataSourceConstructor( Class<DataSource> dsClass, List<DataSourceConnectionProvider.DataSource.Argument> arguments ) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException { final Object[] javaArgs = getJavaArgs( arguments ); return (DataSource) ConstructorUtils.invokeConstructor( dsClass, javaArgs ); }
@Override public <T> T newInstance(Class<T> c, Object... params) { try { return ConstructorUtils.invokeConstructor(c, params); } catch (Exception e) { throw new RuntimeException(e); } }
private static Analyzer instantiateAnalyzer(final Version luceneVersion) { final String className = WebloggerConfig.getProperty("lucene.analyzer.class"); try { final Class<?> clazz = Class.forName(className); return (Analyzer) ConstructorUtils.invokeConstructor(clazz, luceneVersion); } catch (final ClassNotFoundException e) { mLogger.error("failed to lookup analyzer class: " + className, e); return instantiateDefaultAnalyzer(luceneVersion); } catch (final NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { mLogger.error("failed to instantiate analyzer: " + className, e); return instantiateDefaultAnalyzer(luceneVersion); } }
/** * @param className * @param objects * @return */ public static Object invokeConstructor(String className, Object[] params) { try { Class converterClass= forName(className); return ConstructorUtils.invokeConstructor(converterClass, params); } catch(Exception ex) { throw new JcrMappingException("Cannot create instance for class " + className, ex); } }