Example usage for java.lang IllegalAccessException getMessage

List of usage examples for java.lang IllegalAccessException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.kangyonggan.api.common.util.Reflections.java

/**
 * , private/protected, ??setter./*from  w w w .j a v a 2s .co 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) {
        log.error("??:{}", e.getMessage());
    }
}

From source file:com.kangyonggan.api.common.util.Reflections.java

/**
 * ?, private/protected, ??getter./* w ww. j  av  a 2 s .  c  om*/
 */
public static Object getFieldValue(final Object obj, final String fieldName) {
    Field field = getAccessibleField(obj, fieldName);

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

    Object result = null;
    try {
        result = field.get(obj);
    } catch (IllegalAccessException e) {
        log.error("??{}", e.getMessage());
    }
    return result;
}

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

/**
 * , private/protected, ??setter./*from w w  w.  j a  v a  2 s  .com*/
 */
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 + "]");
    }
    System.out.println("-----field-----" + field.getType());
    try {
        field.set(obj, value);
    } catch (IllegalAccessException e) {
        logger.error("??:{}", e.getMessage());
    }
}

From source file:com.cxypub.baseframework.sdk.util.ReflectionUtils.java

/**
 * , private/protected, ??setter./*from   www.  j  a  v a2 s. c om*/
 */
public static void setFieldValue(final Object object, final String fieldName, final Object value) {
    Field field = getDeclaredField(object, fieldName);

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

    makeAccessible(field);

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

From source file:com.wineaccess.winerylicensedetail.WineryLicenseDetailAdapterHelper.java

/**
 * This method is used to view the detail of winery license
 * //  w  ww  .  j ava2 s  .c o m
 * @param wineryLicenseDetailViewPO
 *            is used to take input in this PO
 * @return output map containing response
 */
public static Map<String, Object> viewWineryLicenseDetail(
        final WineryLicenseDetailViewPO wineryLicenseDetailViewPO) {

    logger.info("start viewWineryLicenseDetail method");

    final Map<String, Object> output = new ConcurrentHashMap<String, Object>();

    Response response = null;
    WineryLicenseDetailModel wineryLicenseDetailModel = null;

    WineryModel winery = WineryRepository
            .getWineryById(Long.parseLong(wineryLicenseDetailViewPO.getWineryId()));
    if (winery == null) {
        // winery not exist
        response = ApplicationUtils.errorMessageGenerate(

                SystemErrorCode.VIEW_WINERY_LICENSE_INVALID_WINERY,
                SystemErrorCode.VIEW_WINERY_LICENSE_INVALID_WINERY_TEXT, SUCCESS_CODE);

        logger.error("winery not exist");
    }

    if (response == null) {

        wineryLicenseDetailModel = WineryLicenseDetailRepository.getWineryLicenseDetailByWinery(winery);

        if (wineryLicenseDetailModel == null) {
            // WineryLicenseDetail not exist
            response = ApplicationUtils.errorMessageGenerate(

                    SystemErrorCode.NO_ENTITY_FOUND, SystemErrorCode.NO_ENTITY_FOUND_TEXT, SUCCESS_CODE);

            logger.error("Winery License detail Id not exist");
        }
    }

    if (response == null) {

        WineryLicenseDetailViewVO wineryLicenseDetailViewVO = new WineryLicenseDetailViewVO();

        try {
            BeanUtils.copyProperties(wineryLicenseDetailViewVO, wineryLicenseDetailModel);
        } catch (IllegalAccessException e) {
            logger.error("Error in copying value using bean util " + e.getMessage(), e);
        } catch (InvocationTargetException e) {
            logger.error("Error in copying value using bean util " + e.getMessage(), e);
        }

        wineryLicenseDetailViewVO.setWineryId(wineryLicenseDetailModel.getWinery().getId());

        if (wineryLicenseDetailModel.getCaLicenseType() != null) {
            wineryLicenseDetailViewVO.setCaLicenseTypeId(wineryLicenseDetailModel.getCaLicenseType().getId());
        }

        response = new com.wineaccess.response.SuccessResponse(wineryLicenseDetailViewVO, SUCCESS_CODE);

    }

    output.put(OUPUT_PARAM_KEY, response);

    logger.info("exit viewWineryLicenseDetail method");

    return output;
}

From source file:net.shopxx.util.SystemUtils.java

@SuppressWarnings("unchecked")
public static Setting getSetting() {
    Ehcache cache = CACHE_MANAGER.getEhcache(Setting.CACHE_NAME);
    String cacheKey = "setting";
    Element cacheElement = cache.get(cacheKey);
    if (cacheElement == null) {
        Setting setting = new Setting();
        try {// ww w . ja v a  2s . c  om
            File shopxxXmlFile = new ClassPathResource(CommonAttributes.SHOPXX_XML_PATH).getFile();
            Document document = new SAXReader().read(shopxxXmlFile);
            List<org.dom4j.Element> elements = document.selectNodes("/shopxx/setting");
            for (org.dom4j.Element element : elements) {
                try {
                    String name = element.attributeValue("name");
                    String value = element.attributeValue("value");
                    BEAN_UTILS.setProperty(setting, name, value);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(e.getMessage(), e);
                } catch (InvocationTargetException e) {
                    throw new RuntimeException(e.getMessage(), e);
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        } catch (DocumentException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        cache.put(new Element(cacheKey, setting));
        cacheElement = cache.get(cacheKey);
    }
    return (Setting) cacheElement.getObjectValue();
}

From source file:com.cxypub.baseframework.sdk.util.ReflectionUtils.java

/**
 * ?, private/protected, ??getter.//from  w  ww.  j a v a2s  .  c  o m
 */
public static Object getFieldValue(final Object object, final String fieldName) {
    Field field = getDeclaredField(object, fieldName);

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

    makeAccessible(field);

    Object result = null;
    try {
        result = field.get(object);
    } catch (IllegalAccessException e) {
        logger.error("??:" + e.getMessage());
    }
    return result;
}

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

/**
 * value String//  ww  w.  j  av  a  2s .  co  m
 * , 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:com.neusoft.mid.clwapi.tools.JacksonUtils.java

/**
 * String?/*from w ww  .java 2s .  co  m*/
 * 
 * @param obj
 *            ?(?JavaBean,String,Collection,Map)
 * @return ??
 * @throws JacksonEncoderException
 *             jackson?
 */
public static Object jsonEncoder(Object obj) throws JacksonEncoderException {
    logger.debug("obj class is:" + obj.getClass());
    if (obj instanceof String) {
        return jsonCoder((String) obj, true);
    } else if (obj instanceof Map<?, ?>) {
        logger.debug("Object is " + obj.getClass());
        Set<?> entries = ((Map<?, ?>) obj).entrySet();
        Iterator<?> it = entries.iterator();
        while (it.hasNext()) {
            Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) it.next();
            logger.debug("Key is [" + entry.getKey() + "]");
            entry.setValue(jsonEncoder(entry.getValue()));
        }
    } else if (obj instanceof Collection<?>) {
        logger.debug("Object is " + obj.getClass());
        Collection<?> c = (Collection<?>) obj;
        Iterator<?> it = c.iterator();
        while (it.hasNext()) {
            jsonEncoder(it.next());
        }
    } else {
        try {
            Field[] fields = obj.getClass().getFields();
            for (Field f : fields) {
                jsonCoder(obj, f);
            }
        } catch (IllegalAccessException e) {
            logger.error("json??" + e.getMessage());
            throw new JacksonEncoderException(e);
        }
    }
    return obj;
}

From source file:net.shopxx.util.SystemUtils.java

@SuppressWarnings("unchecked")
public static void setSetting(Setting setting) {
    Assert.notNull(setting);//from   www . j a  v a  2  s  .co  m

    try {
        File shopxxXmlFile = new ClassPathResource(CommonAttributes.SHOPXX_XML_PATH).getFile();
        Document document = new SAXReader().read(shopxxXmlFile);
        List<org.dom4j.Element> elements = document.selectNodes("/shopxx/setting");
        for (org.dom4j.Element element : elements) {
            try {
                String name = element.attributeValue("name");
                String value = BEAN_UTILS.getProperty(setting, name);
                Attribute attribute = element.attribute("value");
                attribute.setValue(value);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e.getMessage(), e);
            } catch (InvocationTargetException e) {
                throw new RuntimeException(e.getMessage(), e);
            } catch (NoSuchMethodException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }

        XMLWriter xmlWriter = null;
        try {
            OutputFormat outputFormat = OutputFormat.createPrettyPrint();
            outputFormat.setEncoding("UTF-8");
            outputFormat.setIndent(true);
            outputFormat.setIndent("   ");
            outputFormat.setNewlines(true);
            xmlWriter = new XMLWriter(new FileOutputStream(shopxxXmlFile), outputFormat);
            xmlWriter.write(document);
            xmlWriter.flush();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e.getMessage(), e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e.getMessage(), e);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        } finally {
            try {
                if (xmlWriter != null) {
                    xmlWriter.close();
                }
            } catch (IOException e) {
            }
        }
        Ehcache cache = CACHE_MANAGER.getEhcache(Setting.CACHE_NAME);
        String cacheKey = "setting";
        cache.put(new Element(cacheKey, setting));
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (DocumentException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}