Example usage for java.beans Introspector flushFromCaches

List of usage examples for java.beans Introspector flushFromCaches

Introduction

In this page you can find the example usage for java.beans Introspector flushFromCaches.

Prototype

public static void flushFromCaches(Class<?> clz) 

Source Link

Document

Flush the Introspector's internal cached information for a given class.

Usage

From source file:net.sourceforge.vulcan.web.struts.forms.PluginConfigForm.java

public void introspect(HttpServletRequest request) throws IntrospectionException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException, InstantiationException {
    Class<?> cls = null;/*ww w .  j a v a 2 s. c o  m*/

    if ("pluginConfig".equals(focus)) {
        cls = pluginConfig.getClass();
        this.breadCrumbs.clear();
        this.breadCrumbs.add("Setup");

        if (isProjectPlugin()) {
            this.breadCrumbs.add("Projects");
            this.breadCrumbs.add(projectName);
            this.breadCrumbs.add(this.pluginConfig.getPluginName());
        } else {
            this.breadCrumbs.add("Plugins");
            this.breadCrumbs.add(this.pluginConfig.getPluginName());
        }
    } else {
        cls = PropertyUtils.getPropertyType(this, focus);
        if (cls.isArray()) {
            cls = cls.getComponentType();
        }
    }

    final String prefix = focus + ".";
    final PropertyDescriptor[] pds;

    if (PluginConfigDto.class.isAssignableFrom(cls)) {
        final PluginConfigDto pluginConfig = (PluginConfigDto) getFocusObject();
        final List<PropertyDescriptor> tmp = pluginConfig.getPropertyDescriptors(request.getLocale());
        pds = tmp.toArray(new PropertyDescriptor[tmp.size()]);

        if (pluginConfig instanceof PluginProfileDto) {
            ((PluginProfileDto) pluginConfig).checkPoint();
        }
    } else {
        final BeanInfo beanInfo = Introspector.getBeanInfo(cls);
        Introspector.flushFromCaches(cls);
        pds = beanInfo.getPropertyDescriptors();
    }

    if (isNested()) {
        for (PropertyDescriptor pd : propertyDescriptors) {
            if (focus.startsWith(pd.getName())) {
                breadCrumbs.add(pd.getDisplayName());
            }
        }
    }

    types.clear();
    choices.clear();
    propertyDescriptors.clear();
    hiddenPasswords.clear();

    for (PropertyDescriptor pd : pds) {
        final String name = prefix + pd.getName();
        final PropertyDescriptor cp = new PropertyDescriptor(pd.getName(), pd.getReadMethod(),
                pd.getWriteMethod());
        cp.setShortDescription(pd.getShortDescription());
        cp.setDisplayName(pd.getDisplayName());
        cp.setName(name);
        propertyDescriptors.add(cp);
        types.put(name, getTypeAndPrepare(name, pd));
    }

    putBreadCrumbsInRequest(request);
}

From source file:no.sesat.search.datamodel.generic.MapDataObjectBeanInfo.java

/**
 *
 * @param name/*from   w  w w .  j a  va2  s. c  o  m*/
 * @param cls
 * @return
 */
public static PropertyDescriptor[] addSingleMappedPropertyDescriptor(final String name, final Class<?> cls) {

    try {
        final PropertyDescriptor[] existing = Introspector.getBeanInfo(cls, Introspector.IGNORE_ALL_BEANINFO)
                .getPropertyDescriptors();
        // remove this introspection from the cache to avoid reuse of the IGNORE_ALL_BEANINFO result
        Introspector.flushFromCaches(cls);

        final PropertyDescriptor[] result = new PropertyDescriptor[existing.length + 2];
        System.arraycopy(existing, 0, result, 0, existing.length);
        result[existing.length] = new MappedPropertyDescriptor(name, cls);
        if (!System.getProperty("java.version").startsWith("1.6")) {
            fixForJavaBug4984912(cls, (MappedPropertyDescriptor) result[existing.length]);
        }

        final String captialised = Character.toUpperCase(name.charAt(0)) + name.substring(1);
        try {
            // try plural with "s" first, then fall back onto "es"
            result[existing.length + 1] = new PropertyDescriptor(name + 's', cls, "get" + captialised + 's',
                    null);
        } catch (IntrospectionException ie) {
            // who on earth designed the english language!?? :@
            result[existing.length + 1] = new PropertyDescriptor(name + "es", cls, "get" + captialised + 's',
                    null);
        }
        return result;

    } catch (IntrospectionException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new IllegalStateException('[' + cls.getSimpleName() + ']' + ex.getMessage(), ex);
    }
}

From source file:org.hopen.framework.rewrite.CachedIntrospectionResults.java

/**
 * Create a new CachedIntrospectionResults instance for the given class.
 * @param beanClass the bean class to analyze
 * @throws BeansException in case of introspection failure
 *///from   w w w.java 2 s .c  o  m
private CachedIntrospectionResults(Class beanClass, boolean cacheFullMetadata) throws BeansException {
    try {
        if (logger.isTraceEnabled()) {
            logger.trace("Getting BeanInfo for class [" + beanClass.getName() + "]");
        }

        BeanInfo beanInfo = null;
        for (BeanInfoFactory beanInfoFactory : beanInfoFactories) {
            beanInfo = beanInfoFactory.getBeanInfo(beanClass);
            if (beanInfo != null) {
                break;
            }
        }
        if (beanInfo == null) {
            // If none of the factories supported the class, fall back to the default
            beanInfo = Introspector.getBeanInfo(beanClass);
        }
        this.beanInfo = beanInfo;

        // Immediately remove class from Introspector cache, to allow for proper
        // garbage collection on class loader shutdown - we cache it here anyway,
        // in a GC-friendly manner. In contrast to CachedIntrospectionResults,
        // Introspector does not use WeakReferences as values of its WeakHashMap!
        Class classToFlush = beanClass;
        do {
            Introspector.flushFromCaches(classToFlush);
            classToFlush = classToFlush.getSuperclass();
        } while (classToFlush != null);

        if (logger.isTraceEnabled()) {
            logger.trace("Caching PropertyDescriptors for class [" + beanClass.getName() + "]");
        }
        this.propertyDescriptorCache = new LinkedHashMap<String, PropertyDescriptor>();

        // This call is slow so we do it once.
        PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor pd : pds) {
            if (Class.class.equals(beanClass) && "classLoader".equals(pd.getName())) {
                // Ignore Class.getClassLoader() method - nobody needs to bind to that
                continue;
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Found bean property '" + pd.getName() + "'"
                        + (pd.getPropertyType() != null ? " of type [" + pd.getPropertyType().getName() + "]"
                                : "")
                        + (pd.getPropertyEditorClass() != null
                                ? "; editor [" + pd.getPropertyEditorClass().getName() + "]"
                                : ""));
            }
            if (cacheFullMetadata) {
                pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
            }
            this.propertyDescriptorCache.put(pd.getName(), pd);
        }
    } catch (IntrospectionException ex) {
        throw new FatalBeanException("Failed to obtain BeanInfo for class [" + beanClass.getName() + "]", ex);
    }
}

From source file:org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.java

private static void cleanUpLoader(ClassLoader loader, Set<ClassLoader> encounteredLoaders,
        Set<Class<?>> encounteredClasses) throws Exception {
    if (!(loader instanceof GroovyClassLoader)) {
        return;/*from  w  w  w . ja  v a  2  s  . co  m*/
    }
    if (!encounteredLoaders.add(loader)) {
        return;
    }
    cleanUpLoader(loader.getParent(), encounteredLoaders, encounteredClasses);
    LOGGER.log(Level.FINER, "found {0}", String.valueOf(loader));
    SerializableClassRegistry.getInstance().release(loader);
    cleanUpGlobalClassValue(loader);
    GroovyClassLoader gcl = (GroovyClassLoader) loader;
    for (Class<?> clazz : gcl.getLoadedClasses()) {
        if (encounteredClasses.add(clazz)) {
            LOGGER.log(Level.FINER, "found {0}", clazz.getName());
            Introspector.flushFromCaches(clazz);
            cleanUpGlobalClassSet(clazz);
            cleanUpObjectStreamClassCaches(clazz);
            cleanUpLoader(clazz.getClassLoader(), encounteredLoaders, encounteredClasses);
        }
    }
    gcl.clearCache();
}

From source file:org.nextframework.controller.CachedIntrospectionResults.java

/**
 * Create new CachedIntrospectionResults instance fot the given class.
 *///from   w  w  w. ja  va 2s  . c o m
@SuppressWarnings("unchecked")
private CachedIntrospectionResults(Class clazz) throws BeansException {
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Getting BeanInfo for class [" + clazz.getName() + "]");
        }
        this.beanInfo = Introspector.getBeanInfo(clazz);

        // Immediately remove class from Introspector cache, to allow for proper
        // garbage collection on class loader shutdown - we cache it here anyway,
        // in a GC-friendly manner. In contrast to CachedIntrospectionResults,
        // Introspector does not use WeakReferences as values of its WeakHashMap!
        Class classToFlush = clazz;
        do {
            Introspector.flushFromCaches(classToFlush);
            classToFlush = classToFlush.getSuperclass();
        } while (classToFlush != null);

        if (logger.isDebugEnabled()) {
            logger.debug("Caching PropertyDescriptors for class [" + clazz.getName() + "]");
        }
        this.propertyDescriptorCache = new HashMap();

        // This call is slow so we do it once.
        PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
        for (int i = 0; i < pds.length; i++) {
            if (logger.isDebugEnabled()) {
                logger.debug("Found property '" + pds[i].getName() + "'"
                        + (pds[i].getPropertyType() != null
                                ? " of type [" + pds[i].getPropertyType().getName() + "]"
                                : "")
                        + (pds[i].getPropertyEditorClass() != null
                                ? "; editor [" + pds[i].getPropertyEditorClass().getName() + "]"
                                : ""));
            }

            // Set methods accessible if declaring class is not public, for example
            // in case of package-protected base classes that define bean properties.
            Method readMethod = pds[i].getReadMethod();
            if (readMethod != null && !Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
                readMethod.setAccessible(true);
            }
            Method writeMethod = pds[i].getWriteMethod();
            if (writeMethod != null && !Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
                writeMethod.setAccessible(true);
            }

            this.propertyDescriptorCache.put(pds[i].getName(), pds[i]);
        }
    } catch (IntrospectionException ex) {
        throw new FatalBeanException("Cannot get BeanInfo for object of class [" + clazz.getName() + "]", ex);
    }
}

From source file:org.tinygroup.beanwrapper.CachedIntrospectionResults.java

/**
 * Create a new CachedIntrospectionResults instance for the given class.
 * @param beanClass the bean class to analyze
 * @throws BeansException in case of introspection failure
 *//*ww w . j ava  2  s.  co  m*/
private CachedIntrospectionResults(Class beanClass) throws BeansException {
    try {
        if (logger.isTraceEnabled()) {
            logger.trace("Getting BeanInfo for class [" + beanClass.getName() + "]");
        }
        this.beanInfo = Introspector.getBeanInfo(beanClass);

        // Immediately remove class from Introspector cache, to allow for proper
        // garbage collection on class loader shutdown - we cache it here anyway,
        // in a GC-friendly manner. In contrast to CachedIntrospectionResults,
        // Introspector does not use WeakReferences as values of its WeakHashMap!
        Class classToFlush = beanClass;
        do {
            Introspector.flushFromCaches(classToFlush);
            classToFlush = classToFlush.getSuperclass();
        } while (classToFlush != null);

        if (logger.isTraceEnabled()) {
            logger.trace("Caching PropertyDescriptors for class [" + beanClass.getName() + "]");
        }
        this.propertyDescriptorCache = new HashMap();

        // This call is slow so we do it once.
        PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
        for (int i = 0; i < pds.length; i++) {
            PropertyDescriptor pd = pds[i];
            if (logger.isTraceEnabled()) {
                logger.trace("Found bean property '" + pd.getName() + "'"
                        + (pd.getPropertyType() != null ? " of type [" + pd.getPropertyType().getName() + "]"
                                : "")
                        + (pd.getPropertyEditorClass() != null
                                ? "; editor [" + pd.getPropertyEditorClass().getName() + "]"
                                : ""));
            }
            if (JdkVersion.isAtLeastJava15()) {
                pd = new GenericTypeAwarePropertyDescriptor(beanClass, pd.getName(), pd.getReadMethod(),
                        pd.getWriteMethod(), pd.getPropertyEditorClass());
            }
            this.propertyDescriptorCache.put(pd.getName(), pd);
        }
    } catch (IntrospectionException ex) {
        throw new FatalBeanException("Cannot get BeanInfo for object of class [" + beanClass.getName() + "]",
                ex);
    }
}