Example usage for java.lang IllegalAccessException printStackTrace

List of usage examples for java.lang IllegalAccessException printStackTrace

Introduction

In this page you can find the example usage for java.lang IllegalAccessException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:com.aw.swing.mvp.view.IPView.java

public static List<JComponent> getCmps(Object target) {
    //        logger.info("searching attributes " + target.getClass().getName());
    List components = new ArrayList();
    List<Field> forms = new ArrayList();
    Class cls = target.getClass();
    Field[] fields = cls.getFields();
    for (int i = 0; i < fields.length; i++) {
        if ((fields[i].getName().startsWith("txt") || fields[i].getName().startsWith("chk"))
                && !fields[i].getName().startsWith("chkSel")) {
            JComponent jComponemt;
            try {
                jComponemt = (JComponent) fields[i].get(target);
                if (jComponemt != null) {
                    jComponemt.putClientProperty("Field", fields[i]);
                    components.add(jComponemt);
                } else {
                    System.out.println("Null:<" + target.getClass() + ">- <" + fields[i].getName() + ">");
                }/*from ww  w .java2  s  .com*/
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                throw new AWSystemException("Error getting teh value of:<" + fields[i].getName() + ">", e);
            }
        }
        if ((fields[i].getType().getSimpleName().startsWith("Frm"))) {
            forms.add(fields[i]);
        }
    }
    if (forms.size() > 0) {
        for (Field field : forms) {
            try {
                Object formToBeChecked = field.get(target);
                if (formToBeChecked != null) {
                    List formAttributes = getCmps(formToBeChecked);
                    if (formAttributes.size() > 0) {
                        components.addAll(formAttributes);
                    }
                } else {
                    throw new IllegalStateException("FRM NULL:" + field.getName());
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                throw new AWSystemException("Problems getting value for:<" + field.getName() + ">", e);
            }
        }
    }
    return components;
}

From source file:com.github.michalbednarski.intentslab.editor.BundleAdapter.java

public static void putInBundle(Bundle bundle, String key, Object value) {
    if (value == null) {
        bundle.putString(key, null);// ww w. j a  v a2s  . co m
        return;
    }

    Pattern putMethodName = Pattern.compile("put[A-Z][A-Za-z]+");
    for (Method method : Bundle.class.getMethods()) {
        if (putMethodName.matcher(method.getName()).matches() && !method.isVarArgs()) {
            final Class<?>[] parameterTypes = method.getParameterTypes();
            if (parameterTypes.length == 2 && parameterTypes[0] == String.class
                    && Utils.toWrapperClass(parameterTypes[1]).isInstance(value)) {
                try {
                    method.invoke(bundle, key, value);
                    return;
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                    // continue
                } catch (InvocationTargetException e) {
                    throw new RuntimeException("Method " + method.getName() + " of bundle thrown exception", e);
                }
            }
        }
    }
    throw new RuntimeException("No put* method found");
}

From source file:io.github.wysohn.triggerreactor.tools.ReflectionUtil.java

public static void setField(Object obj, String fieldName, Object value)
        throws NoSuchFieldException, IllegalArgumentException {
    Class<?> clazz = obj.getClass();

    Field field = clazz.getDeclaredField(fieldName);
    field.setAccessible(true);/*from   w  w  w.j a  v a  2  s  . co  m*/

    try {
        field.set(obj, value);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:io.github.wysohn.triggerreactor.tools.ReflectionUtil.java

public static Object getField(Class<?> clazz, Object obj, String fieldName)
        throws NoSuchFieldException, IllegalArgumentException {
    Field field = clazz.getDeclaredField(fieldName);
    field.setAccessible(true);/*from  w  w w.  j  ava 2s  .com*/

    try {
        return field.get(obj);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:io.github.wysohn.triggerreactor.tools.ReflectionUtil.java

public static Object getField(Object obj, String fieldName)
        throws NoSuchFieldException, IllegalArgumentException {
    Class<?> clazz = obj.getClass();

    Field field = clazz.getDeclaredField(fieldName);
    field.setAccessible(true);/*from ww  w .  j  a v a  2 s . c  o m*/

    try {
        return field.get(obj);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.ghy.common.util.reflection.ReflectionUtils.java

/**
 * value String//w  w  w .ja v  a 2s . com
 * , private/protected, ??setter.
 */
public static void setFieldsValues(final Object obj, final String fieldName, final Object value) {
    Field field = getAccessibleField(obj, fieldName);

    if (field == null) {
        return;
    }

    try {
        Class<?> type = field.getType();
        if (type.equals(Integer.class) || type.equals(int.class)) {
            field.set(obj, Integer.valueOf((String) value));
        } else if (type.equals(Long.class) || type.equals(long.class)) {
            field.set(obj, Long.valueOf((String) value));
        } else if (type.equals(Double.class) || type.equals(double.class)) {
            field.set(obj, Double.valueOf((String) value));
        } else if (type.equals(Float.class) || type.equals(float.class)) {
            field.set(obj, Float.valueOf((String) value));
        } else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
            field.set(obj, Boolean.valueOf((String) value));
        } else if (type.equals(Date.class)) {
            field.set(obj, new SimpleDateFormat("yyyyMMddHHmmsssss").parse((String) value));
        } else {
            field.set(obj, value);
        }
    } catch (IllegalAccessException e) {
        logger.error(":{}", e.getMessage());
    } catch (IllegalArgumentException e) {
        logger.error(":{}", e.getMessage());
        e.printStackTrace();
    } catch (ParseException e) {
        logger.error(":{}", e.getMessage());
        e.printStackTrace();
    }
}

From source file:de.beyondjava.angularFaces.core.ELTools.java

/**
 * Returns a list of String denoting every primitively typed property of a certain bean.
 *
 * @param p_expression//from   www  .j  a v  a2s  . co  m
 *            The EL expression describing the bean. The EL expression is passed without the leading "#{" and the
 *            trailing brace "}".
 * @param p_recursive
 *            if true, the list also contains properties of nested beans.
 * @return a list of strings consisting of EL expressions without the leading "#{" and the trailing brace "}".
 */
public static List<String> getEveryProperty(String p_expression, boolean p_recursive) {
    synchronized (propertyLists) {
        if (propertyLists.containsKey(p_expression)) {
            return propertyLists.get(p_expression);
        }
    }

    Object container = evalAsObject("#{" + p_expression + "}");

    Class<? extends Object> c = container == null ? null : container.getClass();
    List<String> propertyNames = new ArrayList<String>();
    if (isPrimitive(c)) {
        propertyNames.add(p_expression);
    } else {
        try {
            @SuppressWarnings("unchecked")
            Map<String, Object> description = BeanUtilsBean2.getInstance().describe(container);
            for (String o : description.keySet()) {
                Object object = description.get(o);
                if (object == null) {
                    // might be an array
                } else if (o.equals("class")) {
                    continue;
                } else if (isPrimitive(object.getClass())) {
                    propertyNames.add(o);
                }

                else if (p_recursive) {
                    List<String> nested = getEveryProperty(p_expression + "." + o, p_recursive);
                    for (String n : nested) {
                        propertyNames.add(o + "." + n);
                    }
                }
            }
            synchronized (propertyLists) {
                propertyLists.put(p_expression, propertyNames);
            }
        } catch (IllegalAccessException e) {
            // todo replace by a logger
            LOGGER.log(Level.SEVERE, "Couldn\"t read property list of " + p_expression, e);
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // todo replace by a logger
            LOGGER.log(Level.SEVERE, "Couldn\"t read property list of " + p_expression, e);
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            // todo replace by a logger
            LOGGER.log(Level.SEVERE, "Couldn\"t read property list of " + p_expression, e);
        }
    }
    return propertyNames;
}

From source file:com.kangdainfo.common.util.BeanUtil.java

/**
 * This method takes 2 JavaBeans of the same type and copies the properties of one bean to the other.
 * <br>//from   ww w .j  a v a  2s. co  m
 * @param from
 * @param to
 * @param ignoreFields
 * @throws InvocationTargetException
 * @throws IntrospectionException
 */
public static void copyBeanToBean(Object from, Object to, String[] ignoreFields)
        throws InvocationTargetException, IntrospectionException {
    if (from != null && to != null) {
        PropertyDescriptor[] pds = Introspector.getBeanInfo(from.getClass()).getPropertyDescriptors();
        for (int i = 0; i < pds.length; i++) {
            try {
                boolean flag = false;
                if (ignoreFields != null && ignoreFields.length > 0) {
                    for (int j = 0; j < ignoreFields.length; j++) {
                        if (pds[i].getName().equals(ignoreFields[j]))
                            flag = true;
                    }
                }
                if (pds[i].getName().equals("class") || flag == true)
                    continue;
                Object[] value = { pds[i].getReadMethod().invoke(from) };
                if (pds[i].getWriteMethod() != null)
                    pds[i].getWriteMethod().invoke(to, value);
            } catch (IllegalAccessException iae) {
                iae.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.plusub.lib.annotate.JsonParserUtils.java

/**
 * /*  w  w w  .  j  a  va  2  s.  co m*/
 * <p>Title: setFieldValue
 * <p>Description: 
 * @param object 
 * @param field 
 * @param value 
 */
private static void setFieldValue(Object object, Field field, Object value) {
    Object ov = null;
    try {
        ov = getType(field, value, field.getName());
        field.set(object, ov);
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        if (showLog) {
            e.printStackTrace();
        }

        //fieldset
        try {
            Method m = object.getClass().getMethod(getSetMethodName(field), field.getType());
            if (m != null) {
                m.invoke(object, ov);
            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            if (showLog) {
                Logger.e(TAG,
                        "set field value fail field:" + field.getName() + " method:" + getSetMethodName(field));
                e1.printStackTrace();
            }
        }
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        if (showLog) {
            e.printStackTrace();
        }
    } catch (Exception e) {
        if (showLog) {
            e.printStackTrace();
        }
    }
}

From source file:com.nerve.commons.repository.utils.reflection.ReflectionUtils.java

/**
 * , private/protected, ??setter.//from  ww  w . ja va 2 s.  c o m
 */
public static void setFieldValue(final Object obj, final String fieldName, final Object value) {
    Field field = getAccessibleField(obj, fieldName);

    if (field == null) {
        throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + "]");
    }

    try {
        field.set(obj, value);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        logger.error("??:{}", e.getMessage());
    }
}