当前位置: 首页>>代码示例>>Java>>正文


Java BeanUtilsBean类代码示例

本文整理汇总了Java中org.apache.commons.beanutils.BeanUtilsBean的典型用法代码示例。如果您正苦于以下问题:Java BeanUtilsBean类的具体用法?Java BeanUtilsBean怎么用?Java BeanUtilsBean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BeanUtilsBean类属于org.apache.commons.beanutils包,在下文中一共展示了BeanUtilsBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGet

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
    User user = new User();
    HashMap map = new HashMap();
    Enumeration names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        map.put(name, request.getParameterValues(name));
    }
    try{
        BeanUtils.populate(user, map); //BAD

        BeanUtilsBean beanUtl = BeanUtilsBean.getInstance();
        beanUtl.populate(user, map); //BAD
    }catch(Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:18,代码来源:BeanInjection.java

示例2: checkProperties

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
/**
 * Checks if the Property Values of the item are valid for the Request.
 *
 * @param item
 * @throws AirtableException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 */
private void checkProperties(T item) throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (propertyExists(item, FIELD_ID) || propertyExists(item, FIELD_CREATED_TIME)) {
        Field[] attributes = item.getClass().getDeclaredFields();
        for (Field attribute : attributes) {
            String attrName = attribute.getName();
            if (FIELD_ID.equals(attrName) || FIELD_CREATED_TIME.equals(attrName)) {
                if (BeanUtils.getProperty(item, attribute.getName()) != null) {
                    throw new AirtableException("Property " + attrName + " should be null!");
                }
            } else if ("photos".equals(attrName)) {
                List<Attachment> obj = (List<Attachment>) BeanUtilsBean.getInstance().getPropertyUtils().getProperty(item, "photos");
                checkPropertiesOfAttachement(obj);
            }
        }
    }

}
 
开发者ID:Sybit-Education,项目名称:airtable.java,代码行数:28,代码来源:Table.java

示例3: doUpdateAccess

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
/**
 * @param accesses 不可操作的字段
 * @param params   参数上下文
 * @return true
 * @see BeanUtilsBean
 * @see org.apache.commons.beanutils.PropertyUtilsBean
 */
protected boolean doUpdateAccess(FieldFilterDataAccessConfig accesses, AuthorizingContext params) {
    Object supportParam = params.getParamContext().getParams().values().stream()
            .filter(param -> (param instanceof Entity) || (param instanceof Model) || (param instanceof Map))
            .findAny()
            .orElse(null);
    if (null != supportParam) {
        for (String field : accesses.getFields()) {
            try {
                //设置值为null,跳过修改
                BeanUtilsBean.getInstance()
                        .getPropertyUtils()
                        .setProperty(supportParam, field, null);
            } catch (Exception e) {
                logger.warn("can't set {} null", field, e);
            }
        }
    } else {
        logger.warn("doUpdateAccess skip ,because can not found any support entity in param!");
    }
    return true;
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:29,代码来源:FieldFilterDataAccessHandler.java

示例4: main

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
   BeanUtilsBean utilsBean = BeanUtilsBean2.getInstance();
   utilsBean.getConvertUtils().register(false, false, 0);
   BeanOne one = new BeanOne();

   one.setPropertyOne("One");
   one.setPropertyTwo("Two");
   one.setPropertyThree(3L);
   one.setPropertyFour(4);  //this is a string in BeanTwo

   BeanTwo two = new BeanTwo();

   utilsBean.copyProperties(two, one);

   BeanUtilsBean.getInstance().getConvertUtils().register(false, false, 0);

   System.out.println(two);
}
 
开发者ID:developerSid,项目名称:AwesomeJavaLibraryExamples,代码行数:19,代码来源:CopyFromDifferentObjects.java

示例5: BTB

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
/**
 * 把srcObj的值拷贝到destObj
 *
 * @param obj
 * @param obj1
 * @throws Exception
 */
public void BTB(Object srcBean, Object destBean) {
	BeanUtilsBean beanUtils = new BeanUtilsBean();
	PropertyDescriptor[] origDescriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(srcBean);
	for (int i = 0; i < origDescriptors.length; i++) {
		String name = origDescriptors[i].getName();
		if ("class".equals(name)) {
			continue;
		}
		if (beanUtils.getPropertyUtils().isReadable(srcBean, name) && beanUtils.getPropertyUtils().isWriteable(srcBean, name)) {
			try {
				Object value = beanUtils.getPropertyUtils().getSimpleProperty(srcBean, name);
				if (value != null) {
					beanUtils.copyProperty(destBean, name, value);
				}
			} catch (Exception e) {
				 logger.error("BTB():error:e:"+e.getMessage(),e);
			}
		}
	}
}
 
开发者ID:cpusoft,项目名称:common,代码行数:28,代码来源:BeanToBean.java

示例6: getPropertyType

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
protected Type getPropertyType(Object instance, String propertyName) {
	try {
		if (instance != null) {
			Field field = instance.getClass().getField(propertyName);
			return field.getGenericType();
		} else {
			// instance is null for anonymous class, use default type
		}
	} catch (NoSuchFieldException e1) {
		try {
			BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
			PropertyUtilsBean propertyUtils = beanUtilsBean.getPropertyUtils();
			PropertyDescriptor propertyDescriptor = propertyUtils.getPropertyDescriptor(instance, propertyName);
			return propertyDescriptor.getReadMethod().getGenericReturnType();
		} catch (Exception e2) {
			// nothing
		}
	} catch (Exception e) {
		// ignore other exceptions
	}
	// return Object class type by default
	return Object.class;
}
 
开发者ID:Kyunghwa-Yoo,项目名称:StitchRTSP,代码行数:24,代码来源:Input.java

示例7: isGenerateRegex

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
/**
 * Verifica se as propriedades especificadas no map regexRules batem com as propriedades da JavaClass informada.
 * 
 * @param javaClass
 * @return
 */
protected boolean isGenerateRegex(final JavaClass javaClass) {
	final Set<String> keys = this.regexRules.keySet();
	// itera todas as chaves
	for (final String keyProp : keys) {
		
		String jcPropValue;
		try {
			jcPropValue = BeanUtilsBean.getInstance().getProperty(javaClass, keyProp);
		} catch (final Exception e) {
			// se a propriedade não existe sai do for
			break;
		}
		
		final String regexRule = this.regexRules.get(keyProp);
		
		// se o valor encontrado é diferente do valor esperado não roda do template
		if (jcPropValue != null && !jcPropValue.matches(regexRule)) {
			this.log.warn(FreemarkerTemplateRules.mf.format("rules.regexmap", this.template.getName(), javaClass.getName(), keyProp,
					jcPropValue, regexRule));
			return false;
		}
	}
	
	return true;
}
 
开发者ID:darciopacifico,项目名称:omr,代码行数:32,代码来源:FreemarkerTemplateRules.java

示例8: isGenerateRegex

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
/**
 * Verifica se as propriedades especificadas no map regexRules batem com as propriedades da JavaClass informada.
 * 
 * @param javaClass
 * @return
 */
protected boolean isGenerateRegex(final JavaClass javaClass) {
	final Set<String> keys = this.regexRules.keySet();
	// itera todas as chaves
	for (final String keyProp : keys) {
		
		String jcPropValue;
		try {
			jcPropValue = BeanUtilsBean.getInstance().getProperty(javaClass, keyProp);
		} catch (final Exception e) {
			// se a propriedade n�o existe sai do for
			break;
		}
		
		final String regexRule = this.regexRules.get(keyProp);
		
		// se o valor encontrado � diferente do valor esperado n�o roda do template
		if (jcPropValue != null && !jcPropValue.matches(regexRule)) {
			this.log.warn(FreemarkerTemplateRules.mf.format("rules.regexmap", this.template.getName(), javaClass.getName(), keyProp,
					jcPropValue, regexRule));
			return false;
		}
	}
	
	return true;
}
 
开发者ID:darciopacifico,项目名称:omr,代码行数:32,代码来源:FreemarkerTemplateRules.java

示例9: isGenerateRegex

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
/**
 * Verifica se as propriedades especificadas no map regexRules batem com as propriedades da JavaClass informada.
 * 
 * @param javaClass
 * @return
 */
protected boolean isGenerateRegex(JavaClass javaClass) {
	Set<String> keys = this.regexRules.keySet();
	// itera todas as chaves
	for (String keyProp : keys) {

		String jcPropValue;
		try {
			jcPropValue = BeanUtilsBean.getInstance().getProperty(javaClass, keyProp);
		} catch (Exception e) {
			// se a propriedade não existe sai do for
			break;
		}

		String regexRule = this.regexRules.get(keyProp);

		// se o valor encontrado é diferente do valor esperado não roda do template
		if (jcPropValue != null && !jcPropValue.matches(regexRule)) {
			log.warn(mf.format("rules.regexmap", this.template.getName(), javaClass.getName(), keyProp, jcPropValue, regexRule));
			return false;
		}
	}

	return true;
}
 
开发者ID:darciopacifico,项目名称:omr,代码行数:31,代码来源:FreemarkerTemplateRules.java

示例10: createBeanUtilsNull

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
public static BeanUtilsBean createBeanUtilsNull() {
    BeanUtilsBean out = new BeanUtilsBean();
    IntegerConverter iconverter = new IntegerConverter(null);
    LongConverter longConverter = new LongConverter(null);
    FloatConverter floatConverter = new FloatConverter(null);
    DoubleConverter doubleConverter = new DoubleConverter(null);
    NumericIntervalConverter numericIntervalConverter = new NumericIntervalConverter(null);
    AbundanceConverter abundanceConverter = new AbundanceConverter(null);
    //ArrayConverter arrayConverter = new ArrayConverter(String[].class, new StringConverter(null));
    ArrayConverter arrayConverter = new ArrayConverter(Integer[].class, iconverter);
    out.getConvertUtils().register(iconverter, Integer.class);
    out.getConvertUtils().register(longConverter, Long.class);
    out.getConvertUtils().register(floatConverter, Float.class);
    out.getConvertUtils().register(doubleConverter, Double.class);
    out.getConvertUtils().register(arrayConverter, Integer[].class);
    out.getConvertUtils().register(numericIntervalConverter, NumericInterval.class);
    out.getConvertUtils().register(abundanceConverter, Abundance.class);
    //beanUtilsNull.getConvertUtils().register(arrayConverter, String[].class);
    return out;
}
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:21,代码来源:BeanUtils.java

示例11: createBeanUtilsNullSafeHTML

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
public static BeanUtilsBean createBeanUtilsNullSafeHTML() {
        BeanUtilsBean out = new BeanUtilsBean();
        IntegerConverter iconverter = new IntegerConverter(null);
        LongConverter longConverter = new LongConverter(null);
        ArrayConverter arrayConverter = new ArrayConverter(Integer[].class, iconverter);
        SafeHTMLStringConverter stringConverter = new SafeHTMLStringConverter(null);
        NumericIntervalConverter numericIntervalConverter = new NumericIntervalConverter(null);
        AbundanceConverter abundanceConverter = new AbundanceConverter(null);
        out.getConvertUtils().register(iconverter, Integer.class);
        out.getConvertUtils().register(longConverter, Long.class);
//        beanUtilsNullSafeHTML.getConvertUtils().register(floatConverter, Float.class);
//        beanUtilsNullSafeHTML.getConvertUtils().register(doubleConverter, Double.class);
        out.getConvertUtils().register(arrayConverter, Integer[].class);
        out.getConvertUtils().register(stringConverter, SafeHTMLString.class);
        out.getConvertUtils().register(numericIntervalConverter, NumericInterval.class);
        out.getConvertUtils().register(abundanceConverter, Abundance.class);
        return out;
    }
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:19,代码来源:BeanUtils.java

示例12: updateBean

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
/**
 * Updates a oldBean with all non-null values in the newBean.
 * @param cls
 * @param ignoreProperties
 * @param oldBean
 * @param newBean
 * @param <T>
 * @return
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 * @throws FloraOnException
 * @throws InstantiationException
 */
public static <T extends DiffableBean> T updateBean(Class<T> cls, Collection<String> ignoreProperties, T oldBean, T newBean) throws IllegalAccessException
        , InvocationTargetException, NoSuchMethodException, FloraOnException, InstantiationException {
    BeanMap propertyMap = new BeanMap(oldBean);    // we assume beans are the same class! so we take the first as a model
    PropertyUtilsBean propUtils = new PropertyUtilsBean();
    BeanUtilsBean bub = createBeanUtilsNull();

    T out = cls.newInstance();

    for (Object propNameObject : propertyMap.keySet()) {
        String propertyName = (String) propNameObject;
        if(ignoreProperties != null && ignoreProperties.contains(propertyName)) continue;
        System.out.println("PROP: " + propertyName);
        Object newProperty;

        newProperty = propUtils.getProperty(newBean, propertyName);

        if(newProperty == null)
            bub.setProperty(out, propertyName, propUtils.getProperty(oldBean, propertyName));
        else
            bub.setProperty(out, propertyName, newProperty);
        // TODO: nested beans
    }
    return out;
}
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:39,代码来源:BeanUtils.java

示例13: init

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
@Override
public void init(ServletConfig config) throws ServletException {
    this.config = config;
    BlockingQueue<Filter> waiters = (BlockingQueue<Filter>) config.getServletContext()
            .getAttribute(APPLICATION_CONTEXT_LOCK_KEY);
    if (waiters != null) {
        waiters.add(this);
    } else {
        //Servlet 2.5 lazy filter initing
        delayedInit();
    }
    // register the bean utils converter to fail if encounters a type mismatch between the destination
    // and the original, see RTFACT-3610
    BeanUtilsBean instance = BeanUtilsBean2.getInstance();
    instance.getConvertUtils().register(true, false, 0);
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:18,代码来源:ArtifactoryRestServlet.java

示例14: testTCPURI

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
@Test
public void testTCPURI() throws Exception {
   TransportConfiguration tc = new TransportConfiguration(NettyConnectorFactory.class.getName());
   HashMap<String, Object> params = new HashMap<>();
   params.put("host", "localhost1");
   params.put("port", 61617);
   TransportConfiguration tc2 = new TransportConfiguration(NettyConnectorFactory.class.getName(), params);
   HashMap<String, Object> params2 = new HashMap<>();
   params2.put("host", "localhost2");
   params2.put("port", 61618);
   TransportConfiguration tc3 = new TransportConfiguration(NettyConnectorFactory.class.getName(), params2);
   ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, tc, tc2, tc3);
   URI tcp = parser.createSchema("tcp", connectionFactoryWithHA);
   ActiveMQConnectionFactory factory = parser.newObject(tcp, null);
   BeanUtilsBean bean = new BeanUtilsBean();
   checkEquals(bean, connectionFactoryWithHA, factory);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:18,代码来源:ConnectionFactoryURITest.java

示例15: testJGroupsFileURI

import org.apache.commons.beanutils.BeanUtilsBean; //导入依赖的package包/类
@Test
public void testJGroupsFileURI() throws Exception {
   DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration();
   JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName("channel-name").setFile("channel-file.xml");
   discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpointFactory);
   ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF);
   URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA);
   ActiveMQConnectionFactory factory = parser.newObject(tcp, null);
   DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration();
   Assert.assertNotNull(dgc);
   BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory();
   Assert.assertNotNull(befc);
   Assert.assertTrue(befc instanceof JGroupsFileBroadcastEndpointFactory);
   Assert.assertEquals(dgc.getName(), "foo");
   Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678);
   Assert.assertEquals(dgc.getRefreshTimeout(), 12345);
   JGroupsFileBroadcastEndpointFactory fileBroadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) befc;
   Assert.assertEquals(fileBroadcastEndpointFactory.getFile(), "channel-file.xml");
   Assert.assertEquals(fileBroadcastEndpointFactory.getChannelName(), "channel-name");

   BeanUtilsBean bean = new BeanUtilsBean();
   checkEquals(bean, connectionFactoryWithHA, factory);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:24,代码来源:ConnectionFactoryURITest.java


注:本文中的org.apache.commons.beanutils.BeanUtilsBean类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。