List of usage examples for org.apache.commons.beanutils DynaBean get
public Object get(String name);
From source file:com.xpfriend.fixture.cast.temp.Database.java
private String toString(List<String> keyColumns, DynaBean keyRow) { StringBuilder text = new StringBuilder(); for (String columnName : keyColumns) { if (text.length() == 0) { text.append("{"); } else {//from w w w. jav a2s . c o m text.append(", "); } text.append(columnName).append("=").append(keyRow.get(columnName)); } text.append("}"); return text.toString(); }
From source file:net.sf.json.TestUserSubmitted.java
public void testDynaBeanAttributeMap() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { // submited by arco.vandenheuvel[at]points[dot].com JSONObject jsonObject = JSONObject.fromObject(new JSONTestBean()); String jsonString = jsonObject.toString(); DynaBean jsonBean = (DynaBean) JSONObject.toBean(JSONObject.fromObject(jsonString)); assertNotNull(jsonBean);//from www . ja v a2 s . co m assertEquals("wrong inventoryID", "", jsonBean.get("inventoryID")); }
From source file:net.mlw.vlh.web.tag.DynaBeanColumnsTag.java
/** * @see javax.servlet.jsp.tagext.Tag#doEndTag() *//*from w w w.jav a2s.c om*/ public int doEndTag() throws JspException { ValueListSpaceTag rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class); DefaultRowTag rowTag = (DefaultRowTag) JspUtils.getParent(this, DefaultRowTag.class); DynaBean bean = (DynaBean) pageContext.getAttribute(rowTag.getBeanName()); if (bean == null) { LOGGER.error("Zero results where returned."); return SKIP_BODY; } DynaClass dClass = bean.getDynaClass(); StringBuffer sb = new StringBuffer(); for (int i = 0, length = dClass.getDynaProperties().length; i < length; i++) { String name = dClass.getDynaProperties()[i].getName(); if ((include.isEmpty() || include.contains(name)) && (exclude.isEmpty() || !exclude.contains(name))) { if (rowTag.getCurrentRowNumber() == 0) { String displayName = name.substring(0, 1).toUpperCase() + name.substring(1); rowTag.addColumnInfo(new ColumnInfo(displayName, name, defaultSort, null)); } sb.append(rowTag.getDisplayProvider().getCellPreProcess(null)); if (bean.get(name) == null) { sb.append(rootTag.getConfig().getNullToken()); } else { sb.append(bean.get(name)); } sb.append(rowTag.getDisplayProvider().getCellPostProcess()); } } JspUtils.write(pageContext, sb.toString()); release(); return EVAL_PAGE; }
From source file:net.sf.json.TestUserSubmitted.java
public void testBug_1635890() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { // submited by arco.vandenheuvel[at]points[dot].com String TEST_JSON_STRING = "{\"rateType\":\"HOTRATE\",\"rateBreakdown\":{\"rate\":[{\"amount\":\"109.74\",\"date\":{\"month\":\"01\",\"day\":\"15\",\"year\":\"2007\"}},{\"amount\":\"109.74\",\"date\":{\"month\":\"1\",\"day\":\"16\",\"year\":\"2007\"}}]}}"; DynaBean jsonBean = (DynaBean) JSONObject.toBean(JSONObject.fromObject(TEST_JSON_STRING)); assertNotNull(jsonBean);/*from w ww . j av a 2 s . c om*/ assertEquals("wrong rate Type", "HOTRATE", jsonBean.get("rateType")); assertNotNull("null rate breakdown", jsonBean.get("rateBreakdown")); DynaBean jsonRateBreakdownBean = (DynaBean) jsonBean.get("rateBreakdown"); assertNotNull("null rate breakdown ", jsonRateBreakdownBean); Object jsonRateBean = jsonRateBreakdownBean.get("rate"); assertNotNull("null rate ", jsonRateBean); assertTrue("list", jsonRateBean instanceof ArrayList); assertNotNull("null rate ", jsonRateBreakdownBean.get("rate", 0)); }
From source file:com.xpfriend.fixture.cast.temp.Database.java
private void setQueryString(TempDynaSet table, DynaBean row, DbCommand command, String queryPrefix, List<String> columnNames) throws SQLException { DynaClass metaData = getMetaDataTable(table.getTableName()); StringBuilder query = new StringBuilder(); for (String columnName : columnNames) { Class<?> columnType = getColumnType(columnName, metaData, table); Object columnValue = convertType(columnType, row.get(columnName)); addParameter(command, queryPrefix, query, columnName, columnType, columnValue); }/* w w w . jav a 2s . co m*/ command.setSQL(query.toString(), true); }
From source file:com.xwtec.xwserver.util.json.JSONObject.java
private static JSONObject _fromDynaBean(DynaBean bean, JsonConfig jsonConfig) { if (bean == null) { fireObjectStartEvent(jsonConfig); fireObjectEndEvent(jsonConfig);// w ww .j a va2 s. c o m return new JSONObject(true); } if (!addInstance(bean)) { try { return jsonConfig.getCycleDetectionStrategy().handleRepeatedReferenceAsObject(bean); } catch (JSONException jsone) { removeInstance(bean); fireErrorEvent(jsone, jsonConfig); throw jsone; } catch (RuntimeException e) { removeInstance(bean); JSONException jsone = new JSONException(e); fireErrorEvent(jsone, jsonConfig); throw jsone; } } fireObjectStartEvent(jsonConfig); JSONObject jsonObject = new JSONObject(); try { DynaProperty[] props = bean.getDynaClass().getDynaProperties(); Collection exclusions = jsonConfig.getMergedExcludes(); PropertyFilter jsonPropertyFilter = jsonConfig.getJsonPropertyFilter(); for (int i = 0; i < props.length; i++) { boolean bypass = false; DynaProperty dynaProperty = props[i]; String key = dynaProperty.getName(); if (exclusions.contains(key)) { continue; } Class type = dynaProperty.getType(); Object value = bean.get(dynaProperty.getName()); if (jsonPropertyFilter != null && jsonPropertyFilter.apply(bean, key, value)) { continue; } JsonValueProcessor jsonValueProcessor = jsonConfig.findJsonValueProcessor(type, key); if (jsonValueProcessor != null) { value = jsonValueProcessor.processObjectValue(key, value, jsonConfig); bypass = true; if (!JsonVerifier.isValidJsonValue(value)) { throw new JSONException("Value is not a valid JSON value. " + value); } } setValue(jsonObject, key, value, type, jsonConfig, bypass); } } catch (JSONException jsone) { removeInstance(bean); fireErrorEvent(jsone, jsonConfig); throw jsone; } catch (RuntimeException e) { removeInstance(bean); JSONException jsone = new JSONException(e); fireErrorEvent(jsone, jsonConfig); throw jsone; } removeInstance(bean); fireObjectEndEvent(jsonConfig); return jsonObject; }
From source file:no.sesat.search.mode.command.GoogleSearchCommand.java
@Override public ResultList<ResultItem> execute() { final ResultList<ResultItem> result = new BasicResultList<ResultItem>(); final BufferedReader reader; try {/* ww w . jav a2 s. com*/ reader = getRestful().getHttpReader("UTF8"); if (null != reader) { final StringBuilder builder = new StringBuilder(); String line; while (null != (line = reader.readLine())) { builder.append(line); } final DynaBean bean = (DynaBean) JSONSerializer.toJava(JSONSerializer.toJSON(builder.toString())); final DynaBean data = (DynaBean) bean.get("responseData"); final String totalResults = ((DynaBean) data.get("cursor")).get("estimatedResultCount").toString(); result.setHitCount(Integer.parseInt(totalResults)); final List<DynaBean> results = (List<DynaBean>) data.get("results"); for (DynaBean r : results) { result.addResult(createItem(r)); } } } catch (SocketTimeoutException ste) { LOG.error(getSearchConfiguration().getName() + " --> " + ste.getMessage()); return new BasicResultList<ResultItem>(); } catch (IOException ex) { throw new SearchCommandException(ex); } return result; }
From source file:no.sesat.search.mode.command.GoogleSearchCommand.java
protected ResultItem createItem(final DynaBean entry) { ResultItem resItem = new BasicResultItem(); final DynaProperty[] descriptors = entry.getDynaClass().getDynaProperties(); for (DynaProperty d : descriptors) { if (entry.get(d.getName()) instanceof Serializable) { resItem = resItem.addObjectField(d.getName(), (Serializable) entry.get(d.getName())); }/*from ww w . j av a2 s .co m*/ } return resItem; }
From source file:org.apache.action2.legacy.DynaBeanPropertyAccessor.java
public Object getProperty(Map context, Object target, Object name) throws OgnlException { if (target instanceof DynaBean && name != null) { DynaBean bean = (DynaBean) target; DynaClass cls = bean.getDynaClass(); String key = name.toString(); if (cls.getDynaProperty(key) != null) { return bean.get(key); }/*from ww w . j a v a 2 s .c o m*/ } return null; }
From source file:org.apache.ddlutils.DatabaseTestHelper.java
/** * Helper method for build a SELECT statement. * //from ww w. j av a 2 s .c o m * @param targetPlatform The platform for the queried database * @param table The queried table * @param whereCols The optional columns that make up the WHERE clause * @param whereValues The optional column value that make up the WHERE clause * @return The query string */ private String buildQueryString(Platform targetPlatform, Table table, Column[] whereCols, DynaBean whereValues) { StringBuffer result = new StringBuffer(); result.append("SELECT * FROM "); if (targetPlatform.isDelimitedIdentifierModeOn()) { result.append(targetPlatform.getPlatformInfo().getDelimiterToken()); } result.append(table.getName()); if (targetPlatform.isDelimitedIdentifierModeOn()) { result.append(targetPlatform.getPlatformInfo().getDelimiterToken()); } if ((whereCols != null) && (whereCols.length > 0)) { result.append(" WHERE "); for (int idx = 0; idx < whereCols.length; idx++) { Object value = (whereValues == null ? null : whereValues.get(whereCols[idx].getName())); if (idx > 0) { result.append(" AND "); } if (targetPlatform.isDelimitedIdentifierModeOn()) { result.append(targetPlatform.getPlatformInfo().getDelimiterToken()); } result.append(whereCols[idx].getName()); if (targetPlatform.isDelimitedIdentifierModeOn()) { result.append(targetPlatform.getPlatformInfo().getDelimiterToken()); } result.append(" = "); if (value == null) { result.append("NULL"); } else { if (!whereCols[idx].isOfNumericType()) { result.append(targetPlatform.getPlatformInfo().getValueQuoteToken()); } result.append(value.toString()); if (!whereCols[idx].isOfNumericType()) { result.append(targetPlatform.getPlatformInfo().getValueQuoteToken()); } } } } return result.toString(); }