本文整理汇总了Java中org.apache.commons.beanutils.BasicDynaClass.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDynaClass.newInstance方法的具体用法?Java BasicDynaClass.newInstance怎么用?Java BasicDynaClass.newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.beanutils.BasicDynaClass
的用法示例。
在下文中一共展示了BasicDynaClass.newInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: objectArrayToBean
import org.apache.commons.beanutils.BasicDynaClass; //导入方法依赖的package包/类
/**
* Constructs a DynaBean using the values and properties specified.
* @param values property values.
* @param properties properties to add to the bean.
* @param classes properties types.
* @return DynBean with the values and properties specified.
*/
protected DynaBean objectArrayToBean(Object[] values, String[] properties, Class<?>[] classes) {
DynaBean dynaBean = null;
try {
DynaProperty[] columnsDynaProperties = getColumnsDynaProperties(properties, classes);
BasicDynaClass clazz = new BasicDynaClass(this.getClass().getSimpleName(), BasicDynaBean.class, columnsDynaProperties);
dynaBean = clazz.newInstance();
for(int i = 0; i < columnsDynaProperties.length; i++) {
dynaBean.set(columnsDynaProperties[i].getName(), values[i]);
}
} catch (Exception e) {
throw new RuntimeException("Error creating dynamic bean", e);
}
return dynaBean;
}
示例2: addValue
import org.apache.commons.beanutils.BasicDynaClass; //导入方法依赖的package包/类
/**
* Creates a {@link org.apache.commons.beanutils.DynaBean} with a
* {@link org.apache.commons.beanutils.DynaProperty} named
* <code>propertyName,</code> sets the value of the property to <code>v</code>
* and adds the DynaBean to the underlying list.
*
*/
public void addValue(double v) {
DynaProperty[] props = new DynaProperty[] {
new DynaProperty(propertyName, Double.class)
};
BasicDynaClass dynaClass = new BasicDynaClass(null, null, props);
DynaBean dynaBean = null;
try {
dynaBean = dynaClass.newInstance();
} catch (Exception ex) { // InstantiationException, IllegalAccessException
throw new RuntimeException(ex); // should never happen
}
dynaBean.set(propertyName, Double.valueOf(v));
addObject(dynaBean);
}
示例3: addValue
import org.apache.commons.beanutils.BasicDynaClass; //导入方法依赖的package包/类
/**
* Creates a {@link org.apache.commons.beanutils.DynaBean} with a
* {@link org.apache.commons.beanutils.DynaProperty} named
* <code>propertyName,</code> sets the value of the property to <code>v</code>
* and adds the DynaBean to the underlying list.
*
*/
public void addValue(double v) {
DynaProperty[] props = new DynaProperty[] {
new DynaProperty(propertyName, Double.class)
};
BasicDynaClass dynaClass = new BasicDynaClass(null, null, props);
DynaBean dynaBean = null;
try {
dynaBean = dynaClass.newInstance();
} catch (Exception ex) { // InstantiationException, IllegalAccessException
throw new RuntimeException(ex); // should never happen
}
dynaBean.set(propertyName, new Double(v));
addObject(dynaBean);
}