Example usage for java.beans IntrospectionException getMessage

List of usage examples for java.beans IntrospectionException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.jabsorb.serializer.impl.BeanSerializer.java

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

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

    // create a concrete ObjectMatch that is always returned in order to satisfy circular reference requirements
    ObjectMatch returnValue = new ObjectMatch(-1);
    state.setSerialized(o, returnValue);

    ObjectMatch m = null;
    ObjectMatch tmp;
    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 (tmp != null) {
                    if (m == null) {
                        m = tmp;
                    } else {
                        m = m.max(tmp);
                    }
                }
            } catch (UnmarshallException e) {
                throw new UnmarshallException("bean " + clazz.getName() + " " + e.getMessage(), e);
            } catch (JSONException e) {
                throw new UnmarshallException("bean " + clazz.getName() + " " + e.getMessage(), e);
            }
        } else {
            mismatch++;
        }
    }
    if (m != null) {
        returnValue.setMismatch(m.max(new ObjectMatch(mismatch)).getMismatch());
    } else {
        returnValue.setMismatch(mismatch);
    }
    return returnValue;
}

From source file:de.terrestris.shogun.dao.DatabaseDao.java

/**
 *
 * @param list/*from   ww  w  . ja  v  a 2s . c om*/
 * @param mainClass
 */
protected void initializeDeepList(List<? extends Object> list, Class<?> mainClass) {
    List<Field> fields = getAllFields(new ArrayList<Field>(), mainClass);
    List<Method> methods = new ArrayList<Method>();

    for (Field field : fields) {
        if (field.getType().isAssignableFrom(Set.class)) {
            // yes, we have to initialize this field via its getter
            Method method = null;
            try {
                method = new PropertyDescriptor(field.getName(), mainClass).getReadMethod();
            } catch (IntrospectionException e) {
                LOGGER.error("Failed to determine getter for field '" + field.getName() + "' of class '"
                        + mainClass.getSimpleName() + "'.");
            }
            methods.add(method);
        }
    }

    for (Iterator<Object> iterator = (Iterator<Object>) list.iterator(); iterator.hasNext();) {
        Object obj = iterator.next();
        if (obj == null) {
            continue;
        }
        for (Method method : methods) {
            String errMsg = "Failed to invoke getter '" + method.getName() + "' of class '"
                    + mainClass.getSimpleName() + "': ";
            try {
                Hibernate.initialize(method.invoke(obj));
            } catch (HibernateException e) {
                LOGGER.error(errMsg + " HibernateException '" + e.getMessage() + "'.");
            } catch (IllegalArgumentException e) {
                LOGGER.error(errMsg + " IllegalArgumentException '" + e.getMessage() + "'.");
            } catch (IllegalAccessException e) {
                LOGGER.error(errMsg + " IllegalAccessException '" + e.getMessage() + "'.");
            } catch (InvocationTargetException e) {
                LOGGER.error(errMsg + " InvocationTargetException '" + e.getMessage() + "'.");
            }
        }
    }
}

From source file:com.jetyun.pgcd.rpc.serializer.impl.BeanSerializer.java

public Object unmarshall(Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;/*from w  ww .  j av  a 2  s .  c om*/
    BeanData bd;
    try {
        bd = getBeanData(clazz);
    } catch (IntrospectionException e) {
        throw new UnmarshallException(clazz.getName() + " is not a bean", e);
    }
    if (log.isDebugEnabled()) {
        log.debug("instantiating " + clazz.getName());
    }
    Object instance;
    try {
        instance = clazz.newInstance();
    } catch (InstantiationException e) {
        throw new UnmarshallException(
                "could not instantiate bean of type " + clazz.getName() + ", make sure it has a no argument "
                        + "constructor and that it is not an interface or " + "abstract class",
                e);
    } catch (IllegalAccessException e) {
        throw new UnmarshallException("could not instantiate bean of type " + clazz.getName(), e);
    } catch (RuntimeException e) {
        throw new UnmarshallException("could not instantiate bean of type " + clazz.getName(), e);
    }
    Object invokeArgs[] = new Object[1];
    Object fieldVal;
    Iterator 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();
                fieldVal = ser.unmarshall(param[0], jso.get(field));
            } catch (UnmarshallException e) {
                throw new UnmarshallException(
                        "could not unmarshall field \"" + field + "\" of bean " + clazz.getName(), e);
            } catch (Exception e) {
                throw new UnmarshallException(
                        "could not unmarshall field \"" + field + "\" of bean " + clazz.getName(), e);
            }
            if (log.isDebugEnabled()) {
                log.debug("invoking " + setMethod.getName() + "(" + fieldVal + ")");
            }
            invokeArgs[0] = fieldVal;
            try {
                setMethod.invoke(instance, invokeArgs);
            } catch (Throwable e) {
                if (e instanceof InvocationTargetException) {
                    e = ((InvocationTargetException) e).getTargetException();
                }
                throw new UnmarshallException("bean " + clazz.getName() + "can't invoke " + setMethod.getName()
                        + ": " + e.getMessage(), e);
            }
        }
    }
    return instance;
}

From source file:org.jabsorb.serializer.impl.BeanSerializer.java

public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;//www .j av  a 2 s  .c om
    BeanData bd;
    try {
        bd = getBeanData(clazz);
    } catch (IntrospectionException e) {
        throw new UnmarshallException(clazz.getName() + " is not a bean", e);
    }
    if (log.isDebugEnabled()) {
        log.debug("instantiating " + clazz.getName());
    }
    Object instance;
    try {
        instance = clazz.newInstance();
    } catch (InstantiationException e) {
        throw new UnmarshallException(
                "could not instantiate bean of type " + clazz.getName() + ", make sure it has a no argument "
                        + "constructor and that it is not an interface or " + "abstract class",
                e);
    } catch (IllegalAccessException e) {
        throw new UnmarshallException("could not instantiate bean of type " + clazz.getName(), e);
    } catch (RuntimeException e) {
        throw new UnmarshallException("could not instantiate bean of type " + clazz.getName(), e);
    }
    state.setSerialized(o, instance);
    Object invokeArgs[] = new Object[1];
    Object fieldVal;
    Iterator 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();
                fieldVal = ser.unmarshall(state, param[0], jso.get(field));
            } catch (UnmarshallException e) {
                throw new UnmarshallException(
                        "could not unmarshall field \"" + field + "\" of bean " + clazz.getName(), e);
            } catch (JSONException e) {
                throw new UnmarshallException(
                        "could not unmarshall field \"" + field + "\" of bean " + clazz.getName(), e);
            }
            if (log.isDebugEnabled()) {
                log.debug("invoking " + setMethod.getName() + "(" + fieldVal + ")");
            }
            invokeArgs[0] = fieldVal;
            try {
                setMethod.invoke(instance, invokeArgs);
            } catch (Throwable e) {
                if (e instanceof InvocationTargetException) {
                    e = ((InvocationTargetException) e).getTargetException();
                }
                throw new UnmarshallException("bean " + clazz.getName() + "can't invoke " + setMethod.getName()
                        + ": " + e.getMessage(), e);
            }
        }
    }
    return instance;
}

From source file:org.jabsorb.ng.serializer.impl.BeanSerializer.java

@Override
public Object unmarshall(final SerializerState state, final Class<?> clazz, final Object o)
        throws UnmarshallException {

    final JSONObject jso = (JSONObject) o;
    BeanData bd;//from   ww w.ja v a 2  s .c o  m
    try {
        bd = getBeanData(clazz);
    } catch (final IntrospectionException e) {
        throw new UnmarshallException(clazz.getName() + " is not a bean", e);
    }
    if (log.isDebugEnabled()) {
        log.debug("unmarshall", "instantiating " + clazz.getName());
    }
    Object instance;
    try {
        instance = clazz.newInstance();
    } catch (final InstantiationException e) {
        throw new UnmarshallException(
                "could not instantiate bean of type " + clazz.getName() + ", make sure it has a no argument "
                        + "constructor and that it is not an interface or " + "abstract class",
                e);
    } catch (final IllegalAccessException e) {
        throw new UnmarshallException("could not instantiate bean of type " + clazz.getName(), e);
    } catch (final RuntimeException e) {
        throw new UnmarshallException("could not instantiate bean of type " + clazz.getName(), e);
    }
    state.setSerialized(o, instance);
    final Object invokeArgs[] = new Object[1];
    Object fieldVal;
    final Iterator<?> i = jso.keys();
    while (i.hasNext()) {
        final String field = (String) i.next();
        final Method setMethod = bd.writableProps.get(field);
        if (setMethod != null) {
            try {
                final Class<?> param[] = setMethod.getParameterTypes();
                fieldVal = ser.unmarshall(state, param[0], jso.get(field));
            } catch (final UnmarshallException e) {
                throw new UnmarshallException(
                        "could not unmarshall field \"" + field + "\" of bean " + clazz.getName(), e);
            } catch (final JSONException e) {
                throw new UnmarshallException(
                        "could not unmarshall field \"" + field + "\" of bean " + clazz.getName(), e);
            }
            if (log.isDebugEnabled()) {
                log.debug("unmarshall", "invoking " + setMethod.getName() + "(" + fieldVal + ")");
            }
            invokeArgs[0] = fieldVal;
            try {
                setMethod.invoke(instance, invokeArgs);
            } catch (Throwable e) {
                if (e instanceof InvocationTargetException) {
                    e = ((InvocationTargetException) e).getTargetException();
                }
                throw new UnmarshallException("bean " + clazz.getName() + "can't invoke " + setMethod.getName()
                        + ": " + e.getMessage(), e);
            }
        }
    }
    return instance;
}