Example usage for java.lang Class isAssignableFrom

List of usage examples for java.lang Class isAssignableFrom

Introduction

In this page you can find the example usage for java.lang Class isAssignableFrom.

Prototype

@HotSpotIntrinsicCandidate
public native boolean isAssignableFrom(Class<?> cls);

Source Link

Document

Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter.

Usage

From source file:org.mashupmedia.validator.EditRemoteLibraryPageValidator.java

@Override
public boolean supports(Class<?> clazz) {
    return clazz.isAssignableFrom(EditRemoteLibraryPage.class);
}

From source file:org.mashupmedia.validator.EditUserPageValidator.java

@Override
public boolean supports(Class<?> clazz) {
    return clazz.isAssignableFrom(EditUserPage.class);
}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Coerces a value to the specified Class that is not covered by any
 * of the above cases/*from  ww  w.j a v  a2  s  .  c om*/
 */
public static Object coerceToObject(Object pValue, Class pClass) throws ElException {
    if (pValue == null) {
        return null;
    } else if (pClass.isAssignableFrom(pValue.getClass())) {
        return pValue;
    } else if (pValue instanceof String) {
        String str = (String) pValue;
        PropertyEditor pe = PropertyEditorManager.findEditor(pClass);
        if (pe == null) {
            if ("".equals(str)) {
                return null;
            } else {
                if (log.isErrorEnabled()) {
                    String message = MessageUtil.getMessageWithArgs(Constants.NO_PROPERTY_EDITOR, str,
                            pClass.getName());
                    log.error(message);
                    throw new ElException(message);
                }
                return null;
            }
        }
        try {
            pe.setAsText(str);
            return pe.getValue();
        } catch (IllegalArgumentException exc) {
            if ("".equals(str)) {
                return null;
            } else {
                if (log.isErrorEnabled()) {
                    String message = MessageUtil.getMessageWithArgs(Constants.PROPERTY_EDITOR_ERROR, pValue,
                            pClass.getName());
                    log.error(message, exc);
                    throw new ElException(message, exc);
                }
                return null;
            }
        }
    } else {
        if (log.isErrorEnabled()) {
            String message = MessageUtil.getMessageWithArgs(Constants.COERCE_TO_OBJECT,
                    pValue.getClass().getName(), pClass.getName());
            log.error(message);
            throw new ElException(message);
        }
        return null;
    }
}

From source file:se.omegapoint.facepalm.client.security.DbAuthenticationProvider.java

@Override
public boolean supports(final Class<?> authentication) {
    return authentication.isAssignableFrom(UsernamePasswordAuthenticationToken.class);
}

From source file:nl.surfnet.coin.teams.service.impl.InvitationFormValidator.java

/**
 * {@inheritDoc}/*from w ww  .  jav a 2s.  com*/
 */
@Override
public boolean supports(Class<?> clazz) {
    return clazz.isAssignableFrom(InvitationForm.class);
}

From source file:com.parse.simple.SimpleParse.java

public synchronized static <T> T load(T from, ParseObject to) {
    for (Map.Entry<SimpleField, SimpleParseColumn> fieldEntry : SimpleParseCache.get()
            .getColumnFields(from.getClass()).entrySet()) {
        final SimpleField field = fieldEntry.getKey();
        final SimpleParseColumn column = fieldEntry.getValue();
        final String columnName = SimpleParseCache.get().getColumnName(field, column);

        if (TextUtils.isEmpty(columnName))
            continue;

        Bundle icicle = SimpleParseCache.get().columnDataCache.get(columnName);
        if (icicle == null) {
            icicle = new Bundle();
            SimpleParseCache.get().columnDataCache.put(columnName, icicle);
        }/*from  ww w  .  ja v a 2  s. c o m*/

        Class<?> fieldType = field.getType();
        field.setAccessible(true);
        try {
            Class<? extends Filter> filterClass = column.filter();
            Filter filter = null;
            if (!OptionalFilter.class.equals(filterClass)) {
                filter = SimpleParseCache.get().getFilter(column.filter());
            }
            boolean filtered = false;
            Object saveValue = null;

            if (!Optional.class.equals(column.loader())) {
                filtered = true;
                saveValue = ((Value) SimpleParseCache.get().getObject(column.loader())).value();
            } else if (NullValue.class.equals(column.loader())) {
                continue;
            } else if (filter != null) {
                Class<?> saveType = filter.getSaveType();
                if (!saveType.equals(fieldType)) {
                    filtered = true;
                    if (column.self() && saveType.isAssignableFrom(ParseObject.class)) {
                        saveValue = (ParseObject) to;
                        saveValue = (ParseObject) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(Byte.class) || saveType.equals(byte.class)) {
                        saveValue = (byte) to.getInt(columnName);
                        saveValue = (byte) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(Short.class) || saveType.equals(short.class)) {
                        saveValue = (short) to.getInt(columnName);
                        saveValue = (short) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(Integer.class) || saveType.equals(int.class)) {
                        saveValue = to.getInt(columnName);
                        saveValue = (int) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(Long.class) || saveType.equals(long.class)) {
                        saveValue = to.getLong(columnName);
                        saveValue = (long) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(Float.class) || saveType.equals(float.class)) {
                        saveValue = (float) to.getDouble(columnName);
                        saveValue = (float) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(Double.class) || saveType.equals(double.class)) {
                        saveValue = to.getDouble(columnName);
                        saveValue = (double) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(Boolean.class) || saveType.equals(boolean.class)) {
                        saveValue = to.getBoolean(columnName);
                        saveValue = (boolean) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(Character.class) || saveType.equals(char.class)) {
                        saveValue = to.getString(columnName);
                        saveValue = (String) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(String.class)) {
                        if (SimpleParseObject.OBJECT_ID.equals(columnName)) {
                            saveValue = to.getObjectId();
                        } else {
                            saveValue = to.getString(columnName);
                        }

                        saveValue = (String) filter.onLoad(saveValue, icicle, from, to);

                        String prefix = column.prefix();
                        Class<?> prefixClass = column.prefixClass();

                        if (!Optional.class.equals(prefixClass)) {
                            prefix = (String) ((Value) SimpleParseCache.get().getObject(prefixClass)).value();
                        }

                        String suffix = column.suffix();
                        Class<?> suffixClass = column.suffixClass();

                        if (!Optional.class.equals(suffixClass)) {
                            suffix = (String) ((Value) SimpleParseCache.get().getObject(suffixClass)).value();
                        }

                        saveValue = prefix + saveValue + suffix;
                    } else if (saveType.equals(Byte[].class) || saveType.equals(byte[].class)) {
                        saveValue = to.getString(columnName);
                        saveValue = (String) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(JSONObject.class)) {
                        saveValue = to.getJSONObject(columnName);
                        saveValue = (JSONObject) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(List.class)) {
                        saveValue = to.getList(columnName);
                        saveValue = (List) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(Date.class)) {
                        saveValue = to.getDate(columnName);
                        saveValue = (Date) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(ParseUser.class)) {
                        saveValue = to.getParseUser(columnName);
                        saveValue = (ParseUser) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(ParseGeoPoint.class)) {
                        saveValue = to.getParseGeoPoint(columnName);
                        saveValue = (ParseGeoPoint) filter.onLoad(saveValue, icicle, from, to);
                    } else if (saveType.equals(ParseObject.class)) {
                        saveValue = to.getParseObject(columnName);
                        saveValue = (ParseObject) filter.onLoad(saveValue, icicle, from, to);
                    }
                }
            }

            if (column.self() && fieldType.isAssignableFrom(ParseObject.class)) {
                ParseObject value = (ParseObject) (filtered ? saveValue : to);

                field.set(from, value);
            } else if (fieldType.equals(Byte.class) || fieldType.equals(byte.class)) {
                byte value = (byte) (filtered ? saveValue : to.getInt(columnName));

                field.setByte(from, value);
            } else if (fieldType.equals(Short.class) || fieldType.equals(short.class)) {
                short value = (short) (filtered ? saveValue : to.getInt(columnName));

                field.setShort(from, value);
            } else if (fieldType.equals(Integer.class) || fieldType.equals(int.class)) {
                int value = (int) (filtered ? saveValue : to.getInt(columnName));

                field.setInt(from, value);
            } else if (fieldType.equals(Long.class) || fieldType.equals(long.class)) {
                long value = (long) (filtered ? saveValue : to.getLong(columnName));

                field.setLong(from, value);
            } else if (fieldType.equals(Float.class) || fieldType.equals(float.class)) {
                float value = (float) (filtered ? saveValue : to.getDouble(columnName));

                field.setFloat(from, value);
            } else if (fieldType.equals(Double.class) || fieldType.equals(double.class)) {
                double value = (double) (filtered ? saveValue : to.getDouble(columnName));

                field.setDouble(from, value);
            } else if (fieldType.equals(Boolean.class) || fieldType.equals(boolean.class)) {
                boolean value = (boolean) (filtered ? saveValue : to.getBoolean(columnName));

                field.setBoolean(from, value);
            } else if (fieldType.equals(Character.class) || fieldType.equals(char.class)) {
                String value = (String) (filtered ? saveValue : to.getString(columnName));

                field.set(from, value);
            } else if (fieldType.equals(String.class)) {
                String value = null;
                if (filtered) {
                    value = (String) saveValue;
                } else {
                    if (SimpleParseObject.OBJECT_ID.equals(columnName)) {
                        value = to.getObjectId();
                    } else {
                        value = to.getString(columnName);
                    }

                    String prefix = column.prefix();
                    Class<?> prefixClass = column.prefixClass();
                    if (!Optional.class.equals(prefixClass)) {
                        prefix = (String) ((Value) SimpleParseCache.get().getObject(prefixClass)).value();
                    }

                    String suffix = column.suffix();
                    Class<?> suffixClass = column.suffixClass();
                    if (!Optional.class.equals(suffixClass)) {
                        suffix = (String) ((Value) SimpleParseCache.get().getObject(suffixClass)).value();
                    }

                    value = prefix + value + suffix;
                }

                field.set(from, value);
            } else if (fieldType.equals(Byte[].class) || fieldType.equals(byte[].class)) {
                String value = (String) (filtered ? saveValue : to.getString(columnName));

                field.set(from, value);
            } else if (fieldType.equals(JSONObject.class)) {
                JSONObject value = (JSONObject) (filtered ? saveValue : to.getJSONObject(columnName));

                field.set(from, value);
            } else if (fieldType.equals(List.class)) {
                List value = (List) (filtered ? saveValue : to.getList(columnName));

                field.set(from, value);
            } else if (fieldType.equals(Date.class)) {
                Date value = (Date) (filtered ? saveValue : to.getDate(columnName));

                field.set(from, value);
            } else if (fieldType.equals(ParseUser.class)) {
                ParseUser value = (ParseUser) (filtered ? saveValue : to.getParseUser(columnName));

                field.set(from, value);
            } else if (fieldType.equals(ParseGeoPoint.class)) {
                ParseGeoPoint value = (ParseGeoPoint) (filtered ? saveValue : to.getParseGeoPoint(columnName));

                field.set(from, value);
            } else if (fieldType.equals(ParseObject.class)) {
                ParseObject value = (ParseObject) (filtered ? saveValue : to.getParseObject(columnName));

                field.set(from, value);
            }
            //else if (ReflectionUtils.isSubclassOf(fieldType, Enum.class)) {
            //to.put(columnName, ((Enum<?>) value).name());
            //}
        } catch (IllegalArgumentException e) {
        } catch (IllegalAccessException e) {
        }
    }
    SimpleParseCache.get().columnDataCache.clear();
    return from;
}

From source file:fr.gael.drb.impl.http.HttpNode.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from   ww  w .j a v  a  2s  .  c  o  m*/
public boolean hasImpl(final Class api) {
    if (api.isAssignableFrom(InputStream.class)) {
        return true;
    }
    return false;
}

From source file:com.speedment.spring.boot.autoconfigure.SpeedmentProperties.java

@Override
public boolean supports(Class<?> clazz) {
    return clazz.isAssignableFrom(SpeedmentProperties.class);
}

From source file:org.ngrinder.security.UserSwitchPermissionVoter.java

@Override
public boolean supports(Class<?> clazz) {
    return clazz.isAssignableFrom(FilterInvocation.class);
}

From source file:org.jnap.core.bean.converter.PersistentEnumConverterFactory.java

@Override
public <T extends Enum> Converter<String, T> getConverter(Class<T> targetType) {
    return targetType.isAssignableFrom(PersistentEnum.class)
            ? (Converter<String, T>) new StringToPersistentEnum((Class<? extends Enum>) targetType)
            : new StringToEnum<T>(targetType);
}