List of usage examples for org.apache.commons.beanutils WrapDynaBean WrapDynaBean
public WrapDynaBean(Object instance)
DynaBean
associated with the specified JavaBean instance. From source file:org.latticesoft.util.common.MiscUtil.java
/** * Evaluate others element/*from w ww. j av a 2s. co m*/ */ private static Object evaluateOthersElement(Map map, Object currentObject, String elementName, boolean isObjectFirst) { if (log.isDebugEnabled()) { log.debug("<<isOthers>>"); } // from map directly or attribute // element is an attribute // previousElement.currentAttribute if (currentObject == null) { // 1st element have to retrieve from map currentObject = map.get(elementName); } else { // not the 1st element if (currentObject instanceof Map) { Map m = (Map) currentObject; currentObject = m.get(elementName); } else { try { WrapDynaBean bean = new WrapDynaBean(currentObject); currentObject = bean.get(elementName); } catch (Exception e) { // if it is not an attribute an occur will occur // note that the attribute must have a getter method if (log.isDebugEnabled()) { log.debug(e); } } } // if } return currentObject; }
From source file:org.latticesoft.util.common.StringUtil.java
/** * Print the properties of an object into a xml string. * This is useful in the object's toString method. * @param o the object to be converted/*ww w. j ava 2 s . c om*/ * @param mode one of the above mode * @param displayAll display all attributes including those which are null. * @return the string-fied xml form of the object */ public static String formatObjectToXmlString(Object o, int mode, boolean displayAll) { if (o == null) return "<NullClass/>"; StringBuffer sb = new StringBuffer(); String s = o.getClass().getName(); String p = o.getClass().getPackage().getName(); String className = s.substring(p.length() + 1, s.length()); if (mode == StringUtil.MODE_END_TAG) { sb.append("</"); sb.append(className); sb.append(">"); return sb.toString(); } sb.append("<"); sb.append(className); // list of attributes Field f[] = o.getClass().getDeclaredFields(); WrapDynaBean dyn = null; try { dyn = new WrapDynaBean(o); } catch (Exception e) { } for (int i = 0; i < f.length; i++) { String name = f[i].getName(); int modifier = f[i].getModifiers(); if (Modifier.isFinal(modifier) || Modifier.isAbstract(modifier) || Modifier.isInterface(modifier) || Modifier.isStatic(modifier)) { continue; } Object value = null; try { value = dyn.get(name); } catch (Exception e) { //if (log.isErrorEnabled()) { log.error(e); } } if (name != null) { if ((value != null && !displayAll) || (displayAll)) { sb.append(" "); sb.append(name); sb.append("=\""); sb.append(value); sb.append("\""); } } } switch (mode) { default: case StringUtil.MODE_FULL_STANDARD: sb.append("/>"); break; case StringUtil.MODE_FULL_LONG: sb.append("></"); sb.append(className); sb.append(">"); break; case StringUtil.MODE_START_TAG: sb.append(">"); break; } return sb.toString(); }
From source file:org.latticesoft.util.common.StringUtil.java
public static String formatObjectToString(Object o, boolean includeChild) { if (o == null) return ""; if (o == null) return ""; StringBuffer sb = new StringBuffer(); String className = o.getClass().getName(); sb.append("["); sb.append(className);/* w ww.ja v a 2 s.c o m*/ sb.append("|"); // list of attributes Field f[] = o.getClass().getDeclaredFields(); WrapDynaBean dyn = null; try { dyn = new WrapDynaBean(o); } catch (Exception e) { } for (int i = 0; i < f.length; i++) { String name = f[i].getName(); int modifier = f[i].getModifiers(); if (Modifier.isFinal(modifier) || Modifier.isAbstract(modifier) || Modifier.isInterface(modifier) || Modifier.isStatic(modifier)) { continue; } Object value = null; try { value = dyn.get(name); } catch (Exception e) { //if (log.isErrorEnabled()) { log.error(e); } } if (name != null && value != null) { sb.append(name); sb.append("="); if (value instanceof Map) { Map map = (Map) value; if (includeChild) { sb.append(value); } else { sb.append(map.size()); } sb.append("|"); } else if (value instanceof Collection) { Collection c = (Collection) value; if (includeChild) { sb.append(value); } else { sb.append(c.size()); } sb.append("|"); } else { sb.append(value); sb.append("|"); } } } sb.deleteCharAt(sb.length() - 1); sb.append("]"); return sb.toString(); }
From source file:org.latticesoft.util.resource.dao.Param.java
/** * @see #populate(Object, ResultSet)/*from w w w .jav a 2s . c o m*/ * @exception throws SQLException */ public void populateEx(Object o, ResultSet rs) throws SQLException { Object value = this.readValue(rs); if (o instanceof WrapDynaBean) { WrapDynaBean bean = (WrapDynaBean) o; bean.set(this.getAttribute(), value); } else if (o instanceof Map) { Map map = (Map) o; map.put(this.getAttribute(), value); } else { WrapDynaBean bean = new WrapDynaBean(o); bean.set(this.getAttribute(), value); } }
From source file:org.latticesoft.util.resource.dao.Param.java
/** * @see #prepare(Object, PreparedStatement) * @exception throws SQLException//from w ww . j av a2 s . c om */ public void prepareEx(Object o, PreparedStatement pstmt) throws SQLException { Object param = null; if (o instanceof WrapDynaBean) { WrapDynaBean bean = (WrapDynaBean) o; param = bean.get(this.getAttribute()); } else if (o instanceof Map) { Map map = (Map) o; param = map.get(this.getAttribute()); } else { WrapDynaBean bean = new WrapDynaBean(o); param = bean.get(this.getAttribute()); } this.setValueToStatement(param, pstmt); }
From source file:org.seasar.struts.pojo.form.S2BeanValidatorForm.java
/** * ?POJO???/* w w w. ja v a 2s. c om*/ * * @param bean * {@link ActionForm}?POJO */ public void initBean(Object bean) { super.dynaBean = new WrapDynaBean(bean); }