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


Java PropertyUtils类代码示例

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


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

示例1: getInstanceList

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
/**
 * 封装实体
 * 
 * @param cls
 *            实体类
 * @param list
 *            数据查询结果集
 * @return
 */
public static final <E> List<E> getInstanceList(Class<E> cls, ResultSet rs) {
    List<E> resultList = newArrayList();
    try {
        E object = cls.newInstance();
        Field[] fields = cls.getDeclaredFields();
        while (rs.next()) {
            object = cls.newInstance();
            for (int i = 0; i < fields.length; i++) {
                String fieldName = fields[i].getName();
                PropertyUtils.setProperty(object, fieldName, rs.getObject(fieldName));
            }
            resultList.add(object);
        }
    } catch (Exception e) {
        throw new InstanceException(e);
    }
    return resultList;
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:28,代码来源:InstanceUtil.java

示例2: processEachAnnotatedDeclaredField

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
public static <T extends java.lang.annotation.Annotation, E extends Throwable>  void processEachAnnotatedDeclaredField(final Object targetObject, final Class rootClass, final Class<T> annotationClass, final ProcessAnnotatedFieldCallback<T, E> callBack) throws E{

        processEachDeclaredNonStaticField(targetObject, rootClass, new ProcessFieldCallback<E>() {

            @Override
            public void processField(Field f) throws E {
                if(f.isAnnotationPresent(annotationClass)){
                    Object fieldValue;
                    try {
                         fieldValue = PropertyUtils.getProperty(targetObject, f.getName());
                    } catch (Exception ex) {
                        throw new IllegalStateException("Could not read property value for annotated property '" + f.getName() + "' in class" + f.getDeclaringClass().getName() + "\nThe property should have public getter.", ex);
                    }
                    callBack.processField(f, fieldValue, f.getAnnotation(annotationClass));
                }
            }
        });

        
    }
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:21,代码来源:ReflectionUtils.java

示例3: apiMessageMassPreview

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
/**
 * 群发消息预览
 * 
 * @param towxname
 * @param msg
 * @return
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 * @throws ClientProtocolException
 * @throws URISyntaxException
 * @throws IOException
 * @throws AccessTokenFailException
 */
public BaseResp apiMessageMassPreview(String towxname, MassMsg msg)
		throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClientProtocolException,
		URISyntaxException, IOException, AccessTokenFailException {
	MpAccessToken token = mpApi.apiToken();
	String path = String.format("/message/mass/preview?access_token=%s", token.getAccessToken());

	Map<String, Object> reqMap = PropertyUtils.describe(msg);
	reqMap.put("towxname", towxname);
	String respText = HttpUtil.post(mpApi.config.getApiHttps(), path, reqMap);
	BaseResp resp = new Gson().fromJson(respText, BaseResp.class);
	if (mpApi.log.isInfoEnabled()) {
		mpApi.log.info(String.format("apiMessageMassDelete %s", new Gson().toJson(resp)));
	}
	return resp;
}
 
开发者ID:AlexLee-CN,项目名称:weixin_api,代码行数:30,代码来源:MpMsgApi.java

示例4: loadData

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
@Override
protected void loadData() {

    initCollections(new String[] { "collectionProperties.review.searchkey" });
    ReviewSearchBean searchBean = new ReviewSearchBean();
    BeanUtils.copyProperties(this, searchBean, new String[] { "articleno" });

    try {
        PropertyUtils.setProperty(searchBean, option, key);
    } catch (Exception e) {
        logger.warn(e.getMessage());
    }

    if (StringUtils.isEmpty(pagination.getSortColumn())) {
        pagination.setSortColumn(TReview.PROP_POSTDATE);
        pagination.setSortOrder("DESC");
    }

    // 总件数设置
    pagination.setPreperties(reviewService.getCount(searchBean));
    searchBean.setPagination(pagination);
    reviewList = reviewService.find(searchBean);
    // Setting number of records in the particular page
    pagination.setPageRecords(reviewList.size());
}
 
开发者ID:luckyyeah,项目名称:YiDu-Novel,代码行数:26,代码来源:ReviewListAction.java

示例5: setSiteOptionProperty

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
public void setSiteOptionProperty(String property, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (PropertyUtils.isWriteable(this, property)) {

        switch (PropertyUtils
                .getPropertyDescriptor(this, property).getPropertyType().getSimpleName()) {
            case OPTION_VALUE_TYPE_BOOLEAN:
                value = Boolean.valueOf(value.toString());
                break;
            case OPTION_VALUE_TYPE_INTEGER:
                value = Integer.parseInt(value.toString());
                break;
            case OPTION_VALUE_TYPE_USERREGISTRATION:
                value = UserRegistration.valueOf(value.toString());
                break;
            default:
                break;
        }
        PropertyUtils.setProperty(this, property, value);
    }
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:22,代码来源:SiteOptions.java

示例6: instanceChildObject

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
private void instanceChildObject(Object obj,String propertyName){
	int pointIndex=propertyName.indexOf(".");
	if(pointIndex==-1){
		return;
	}
	String name=propertyName.substring(0,pointIndex);
	propertyName=propertyName.substring(pointIndex+1);
	try {
		Object instance=PropertyUtils.getProperty(obj, name);
		if(instance!=null){
			instanceChildObject(instance,propertyName);
			return;
		}
		Object targetEntity=new GeneralEntity(name);
		PropertyUtils.setProperty(obj, name, targetEntity);
		instanceChildObject(targetEntity,propertyName);
	} catch (Exception e) {
		throw new RuleException(e);
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:21,代码来源:PackageServletHandler.java

示例7: addBooleanColumn

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
/** Ajoute une case a cocher a la place de O et N
 * @param property
 */
public void addBooleanColumn(String property, Boolean alignCenter){
	addGeneratedColumn(property, new Table.ColumnGenerator() {
           /**serialVersionUID**/
		private static final long serialVersionUID = -3483685206189347289L;

		@Override
           public Object generateCell(Table source, Object itemId, Object columnId) {				
			try {
				Object value = PropertyUtils.getProperty(itemId,(String)columnId);
				if (value instanceof Boolean){
					return new IconLabel((Boolean)value,alignCenter);
				}else{
					return value;
				}
			} catch (Exception e) {
				return null;
			}				
           }            
       });
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:24,代码来源:TableFormating.java

示例8: getInstanceList

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
/**
 * 封装实体
 * 
 * @param cls 实体类
 * @param list 数据查询结果集
 * @return
 */
public static final <E> List<E> getInstanceList(Class<E> cls, ResultSet rs) {
	List<E> resultList = newArrayList();
	try {
		E object = cls.newInstance();
		Field[] fields = cls.getDeclaredFields();
		while (rs.next()) {
			object = cls.newInstance();
			for (int i = 0; i < fields.length; i++) {
				String fieldName = fields[i].getName();
				PropertyUtils.setProperty(object, fieldName, rs.getObject(fieldName));
			}
			resultList.add(object);
		}
	} catch (Exception e) {
		throw new InstanceException(e);
	}
	return resultList;
}
 
开发者ID:babymm,项目名称:mumu,代码行数:26,代码来源:InstanceUtil.java

示例9: getContentTypeFromModel

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
private String getContentTypeFromModel(Object model) {
    if (model instanceof ContentItem) {
        ContentItem contentItem = (ContentItem) model;
        return contentItem.getSystem().getType();
    }
    ContentItemMapping contentItemMapping = model.getClass().getAnnotation(ContentItemMapping.class);
    if (contentItemMapping != null) {
        return contentItemMapping.value();
    }
    try {
        Object system = PropertyUtils.getProperty(model, "system");
        if (system instanceof System) {
            return ((System) system).getType();
        }
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        logger.debug("Unable to find System property on model", e);
    }
    return null;
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:20,代码来源:ThymeleafTemplateEngine.java

示例10: initPage

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws ServletException {
String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(sessionMapID);
SurveyForm existForm = (SurveyForm) sessionMap.get(SurveyConstants.ATTR_SURVEY_FORM);

SurveyForm surveyForm = (SurveyForm) form;
try {
    PropertyUtils.copyProperties(surveyForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(SurveyConstants.SUCCESS);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:AuthoringAction.java

示例11: AnswerDTO

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
public AnswerDTO(SurveyQuestion question) {
try {
    PropertyUtils.copyProperties(this, question);
} catch (Exception e) {
    logger.error("Error occurs during creating AnswerDTO");
}

// clone options
Set<SurveyOption> optList = question.getOptions();
if (optList != null) {
    SortedSet<SurveyOption> newOptions = new TreeSet<SurveyOption>(new SurveyOptionComparator());
    for (SurveyOption option : optList) {
	SurveyOption newOption = (SurveyOption) option.clone();
	// clone does not copy the UID, here copy it back
	newOption.setUid(option.getUid());
	newOptions.add(newOption);
    }
    this.setOptions(newOptions);
}

String desc = this.getDescription();
desc = desc.replaceAll("<(.|\n)*?>", "");
this.setShortTitle(StringUtils.abbreviate(desc, SHORT_TITLE_LENGTH));

   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:AnswerDTO.java

示例12: initPage

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws ServletException {
String sessionMapID = WebUtil.readStrParam(request, AssessmentConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
AssessmentForm existForm = (AssessmentForm) sessionMap.get(AssessmentConstants.ATTR_ASSESSMENT_FORM);

AssessmentForm assessmentForm = (AssessmentForm) form;
try {
    PropertyUtils.copyProperties(assessmentForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(AssessmentConstants.SUCCESS);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:AuthoringAction.java

示例13: initPage

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws ServletException {
String sessionMapID = WebUtil.readStrParam(request, PeerreviewConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
PeerreviewForm existForm = (PeerreviewForm) sessionMap.get(PeerreviewConstants.ATTR_PEERREVIEW_FORM);

PeerreviewForm peerreviewForm = (PeerreviewForm) form;
try {
    PropertyUtils.copyProperties(peerreviewForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(PeerreviewConstants.SUCCESS);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:AuthoringAction.java

示例14: initPage

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws ServletException {
String sessionMapID = WebUtil.readStrParam(request, ResourceConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(sessionMapID);
ResourceForm existForm = (ResourceForm) sessionMap.get(ResourceConstants.ATTR_RESOURCE_FORM);

ResourceForm resourceForm = (ResourceForm) form;
try {
    PropertyUtils.copyProperties(resourceForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(ResourceConstants.SUCCESS);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:AuthoringAction.java

示例15: initPage

import org.apache.commons.beanutils.PropertyUtils; //导入依赖的package包/类
/**
    * Display same entire authoring page content from HttpSession variable.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws ServletException
    */
   private ActionForward initPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws ServletException {
String sessionMapID = WebUtil.readStrParam(request, CommonCartridgeConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(sessionMapID);
CommonCartridgeForm existForm = (CommonCartridgeForm) sessionMap
	.get(CommonCartridgeConstants.ATTR_RESOURCE_FORM);

CommonCartridgeForm commonCartridgeForm = (CommonCartridgeForm) form;
try {
    PropertyUtils.copyProperties(commonCartridgeForm, existForm);
} catch (Exception e) {
    throw new ServletException(e);
}

ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request);
request.setAttribute(AttributeNames.ATTR_MODE, mode.toString());

return mapping.findForward(CommonCartridgeConstants.SUCCESS);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:AuthoringAction.java


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