本文整理汇总了Java中org.apache.commons.beanutils.DynaBean类的典型用法代码示例。如果您正苦于以下问题:Java DynaBean类的具体用法?Java DynaBean怎么用?Java DynaBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DynaBean类属于org.apache.commons.beanutils包,在下文中一共展示了DynaBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: searchByName
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
public ActionForward searchByName(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
DynaBean lazyForm = (DynaBean) form;
String name = (String)lazyForm.get("search");
String last_name="",first_name="";
if (name != null && !name.equals("")) {
if (name.indexOf(',') < 0) {
last_name = name;
} else {
name = name.substring(0, name.indexOf(','));
first_name = name.substring(name.indexOf(',') + 1, name.length());
}
}
List<ProfessionalSpecialist> referrals = psDao.findByFullName(last_name, first_name);
request.setAttribute("referrals", referrals);
request.setAttribute("searchBy", "searchByName");
return mapping.findForward("list");
}
示例2: addRole
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
public ActionForward addRole(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
DynaBean lazyForm = (DynaBean) form;
Site site = (Site) lazyForm.get("site");
String roleId = request.getParameter("roleId");
String roleType = request.getParameter("roleType");
SuperSiteUtil superSiteUtil = (SuperSiteUtil) SpringUtils.getBean("superSiteUtil");
SiteRoleMpgDao siteRoleMpgDao = SpringUtils.getBean(SiteRoleMpgDao.class);
if(roleType!=null)
{
if(roleType.equalsIgnoreCase("access"))
siteRoleMpgDao.addAccessRoleToSite(site.getId(), Integer.parseInt(roleId));
else if(roleType.equalsIgnoreCase("admit_discharge"))
siteRoleMpgDao.addAdmitDischargeRoleToSite(site.getId(), Integer.parseInt(roleId));
}
request.setAttribute("siteId", site.getId()+"");
lazyForm.set("site", site);
return mapping.findForward("details");
}
示例3: deleteRole
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
public ActionForward deleteRole(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
DynaBean lazyForm = (DynaBean) form;
Site site = (Site) lazyForm.get("site");
String roleId = request.getParameter("roleId");
String roleType = request.getParameter("roleType");
SuperSiteUtil superSiteUtil = (SuperSiteUtil) SpringUtils.getBean("superSiteUtil");
SiteRoleMpgDao siteRoleMpgDao = SpringUtils.getBean(SiteRoleMpgDao.class);
if(roleType!=null)
{
if(roleType.equalsIgnoreCase("access"))
siteRoleMpgDao.deleteAccessRoleFromSite(site.getId(), Integer.parseInt(roleId));
else if(roleType.equalsIgnoreCase("admit_discharge"))
siteRoleMpgDao.deleteAdmitDischargeRoleToSite(site.getId(), Integer.parseInt(roleId));
}
request.setAttribute("siteId", site.getId()+"");
lazyForm.set("site", site);
return mapping.findForward("details");
}
示例4: createUpdateSql
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* Creates the SQL for updating an object of the given type. If a concrete bean is given,
* then a concrete update statement is created, otherwise an update statement usable in a
* prepared statement is build.
*
* @param model The database model
* @param dynaClass The type
* @param primaryKeys The primary keys
* @param properties The properties to write
* @param oldBean Contains column values to identify the rows to update (i.e. for the WHERE clause)
* @param newBean Contains the new column values to write
* @return The SQL required to update the instance
*/
protected String createUpdateSql(Database model, SqlDynaClass dynaClass, SqlDynaProperty[] primaryKeys, SqlDynaProperty[] properties, DynaBean oldBean, DynaBean newBean)
{
Table table = model.findTable(dynaClass.getTableName());
HashMap oldColumnValues = toColumnValues(primaryKeys, oldBean);
HashMap newColumnValues = toColumnValues(properties, newBean);
if (primaryKeys.length == 0)
{
_log.info("Cannot update instances of type " + dynaClass + " because it has no primary keys");
return null;
}
else
{
return _builder.getUpdateSql(table, oldColumnValues, newColumnValues, newBean == null);
}
}
示例5: getUpdateSql
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public String getUpdateSql(Database model, DynaBean dynaBean)
{
SqlDynaClass dynaClass = model.getDynaClassFor(dynaBean);
SqlDynaProperty[] primaryKeys = dynaClass.getPrimaryKeyProperties();
SqlDynaProperty[] nonPrimaryKeys = dynaClass.getNonPrimaryKeyProperties();
if (primaryKeys.length == 0)
{
_log.info("Cannot update instances of type " + dynaClass + " because it has no primary keys");
return null;
}
else
{
return createUpdateSql(model, dynaClass, primaryKeys, nonPrimaryKeys, dynaBean);
}
}
示例6: getDeleteSql
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public String getDeleteSql(Database model, DynaBean dynaBean)
{
SqlDynaClass dynaClass = model.getDynaClassFor(dynaBean);
SqlDynaProperty[] primaryKeys = dynaClass.getPrimaryKeyProperties();
if (primaryKeys.length == 0)
{
_log.warn("Cannot delete instances of type " + dynaClass + " because it has no primary keys");
return null;
}
else
{
return createDeleteSql(model, dynaClass, primaryKeys, dynaBean);
}
}
示例7: write
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* Writes the beans contained in the given iterator.
*
* @param beans The beans iterator
*/
public void write(Iterator beans) throws DataWriterException
{
while (beans.hasNext())
{
DynaBean bean = (DynaBean)beans.next();
if (bean instanceof SqlDynaBean)
{
write((SqlDynaBean)bean);
}
else
{
_log.warn("Cannot write normal dyna beans (type: "+bean.getDynaClass().getName()+")");
}
}
}
示例8: buildIdentityFromFK
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* Builds an identity object for the specified foreign key using the foreignkey column values
* of the supplied bean.
*
* @param owningTable The table owning the foreign key
* @param fk The foreign key
* @param bean The bean
* @return The identity
*/
private Identity buildIdentityFromFK(Table owningTable, ForeignKey fk, DynaBean bean)
{
Identity identity = new Identity(fk.getForeignTable(), getFKName(owningTable, fk));
for (int idx = 0; idx < fk.getReferenceCount(); idx++)
{
Reference reference = (Reference)fk.getReference(idx);
Object value = bean.get(reference.getLocalColumnName());
if (value == null)
{
return null;
}
identity.setColumnValue(reference.getForeignColumnName(), value);
}
return identity;
}
示例9: testToColumnValues
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* Test the toColumnValues method.
*/
public void testToColumnValues()
{
final String schema =
"<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
"<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='ddlutils'>\n"+
" <table name='TestTable'>\n"+
" <column name='id' autoIncrement='true' type='INTEGER' primaryKey='true'/>\n"+
" <column name='name' type='VARCHAR' size='15'/>\n"+
" </table>\n"+
"</database>";
Database database = parseDatabaseFromString(schema);
PlatformImplBase platform = new TestPlatform();
Table table = database.getTable(0);
SqlDynaClass clz = SqlDynaClass.newInstance(table);
DynaBean db = new SqlDynaBean(SqlDynaClass.newInstance(table));
db.set("name", "name");
Map map = platform.toColumnValues(clz.getSqlDynaProperties(), db);
assertEquals("name",
map.get("name"));
assertTrue(map.containsKey("id"));
}
示例10: getPropertyValue
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* Determines the value of the bean's property that has the given name. Depending on the
* case-setting of the current builder, the case of teh name is considered or not.
*
* @param bean The bean
* @param propName The name of the property
* @return The value
*/
protected Object getPropertyValue(DynaBean bean, String propName)
{
if (getPlatform().isDelimitedIdentifierModeOn())
{
return bean.get(propName);
}
else
{
DynaProperty[] props = bean.getDynaClass().getDynaProperties();
for (int idx = 0; idx < props.length; idx++)
{
if (propName.equalsIgnoreCase(props[idx].getName()))
{
return bean.get(props[idx].getName());
}
}
throw new IllegalArgumentException("The bean has no property with the name "+propName);
}
}
示例11: assertEquals
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* Compares the specified attribute value of the given bean with the expected object.
*
* @param expected The expected object
* @param bean The bean
* @param attrName The attribute name
*/
protected void assertEquals(Object expected, Object bean, String attrName)
{
DynaBean dynaBean = (DynaBean)bean;
Object value = dynaBean.get(attrName);
if ((value instanceof byte[]) && !(expected instanceof byte[]) && (dynaBean instanceof SqlDynaBean))
{
SqlDynaClass dynaClass = (SqlDynaClass)((SqlDynaBean)dynaBean).getDynaClass();
Column column = ((SqlDynaProperty)dynaClass.getDynaProperty(attrName)).getColumn();
if (TypeMap.isBinaryType(column.getTypeCode()))
{
value = new BinaryObjectsHelper().deserialize((byte[])value);
}
}
if (expected == null)
{
assertNull(value);
}
else
{
assertEquals(expected, value);
}
}
示例12: definePropertyType
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* Calculate the property type.
*
* @param target The bean
* @param name The property name
* @param propName The Simple name of target property
* @return The property's type
*
* @throws IllegalAccessException if the caller does not have
* access to the property accessor method
* @throws InvocationTargetException if the property accessor method
* throws an exception
*/
protected Class<?> definePropertyType(final Object target, final String name, final String propName)
throws IllegalAccessException, InvocationTargetException {
Class<?> type = null; // Java type of target property
if (target instanceof DynaBean) {
final DynaClass dynaClass = ((DynaBean) target).getDynaClass();
final DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
if (dynaProperty == null) {
return null; // Skip this property setter
}
type = dynaProperty.getType();
}
else {
PropertyDescriptor descriptor = null;
try {
descriptor =
getPropertyUtils().getPropertyDescriptor(target, name);
if (descriptor == null) {
return null; // Skip this property setter
}
}
catch (final NoSuchMethodException e) {
return null; // Skip this property setter
}
if (descriptor instanceof MappedPropertyDescriptor) {
type = ((MappedPropertyDescriptor) descriptor).
getMappedPropertyType();
}
else if (descriptor instanceof IndexedPropertyDescriptor) {
type = ((IndexedPropertyDescriptor) descriptor).
getIndexedPropertyType();
}
else {
type = descriptor.getPropertyType();
}
}
return type;
}
示例13: canReuseActionForm
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* <p>Determine whether <code>instance</code> of <code>ActionForm</code> is
* suitable for re-use as an instance of the form described by
* <code>config</code>.</p>
* @param instance an instance of <code>ActionForm</code> which was found,
* probably in either request or session scope.
* @param config the configuration for the ActionForm which is needed.
* @return true if the instance found is "compatible" with the type required
* in the <code>FormBeanConfig</code>; false if not, or if <code>instance</code>
* is null.
* @throws ClassNotFoundException if the <code>type</code> property of
* <code>config</code> is not a valid Class name.
*/
private static boolean canReuseActionForm(ActionForm instance, FormBeanConfig config)
throws ClassNotFoundException
{
if (instance == null) {
return (false);
}
boolean canReuse = false;
String formType = null;
String className = null;
if (config.getDynamic()) {
className = ((DynaBean) instance).getDynaClass().getName();
canReuse = className.equals(config.getName());
formType = "DynaActionForm";
} else {
Class configClass = applicationClass(config.getType());
className = instance.getClass().getName();
canReuse = configClass.isAssignableFrom(instance.getClass());
formType = "ActionForm";
}
if (log.isDebugEnabled()) {
log.debug(
" Can recycle existing "
+ formType
+ " instance "
+ "of type '"
+ className
+ "'?: "
+ canReuse);
log.trace(" --> " + instance);
}
return (canReuse);
}
示例14: newInstance
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* <p>Instantiate and return a new {@link DynaActionForm} instance,
* associated with this <code>DynaActionFormClass</code>. The
* properties of the returned {@link DynaActionForm} will have been
* initialized to the default values specified in the form bean
* configuration information.</p>
*
* @exception IllegalAccessException if the Class or the appropriate
* constructor is not accessible
* @exception InstantiationException if this Class represents an abstract
* class, an array class, a primitive type, or void; or if instantiation
* fails for some other reason
*/
public DynaBean newInstance()
throws IllegalAccessException, InstantiationException {
DynaActionForm dynaBean =
(DynaActionForm) getBeanClass().newInstance();
dynaBean.setDynaActionFormClass(this);
FormPropertyConfig props[] = config.findFormPropertyConfigs();
for (int i = 0; i < props.length; i++) {
dynaBean.set(props[i].getName(), props[i].initial());
}
return (dynaBean);
}
示例15: format
import org.apache.commons.beanutils.DynaBean; //导入依赖的package包/类
/**
* Formats the input object based on the layout specified in the ColumnModel.
*/
private static String format(Object value, DynaBean columnModel) {
try {
String layout = (String) columnModel.get("layout");
if ("[hh:mm]".equals(layout))
return decimal2hmm(value);
} catch (Exception e) {
}
return value != null ? value.toString() : "";
}