List of usage examples for org.apache.commons.beanutils DynaBean getDynaClass
public DynaClass getDynaClass();
DynaClass
instance that describes the set of properties available for this DynaBean. From source file:org.apache.struts.faces.application.PropertyResolverImpl.java
/** * <p>Return the <code>DynaProperty</code> describing the specified * property of the specified <code>DynaBean</code>, or <code>null</code> * if there is no such property defined on the underlying * <code>DynaClass</code>.</p> * * @param bean <code>DynaBean</code> to be checked * @param name Name of the property to be checked *//*from w ww . jav a2s.co m*/ private DynaProperty getDynaProperty(DynaBean bean, String name) throws PropertyNotFoundException { DynaProperty dynaProperty = null; try { dynaProperty = bean.getDynaClass().getDynaProperty(name); } catch (IllegalArgumentException e) { ; } return (dynaProperty); }
From source file:org.ejbca.ui.cli.FieldEditor.java
/** Lists methods in a class the has "setXyz", and prints them as "Xyz". * Ignores (does not list) type, version, latestVersion, upgrade and class * /*from w w w . ja v a2 s .com*/ * @param obj the Object where to look for setMethods */ public void listSetMethods(final Object obj) { DynaBean wrapper = new WrapDynaBean(obj); DynaProperty[] props = wrapper.getDynaClass().getDynaProperties(); for (DynaProperty dynaProperty : props) { if (!excluded.contains(dynaProperty.getName())) { logger.info(dynaProperty.getName() + ", " + dynaProperty.getType()); } } }
From source file:org.ejbca.ui.cli.FieldEditor.java
public List<String> getSetMethodNames(final Object obj) { List<String> result = new ArrayList<String>(); DynaBean wrapper = new WrapDynaBean(obj); DynaProperty[] props = wrapper.getDynaClass().getDynaProperties(); for (DynaProperty dynaProperty : props) { if (!excluded.contains(dynaProperty.getName())) { result.add(dynaProperty.getName()); }//from w w w . j a v a2s . c o m } return result; }
From source file:org.jwebsocket.dynamicsql.SupportUtils.java
/** * Convert a DynaBean object to Map./*from w w w . j a va 2 s . co m*/ * * @param aDynaBean The DynaBean object. * @return The Map<String, Object> */ public static Map<String, Object> convertToMap(DynaBean aDynaBean) { Map<String, Object> lMap = new FastMap<String, Object>(); for (DynaProperty lDynaProperty : aDynaBean.getDynaClass().getDynaProperties()) { lMap.put(lDynaProperty.getName(), aDynaBean.get(lDynaProperty.getName())); } return lMap; }
From source file:org.kohsuke.stapler.jelly.groovy.JellyBuilder.java
private void configureTag(Tag tag, Map attributes) throws JellyException { if (tag instanceof DynaTag) { DynaTag dynaTag = (DynaTag) tag; for (Object o : attributes.entrySet()) { Entry entry = (Entry) o;//from w w w . j av a 2s . c o m String name = (String) entry.getKey(); if (name.equals("xmlns")) continue; // we'll process this by ourselves Object value = getValue(entry, dynaTag.getAttributeType(name)); dynaTag.setAttribute(name, value); } } else { // treat the tag as a bean DynaBean dynaBean = new ConvertingWrapDynaBean(tag); for (Object o : attributes.entrySet()) { Entry entry = (Entry) o; String name = (String) entry.getKey(); if (name.equals("xmlns")) continue; // we'll process this by ourselves DynaProperty property = dynaBean.getDynaClass().getDynaProperty(name); if (property == null) { throw new JellyException("This tag does not understand the '" + name + "' attribute"); } dynaBean.set(name, getValue(entry, property.getType())); } } }
From source file:org.kordamp.ezmorph.bean.BeanMorpher.java
public Object morph(Object sourceBean) { if (sourceBean == null) { return null; }/*from w ww . j a v a 2 s . co m*/ if (!supports(sourceBean.getClass())) { throw new MorphException("unsupported class: " + sourceBean.getClass().getName()); } Object targetBean = null; try { targetBean = beanClass.newInstance(); PropertyDescriptor[] targetPds = PropertyUtils.getPropertyDescriptors(beanClass); for (int i = 0; i < targetPds.length; i++) { PropertyDescriptor targetPd = targetPds[i]; String name = targetPd.getName(); if (targetPd.getWriteMethod() == null) { log.info("Property '" + beanClass.getName() + "." + name + "' has no write method. SKIPPED."); continue; } Class sourceType = null; if (sourceBean instanceof DynaBean) { DynaBean dynaBean = (DynaBean) sourceBean; DynaProperty dynaProperty = dynaBean.getDynaClass().getDynaProperty(name); if (dynaProperty == null) { log.warn("DynaProperty '" + name + "' does not exist. SKIPPED."); continue; } sourceType = dynaProperty.getType(); } else { PropertyDescriptor sourcePd = PropertyUtils.getPropertyDescriptor(sourceBean, name); if (sourcePd == null) { log.warn("Property '" + sourceBean.getClass().getName() + "." + name + "' does not exist. SKIPPED."); continue; } else if (sourcePd.getReadMethod() == null) { log.warn("Property '" + sourceBean.getClass().getName() + "." + name + "' has no read method. SKIPPED."); continue; } sourceType = sourcePd.getPropertyType(); } Class targetType = targetPd.getPropertyType(); Object value = PropertyUtils.getProperty(sourceBean, name); setProperty(targetBean, name, sourceType, targetType, value); } } catch (MorphException me) { throw me; } catch (Exception e) { throw new MorphException(e); } return targetBean; }