Example usage for java.beans IntrospectionException printStackTrace

List of usage examples for java.beans IntrospectionException printStackTrace

Introduction

In this page you can find the example usage for java.beans IntrospectionException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.metaparadigm.jsonrpc.BeanSerializer.java

public ObjectMatch tryUnmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;/*from w  w  w.j av a 2s  .  c om*/
    BeanData bd = null;
    try {
        bd = getBeanData(clazz);
    } catch (IntrospectionException e) {
        throw new UnmarshallException(clazz.getName() + " is not a bean");
    }

    int match = 0, mismatch = 0;
    Iterator i = bd.writableProps.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry ent = (Map.Entry) i.next();
        String prop = (String) ent.getKey();
        Method method = (Method) ent.getValue();
        if (jso.has(prop))
            match++;
        else
            mismatch++;
    }
    if (match == 0)
        throw new UnmarshallException("bean has no matches");

    ObjectMatch m = null, tmp = null;
    i = jso.keys();
    while (i.hasNext()) {
        String field = (String) i.next();
        Method setMethod = (Method) bd.writableProps.get(field);
        if (setMethod != null) {
            try {
                Class param[] = setMethod.getParameterTypes();
                if (param.length != 1)
                    throw new UnmarshallException("bean " + clazz.getName() + " method " + setMethod.getName()
                            + " does not have one arg");
                tmp = ser.tryUnmarshall(state, param[0], jso.get(field));
                if (m == null)
                    m = tmp;
                else
                    m = m.max(tmp);
            } catch (UnmarshallException e) {
                throw new UnmarshallException("bean " + clazz.getName() + " " + e.getMessage());
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            mismatch++;
        }
    }
    return m.max(new ObjectMatch(mismatch));
}