/** * <p>Constructs a new object instance based off the * provided class name.</p> * @param className the class of the object to instantiate * @return a new instances of said class * @throws InstantiationException if the class cannot be instantiated * @throws IllegalAccessException if there is a security violation */ public static Object newInstance(String className) throws InstantiationException, IllegalAccessException { ClassLoader loader = Util.getCurrentLoader(null); if (loader == null) { return null; } return getMetaData(loader, className).lookupClass().newInstance(); }
/** * <p>Return the <code>MetaData</code> for the specified Class.</p> * * <p>This will check the cache associated with the specified * <code>ClassLoader</code>. If there is no cache hit, then a new * <code>MetaData</code> instance will be created and stored. * * @param loader <code>ClassLoader</code> * @param clazz the Class of interest * @return a <code>MetaData</code> object for the specified Class */ private static MetaData getMetaData(ClassLoader loader, Class<?> clazz) { ConcurrentMap<String, MetaData> cache = REFLECTION_CACHE.get(loader); if (cache == null) { initCache(loader); cache = REFLECTION_CACHE.get(loader); } MetaData meta = cache.get(clazz.getName()); if (meta == null) { meta = new MetaData(clazz); cache.put(clazz.getName(), meta); } return meta; }
ReflectionUtils.lookupConstructor( clazz, rootType);
/** * Creates an instance of a class with the given fully qualified class name. * * @param <T> The generic object type. * @param className fully qualified class name of the class for which an instance needs to be created * @return an instance of the class denoted by className * @throws IllegalStateException if the class cannot be found */ @SuppressWarnings("unchecked") public static <T> T instance(String className) { return (T) instance(toClass(className)); }
private static void addEL3_0_Resolvers(FacesCompositeELResolver composite, ApplicationAssociate associate) { ExpressionFactory expressionFactory = associate.getExpressionFactory(); Method getStreamELResolverMethod = lookupMethod(ExpressionFactory.class, "getStreamELResolver", EMPTY_CLASS_ARGS); if (getStreamELResolverMethod != null) { try { ELResolver streamELResolver = (ELResolver) getStreamELResolverMethod.invoke(expressionFactory, (Object[]) null); composite.addRootELResolver(streamELResolver); // Assume that if we have getStreamELResolver, then we must have // javax.el.staticFieldELResolver composite.addRootELResolver((ELResolver) newInstance("javax.el.StaticFieldELResolver")); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException t) { // This is normal on containers that do not have these ELResolvers } } }
ReflectionUtils.clearCache(Thread.currentThread().getContextClassLoader()); WebConfiguration.clear(servletContext); ReflectionUtils.initCache(Thread.currentThread().getContextClassLoader());
/** * Looks for the presence of a declared method (by name) in the specified * class and returns a <code>boolean</code> outcome (true, if the method * exists). * * @param instance The instance of the class that will be used as * the search domain. * * @return <code>true</code> if the method exists, otherwise * <code>false</code> */ private boolean hasGetStateMethod(ResponseStateManager instance) { return (ReflectionUtils.lookupMethod( instance.getClass(), "getState", FacesContext.class, String.class) != null); }
FactoryFinder.releaseFactories(); initContext.release(); ReflectionUtils.clearCache(Thread.currentThread().getContextClassLoader()); WebConfiguration.clear(context);
instance = ReflectionUtils.newInstance(((String) type.getValue(faces.getELContext()))); } catch (InstantiationException | IllegalAccessException e) { throw new AbortProcessingException(e.getMessage(), e);
private Object copyBeanAndPopulateWithCandidateValues(FacesContext context, ValueExpression wholeBeanVE, Object wholeBean, String copierType, Map<String, Map<String, Object>> candidate) { // Populate the bean copy with the validated values from the candidate Map<String, Object> propertiesToSet = new HashMap<>(); for (Entry<String, Map<String, Object>> propertyEntry : candidate.entrySet()) { propertiesToSet.put(propertyEntry.getKey(), propertyEntry.getValue().get("value")); } // Copy the whole bean so that class-level validation can be performed // without corrupting the real whole bean Object wholeBeanCopy = getCopier(context, copierType) .copy(wholeBean); if (wholeBeanCopy == null) { throw new FacesException("Unable to copy bean from " + wholeBeanVE.getExpressionString()); } setProperties(wholeBeanCopy, propertiesToSet); return wholeBeanCopy; }
public static Copier getCopier(FacesContext context, String copierType) { Copier copier = null; if (!isEmpty(copierType)) { // TODO: or should validate only against {"MultiStrategyCopier", "SerializationCopier", // "NewInstanceCopier", "CopyCtorCopier", "CloneCopier"} strings / enum if (isCopierTypeSimpleName(copierType)) { copierType = COPIER_PREFIX.concat(copierType); } else if (!isName(copierType)) { throw new IllegalArgumentException(ERROR_COPIER_NAME); } Object expressionResult = evaluateExpressionGet(context, copierType); if (expressionResult instanceof Copier) { copier = (Copier) expressionResult; } else if (expressionResult instanceof String) { copier = instance((String) expressionResult); } } if (copier == null) { copier = new MultiStrategyCopier(); } return copier; }
ReflectionUtils.clearCache(Thread.currentThread().getContextClassLoader()); WebConfiguration.clear(servletContext); ReflectionUtils.initCache(Thread.currentThread().getContextClassLoader());
static void addChildToParentTagAndParentComponent(UIComponent child, UIComponentClassicTagBase parentTag) { Method addChildToComponentAndTag; if (null != (addChildToComponentAndTag = ReflectionUtils.lookupMethod(UIComponentClassicTagBase.class, "addChildToComponentAndTag", UIComponent.class))) { try { addChildToComponentAndTag.setAccessible(true); addChildToComponentAndTag.invoke(parentTag, child); } catch (IllegalAccessException | IllegalArgumentException accessException) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to add " + child + " to tree:", accessException); } } catch (InvocationTargetException targetException) { Throwable cause = targetException.getCause(); if (cause instanceof RuntimeException) { throw ((RuntimeException) cause); } } } }
private static void addEL3_0_Resolvers(FacesCompositeELResolver composite, ApplicationAssociate associate) { ExpressionFactory expressionFactory = associate.getExpressionFactory(); Method getStreamELResolverMethod = lookupMethod( ExpressionFactory.class, "getStreamELResolver", EMPTY_CLASS_ARGS); if (getStreamELResolverMethod != null) { try { ELResolver streamELResolver = (ELResolver) getStreamELResolverMethod.invoke( expressionFactory, (Object[]) null); composite.addRootELResolver(streamELResolver); // Assume that if we have getStreamELResolver, then we must have // javax.el.staticFieldELResolver composite.addRootELResolver((ELResolver) newInstance("javax.el.StaticFieldELResolver")); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException t) { // This is normal on containers that do not have these ELResolvers } } }
ConfigManager.removeInstance(context); FactoryFinder.releaseFactories(); ReflectionUtils.clearCache(Thread.currentThread().getContextClassLoader()); WebConfiguration.clear(context); InitFacesContext.cleanupInitMaps(context);
instance = ReflectionUtils.newInstance(((String) type.getValue(faces.getELContext()))); } catch (Exception e) { throw new AbortProcessingException(e.getMessage(), e);
/** * Creates an instance of a class with the given fully qualified class name. * * @param <T> The generic object type. * @param className fully qualified class name of the class for which an instance needs to be created * @return an instance of the class denoted by className * @throws IllegalStateException if the class cannot be found */ @SuppressWarnings("unchecked") public static <T> T instance(String className) { return (T) instance(toClass(className)); }
private Object copyBeanAndPopulateWithCandidateValues(FacesContext context, ValueExpression wholeBeanVE, Object wholeBean, String copierType, Map<String, Map<String, Object>> candidate) { // Populate the bean copy with the validated values from the candidate Map<String, Object> propertiesToSet = new HashMap<>(); for (Entry<String, Map<String, Object>> propertyEntry : candidate.entrySet()) { propertiesToSet.put(propertyEntry.getKey(), propertyEntry.getValue().get("value")); } // Copy the whole bean so that class-level validation can be performed // without corrupting the real whole bean Object wholeBeanCopy = getCopier(context, copierType) .copy(wholeBean); if (wholeBeanCopy == null) { throw new FacesException("Unable to copy bean from " + wholeBeanVE.getExpressionString()); } setProperties(wholeBeanCopy, propertiesToSet); return wholeBeanCopy; }
public static Copier getCopier(FacesContext context, String copierType) { Copier copier = null; if (!isEmpty(copierType)) { // TODO: or should validate only against {"MultiStrategyCopier", "SerializationCopier", // "NewInstanceCopier", "CopyCtorCopier", "CloneCopier"} strings / enum if (isCopierTypeSimpleName(copierType)) { copierType = COPIER_PREFIX.concat(copierType); } else if (!isName(copierType)) { throw new IllegalArgumentException(ERROR_COPIER_NAME); } Object expressionResult = evaluateExpressionGet(context, copierType); if (expressionResult instanceof Copier) { copier = (Copier) expressionResult; } else if (expressionResult instanceof String) { copier = instance((String) expressionResult); } } if (copier == null) { copier = new MultiStrategyCopier(); } return copier; }
/** * <p>Constructs a new object instance based off the * provided class name.</p> * @param className the class of the object to instantiate * @return a new instances of said class * @throws InstantiationException if the class cannot be instantiated * @throws IllegalAccessException if there is a security violation */ public static Object newInstance(String className) throws InstantiationException, IllegalAccessException { ClassLoader loader = Util.getCurrentLoader(null); if (loader == null) { return null; } return getMetaData(loader, className).lookupClass().newInstance(); }