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

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

Introduction

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

Prototype

public IllegalClassException(Class expected, Class actual) 

Source Link

Document

Instantiates with the expected and actual types.

Usage

From source file:com.noxpvp.mmo.abilities.BasePlayerAbility.java

public Player getPlayer() {
    if (!(getEntity() instanceof Player))
        throw new IllegalStateException("Internal Data was tampered with..",
                new IllegalClassException(Player.class, Entity.class));
    return (Player) getEntity();
}

From source file:org.apache.storm.trident.windowing.WindowsStateUpdater.java

@Override
public void updateState(WindowsState state, List<TridentTuple> tuples, TridentCollector collector) {
    Long currentTxId = state.getCurrentTxId();
    LOG.debug("Removing triggers using WindowStateUpdater, txnId: [{}] ", currentTxId);
    for (TridentTuple tuple : tuples) {
        try {//from www. j  av a 2  s. c  o m
            Object fieldValue = tuple.getValueByField(WindowTridentProcessor.TRIGGER_FIELD_NAME);
            if (!(fieldValue instanceof WindowTridentProcessor.TriggerInfo)) {
                throw new IllegalClassException(WindowTridentProcessor.TriggerInfo.class,
                        fieldValue.getClass());
            }
            WindowTridentProcessor.TriggerInfo triggerInfo = (WindowTridentProcessor.TriggerInfo) fieldValue;
            String triggerCompletedKey = WindowTridentProcessor
                    .getWindowTriggerInprocessIdPrefix(triggerInfo.windowTaskId) + currentTxId;

            LOG.debug("Removing trigger key [{}] and trigger completed key [{}] from store: [{}]", triggerInfo,
                    triggerCompletedKey, windowsStore);

            windowsStore.removeAll(Lists.newArrayList(triggerInfo.generateTriggerKey(), triggerCompletedKey));
        } catch (Exception ex) {
            LOG.warn(ex.getMessage());
            collector.reportError(ex);
            throw new FailedException(ex);
        }
    }
}

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

private String serializeValue(Object obj, String type, boolean secured) throws IllegalClassException {
    if (obj == null || type == null) {
        return null;
    }//ww  w . j  av a  2s . c om

    String string;

    if (ServerConfigurationService.TYPE_STRING.equals(type)) {
        if (obj instanceof String) {
            string = String.valueOf(obj);
        } else {
            throw new IllegalClassException(String.class, obj);
        }
    } else if (ServerConfigurationService.TYPE_INT.equals(type)) {
        if (obj instanceof Integer) {
            string = Integer.toString((Integer) obj);
        } else {
            throw new IllegalClassException(Integer.class, obj);
        }
    } else if (ServerConfigurationService.TYPE_BOOLEAN.equals(type)) {
        if (obj instanceof Boolean) {
            string = Boolean.toString((Boolean) obj);
        } else {
            throw new IllegalClassException(Boolean.class, obj);
        }
    } else if (ServerConfigurationService.TYPE_ARRAY.equals(type)) {
        if (obj instanceof String[]) {
            string = StringUtils.join((String[]) obj, HibernateConfigItem.ARRAY_SEPARATOR);
        } else {
            throw new IllegalClassException("serializeValue() expected an array of type String[]");
        }
    } else {
        throw new IllegalClassException("serializeValue() invalid TYPE, while serializing");
    }

    if (secured) {
        string = textEncryptor.encrypt(string);
    }

    return string;
}

From source file:org.uimafit.factory.ConfigurationParameterFactory.java

/**
 * Sets the specified parameter in the given resource specifier. If the specified is a
 * {@link CustomResourceSpecifier} an exception is thrown if the parameter value not a String.
 * /*from w ww .j  av  a  2  s  .c  o m*/
 * @param aSpec a resource specifier.
 * @param name the parameter name.
 * @param value the parameter value.
 * @throws IllegalClassException if the value is not of a supported type for the given 
 * specifier.
 */
public static void setParameter(ResourceSpecifier aSpec, String name, Object value) {
    if (aSpec instanceof CustomResourceSpecifier) {
        if (!(value instanceof String || value == null)) {
            throw new IllegalClassException(String.class, value);
        }
        CustomResourceSpecifier spec = (CustomResourceSpecifier) aSpec;

        // If the parameter is already there, update it
        boolean found = false;
        for (Parameter p : spec.getParameters()) {
            if (p.getName().equals(name)) {
                p.setValue((String) value);
                found = true;
            }
        }

        // If the parameter is not there, add it
        if (!found) {
            Parameter[] params = new Parameter[spec.getParameters().length + 1];
            System.arraycopy(spec.getParameters(), 0, params, 0, spec.getParameters().length);
            params[params.length - 1] = new Parameter_impl();
            params[params.length - 1].setName(name);
            params[params.length - 1].setValue((String) value);
            spec.setParameters(params);
        }
    } else if (aSpec instanceof ResourceCreationSpecifier) {
        ResourceMetaData md = ((ResourceCreationSpecifier) aSpec).getMetaData();

        if (md.getConfigurationParameterDeclarations().getConfigurationParameter(null, name) == null) {
            throw new IllegalArgumentException("Cannot set undeclared parameter [" + name + "]");
        }

        md.getConfigurationParameterSettings().setParameterValue(name, value);
    } else if (aSpec instanceof ConfigurableDataResourceSpecifier) {
        ResourceMetaData md = ((ConfigurableDataResourceSpecifier) aSpec).getMetaData();

        if (md.getConfigurationParameterDeclarations().getConfigurationParameter(null, name) == null) {
            throw new IllegalArgumentException("Cannot set undeclared parameter [" + name + "]");
        }

        md.getConfigurationParameterSettings().setParameterValue(name, value);
    } else {
        throw new IllegalClassException("Unsupported resource specifier class [" + aSpec.getClass() + "]");
    }
}

From source file:org.vulpe.commons.util.VulpeBeanComparatorUtil.java

/**
 * Compare beans and return map with differences by field.
 * /* ww  w  .j  a  v a  2 s  .  c  o m*/
 * @param bean1
 * @param bean2
 * @return Map with differences by field.
 */
public static Map<String, Object[]> compare(final Object bean1, final Object bean2, boolean skipCollections,
        boolean skipTransient) {
    if (VulpeValidationUtil.isEmpty(bean1, bean2)) {
        throw new NullArgumentException("bean1(" + bean1 + ") bean2(" + bean2 + ")");
    }
    if (VulpeValidationUtil.isNotEmpty(bean1, bean2) && !bean1.getClass().equals(bean2.getClass())) {
        throw new IllegalClassException(bean1.getClass(), bean2.getClass());
    }
    final Class<?> baseClass = bean1 != null ? bean1.getClass() : bean2.getClass();
    final Map<String, Object[]> diffMap = new HashMap<String, Object[]>();
    final List<Field> fields = VulpeReflectUtil.getFields(baseClass);
    for (final Field field : fields) {
        if (VulpeReflectUtil.isAnnotationInField(SkipCompare.class, baseClass, field)
                || (skipCollections && Collection.class.isAssignableFrom(field.getType()))
                || (skipTransient && (Modifier.isTransient(field.getModifiers())
                        || field.isAnnotationPresent(Transient.class)))) {
            continue;
        }
        try {
            Object value1 = VulpeValidationUtil.isNotEmpty(bean1)
                    ? VulpeReflectUtil.getFieldValue(bean1, field.getName())
                    : null;
            Object value2 = VulpeValidationUtil.isNotEmpty(bean2)
                    ? VulpeReflectUtil.getFieldValue(bean2, field.getName())
                    : null;
            if (VulpeValidationUtil.isNull(value1, value2)) {
                continue;
            }
            boolean diff = false;
            if ((VulpeValidationUtil.isEmpty(value1) && VulpeValidationUtil.isNotEmpty(value2))
                    || (VulpeValidationUtil.isNotEmpty(value1) && VulpeValidationUtil.isEmpty(value2))) {
                diff = true;
                if (Date.class.isAssignableFrom(field.getType())) {
                    if (VulpeValidationUtil.isNotEmpty(value1)) {
                        if (value1 instanceof Timestamp) {
                            value1 = VulpeDateUtil.getDate((Date) value1,
                                    VulpeConfigHelper.getDateTimePattern());
                        } else {
                            value1 = VulpeDateUtil.getDate((Date) value1, VulpeConfigHelper.getDatePattern());
                        }
                    }
                    if (VulpeValidationUtil.isNotEmpty(value2)) {
                        if (value2 instanceof Timestamp) {
                            value2 = VulpeDateUtil.getDate((Date) value2,
                                    VulpeConfigHelper.getDateTimePattern());
                        } else {
                            value2 = VulpeDateUtil.getDate((Date) value2, VulpeConfigHelper.getDatePattern());
                        }
                    }
                } else if (VulpeEntity.class.isAssignableFrom(field.getType())) {
                    if (VulpeValidationUtil.isNotEmpty(value1)) {
                        value1 = ((VulpeEntity<?>) value1).getId();
                    }
                    if (VulpeValidationUtil.isNotEmpty(value2)) {
                        value2 = ((VulpeEntity<?>) value2).getId();
                    }
                }
            } else {
                if (Date.class.isAssignableFrom(field.getType())) {
                    if (((Date) value1).getTime() != ((Date) value2).getTime()) {
                        if (value1 instanceof Timestamp || value2 instanceof Timestamp) {
                            value1 = VulpeDateUtil.getDate((Date) value1,
                                    VulpeConfigHelper.getDateTimePattern());
                            value2 = VulpeDateUtil.getDate((Date) value2,
                                    VulpeConfigHelper.getDateTimePattern());
                        } else {
                            value1 = VulpeDateUtil.getDate((Date) value1, VulpeConfigHelper.getDatePattern());
                            value2 = VulpeDateUtil.getDate((Date) value2, VulpeConfigHelper.getDatePattern());
                        }
                        diff = true;
                    }
                } else if (VulpeEntity.class.isAssignableFrom(field.getType())) {
                    if (!((VulpeEntity<?>) value1).getId().equals(((VulpeEntity<?>) value2).getId())) {
                        value1 = ((VulpeEntity<?>) value1).getId();
                        value2 = ((VulpeEntity<?>) value2).getId();
                        diff = true;
                    }
                } else if (!value1.equals(value2)) {
                    diff = true;
                }
            }
            if (diff) {
                diffMap.put(field.getName(), new Object[] { value1, value2 });
            }
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
    }
    return diffMap;
}