當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。