Java Code Examples for org.apache.commons.beanutils.PropertyUtils.getSimpleProperty()

The following are Jave code examples for showing how to use getSimpleProperty() of the org.apache.commons.beanutils.PropertyUtils 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: yajsw   File: ObservableObject.java   View Source Code Vote up 6 votes
public void update(String field, Object obj)
  {
  	Object newValue;
try
{
	newValue = PropertyUtils.getSimpleProperty(obj, field);
  	Object oldValue = PropertyUtils.getSimpleProperty(_root, field);
  	if (oldValue != null && !oldValue.equals(newValue))
  	{
  		PropertyUtils.setSimpleProperty(_root, field, newValue);
  		support.firePropertyChange(field, oldValue, newValue);
  	}
}
catch (Exception e)
{
	e.printStackTrace();
}
  }
 
Example 2
Project: helium   File: ExpedientConsultaInformeController.java   View Source Code Vote up 6 votes
private Map<String, Object> processarValorsFiltre(
		Object filtreCommand,
		List<TascaDadaDto> dadesFiltre,
		Map<String, Object> valors) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
	Map<String, Object> valorsPerService = new HashMap<String, Object>();
	for (TascaDadaDto dada: dadesFiltre) {
		String clau = (dada.getDefinicioProcesKey() == null) ? dada.getVarCodi() : dada.getDefinicioProcesKey() + "." + dada.getVarCodi();
		clau = clau.replace(
				ExpedientCamps.EXPEDIENT_PREFIX_JSP,
				ExpedientCamps.EXPEDIENT_PREFIX);
		if (CampTipusDto.BOOLEAN.equals(dada.getCampTipus()) && PropertyUtils.isReadable(filtreCommand, dada.getVarCodi())) {
			Boolean valor = (Boolean) PropertyUtils.getSimpleProperty(
					filtreCommand,
					dada.getVarCodi());
			valors.put(
					dada.getVarCodi(),
					valor);
		}
		valorsPerService.put(
				clau,
				valors.get(dada.getVarCodi()));
	}
	return valorsPerService;
}
 
Example 3
Project: helium   File: ExpedientConsultaLlistatController.java   View Source Code Vote up 6 votes
private Map<String, Object> processarValorsFiltre(
		Object filtreCommand,
		List<TascaDadaDto> dadesFiltre,
		Map<String, Object> valors) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
	Map<String, Object> valorsPerService = new HashMap<String, Object>();
	for (TascaDadaDto dada: dadesFiltre) {
		String clau = (dada.getDefinicioProcesKey() == null) ? dada.getVarCodi() : dada.getDefinicioProcesKey() + "." + dada.getVarCodi();
		clau = clau.replace(
				ExpedientCamps.EXPEDIENT_PREFIX_JSP,
				ExpedientCamps.EXPEDIENT_PREFIX);
		if (CampTipusDto.BOOLEAN.equals(dada.getCampTipus()) && PropertyUtils.isReadable(filtreCommand, dada.getVarCodi())) {
			Boolean valor = (Boolean) PropertyUtils.getSimpleProperty(
					filtreCommand,
					dada.getVarCodi());
			valors.put(
					dada.getVarCodi(),
					valor);
		}
		valorsPerService.put(
				clau,
				valors.get(dada.getVarCodi()));
	}
	return valorsPerService;
}
 
Example 4
Project: helium   File: TascaFormUtil.java   View Source Code Vote up 6 votes
public static Map<String, List<Object>> getValorsPerSuggest(TascaDto tasca, Object command) {
	Map<String, List<Object>> resposta = new HashMap<String, List<Object>>();
	if (tasca.getValorsMultiplesDomini() != null) {
		for (String key: tasca.getValorsMultiplesDomini().keySet()) {
			List<Object> liniaResposta = new ArrayList<Object>();
			try {
				Object value = PropertyUtils.getSimpleProperty(command, key);
				for (int i = 0; i < Array.getLength(value); i++) {
					String valor = null;
					for (ParellaCodiValorDto parella: tasca.getValorsMultiplesDomini().get(key)) {
						if (parella.getCodi().equals(Array.get(value, i))) {
							valor = parella.getValor().toString();
							break;
						}
					}
					liniaResposta.add(valor);
				}
				resposta.put(key, liniaResposta);
			} catch (Exception ex) {}
		}
	}
	return resposta;
}
 
Example 5
Project: helium   File: TascaFormUtil.java   View Source Code Vote up 6 votes
private static Object cloneMultipleArray(
		String field,
		Object command,
		List<Camp> camps,
		int addTolength) throws Exception {
	for (Camp camp: camps) {
		if (camp.getCodi().equals(field)) {
			Object value = PropertyUtils.getSimpleProperty(command, field);
			if (value != null) {
				int length = ((Object[])value).length;
				return Array.newInstance(
						getJavaClass(camp.getTipus()),
						length + addTolength);
			} else {
				return Array.newInstance(
						getJavaClass(camp.getTipus()),
						1);
			}
		}
	}
	return null;
}
 
Example 6
Project: abina-common-util   File: ParamsUtils.java   View Source Code Vote up 6 votes
/**
 * 对象拷贝 数据对象空值不拷贝到目标对象
 * 
 * @param databean 待拷贝对象
 * @param tobean 目标对象
 * @throws NoSuchMethodException
 */
public static void copyBeanNotNull2Bean(Object databean, Object tobean) throws Exception {
	PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(databean);
	for (int i = 0; i < origDescriptors.length; i++) {
		String name = origDescriptors[i].getName();
		// String type = origDescriptors[i].getPropertyType().toString();
		if ("class".equals(name)) {
			continue; // No point in trying to set an object's class
		}
		if (PropertyUtils.isReadable(databean, name) && PropertyUtils.isWriteable(tobean, name)) {
			try {
				Object value = PropertyUtils.getSimpleProperty(databean, name);
				if (value != null) {
					getInstance().setSimpleProperty(tobean, name, value);
				}
			} catch (java.lang.IllegalArgumentException ie) {
				; // Should not happen
			} catch (Exception e) {
				; // Should not happen
			}

		}
	}
}
 
Example 7
Project: easycode   File: Entitys.java   View Source Code Vote up 6 votes
/**
 * 获取主键的值
 * @param target	Entity的class类型
 * @return	如果该Entity没有@Id注解,则return null,如果有一个则返回{val},两个则返回{val1, val2}
 * 			其中的val值可能为null,所以需要实时判断下
 */
public static Object[] getPkValues(Object target) {
	Assert.notNull(target, "target param must not be null.");
	Assert.isInstanceOf(Entity.class, target);
	com.easycodebox.jdbc.Table table = Configuration.getTable(target.getClass());
	if(table != null) {
		List<com.easycodebox.jdbc.PkColumn> pks = table.getPrimaryKeys();
		if(pks != null && pks.size() > 0) {
			Object[] vals = new Object[pks.size()];
			for(int i = 0; i < pks.size(); i++) {
				Object val;
				try {
					val = PropertyUtils.getSimpleProperty(target, pks.get(i).getName());
				} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
					throw new BaseException("Obtain object({0}) property({1}) error.", e, target, pks.get(i).getName());
				}
				vals[i] = val;
			}
			return vals;
		}
	}
	return null;
}
 
Example 8
Project: yajsw   File: BeanTableFormat.java   View Source Code Vote up 5 votes
public Object getColumnValue(E obj, int i)
{
	try
	{
		if (obj instanceof ObservableObject)
			return PropertyUtils.getSimpleProperty(((ObservableObject)obj)._root, _propertyNames.get(i));
		else
			PropertyUtils.getSimpleProperty(obj, _propertyNames.get(i));
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
	return null;
}
 
Example 9
Project: helium   File: TascaFormValidatorHelper.java   View Source Code Vote up 5 votes
private List<TascaDadaDto> getTascaDades(Object command) throws Exception {
	if (tascaDades != null) {
		return tascaDades;
	} else {
		String id = (String)PropertyUtils.getSimpleProperty(command, "id");
		return tascaService.findDades(id);
	}
}
 
Example 10
Project: helium   File: CommonRegistreHelper.java   View Source Code Vote up 5 votes
public void validate(Object command, Errors errors) {
	try {
		Long registreId = (Long)PropertyUtils.getSimpleProperty(command, "registreId");
		Camp camp = dissenyService.getCampById(registreId);
		for (CampRegistre campRegistre: camp.getRegistreMembres()) {
			if (campRegistre.isObligatori())
				ValidationUtils.rejectIfEmpty(errors, campRegistre.getMembre().getCodi(), "not.blank");
		}
	} catch (Exception ex) {
		errors.reject("error.validator");
	}
}
 
Example 11
Project: helium   File: ExpedientInformeController.java   View Source Code Vote up 5 votes
@SuppressWarnings("static-access")
private Map<String, Object> getValorsPerService(Object filtreCommand, List<TascaDadaDto> camps, Map<String, Object> valors) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
	Map<String, Object> valorsPerService = new HashMap<String, Object>();
	for (TascaDadaDto camp : camps) {
		String clau = (camp.getDefinicioProcesKey() == null) ? camp.getVarCodi() : camp.getDefinicioProcesKey() + "." + camp.getVarCodi();
		clau = camp.getVarCodi().replace(ExpedientCamps.EXPEDIENT_PREFIX_JSP, ExpedientCamps.EXPEDIENT_PREFIX);
		if (camp.getCampTipus().BOOLEAN.equals(camp.getCampTipus()) && PropertyUtils.isReadable(filtreCommand, camp.getVarCodi())) {
			Boolean valor = (Boolean) PropertyUtils.getSimpleProperty(filtreCommand, camp.getVarCodi());
			valors.put(camp.getVarCodi(), valor);
		}
		valorsPerService.put(clau, valors.get(camp.getVarCodi()));
	}
	return valorsPerService;
}
 
Example 12
Project: helium   File: CommonRegistreValidator.java   View Source Code Vote up 5 votes
public void validate(Object command, Errors errors) {
	try {
		Long registreId = (Long)PropertyUtils.getSimpleProperty(command, "registreId");
		Camp camp = dissenyService.getCampById(registreId);
		for (CampRegistre campRegistre: camp.getRegistreMembres()) {
			if (campRegistre.isObligatori())
				ValidationUtils.rejectIfEmpty(errors, campRegistre.getMembre().getCodi(), "not.blank");
		}
	} catch (Exception ex) {
		errors.reject("error.validator");
	}
}
 
Example 13
Project: helium   File: TascaFormUtil.java   View Source Code Vote up 5 votes
public static Object addMultiple(String field, Object command, List<Camp> camps) throws Exception {
	Object value = PropertyUtils.getSimpleProperty(command, field);
	Object newArray = cloneMultipleArray(field, command, camps, 1);
	for (int i = 0; i < Array.getLength(newArray) - 1; i++)
		Array.set(newArray, i, Array.get(value, i));
	return newArray;
}
 
Example 14
Project: helium   File: TascaFormUtil.java   View Source Code Vote up 5 votes
public static Object deleteMultiple(String field, Object command, List<Camp> camps, int index) throws Exception {
	Object value = PropertyUtils.getSimpleProperty(command, field);
	Object newArray = cloneMultipleArray(field, command, camps, -1);
	int j = 0;
	for (int i = 0; i < Array.getLength(value); i++)
		if (i != index)
			Array.set(newArray, j++, Array.get(value, i));
	return newArray;
}
 
Example 15
Project: audible   File: TypeSafeCopy.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public void copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException {
    PropertyDescriptor[] origDescriptors =
            PropertyUtils.getPropertyDescriptors(orig);
    for (PropertyDescriptor origDescriptor : origDescriptors) {
        String name = origDescriptor.getName();
        if ("class".equals(name)) {
            continue; // No point in trying to set an object's class
        }
        if (PropertyUtils.isReadable(orig, name) &&
                PropertyUtils.isWriteable(dest, name)) {


            try {
                Class origPropClass = PropertyUtils.getPropertyType(orig, name);
                Class destPropClass = PropertyUtils.getPropertyType(dest, name);

                if (destPropClass.isAssignableFrom(origPropClass)) {
                    Object value =
                            PropertyUtils.getSimpleProperty(orig, name);
                    BeanUtils.copyProperty(dest, name, value);
                }
            } catch (NoSuchMethodException e) {
                // Should not happen
            }
        }
    }
}
 
Example 16
Project: graylog-plugin-pipeline-processor   File: FieldAccessExpression.java   View Source Code Vote up 5 votes
private Object getProperty(Object bean, String fieldName) {
    try {
        Object property = PropertyUtils.getProperty(bean, fieldName);
        if (property == null) {
            // in case the bean is a Map, try again with a simple property, it might be masked by the Map
            property = PropertyUtils.getSimpleProperty(bean, fieldName);
        }
        log.debug("[field access] property {} of bean {}: {}", fieldName, bean.getClass().getTypeName(), property);
        return property;
    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
        log.debug("Unable to read property {} from {}", fieldName, bean);
        return null;
    }
}
 
Example 17
Project: easycode   File: IfEnum.java   View Source Code Vote up 5 votes
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public int doStartTag() throws JspException {
	Assert.notNull(test, "test can not be null.");
	Assert.notBlank(enumValue, "enumValue can not be blank.");
	
	String[] array = enumValue.split("\\.");
	if(array.length != 2) {
		throw new IllegalArgumentException("enumValue error format.");
	}
	
	Class<? extends Enum<?>> enumClass 
			= (Class<? extends Enum<?>>)EnumClassFactory.newInstance(array[0]);
	
	Enum e = Enum.valueOf((Class)enumClass, array[1]);
	Boolean answer;
	if(enumProperty == null) {
		if(test instanceof String && e.name().equals(test)
				|| e.equals(test))
			answer = Boolean.TRUE;
		else
			answer = Boolean.FALSE;
	}else {
		try {
			Object pro = PropertyUtils.getSimpleProperty(e, enumProperty);
			if(pro != null && test.toString().equals(pro.toString()))
				answer = Boolean.TRUE;
			else
				answer = Boolean.FALSE;
		} catch (Exception e1) {
			throw new BaseException("Obtain enum({0}) property({1}) error.", e1, e, enumProperty);
		}
	}
	
       pageContext.setAttribute(ANSWER, answer);
	return answer ? EVAL_BODY_INCLUDE : SKIP_BODY;
}
 
Example 18
Project: lams   File: LocaleAction.java   View Source Code Vote up 4 votes
/**
 * <p>
 * Change the user's {@link java.util.Locale} based on {@link ActionForm}
 * properties.
 * </p>
 * <p>
 * This <code>Action</code> looks for <code>language</code> and
 * <code>country</code> properties on the given form, constructs an
 * appropriate Locale object, and sets it as the Struts Locale for this
 * user's session.
 * Any <code>ActionForm</code>, including a 
 * {@link org.apache.struts.action.DynaActionForm}, may be used.
 * </p>
 * <p>
 * If a <code>page</code> property is also provided, then after
 * setting the Locale, control is forwarded to that URI path.
 * Otherwise, control is forwarded to "success".
 * </p>
 *
 * @param mapping The ActionMapping used to select this instance
 * @param form The optional ActionForm bean for this request (if any)
 * @param request The HTTP request we are processing
 * @param response The HTTP response we are creating
 *
 * @return Action to forward to
 * @exception java.lang.Exception if an input/output error or servlet exception occurs
 */
public ActionForward execute(ActionMapping mapping,
             ActionForm form,
             HttpServletRequest request,
             HttpServletResponse response)
throws Exception {

// Extract attributes we will need
HttpSession session = request.getSession();
Locale locale = getLocale(request);

String language = null;
String country = null;
String page = null;

try {
        language = (String)
          PropertyUtils.getSimpleProperty(form, "language");
        country = (String)
          PropertyUtils.getSimpleProperty(form, "country");
        page = (String)
          PropertyUtils.getSimpleProperty(form, "page");
    } catch (Exception e) {
       log.error(e.getMessage(), e);
    }

    boolean isLanguage = (language != null && language.length() > 0);
    boolean isCountry = (country != null && country.length() > 0);

    if ((isLanguage) && (isCountry)) {
       locale = new java.util.Locale(language, country);
    } else if (isLanguage) {
       locale = new java.util.Locale(language, "");
}

    session.setAttribute(Globals.LOCALE_KEY, locale);

    if (null==page) return mapping.findForward("success");
    else return new ActionForward(page);

}
 
Example 19
Project: jerrydog   File: StandardServer.java   View Source Code Vote up 4 votes
/**
 * Store the relevant attributes of the specified JavaBean.
 *
 * @param writer PrintWriter to which we are storing
 * @param include Should we include a <code>className</code> attribute?
 * @param bean Bean whose properties are to be rendered as attributes,
 *
 * @exception Exception if an exception occurs while storing
 */
private void storeAttributes(PrintWriter writer, boolean include,
                             Object bean) throws Exception {

    // Render a className attribute if requested
    if (include) {
        writer.print(" className=\"");
        writer.print(bean.getClass().getName());
        writer.print("\"");
    }

    // Acquire the list of properties for this bean
    PropertyDescriptor descriptors[] =
        PropertyUtils.getPropertyDescriptors(bean);
    if (descriptors == null) {
        descriptors = new PropertyDescriptor[0];
    }

    // Render the relevant properties of this bean
    String className = bean.getClass().getName();
    for (int i = 0; i < descriptors.length; i++) {
        if (descriptors[i] instanceof IndexedPropertyDescriptor) {
            continue; // Indexed properties are not persisted
        }
        if (!isPersistable(descriptors[i].getPropertyType()) ||
            (descriptors[i].getReadMethod() == null) ||
            (descriptors[i].getWriteMethod() == null)) {
            continue; // Must be a read-write primitive or String
        }
        Object value =
            PropertyUtils.getSimpleProperty(bean,
                                            descriptors[i].getName());
        if (value == null) {
            continue; // Null values are not persisted
        }
        if (isException(className, descriptors[i].getName())) {
            continue; // Skip the specified exceptions
        }
        if (!(value instanceof String)) {
            value = value.toString();
        }
        writer.print(' ');
        writer.print(descriptors[i].getName());
        writer.print("=\"");
        String strValue = convertStr((String) value);
        writer.print(strValue);
        writer.print("\"");
    }

}
 
Example 20
Project: helium   File: TascaFormHelper.java   View Source Code Vote up 4 votes
public static Map<String, Object> getValorsFromCommand(
			List<TascaDadaDto> tascaDades,
			Object command,
			boolean esConsultaPerTipus,
			boolean esIniciExpedient) {
    	Map<String, Object> resposta = new HashMap<String, Object>();
    	for (TascaDadaDto tascaDada: tascaDades) {
    		try {
    			if (!tascaDada.getCampTipus().equals(CampTipusDto.ACCIO)) {
    				Object valor = PropertyUtils.getSimpleProperty(
			    				command,
			    				tascaDada.getVarCodi());
	    			if (tascaDada.isReadOnly() && !tascaDada.getCampTipus().equals(CampTipusDto.REGISTRE)) {
	    				valor = tascaDada.getVarValor();
	    				setSimpleProperty(
								command,
								tascaDada.getVarCodi(),
								valor);
	    			} else if (tascaDada.getCampTipus().equals(CampTipusDto.REGISTRE)) {
    					valor = getArrayFromRegistre(tascaDada, valor, esIniciExpedient);
    				}
		    		if (!esConsultaPerTipus && tascaDada.isCampMultiple()) {
	    				// Lleva els valors buits de l'array
		    			List<Object> valorSenseBuits = new ArrayList<Object>();
		    			if (valor != null)
			    			for (int i = 0; i < Array.getLength(valor); i++) {
			    				Object va = Array.get(valor, i);
			    				if (tascaDada.getCampTipus().equals(CampTipusDto.BOOLEAN) && va == null) {
					    			va = Boolean.FALSE;
					    		}
			    				if (!empty(va)) {
			    					if (tascaDada.getCampTipus().equals(CampTipusDto.TERMINI)) {
			    						String[] pre_va = (String[])va; 
				    					if((pre_va).length < 3)
				    						va = null;
				    					else
				    						va = obtenirValorTermini(pre_va);
				    				}
			    					valorSenseBuits.add(va);
			    				}
			    			}
		    			Object newArray = null;
		    			if (!valorSenseBuits.isEmpty()) {
	    					newArray = Array.newInstance(
	    							tascaDada.getCampTipus().equals(CampTipusDto.TERMINI) ? String.class : tascaDada.getJavaClass(),
	    							valorSenseBuits.size());
		    				int index = 0;
		    				for (Object val: valorSenseBuits) {
		    					Array.set(newArray, index++, val);
		    				}
		    			}
		    			if (!tascaDada.getCampTipus().equals(CampTipusDto.REGISTRE) || valor != null) {
		    				resposta.put(
		    						tascaDada.getVarCodi(),
		    						newArray);
		    			}
		    		} else {
		    			if (tascaDada.getCampTipus().equals(CampTipusDto.TERMINI) && valor != null) {
		    				String[] pre_valor = (String[])valor; 
	    					if((pre_valor).length < 3)
	    						valor = null;
	    					else
	    						valor = obtenirValorTermini(pre_valor);
	    				}
		    			if (tascaDada.getCampTipus().equals(CampTipusDto.BOOLEAN) && valor == null) {
			    			valor = Boolean.FALSE;
			    		}
//		    			valor = compatibilitat26(camp, valor);
		    			if (!tascaDada.getCampTipus().equals(CampTipusDto.REGISTRE) || valor != null) {
		    				resposta.put(
			    					tascaDada.getVarCodi(),
				    				valor);
		    			}
		    		}
    			}
    		} catch (Exception ignored) {}
    	}
    	return resposta;
	}
 
Example 21
Project: Camel   File: GoraUtils.java   View Source Code Vote up 2 votes
/**
 * Utility method to extract value from configuration
 *
 * @param attr
 * @param conf
 * @return
 * @throws IllegalAccessException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 */
protected static Object getAttribute(final GoraAttribute attr,
                                     final GoraConfiguration conf) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {

    return PropertyUtils.getSimpleProperty(conf, attr.value);
}
 
Example 22
Project: Camel   File: GoraUtils.java   View Source Code Vote up 2 votes
/**
 * Utility method to check if a value exist in the configuration class
 *
 * <b>NOTE:</>
 * Checks only if is not null
 *
 * @param attr
 * @param conf
 * @return
 * @throws IllegalAccessException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 */
protected static boolean configurationExist(final GoraAttribute attr,
                                            final GoraConfiguration conf) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {

    return PropertyUtils.getSimpleProperty(conf, attr.value) != null;
}