Methods Summary |
---|
private static java.lang.reflect.Method | getGetter(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.PropertyDescriptor | getPropertyDescriptor(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.Method | getSetter(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.Object | instantiate(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.Object | invokeGetter(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 void | invokeSetter(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 boolean | isAttributeReadable(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 boolean | isAttributeSupported(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 boolean | isAttributeWritable(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 void | main(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);
|