Returns the bean descriptor. - Java Reflection

Java examples for Reflection:Java Bean

Description

Returns the bean descriptor.

Demo Code

/*//from www . j a  va 2  s  . com
 * Copyright 2004-2010 the Seasar Foundation and the Others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.http.HttpServletRequest;

public class Main{
    public static void main(String[] argv) throws Exception{
        Class beanClass = String.class;
        System.out.println(getBeanDesc(beanClass));
    }
    private static ConcurrentHashMap<String, BeanDesc> beanDescCache = new ConcurrentHashMap<String, BeanDesc>(
            200);
    private static volatile boolean initialized = false;
    /**
     * Returns the bean descriptor.
     * 
     * @param beanClass
     *            the bean class
     * @return the bean descriptor
     * @throws NullPointerException
     *             if the beanClass parameter is null
     * 
     */
    public static BeanDesc getBeanDesc(Class<?> beanClass)
            throws NullPointerException {
        if (beanClass == null) {
            throw new NullPointerException(
                    "The beanClass parameter is null.");
        }
        if (!initialized) {
            initialize();
        }

        BeanDesc beanDesc = beanDescCache.get(beanClass.getName());
        if (beanDesc != null) {
            return beanDesc;
        }
        beanDesc = BeanDesc.create(beanClass);
        beanDescCache.put(beanClass.getName(), beanDesc);
        return beanDesc;
    }
    private static void initialize() {
        Cleaner.add(new Cleanable() {
            public void clean() {
                beanDescCache.clear();
                initialized = false;
            }
        });
        initialized = true;
    }
}

Related Tutorials