FileDocCategorySizeDatePackage
ConfigBeanIntrospector.javaAPI DocGlassfish v2 API8083Fri May 04 22:33:56 BST 2007com.sun.enterprise.admin.server.core.mbean.config

ConfigBeanIntrospector

public final class ConfigBeanIntrospector extends Object

Fields Summary
private static final Logger
sLogger
Constructors Summary
Methods Summary
private static java.lang.reflect.MethodgetGetter(java.lang.Class beanClass, java.lang.String attributeName)

        Method m = null;
        PropertyDescriptor pd = getPropertyDescriptor(beanClass, attributeName);
        if (pd != null)
        {
            m = pd.getReadMethod();
        }
        return m;
    
private static java.beans.PropertyDescriptorgetPropertyDescriptor(java.lang.Class beanClass, java.lang.String attributeName)

        PropertyDescriptor descriptor = null;
        BeanInfo javaBeanInfo = Introspector.getBeanInfo(beanClass);
        PropertyDescriptor[] pds = javaBeanInfo.getPropertyDescriptors();
        for (int i = 0; i < pds.length; i++)
        {
            PropertyDescriptor pd = pds[i];
            if (pd.getName().equals(attributeName))
            {
                descriptor = pd;
                break;
            }
        }
        return descriptor;
    
private static java.lang.reflect.MethodgetSetter(java.lang.Class beanClass, java.lang.String attributeName)

        Method m = null;
        PropertyDescriptor pd = getPropertyDescriptor(beanClass, attributeName);
        if (pd != null)
        {
            m = pd.getWriteMethod();
        }
        return m;
    
public static java.lang.Objectinstantiate(java.lang.Class bean, java.lang.Object[] params)


           
         
    
        ArgChecker.checkValid(bean, "bean");        //NOI18N
        ArgChecker.checkValid(params, "params");    //NOI18N

        Class[] paramTypes = new Class[params.length];
        for (int i = 0; i < params.length; i++)
        {
            paramTypes[i] = params[i].getClass();
        }
        Constructor ctor = bean.getConstructor(paramTypes);
        Object inst = ctor.newInstance(params);
        return inst;
    
public static java.lang.ObjectinvokeGetter(java.lang.Object target, java.lang.String attributeName)

        ArgChecker.checkValid(target, "target"); //NOI18N
        ArgChecker.checkValid(attributeName, "attributeName"); //NOI18N

        Object ret = null;
        Class beanClass = target.getClass();
        Method getter = getGetter(beanClass, attributeName);
        if (getter != null)
        {
            ret = getter.invoke(target, (Object[])null);
        }
        return ret;
    
public static voidinvokeSetter(java.lang.Object target, java.lang.String attributeName, java.lang.Object value)

        ArgChecker.checkValid(target, "target"); //NOI18N
        ArgChecker.checkValid(attributeName, "attributeName"); //NOI18N

        Class beanClass = target.getClass();
        Method setter = getSetter(beanClass, attributeName);
        if (setter != null)
        {
            setter.invoke(target, new Object[] {value});
        }
    
public static booleanisAttributeReadable(java.lang.Class beanClass, java.lang.String attributeName)

        boolean isReadable = false;
        try
        {
            Method m = getGetter(beanClass, attributeName);
            isReadable = (m != null);
        }
        catch (Exception e)
        {
            sLogger.throwing(ConfigBeanIntrospector.class.getName(), 
                    "isAttributeReadable", e);
            isReadable = false;
        }
        return isReadable;
    
public static booleanisAttributeSupported(java.lang.Class beanClass, java.lang.String attributeName)

        boolean isSupported = false;
        try
        {
            PropertyDescriptor pd = getPropertyDescriptor(beanClass, 
                                                          attributeName);
            isSupported = (pd != null);
        }
        catch (Exception e)
        {
            sLogger.throwing(ConfigBeanIntrospector.class.getName(), 
                    "isAttributeSupported", e);
            isSupported = false;
        }
        return isSupported;
    
public static booleanisAttributeWritable(java.lang.Class beanClass, java.lang.String attributeName)

        boolean isWritable = false;
        try
        {
            Method m = getSetter(beanClass, attributeName);
            isWritable = (m != null);
        }
        catch (Exception e)
        {
            sLogger.throwing(ConfigBeanIntrospector.class.getName(), 
                    "isAttributeWritable", e);
            isWritable = false;
        }
        return isWritable;
    
public static voidmain(java.lang.String[] args)

        ConfigContext ctx = ConfigFactory.createConfigContext(
                "/u/ramakant/server.xml", true);
        Object obj = null;
//        Server baseBean = (Server) ctx.getRootConfigBean();
        Config          config  = (Config)ConfigBeansFactory.getConfigBeanByXPath(ctx, ServerXPathHelper.XPATH_CONFIG);
            
        IiopService iiopService = config.getIiopService();
        obj = iiopService.getIiopListenerById("orb-listener-1");

        //Getters
        Object value = ConfigBeanIntrospector.invokeGetter(obj, "id");
        sLogger.info(value.toString());
        try
        {
            ConfigBeanIntrospector.invokeGetter(obj, "abcd");
        }
        catch (Exception e)
        {
            sLogger.info("OK " + e.getMessage());
        }
        //Setters
        ConfigBeanIntrospector.invokeSetter(obj, "id", "surya10");
        ConfigBeanIntrospector.invokeSetter(obj, "port", 
                new Integer(8888).toString());

        ctx.flush(true);