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 Object marshall(SerializerState state, Object p, Object o) throws MarshallException {
    BeanData bd;//from   www . j  a  v  a2s . c  o m
    try {
        bd = getBeanData(o.getClass());
    } catch (IntrospectionException e) {
        throw new MarshallException(o.getClass().getName() + " is not a bean", e);
    }

    JSONObject val = new JSONObject();
    if (ser.getMarshallClassHints()) {
        try {
            val.put("javaClass", o.getClass().getName());
        } catch (JSONException e) {
            throw new MarshallException("JSONException: " + e.getMessage(), e);
        }
    }
    Iterator i = bd.readableProps.entrySet().iterator();
    Object args[] = new Object[0];
    Object result;
    while (i.hasNext()) {
        Map.Entry ent = (Map.Entry) i.next();
        String prop = (String) ent.getKey();
        Method getMethod = (Method) ent.getValue();
        if (log.isDebugEnabled()) {
            log.debug("invoking " + getMethod.getName() + "()");
        }
        try {
            result = getMethod.invoke(o, args);
        } catch (Throwable e) {
            if (e instanceof InvocationTargetException) {
                e = ((InvocationTargetException) e).getTargetException();
            }
            throw new MarshallException("bean " + o.getClass().getName() + " can't invoke "
                    + getMethod.getName() + ": " + e.getMessage(), e);
        }
        try {
            if (result != null || ser.getMarshallNullAttributes()) {
                try {
                    Object json = ser.marshall(state, o, result, prop);

                    // omit the object entirely if it's a circular reference or duplicate
                    // it will be regenerated in the fixups phase
                    if (JSONSerializer.CIRC_REF_OR_DUPLICATE != json) {
                        val.put(prop, json);
                    }
                } catch (JSONException e) {
                    throw new MarshallException("JSONException: " + e.getMessage(), e);
                }
            }
        } catch (MarshallException e) {
            throw new MarshallException("bean " + o.getClass().getName() + " " + e.getMessage(), e);
        }
    }

    return val;
}

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

@Override
public Object marshall(final SerializerState state, final Object p, final Object o) throws MarshallException {

    BeanData bd;/*from w  ww.  j a va2  s .  co m*/
    try {
        bd = getBeanData(o.getClass());
    } catch (final IntrospectionException e) {
        throw new MarshallException(o.getClass().getName() + " is not a bean", e);
    }

    final JSONObject val = new JSONObject();
    if (ser.getMarshallClassHints()) {
        try {
            val.put("javaClass", o.getClass().getName());
        } catch (final JSONException e) {
            throw new MarshallException("JSONException: " + e.getMessage(), e);
        }
    }

    final Object args[] = new Object[0];
    Object result;
    for (final Entry<String, Method> ent : bd.readableProps.entrySet()) {
        final String prop = ent.getKey();
        final Method getMethod = ent.getValue();
        if (log.isDebugEnabled()) {
            log.debug("marshall", "invoking " + getMethod.getName() + "()");
        }
        try {
            result = getMethod.invoke(o, args);
        } catch (Throwable e) {
            if (e instanceof InvocationTargetException) {
                e = ((InvocationTargetException) e).getTargetException();
            }
            throw new MarshallException("bean " + o.getClass().getName() + " can't invoke "
                    + getMethod.getName() + ": " + e.getMessage(), e);
        }
        try {
            if (result != null || ser.getMarshallNullAttributes()) {
                try {
                    final Object json = ser.marshall(state, o, result, prop);

                    // omit the object entirely if it's a circular reference
                    // or duplicate
                    // it will be regenerated in the fixups phase
                    if (JSONSerializer.CIRC_REF_OR_DUPLICATE != json) {
                        val.put(prop, json);
                    }
                } catch (final JSONException e) {
                    throw new MarshallException("JSONException: " + e.getMessage(), e);
                }
            }
        } catch (final MarshallException e) {
            throw new MarshallException("bean " + o.getClass().getName() + " " + e.getMessage(), e);
        }
    }

    return val;
}

From source file:ResultSetIterator.java

/**
 * Returns a PropertyDescriptor[] for the given Class.
 *
 * @param c The Class to retrieve PropertyDescriptors for.
 * @return A PropertyDescriptor[] describing the Class.
 * @throws SQLException if introspection failed.
 *//*from  ww  w  .  j  av  a2  s  .  c om*/
private PropertyDescriptor[] propertyDescriptors(Class c) throws SQLException {
    // Introspector caches BeanInfo classes for better performance
    BeanInfo beanInfo = null;
    try {
        beanInfo = Introspector.getBeanInfo(c);

    } catch (IntrospectionException e) {
        throw new SQLException("Bean introspection failed: " + e.getMessage());
    }

    return beanInfo.getPropertyDescriptors();
}

From source file:com.neteast.rmp.rpc.serializer.impl.BeanSerializer.java

public Object marshall(Object p, Object o) throws MarshallException {
    BeanData bd;//from w  w  w  .j a  va2s.c o m
    try {
        bd = getBeanData(o.getClass());
    } catch (IntrospectionException e) {
        throw new MarshallException(o.getClass().getName() + " is not a bean", e);
    }

    JSONObject val = new JSONObject();
    Iterator i = bd.readableProps.entrySet().iterator();
    Object args[] = new Object[0];
    Object result;
    while (i.hasNext()) {
        Map.Entry ent = (Map.Entry) i.next();
        String prop = (String) ent.getKey();
        if (StringUtils.equals(prop, "hibernateLazyInitializer")) {
            continue;
        }

        Method getMethod = (Method) ent.getValue();
        if (log.isDebugEnabled()) {
            log.debug("invoking " + getMethod.getName() + "()");
        }
        try {
            result = getMethod.invoke(o, args);
        } catch (Throwable e) {
            if (e instanceof InvocationTargetException) {
                e = ((InvocationTargetException) e).getTargetException();
            }
            throw new MarshallException("bean " + o.getClass().getName() + " can't invoke "
                    + getMethod.getName() + ": " + e.getMessage(), e);
        }
        try {
            if (result != null) {
                try {
                    Object json = ser.marshall(o, result);

                    // omit the object entirely if it's a circular reference or duplicate
                    // it will be regenerated in the fixups phase
                    if (new Object() != json) {
                        val.put(prop, json);
                    }
                } catch (Exception e) {
                    throw new MarshallException("JSONException: " + e.getMessage(), e);
                }
            }
        } catch (MarshallException e) {
            throw new MarshallException("bean " + o.getClass().getName() + " " + e.getMessage(), e);
        }
    }

    return val;
}

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

public Object marshall(Object p, Object o) throws MarshallException {
    BeanData bd;/*from w w w  .j  a v a 2s  .co  m*/
    try {
        bd = getBeanData(o.getClass());
    } catch (IntrospectionException e) {
        throw new MarshallException(o.getClass().getName() + " is not a bean", e);
    }

    JSONObject val = new JSONObject();
    Iterator i = bd.readableProps.entrySet().iterator();
    Object args[] = new Object[0];
    Object result;
    while (i.hasNext()) {
        Map.Entry ent = (Map.Entry) i.next();
        String prop = (String) ent.getKey();
        if (StringUtils.equals(prop, "hibernateLazyInitializer")) {
            continue;
        }

        Method getMethod = (Method) ent.getValue();
        if (log.isDebugEnabled()) {
            log.debug("invoking " + getMethod.getName() + "()");
        }
        try {
            result = getMethod.invoke(o, args);
        } catch (Throwable e) {
            if (e instanceof InvocationTargetException) {
                e = ((InvocationTargetException) e).getTargetException();
            }
            throw new MarshallException("bean " + o.getClass().getName() + " can't invoke "
                    + getMethod.getName() + ": " + e.getMessage(), e);
        }
        try {
            if (result != null) {
                try {
                    Object json = ser.marshall(o, result);

                    // omit the object entirely if it's a circular reference
                    // or duplicate
                    // it will be regenerated in the fixups phase
                    if (new Object() != json) {
                        val.put(prop, json);
                    }
                } catch (Exception e) {
                    throw new MarshallException("JSONException: " + e.getMessage(), e);
                }
            }
        } catch (MarshallException e) {
            throw new MarshallException("bean " + o.getClass().getName() + " " + e.getMessage(), e);
        }
    }

    return val;
}

From source file:be.fgov.kszbcss.rhq.websphere.component.jdbc.db2.pool.ConnectionContextImpl.java

ConnectionContextImpl(Map<String, Object> properties) {
    dataSource = new DB2SimpleDataSource();
    BeanInfo beanInfo;/* w  w w.j  a va 2s.com*/
    try {
        beanInfo = Introspector.getBeanInfo(DB2SimpleDataSource.class);
    } catch (IntrospectionException ex) {
        throw new Error(ex);
    }
    for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
        String name = descriptor.getName();
        if (properties.containsKey(name)) {
            Object value = properties.get(name);
            Class<?> propertyType = descriptor.getPropertyType();
            if (log.isDebugEnabled()) {
                log.debug("Setting property " + name + ": propertyType=" + propertyType.getName() + ", value="
                        + value + " (class=" + (value == null ? "<N/A>" : value.getClass().getName()) + ")");
            }
            if (propertyType != String.class && value instanceof String) {
                // Need to convert value to correct type
                if (propertyType == Integer.class || propertyType == Integer.TYPE) {
                    value = Integer.valueOf((String) value);
                }
                if (log.isDebugEnabled()) {
                    log.debug("Converted value to " + value + " (class=" + value.getClass().getName() + ")");
                }
            }
            try {
                descriptor.getWriteMethod().invoke(dataSource, value);
            } catch (IllegalArgumentException ex) {
                throw new RuntimeException("Failed to set '" + name + "' property", ex);
            } catch (IllegalAccessException ex) {
                throw new IllegalAccessError(ex.getMessage());
            } catch (InvocationTargetException ex) {
                Throwable cause = ex.getCause();
                if (cause instanceof RuntimeException) {
                    throw (RuntimeException) cause;
                } else if (cause instanceof Error) {
                    throw (Error) cause;
                } else {
                    throw new RuntimeException(ex);
                }
            }
        }
    }
}

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

public ObjectMatch tryUnmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;//from ww  w  . j ava2  s.c o  m
    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));
}

From source file:com.neteast.rmp.rpc.serializer.impl.BeanSerializer.java

public ObjectMatch tryUnmarshall(Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;//  w w  w.  j a  v  a  2 s. c  o 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);

    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(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(), e);
            } catch (Exception 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:com.jetyun.pgcd.rpc.serializer.impl.BeanSerializer.java

public ObjectMatch tryUnmarshall(Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;/*from   ww w  .  ja  va2s .  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);

    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(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(), e);
            } catch (Exception 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:org.jabsorb.ng.serializer.impl.BeanSerializer.java

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

    final JSONObject jso = (JSONObject) o;
    BeanData bd;/*from w w w  . j  a va2s.  c o m*/
    try {
        bd = getBeanData(clazz);
    } catch (final IntrospectionException e) {
        throw new UnmarshallException(clazz.getName() + " is not a bean", e);
    }

    int match = 0;
    int mismatch = 0;
    for (final String prop : bd.writableProps.keySet()) {
        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
    final ObjectMatch returnValue = new ObjectMatch(-1);
    state.setSerialized(o, returnValue);

    ObjectMatch m = null;
    ObjectMatch tmp;
    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();
                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 (final UnmarshallException e) {
                throw new UnmarshallException("bean " + clazz.getName() + " " + e.getMessage(), e);
            } catch (final 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;
}