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.googlecode.commons.swing.util.BeanUtils.java

public static Object getProperty(Object bean, String property) {
    try {//  ww w  . ja v  a  2  s  .co  m
        return PropertyUtils.getProperty(bean, property);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        return null;
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        return null;
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

static Map<String, Object> objectToMap(Object object) {
    Map<String, Object> map = new HashMap<>();

    Class cls = object.getClass();
    while (cls != null) {
        for (Field field : cls.getDeclaredFields()) {
            field.setAccessible(true);//  w ww. j  a  va 2 s.co m

            Object value = null;
            try {
                value = field.get(object);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

            if (value != null)
                map.put(field.getName(), value);
        }

        cls = cls.getSuperclass();
    }

    return map;
}

From source file:com.life.audiotageditor.utils.ReflectUtil.java

public static String getProperty(Object bean, String name) {
    try {/*from  www  .j  ava  2  s.c  om*/
        String propertyValue = BeanUtils.getProperty(bean, name);
        return propertyValue == null ? Constants.STRING_NONE : propertyValue;
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
    return Constants.STRING_NONE;
}

From source file:Main.java

/**
 * Returns the Jarvis Api Version or -1 if it is not supported
 * @return api version/*from w w  w .ja v a  2  s.  com*/
 */
public static int getJarvisApiVersion() {
    Field[] declaredFields = Build.class.getDeclaredFields();
    for (Field field : declaredFields) {
        if (Modifier.isStatic(field.getModifiers()) && field.getName().equals("JARVIS_VERSION")) {
            try {
                return field.getInt(null);
            } catch (IllegalAccessException ex) {
                ex.printStackTrace();
            } catch (IllegalArgumentException ex) {
                ex.printStackTrace();
            }
        }
    }
    return -1;
}

From source file:Main.java

/**
 * getChildObjs// ww  w  . j  av a  2s  . co m
 *
 * @param object the obj to save to db ,this object contains the property private List<Child> children;
 * @return the List<Child> value
 */
public static List<List> getChildObjs(Object object) {
    Field[] fields = object.getClass().getDeclaredFields();
    List<List> result = new ArrayList<>();
    for (Field field : fields) {
        if ("java.util.List".equals(field.getType().getName())) {
            List list = null;
            try {
                field.setAccessible(true);
                list = (List) field.get(object);
                result.add(list);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
    return result;
}

From source file:Main.java

public static LinkedHashMap<String, String> convertBeans(Object bean) {
    if (bean == null)
        return null;
    try {//from www  .j a va  2s  . co  m
        LinkedHashMap<String, String> returnMap = new LinkedHashMap<String, String>();

        Class<? extends Object> clazz = bean.getClass();
        List<Field> fleids = new ArrayList<Field>();
        for (Class<?> c = clazz; c != Object.class; c = c.getSuperclass()) {
            fleids.addAll(Arrays.asList(c.getDeclaredFields()));
        }

        for (Field field : fleids) {
            String value = "";
            field.setAccessible(true);
            try {
                Object result = field.get(bean);
                if (result == null)
                    continue;
                value = result.toString();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            //            MLogUtil.e("field.getName() "+field.getName());
            //            MLogUtil.e("value "+value);
            returnMap.put(field.getName(), value);
            field.setAccessible(false);
        }
        return returnMap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static Map<String, String> convertBean(Object bean) {
    if (bean == null)
        return null;
    try {// ww w  . ja va2  s.c om
        Class<? extends Object> clazz = bean.getClass();
        Map<String, String> returnMap = new HashMap<String, String>();
        List<Field> fleids = new ArrayList<Field>();
        for (Class<?> c = clazz; c != Object.class; c = c.getSuperclass()) {
            fleids.addAll(Arrays.asList(c.getDeclaredFields()));
        }

        for (Field field : fleids) {
            String value = "";
            field.setAccessible(true);
            try {
                Object result = field.get(bean);
                if (result == null)
                    continue;
                value = result.toString();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            //            MLogUtil.e("field.getName() "+field.getName());
            //            MLogUtil.e("value "+value);
            returnMap.put(field.getName(), value);
            field.setAccessible(false);
        }
        return returnMap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.base2.kagura.rest.helpers.ParameterUtils.java

public static void insertParameters(Parameters parameters, ReportConnector reportConnector,
        List<String> errors) {
    if (reportConnector.getParameterConfig() != null) {
        for (ParamConfig paramConfig : reportConnector.getParameterConfig()) {
            if (parameters.getParameters().containsKey(paramConfig.getId())) {
                Object o = parameters.getParameters().get(paramConfig.getId());
                try {
                    if (o != null && StringUtils.isNotBlank(o.toString()))
                        BeanUtils.setProperty(paramConfig, "value", o);
                    else
                        BeanUtils.setProperty(paramConfig, "value", null);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (ConversionException e) {
                    e.printStackTrace();
                    errors.add("Could not convert parameter: " + paramConfig.getId() + " value " + o);
                }/*from ww w . jav  a  2s . c  om*/
            }
        }
    }
}

From source file:Main.java

public static int hashCode(Object paramObject) {
    int i = 1;//from  w  w w. ja v  a  2 s  .  c  om
    Field[] arrayOfField = paramObject.getClass().getDeclaredFields();
    int j = arrayOfField.length;
    for (int k = 0;; k++) {
        int m;
        int i1;
        if (k < j) {
            Field localField = arrayOfField[k];
            localField.setAccessible(true);
            try {
                Object localObject = localField.get(paramObject);
                m = i * 31;
                if (localObject == null) {
                    i1 = 0;
                } else {
                    int n = localObject.hashCode();
                    i1 = n;
                }
            } catch (IllegalArgumentException localIllegalArgumentException) {
                localIllegalArgumentException.printStackTrace();
                continue;
            } catch (IllegalAccessException localIllegalAccessException) {
                localIllegalAccessException.printStackTrace();
                continue;
            }
        } else {
            return i;
        }
        i = m + i1;
    }
}

From source file:Main.java

public static boolean creteEntity(Object entity, String fileName) {
    boolean flag = false;
    try {//from w ww. j a v  a  2 s .c om
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse(fileName);

        Class clazz = entity.getClass();
        Field[] fields = clazz.getDeclaredFields();
        Node EntityElement = document.getElementsByTagName(clazz.getSimpleName() + "s").item(0);

        Element newEntity = document.createElement(clazz.getSimpleName());
        EntityElement.appendChild(newEntity);

        for (Field field : fields) {
            field.setAccessible(true);
            Element element = document.createElement(field.getName());
            element.appendChild(document.createTextNode(field.get(entity).toString()));
            newEntity.appendChild(element);
        }

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource domSource = new DOMSource(document);
        StreamResult streamResult = new StreamResult(new File(fileName));
        transformer.transform(domSource, streamResult);
        flag = true;
    } catch (ParserConfigurationException pce) {
        System.out.println(pce.getLocalizedMessage());
        pce.printStackTrace();
    } catch (TransformerException te) {
        System.out.println(te.getLocalizedMessage());
        te.printStackTrace();
    } catch (IOException ioe) {
        System.out.println(ioe.getLocalizedMessage());
        ioe.printStackTrace();
    } catch (SAXException sae) {
        System.out.println(sae.getLocalizedMessage());
        sae.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return flag;
}