Example usage for org.apache.commons.lang IllegalClassException getMessage

List of usage examples for org.apache.commons.lang IllegalClassException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.lang IllegalClassException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.sakaiproject.config.impl.StoredConfigService.java

/**
 * Creates an equivalent HibernateConfigItem from a ConfigItem
 *
 * @param item a ConfigItem//w  w  w. jav  a 2  s . c o  m
 * @return a HibernateConfigItem
 * @throws IllegalClassException thrown when the item.getValue doesn't return the right type
 */
public HibernateConfigItem createHibernateConfigItem(ConfigItem item) throws IllegalClassException {
    if (item == null || neverPersistItems.contains(item.getName())) {
        return null;
    }

    if (log.isDebugEnabled()) {
        log.debug("createHibernateConfigItem() New ConfigItem = " + item.toString());
    }

    String serialValue;
    String serialDefaultValue;
    String serialRawValue;

    try {
        serialValue = serializeValue(item.getValue(), item.getType(), item.isSecured());
        serialDefaultValue = serializeValue(item.getDefaultValue(), item.getType(), item.isSecured());
        serialRawValue = serializeValue(getRawProperty(item.getName()), ServerConfigurationService.TYPE_STRING,
                item.isSecured());
    } catch (IllegalClassException ice) {
        log.error("createHibernateConfigItem() IllegalClassException " + ice.getMessage() + " skip ConfigItem "
                + item.toString(), ice);
        return null;
    }

    HibernateConfigItem hItem = new HibernateConfigItem(node, item.getName(), serialValue, serialRawValue,
            item.getType(), item.getDescription(), item.getSource(), serialDefaultValue, item.isRegistered(),
            item.isDefaulted(), item.isSecured(), item.isDynamic());

    if (log.isDebugEnabled()) {
        log.debug("createHibernateConfigItem() Created HibernateConfigItem = " + hItem.toString());
    }

    return hItem;
}

From source file:org.sakaiproject.config.impl.StoredConfigService.java

/**
 * Updates a HibernateConfigItem with a ConfigItem's data; the name, node
 *
 * @param hItem    a HibernateConfigItem
 * @param item     a ConfigItem/*from  w  w  w. ja  va 2 s.c o m*/
 * @return a HibernateConfigItem if it was updated or null if it was not updated
 * @throws IllegalClassException thrown when the item.getValue doesn't return the right type
 */
public HibernateConfigItem updateHibernateConfigItem(HibernateConfigItem hItem, ConfigItem item)
        throws IllegalClassException {
    if (hItem == null || item == null) {
        return null;
    }

    HibernateConfigItem updatedItem = null;

    // check if updating is needed, update it
    if (!hItem.similar(item)) {
        // if they are not similar update it
        if (log.isDebugEnabled()) {
            log.debug("updateHibernateConfigItem() Before " + hItem.toString());
        }

        Object value = deSerializeValue(hItem.getValue(), hItem.getType(), hItem.isSecured());
        Object defaultValue = deSerializeValue(hItem.getDefaultValue(), hItem.getType(), hItem.isSecured());

        try {
            if (value == null) {
                if (item.getValue() != null) {
                    // different update
                    hItem.setValue(serializeValue(item.getValue(), item.getType(), item.isSecured()));
                }
            } else if (!value.equals(item.getValue())) {
                // different update
                hItem.setValue(serializeValue(item.getValue(), item.getType(), item.isSecured()));
            }

            if (defaultValue == null) {
                if (item.getDefaultValue() != null) {
                    // different update
                    hItem.setDefaultValue(
                            serializeValue(item.getDefaultValue(), item.getType(), item.isSecured()));
                }
            } else if (!defaultValue.equals(item.getDefaultValue())) {
                // different update
                hItem.setDefaultValue(serializeValue(item.getDefaultValue(), item.getType(), item.isSecured()));
            }
        } catch (IllegalClassException ice) {
            log.error("updateHibernateConfigItem() IllegalClassException " + ice.getMessage()
                    + " skip ConfigItem " + item.toString(), ice);
            return null;
        }

        hItem.setType(item.getType());
        hItem.setDefaulted(item.isDefaulted());
        hItem.setSecured(item.isSecured());
        hItem.setRegistered(item.isRegistered());
        hItem.setSource(item.getSource());
        hItem.setDescription(item.getDescription());
        hItem.setDynamic(item.isDynamic());
        hItem.setModified(Calendar.getInstance().getTime());

        if (log.isDebugEnabled()) {
            log.debug("updateHibernateConfigItem() After " + hItem.toString());
        }

        updatedItem = hItem;
    }

    // check if raw value needs updating
    // raw values are always strings
    String rawValue = (String) deSerializeValue(hItem.getRawValue(), ServerConfigurationService.TYPE_STRING,
            hItem.isSecured());

    if (!StringUtils.equals(rawValue, getRawProperty(hItem.getName()))) {
        // different update
        hItem.setRawValue(serializeValue(getRawProperty(hItem.getName()),
                ServerConfigurationService.TYPE_STRING, item.isSecured()));
        updatedItem = hItem;
    }

    // only return a hItem if it was updated
    return updatedItem;
}