Example usage for org.apache.wicket.core.util.lang PropertyResolver getPropertyClass

List of usage examples for org.apache.wicket.core.util.lang PropertyResolver getPropertyClass

Introduction

In this page you can find the example usage for org.apache.wicket.core.util.lang PropertyResolver getPropertyClass.

Prototype

@SuppressWarnings("unchecked")
public static <T> Class<T> getPropertyClass(final String expression, final Class<?> clz) 

Source Link

Usage

From source file:net.databinder.models.hib.CriteriaFilterAndSort.java

License:Open Source License

public void buildUnordered(Criteria criteria) {
    super.buildUnordered(criteria);

    Conjunction conj = Restrictions.conjunction();

    for (Map.Entry<String, String> entry : (Set<Map.Entry<String, String>>) filterMap.entrySet()) {
        // System.out.println(String.format("%s\t%s", entry.getKey(), entry.getValue()));
        String property = entry.getKey();
        String value = entry.getValue();
        if (value == null)
            continue;

        String prop = processProperty(criteria, property);
        Class clazz = PropertyResolver.getPropertyClass(property, beanClass);

        if (String.class.isAssignableFrom(clazz)) {
            String[] items = value.split("\\s+");
            for (String item : items) {
                Disjunction dist = Restrictions.disjunction();
                dist.add(Restrictions.ilike(prop, item, MatchMode.ANYWHERE));
                conj.add(dist);//w  w w .  j a va 2 s .com
            }
        } else if (Number.class.isAssignableFrom(clazz)) {
            try {
                Matcher matcher = pattern.matcher(value);
                if (matcher.matches()) {
                    String qualifier = matcher.group(2);
                    value = matcher.group(4);
                    Number num = convertToNumber(value, clazz);
                    if (">".equals(qualifier))
                        conj.add(Restrictions.gt(prop, num));
                    else if ("<".equals(qualifier))
                        conj.add(Restrictions.lt(prop, num));
                    else if (">=".equals(qualifier))
                        conj.add(Restrictions.ge(prop, num));
                    else if ("<=".equals(qualifier))
                        conj.add(Restrictions.le(prop, num));
                } else
                    conj.add(Restrictions.eq(prop, convertToNumber(value, clazz)));
            } catch (ConversionException ex) {
                // ignore filter in this case
            }
        } else if (Boolean.class.isAssignableFrom(clazz)) {
            conj.add(Restrictions.eq(prop, Boolean.parseBoolean(value)));
        }
    }
    criteria.add(conj);
}