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

The following are Jave code examples for showing how to use getProperty() 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: airtable.java   File: Table.java   View Source Code Vote up 6 votes
/**
 * 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);
            }
        }
    }

}
 
Example 2
Project: airtable.java   File: Table.java   View Source Code Vote up 6 votes
/**
 * Check properties of Attachement objects.
 * 
 * @param attachements
 * @throws AirtableException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException 
 */
private void checkPropertiesOfAttachement(List<Attachment> attachements) throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (attachements != null) {
        for (int i = 0; i < attachements.size(); i++) {
            if (propertyExists(attachements.get(i), FIELD_ID) || propertyExists(attachements.get(i), "size") 
                    || propertyExists(attachements.get(i), "type") || propertyExists(attachements.get(i), "filename")) {
                
                final Field[] attributesPhotos = attachements.getClass().getDeclaredFields();
                for (Field attributePhoto : attributesPhotos) {
                    final String namePhotoAttribute = attributePhoto.getName();
                    if (FIELD_ID.equals(namePhotoAttribute) || "size".equals(namePhotoAttribute) 
                            || "type".equals(namePhotoAttribute) || "filename".equals(namePhotoAttribute)) {
                        if (BeanUtils.getProperty(attachements.get(i), namePhotoAttribute) != null) {
                            throw new AirtableException("Property " + namePhotoAttribute + " should be null!");
                        }
                    }
                }
            }
        }
    }
}
 
Example 3
Project: jambo2   File: SQLHelper.java   View Source Code Vote up 6 votes
protected List getOrderedKeyset(Set keys, Object param) throws Exception {
    List orderedKeyset = new ArrayList();
    if (keys.size() > 0) {
        String firstitems = BeanUtils.getProperty(param,
                "_firstitems");
        String firstitemname = null;
        if (firstitems != null) {
            for (StringTokenizer st = new StringTokenizer(firstitems, ","); st
                    .hasMoreTokens(); ) {
                firstitemname = st.nextToken();
                if (keys.contains(firstitemname)) {
                    orderedKeyset.add(firstitemname);
                }
            }
        }
        for (Iterator it = keys.iterator(); it.hasNext(); ) {
            String key = (String) it.next();
            if (!orderedKeyset.contains(key))
                orderedKeyset.add(key);
        }
    }
    return orderedKeyset;
}
 
Example 4
Project: qonduit   File: NotEmptyIfFieldSetValidator.java   View Source Code Vote up 6 votes
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
    if (value == null) {
        return true;
    }

    try {
        final String fieldValue = BeanUtils.getProperty(value, fieldName);
        final String notNullFieldValue = BeanUtils.getProperty(value, notNullFieldName);
        if (StringUtils.equals(fieldValue, fieldSetValue) && StringUtils.isEmpty(notNullFieldValue)) {
            context.disableDefaultConstraintViolation();
            context.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate())
                    .addPropertyNode(notNullFieldName).addConstraintViolation();
            return false;
        }
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        throw new RuntimeException(e);
    }

    return true;
}
 
Example 5
Project: whatsmars   File: DbRouteInterceptor.java   View Source Code Vote up 6 votes
@Before("aopPoint()")
public Object doRoute(JoinPoint jp) throws Throwable {
    boolean result = true;
    Method method = this.getMethod(jp);
    DbRoute dbRoute = method.getAnnotation(DbRoute.class);
    String routeField = dbRoute.field();  // userId
    Object[] args = jp.getArgs();  
    if(args != null && args.length > 0) {  
        for(int i = 0; i < args.length; ++i) {  
            String routeFieldValue = BeanUtils.getProperty(args[i], routeField);
            if(StringUtils.isNotEmpty(routeFieldValue)) {
                if("userId".equals(routeField)) {  
                    this.dbRouter.route(routeField);
                }
                break;  
            }  
        }  
    }  
  
    return Boolean.valueOf(result);
}
 
Example 6
Project: timely   File: NotEmptyIfFieldSetValidator.java   View Source Code Vote up 6 votes
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
    if (value == null) {
        return true;
    }

    try {
        final String fieldValue = BeanUtils.getProperty(value, fieldName);
        final String notNullFieldValue = BeanUtils.getProperty(value, notNullFieldName);
        if (StringUtils.equals(fieldValue, fieldSetValue) && StringUtils.isEmpty(notNullFieldValue)) {
            context.disableDefaultConstraintViolation();
            context.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate())
                    .addPropertyNode(notNullFieldName).addConstraintViolation();
            return false;
        }
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        throw new RuntimeException(e);
    }

    return true;
}
 
Example 7
Project: OpenMobster   File: MobileObjectGateway.java   View Source Code Vote up 6 votes
private String extractRecordId(MobileBean record)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
{
	String id = "";
	
	Class recordClazz = record.getClass();
	Field[] declaredFields = recordClazz.getDeclaredFields();		
	for(Field field: declaredFields)
	{		
		Annotation[] annotations = field.getAnnotations();			
		for(Annotation annotation: annotations)
		{								
			if(annotation instanceof MobileBeanId)
			{
				return BeanUtils.getProperty(record, field.getName());										
			}
		}			
	}
	
	return id;
}
 
Example 8
Project: ibankapp-base   File: IdentifierValidator.java   View Source Code Vote up 6 votes
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
  try {
    final Idtp idtp = (Idtp) PropertyUtils.getProperty(value, typeFieldName);
    final String idno = BeanUtils.getProperty(value, codeFieldName);

    if (idtp.equals(Idtp.IDCARD)) {
      return IdentifierValidation.isIdCardNo(idno);
    }

    if (idtp.equals(Idtp.OCC)) {
      return IdentifierValidation.isOcc(idno);
    }

    if (idtp.equals(Idtp.USCIC)) {
      return IdentifierValidation.isUscic(idno);
    }
  } catch (Exception e) {
    throw new BaseException("E-BASE-000001", e.getMessage()).initCause(e);
  }

  return true;
}
 
Example 9
Project: neoscada   File: StringReplacer.java   View Source Code Vote up 5 votes
/**
 * Create a new ReplaceSource that handles bean references
 *
 * @param properties
 *            the properties to use for replacing
 * @return the new ReplaceSource instance
 */
public static ReplaceSource newBeansSource ( final Map<?, ?> properties )
{
    return new ReplaceSource () {

        @Override
        public String replace ( final String context, final String key )
        {
            String result = null;
            try
            {
                result = BeanUtils.getProperty ( properties, key );
            }
            catch ( final Exception e )
            {
            }
            if ( result != null )
            {
                return result;
            }
            else
            {
                return context;
            }
        }
    };
}
 
Example 10
Project: airtable.java   File: Table.java   View Source Code Vote up 5 votes
/**
 * Get the String Id from the item.
 *
 * @param item
 * @return
 * @throws AirtableException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 */
private String getIdOfItem(T item) throws AirtableException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (propertyExists(item, FIELD_ID)) {
        final String id = BeanUtils.getProperty(item, FIELD_ID);
        if (id != null) {
            return id;
        }
    }
    throw new AirtableException("Id of " + item + " not Found!");
}
 
Example 11
Project: airtable.java   File: Table.java   View Source Code Vote up 5 votes
/**
 *
 * Filter the Fields of the PostRecord Object. Id and created Time are set
 * to null so Object Mapper doesent convert them to JSON.
 *
 * @param item
 * @return
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 */
private T filterFields(T item) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    final Field[] attributes = item.getClass().getDeclaredFields();

    for (Field attribute : attributes) {
        String attrName = attribute.getName();
        if ((FIELD_ID.equals(attrName) || FIELD_CREATED_TIME.equals(attrName)) 
                && (BeanUtils.getProperty(item, attrName) != null)) {
            BeanUtilsBean.getInstance().getPropertyUtils().setProperty(item, attrName, null);
        }
    }

    return item;
}
 
Example 12
Project: urule   File: BaseReteNode.java   View Source Code Vote up 5 votes
protected Object fetchData(Object object,String property){
	try {
		return BeanUtils.getProperty(object, property);
	} catch (Exception e) {
		throw new RuleException(e);
	}
}
 
Example 13
Project: esup-ecandidat   File: MailBean.java   View Source Code Vote up 5 votes
/** Renvoie la valeur de la propriété du bean
 * @param property
 * @return la valeur de la propriété 
 */
public String getValueProperty(String property){
	try {			
		String valueProperty = BeanUtils.getProperty(this, property);
		if (valueProperty!=null){
			return valueProperty.toString();
		}else{
			return "";
		}
	} catch (Exception e) {
		return "";
	}
}
 
Example 14
Project: jambo2   File: BaseVO.java   View Source Code Vote up 5 votes
public String getIdValue()  {
	try {
		return  BeanUtils.getProperty(this, id());
	} catch (Exception e) {
		log.catching(e);
	}
	return null;
}
 
Example 15
Project: OpenMobster   File: Tools.java   View Source Code Vote up 5 votes
public static String getOid(MobileBean record)
{
	try
	{
		String id = "";
		
		Class recordClazz = record.getClass();
		Field[] declaredFields = recordClazz.getDeclaredFields();		
		for(Field field: declaredFields)
		{		
			Annotation[] annotations = field.getAnnotations();			
			for(Annotation annotation: annotations)
			{								
				if(annotation instanceof MobileBeanId)
				{
					return BeanUtils.getProperty(record, field.getName());										
				}
			}			
		}
		
		return id;
	}
	catch(Exception e)
	{
		throw new RuntimeException(e);
	}
}
 
Example 16
Project: document-management-system   File: DatabaseMetadataUtils.java   View Source Code Vote up 5 votes
/**
 * Get virtual column string value
 */
public static String getString(DatabaseMetadataValue value, String column) throws DatabaseException, IllegalAccessException,
		InvocationTargetException, NoSuchMethodException {
	List<DatabaseMetadataType> types = DatabaseMetadataDAO.findAllTypes(value.getTable());

	for (DatabaseMetadataType emt : types) {
		if (emt.getVirtualColumn().equals(column)) {
			return BeanUtils.getProperty(value, emt.getRealColumn());
		}
	}

	return null;
}
 
Example 17
Project: meazza   File: URLUtils.java   View Source Code Vote up 5 votes
/**
 * 拼接URL,参数从obj中通过反射取得
 *
 * @param url
 *            URL
 * @param obj
 *            对象
 * @param names
 *            参数名数组
 * @return 拼接后的URL
 */
public static String addInnerQueryString(String url, Object obj, String[] names) {
    Object[] values = new Object[names.length];
    for (int i = 0; i < names.length; i++) {
        try {
            values[i] = BeanUtils.getProperty(obj, names[i]);
        } catch (Exception e) {
            // ignore
        }
    }
    return addQueryString(url, names, values);
}
 
Example 18
Project: gluu   File: JsonConfigurationAction.java   View Source Code Vote up 5 votes
private void processPasswordProperty(ApplicationConfiguration source, ApplicationConfiguration current, String property) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, EncryptionException {
	String currentValue = BeanUtils.getProperty(current, property);
	if (StringHelper.equals(currentValue, HIDDEN_PASSWORD_TEXT)) {
		String sourceValue = BeanUtils.getSimpleProperty(source, property);
		BeanUtils.setProperty(current, property, sourceValue);
	} else {
		String currentValueEncrypted = StringEncrypter.defaultInstance().encrypt(currentValue, cryptoConfigurationSalt);
		BeanUtils.setProperty(current, property, currentValueEncrypted);
	}
}
 
Example 19
Project: domino   File: DesktopRequestAsyncSender.java   View Source Code Vote up 4 votes
private String getNestedValue(RequestBean arguments, String p) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    if (!isNestedNull(arguments, p.split("\\.")))
        return BeanUtils.getProperty(arguments, p);
    return "";
}
 
Example 20
Project: navi   File: AbstractNaviBaseDto.java   View Source Code Vote up 4 votes
public Object getValue(String key) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    return BeanUtils.getProperty(this, key);
}
 
Example 21
Project: gluu   File: PropertyService.java   View Source Code Vote up 2 votes
/**
 * Returns object property value
 * 
 * @param bean Bean
 * @param name Property value
 * @return Value of property
 * @throws NoSuchMethodException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 */
public Object getPropertyValue(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
	return BeanUtils.getProperty(bean, name);
}