List of usage examples for org.apache.commons.beanutils DynaProperty getName
public String getName()
From source file:com.expressui.core.util.ReflectionUtil.java
/** * Finds all properties in the bean that are complex, that is not BeanUtils.isSimpleValueType * * @param bean bean to reflectively analyze * @return collection of properties on the bean */// w ww. j av a 2 s . c om public static Collection<String> findComplexProperties(Object bean) { Collection<String> complexProperties = new ArrayList<String>(); WrapDynaBean wrapDynaBean = new WrapDynaBean(bean); DynaProperty[] properties = wrapDynaBean.getDynaClass().getDynaProperties(); for (DynaProperty property : properties) { String propertyName = property.getName(); Class propertyType = property.getType(); if (!BeanUtils.isSimpleValueType(propertyType)) { complexProperties.add(propertyName); } } return complexProperties; }
From source file:com.expressui.core.util.ReflectionUtil.java
/** * Asks if the bean's properties are empty. boolean properties that are false and numbers * that are zero are considered empty. String values that are zero-length are considered empty. * All other property types must be null to be considered empty. * * @param bean bean to check/*from w ww. j a va 2 s . com*/ * @return true if bean has no values */ public static boolean isBeanEmpty(Object bean) { if (bean == null) { return true; } WrapDynaBean wrapDynaBean = new WrapDynaBean(bean); DynaProperty[] properties = wrapDynaBean.getDynaClass().getDynaProperties(); for (DynaProperty property : properties) { String propertyName = property.getName(); Class propertyType = property.getType(); Object value = wrapDynaBean.get(propertyName); if (propertyType.isPrimitive()) { if (value instanceof Number && !value.toString().equals("0")) { return false; } else if (value instanceof Boolean && !value.toString().equals("false")) { return false; } else if (!value.toString().isEmpty()) { return false; } } else if (value != null) { if (!(value instanceof Collection)) { String convertedStringValue = ConvertUtils.convert(value); if (!StringUtil.isEmpty(convertedStringValue)) { return false; } } } } return true; }
From source file:com.github.haixing_hu.ilibrary.model.FieldTemplateTest.java
@Test public void testToDynaProperty() { final FieldTemplate title = getTitleField(); final DynaProperty titleProp = title.toDynaProperty(); assertEquals("title", titleProp.getName()); assertEquals(String.class, titleProp.getType()); final FieldTemplate authors = getAuthorsField(); final DynaProperty authorsProp = authors.toDynaProperty(); assertEquals("authors", authorsProp.getName()); assertEquals(List.class, authorsProp.getType()); assertEquals(Responsibility.class, authorsProp.getContentType()); }
From source file:ddf.catalog.data.dynamic.impl.MetacardPropertyDescriptorImpl.java
/** * Creates a property desriptor based on the given DynaProperty object and the specified values for * indexedBySource, tokenized, and stored. * This works for the majority of cases. In cases where the underlying class representing this * property is the same as other property formats, {@link #setFormat(AttributeFormat)} should be * called after creation to set the correct format. * @param dynaProperty descriptor of the attribute (name, value, etc.) * @param indexedBySource indicates whether the source should index this attribute for search * @param stored indicates whether the source should store this value * @param tokenized indicates whether the value for this attribute should be parsed */// w w w. ja v a2s . co m public MetacardPropertyDescriptorImpl(DynaProperty dynaProperty, boolean indexedBySource, boolean stored, boolean tokenized) { super(dynaProperty.getName(), dynaProperty.getType(), dynaProperty.getContentType()); this.indexedBySource = indexedBySource; this.stored = stored; this.tokenized = tokenized; format = getFormatFromClass( dynaProperty.getContentType() == null ? dynaProperty.getType() : dynaProperty.getContentType()); }
From source file:net.sf.json.JSONDynaClass.java
/** * DOCUMENT ME!//from w w w. j ava2 s . c o m * * @param obj DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof JSONDynaClass)) { return false; } JSONDynaClass other = (JSONDynaClass) obj; EqualsBuilder builder = new EqualsBuilder().append(this.name, other.name).append(this.type, other.type); for (int i = 0; i < dynaProperties.length; i++) { DynaProperty a = this.dynaProperties[i]; DynaProperty b = other.dynaProperties[i]; builder.append(a.getName(), b.getName()); builder.append(a.getType(), b.getType()); } return builder.isEquals(); }
From source file:net.sf.json.JSONDynaBean.java
/** * DOCUMENT ME!//from w ww. ja v a2 s . co m * * @return DOCUMENT ME! */ public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder().append(dynaClass); DynaProperty[] props = dynaClass.getDynaProperties(); for (int i = 0; i < props.length; i++) { DynaProperty prop = props[i]; builder.append(dynaValues.get(prop.getName())); } return builder.toHashCode(); }
From source file:net.sf.json.JSONDynaBean.java
/** * DOCUMENT ME!// www .ja v a2 s . co m * * @param obj DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof JSONDynaBean)) { return false; } JSONDynaBean other = (JSONDynaBean) obj; EqualsBuilder builder = new EqualsBuilder().append(this.dynaClass, other.dynaClass); DynaProperty[] props = dynaClass.getDynaProperties(); for (int i = 0; i < props.length; i++) { DynaProperty prop = props[i]; builder.append(dynaValues.get(prop.getName()), dynaValues.get(prop.getName())); } return builder.isEquals(); }
From source file:com.nfwork.dbfound.json.JSONDynaClass.java
private void process() { this.jsonBeanClass = this.type; if (!JSONDynaBean.class.isAssignableFrom(this.jsonBeanClass)) { throw new IllegalArgumentException("Unnasignable dynaClass " + jsonBeanClass); }/*from w ww . j a v a 2s . co m*/ try { Iterator entries = attributes.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); String pname = (String) entry.getKey(); Object pclass = entry.getValue(); DynaProperty dynaProperty = null; if (pclass instanceof String) { dynaProperty = new DynaProperty(pname, Class.forName((String) pclass)); } else if (pclass instanceof Class) { dynaProperty = new DynaProperty(pname, (Class) pclass); } else { throw new IllegalArgumentException("Type must be String or Class"); } properties.put(dynaProperty.getName(), dynaProperty); } } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } }
From source file:com.xpfriend.fixture.cast.temp.Database.java
private void delete(TempDynaSet table, Table tableInfo) { String queryPrefix = "delete from " + table.getTableName() + " where "; List<String> columnNames = new ArrayList<String>(); for (DynaProperty column : table.getColumns()) { columnNames.add(column.getName()); }//from ww w . j a va 2 s . c om List<Row> rowInfo = tableInfo.getRows(); int rowIndex = 0; for (DynaBean row : table.getRows()) { delete(table, row, queryPrefix, columnNames, tableInfo, rowInfo.get(rowIndex++)); } }
From source file:net.sf.json.JSONDynaClass.java
/** * DOCUMENT ME!/* w w w .ja va 2s .co m*/ */ private void process() { this.jsonBeanClass = this.type; if (!JSONDynaBean.class.isAssignableFrom(this.jsonBeanClass)) { throw new IllegalArgumentException("Unnasignable dynaClass " + jsonBeanClass); } try { Iterator entries = attributes.entrySet().iterator(); dynaProperties = new DynaProperty[attributes.size()]; int i = 0; while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); String pname = (String) entry.getKey(); Object pclass = entry.getValue(); DynaProperty dynaProperty = null; if (pclass instanceof String) { dynaProperty = new DynaProperty(pname, Class.forName((String) pclass)); } else if (pclass instanceof Class) { dynaProperty = new DynaProperty(pname, (Class) pclass); } else { throw new IllegalArgumentException("Type must be String or Class"); } properties.put(dynaProperty.getName(), dynaProperty); dynaProperties[i++] = dynaProperty; } } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } // keep properties sorted by name Arrays.sort(dynaProperties, 0, dynaProperties.length, DynaPropertyComparator); }