Java Code Examples for org.apache.commons.beanutils.BeanUtils.cloneBean()

The following are Jave code examples for showing how to use cloneBean() of the org.apache.commons.beanutils.BeanUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: gluu   File: JsonConfigurationAction.java   View Source Code Vote up 6 votes
private String getProtectedOxTrustApplicationConfiguration(ApplicationConfiguration oxTrustApplicationConfiguration) {
	try {
		ApplicationConfiguration resultOxTrustApplicationConfiguration = (ApplicationConfiguration) BeanUtils.cloneBean(oxTrustApplicationConfiguration);

		resultOxTrustApplicationConfiguration.setSvnConfigurationStorePassword(HIDDEN_PASSWORD_TEXT);
		resultOxTrustApplicationConfiguration.setKeystorePassword(HIDDEN_PASSWORD_TEXT);
		resultOxTrustApplicationConfiguration.setIdpSecurityKeyPassword(HIDDEN_PASSWORD_TEXT);
		resultOxTrustApplicationConfiguration.setIdpBindPassword(HIDDEN_PASSWORD_TEXT);
		resultOxTrustApplicationConfiguration.setMysqlPassword(HIDDEN_PASSWORD_TEXT);
		resultOxTrustApplicationConfiguration.setCaCertsPassphrase(HIDDEN_PASSWORD_TEXT);
		resultOxTrustApplicationConfiguration.setOxAuthClientPassword(HIDDEN_PASSWORD_TEXT);

		return jsonService.objectToJson(resultOxTrustApplicationConfiguration);
	} catch (Exception ex) {
		log.error("Failed to prepare JSON from ApplicationConfiguration: '{0}'", ex, oxTrustApplicationConfiguration);
	}

	return null;
}
 
Example 2
Project: scoold   File: QuestionController.java   View Source Code Vote up 5 votes
@PostMapping("/{id}/edit")
public String edit(@PathVariable String id, @RequestParam(required = false) String title,
		@RequestParam(required = false) String body, @RequestParam(required = false) String tags,
		HttpServletRequest req) {

	Post showPost = pc.read(id);
	Profile authUser = utils.getAuthUser(req);
	if (!utils.canEdit(showPost, authUser) || showPost == null) {
		return "redirect:" + req.getRequestURI();
	}
	Post beforeUpdate = null;
	try {
		beforeUpdate = (Post) BeanUtils.cloneBean(showPost);
	} catch (Exception ex) {
		logger.error(null, ex);
	}

	if (!StringUtils.isBlank(title) && title.length() > 10) {
		showPost.setTitle(title);
	}
	if (!StringUtils.isBlank(body)) {
		showPost.setBody(body);
	}
	if (!StringUtils.isBlank(tags) && showPost.isQuestion()) {
		showPost.setTags(Arrays.asList(StringUtils.split(tags, ",")));
	}

	//note: update only happens if something has changed
	if (!showPost.equals(beforeUpdate)) {
		showPost.setLasteditby(authUser.getId());
		showPost.setLastedited(System.currentTimeMillis());
		showPost.update();
		utils.addBadgeOnceAndUpdate(authUser, Badge.EDITOR, true);
	}
	return "redirect:" + showPost.getPostLink(false, false);
}
 
Example 3
Project: UtilsMaven   File: CommonUtils.java   View Source Code Vote up 5 votes
/**
 * 复制一个对象并返回,属于浅度克隆,对象所属类必须符合JavaBean规范
 *
 * @param bean 被复制的对象
 * @return 返回一个被复制对象的一个副本
 */
@SuppressWarnings("unchecked")
public static <T extends Object> T cloneBean(T bean) {
    try {
        T newBean = (T) BeanUtils.cloneBean(bean);
        return newBean;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Project: telco-anomaly-detection-spark   File: CDR.java   View Source Code Vote up 5 votes
public CDR cloneCDR(){
    try {
        return (CDR) BeanUtils.cloneBean(this);
    } catch (IllegalAccessException | InvocationTargetException | InstantiationException | NoSuchMethodException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 5
Project: jk-util   File: JKObjectUtil.java   View Source Code Vote up 3 votes
/**
 * Clone bean.
 *
 * @param <T>
 *            the generic type
 * @param bean
 *            the bean
 * @return the t
 */
public static <T> T cloneBean(final Object bean) {
	try {
		return (T) BeanUtils.cloneBean(bean);
	} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
		throw new RuntimeException(e);
	}
}