Example usage for java.lang Class getClass

List of usage examples for java.lang Class getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:net.sf.morph.reflect.reflectors.BaseReflector.java

/**
 * {@link net.sf.morph.reflect.DecoratedReflector#isReflectable(Class)}
 * @param reflectedType//from   w  w  w . j  a v  a2  s. c  om
 * @param reflectorType
 * @return
 * @throws ReflectionException
 */
public final boolean isReflectable(Class reflectedType, Class reflectorType) throws ReflectionException {
    if (isPerformingLogging() && log.isTraceEnabled()) {
        log.trace("Testing if " + ObjectUtils.getObjectDescription(reflectedType) + " can be reflected with a "
                + ObjectUtils.getObjectDescription(reflectorType));
    }

    if (reflectedType == null) {
        throw new ReflectionException(
                "Cannot determine if a null reflectedType is reflectable; please supply a reflectedType to the "
                        + getClass().getName() + ".isReflectable method");
    }
    if (reflectorType != null && !Reflector.class.isAssignableFrom(reflectorType)) {
        throw new ReflectionException("The reflectorType you specified, "
                + ObjectUtils.getObjectDescription(reflectorType) + ", is invalid.  It must be a child of "
                + ObjectUtils.getObjectDescription(Reflector.class));
    }

    try {
        return reflectorType == null ? isReflectableImpl(reflectedType)
                : isReflectableImpl(reflectedType, reflectorType);
    } catch (ReflectionException e) {
        throw e;
    } catch (Exception e) {
        if (e instanceof RuntimeException && !isWrappingRuntimeExceptions()) {
            throw (RuntimeException) e;
        }
        throw new ReflectionException("Unable to determine if reflectedType '"
                + reflectedType.getClass().getName() + "' is reflectable", e);
    }
}

From source file:org.openamf.io.AMFSerializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) throws IOException {
    Class componentType = array.getClass().getComponentType();

    Object[] result = null;/*w  ww. java 2 s .co  m*/

    if (componentType == null) {
        throw new NullPointerException("componentType is null");
    } else if (componentType == Character.TYPE) {
        char[] carray = (char[]) array;
        result = new Object[carray.length];
        for (int i = 0; i < carray.length; i++) {
            result[i] = new Character(carray[i]);
        }
    } else if (componentType == Byte.TYPE) {
        byte[] barray = (byte[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Byte(barray[i]);
        }
    } else if (componentType == Short.TYPE) {
        short[] sarray = (short[]) array;
        result = new Object[sarray.length];
        for (int i = 0; i < sarray.length; i++) {
            result[i] = new Short(sarray[i]);
        }
    } else if (componentType == Integer.TYPE) {
        int[] iarray = (int[]) array;
        result = new Object[iarray.length];
        for (int i = 0; i < iarray.length; i++) {
            result[i] = new Integer(iarray[i]);
        }
    } else if (componentType == Long.TYPE) {
        long[] larray = (long[]) array;
        result = new Object[larray.length];
        for (int i = 0; i < larray.length; i++) {
            result[i] = new Long(larray[i]);
        }
    } else if (componentType == Double.TYPE) {
        double[] darray = (double[]) array;
        result = new Object[darray.length];
        for (int i = 0; i < darray.length; i++) {
            result[i] = new Double(darray[i]);
        }
    } else if (componentType == Float.TYPE) {
        float[] farray = (float[]) array;
        result = new Object[farray.length];
        for (int i = 0; i < farray.length; i++) {
            result[i] = new Float(farray[i]);
        }
    } else if (componentType == Boolean.TYPE) {
        boolean[] barray = (boolean[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Boolean(barray[i]);
        }
    } else {
        throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName());
    }

    return result;
}

From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) {
    Class<?> componentType = array.getClass().getComponentType();

    Object[] result = null;/*  ww  w .ja  v  a  2  s  .com*/

    if (componentType == null) {
        throw new NullPointerException("componentType is null");
    } else if (componentType == Character.TYPE) {
        char[] carray = (char[]) array;
        result = new Object[carray.length];
        for (int i = 0; i < carray.length; i++) {
            result[i] = new Character(carray[i]);
        }
    } else if (componentType == Byte.TYPE) {
        byte[] barray = (byte[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Byte(barray[i]);
        }
    } else if (componentType == Short.TYPE) {
        short[] sarray = (short[]) array;
        result = new Object[sarray.length];
        for (int i = 0; i < sarray.length; i++) {
            result[i] = new Short(sarray[i]);
        }
    } else if (componentType == Integer.TYPE) {
        int[] iarray = (int[]) array;
        result = new Object[iarray.length];
        for (int i = 0; i < iarray.length; i++) {
            result[i] = Integer.valueOf(iarray[i]);
        }
    } else if (componentType == Long.TYPE) {
        long[] larray = (long[]) array;
        result = new Object[larray.length];
        for (int i = 0; i < larray.length; i++) {
            result[i] = new Long(larray[i]);
        }
    } else if (componentType == Double.TYPE) {
        double[] darray = (double[]) array;
        result = new Object[darray.length];
        for (int i = 0; i < darray.length; i++) {
            result[i] = new Double(darray[i]);
        }
    } else if (componentType == Float.TYPE) {
        float[] farray = (float[]) array;
        result = new Object[farray.length];
        for (int i = 0; i < farray.length; i++) {
            result[i] = new Float(farray[i]);
        }
    } else if (componentType == Boolean.TYPE) {
        boolean[] barray = (boolean[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Boolean(barray[i]);
        }
    } else {
        throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName());
    }

    return result;
}

From source file:org.jbuilt.components.html.raw.base.AbstractCommandComponent.java

public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)
        throws ConverterException {

    String newValue = (String) submittedValue;
    // if we have no local value, try to get the valueExpression.
    ValueExpression valueExpression = component.getValueExpression("value");
    Converter converter = null;//from   ww w.j  a  v  a2 s  .  com

    // If there is a converter attribute, use it to to ask application
    // instance for a converter with this identifer.
    if (component instanceof ValueHolder) {
        converter = ((ValueHolder) component).getConverter();
    }

    if (null == converter && null != valueExpression) {
        Class converterType = valueExpression.getType(context.getELContext());
        // if converterType is null, assume the modelType is "String".
        if (converterType == null || converterType == Object.class) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "No conversion necessary for value {0} of component {1}",
                        new Object[] { submittedValue, component.getId() });
            }
            return newValue;
        }

        // If the converterType is a String, and we don't have a
        // converter-for-class for java.lang.String, assume the type is
        // "String".
        if (converterType == String.class && !hasStringConverter(context)) {
            //              if (logger.isLoggable(Level.FINE)) {
            //                  logger.log(Level.FINE,
            //                             "No conversion necessary for value {0} of component {1}",
            //                             new Object[]{
            //                                   submittedValue,
            //                                   component.getId()});
            //              }
            return newValue;
        }
        // if getType returns a type for which we support a default
        // conversion, acquire an appropriate converter instance.

        try {
            Application application = context.getApplication();
            converter = application.createConverter(converterType);
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "Created converter ({0}) for type {1} for component {2}.",
                        new Object[] { converter.getClass().getName(), converterType.getClass().getName(),
                                component.getId() });
            }
        } catch (Exception e) {
            //              if (logger.isLoggable(Level.SEVERE)) {
            //                  logger.log(Level.SEVERE,
            //                             "Could not instantiate converter for type {0}: {1}",
            //                             new Object[] {
            //                                   converterType,
            //                                   e.toString() });
            //              }
            return null;
        }
    } else if (converter == null) {
        // if there is no valueExpression and converter attribute set,
        // assume the modelType as "String" since we have no way of
        // figuring out the type. So for the selectOne and
        // selectMany, converter has to be set if there is no
        // valueExpression attribute set on the component.
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "No conversion necessary for value {0} of component {1}",
                    new Object[] { submittedValue, component.getId() });
            logger.fine(" since there is no explicitly registered converter "
                    + "and the component value is not bound to a model property");
        }
        return newValue;
    }

    if (converter != null) {
        // If the conversion eventually falls to needing to use EL type coercion,
        // make sure our special ConverterPropertyEditor knows about this value.
        RequestStateManager.set(context, RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME, component);
        return converter.getAsObject(context, component, newValue);
    } else {
        // throw converter exception.
        Object[] params = { newValue, "null Converter" };

        throw new ConverterException(
                MessageFactory.getMessage(context, MessageUtils.CONVERSION_ERROR_MESSAGE_ID, params));
    }

}

From source file:org.bibsonomy.database.DBLogic.java

@Override
public Map<String, List<String>> getExtendedFields(final Class<? extends Resource> resourceType,
        final String userName, final String intraHash, final String key) {
    final DBSession session = this.openSession();

    try {/*from ww  w  . j  a v  a2s  .c  o  m*/
        if (BibTex.class == resourceType) {
            return this.publicationDBManager.getExtendedFields(userName, intraHash, key, session);
        }

        throw new UnsupportedResourceTypeException(
                "The requested resourcetype (" + resourceType.getClass().getName() + ") is not supported.");
    } finally {
        session.close();
    }
}

From source file:org.bibsonomy.database.DBLogic.java

@Override
public void createExtendedField(final Class<? extends Resource> resourceType, final String userName,
        final String intraHash, final String key, final String value) {
    final DBSession session = openSession();

    try {/*from   w  w  w . j ava 2s  .  c om*/
        if (BibTex.class == resourceType) {
            this.publicationDBManager.createExtendedField(userName, intraHash, key, value, session);
        } else {
            throw new UnsupportedResourceTypeException(
                    "The requested resourcetype (" + resourceType.getClass().getName() + ") is not supported.");
        }
    } finally {
        session.close();
    }
}

From source file:org.jbuilt.components.html.raw.base.AbstractInputComponent.java

public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)
        throws ConverterException {
    component = this;

    String newValue = (String) submittedValue;
    // if we have no local value, try to get the valueExpression.
    ValueExpression valueExpression = component.getValueExpression("value");
    Converter converter = null;/*  ww  w  .j av  a2  s  .c  o  m*/

    // If there is a converter attribute, use it to to ask application
    // instance for a converter with this identifer.
    if (component instanceof ValueHolder) {
        converter = ((ValueHolder) component).getConverter();
    }

    if (null == converter && null != valueExpression) {
        Class converterType = valueExpression.getType(context.getELContext());
        // if converterType is null, assume the modelType is "String".
        if (converterType == null || converterType == Object.class) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "No conversion necessary for value {0} of component {1}",
                        new Object[] { submittedValue, component.getId() });
            }
            return newValue;
        }

        // If the converterType is a String, and we don't have a
        // converter-for-class for java.lang.String, assume the type is
        // "String".
        if (converterType == String.class && !hasStringConverter(context)) {
            //              if (logger.isLoggable(Level.FINE)) {
            //                  logger.log(Level.FINE,
            //                             "No conversion necessary for value {0} of component {1}",
            //                             new Object[]{
            //                                   submittedValue,
            //                                   component.getId()});
            //              }
            return newValue;
        }
        // if getType returns a type for which we support a default
        // conversion, acquire an appropriate converter instance.

        try {
            Application application = context.getApplication();
            converter = application.createConverter(converterType);
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "Created converter ({0}) for type {1} for component {2}.",
                        new Object[] { converter.getClass().getName(), converterType.getClass().getName(),
                                component.getId() });
            }
        } catch (Exception e) {
            //              if (logger.isLoggable(Level.SEVERE)) {
            //                  logger.log(Level.SEVERE,
            //                             "Could not instantiate converter for type {0}: {1}",
            //                             new Object[] {
            //                                   converterType,
            //                                   e.toString() });
            //              }
            return null;
        }
    } else if (converter == null) {
        // if there is no valueExpression and converter attribute set,
        // assume the modelType as "String" since we have no way of
        // figuring out the type. So for the selectOne and
        // selectMany, converter has to be set if there is no
        // valueExpression attribute set on the component.
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "No conversion necessary for value {0} of component {1}",
                    new Object[] { submittedValue, component.getId() });
            logger.fine(" since there is no explicitly registered converter "
                    + "and the component value is not bound to a model property");
        }
        return newValue;
    }

    if (converter != null) {
        // If the conversion eventually falls to needing to use EL type coercion,
        // make sure our special ConverterPropertyEditor knows about this value.
        RequestStateManager.set(context, RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME, component);
        return converter.getAsObject(context, component, newValue);
    } else {
        // throw converter exception.
        Object[] params = { newValue, "null Converter" };

        throw new ConverterException(
                MessageFactory.getMessage(context, MessageUtils.CONVERSION_ERROR_MESSAGE_ID, params));
    }

}

From source file:org.bibsonomy.database.DBLogic.java

@Override
public void deleteExtendedField(final Class<? extends Resource> resourceType, final String userName,
        final String intraHash, final String key, final String value) {
    final DBSession session = this.openSession();

    try {/* w  ww. j  a  v  a  2s  .  com*/
        if (BibTex.class == resourceType) {
            if (!present(key)) {
                this.publicationDBManager.deleteAllExtendedFieldsData(userName, intraHash, session);
            } else {
                if (!present(value)) {
                    this.publicationDBManager.deleteExtendedFieldsByKey(userName, intraHash, key, session);
                } else {
                    this.publicationDBManager.deleteExtendedFieldByKeyValue(userName, intraHash, key, value,
                            session);
                }
            }
        } else {
            throw new UnsupportedResourceTypeException(
                    "The requested resourcetype (" + resourceType.getClass().getName() + ") is not supported.");
        }
    } finally {
        session.close();
    }
}

From source file:org.bibsonomy.database.DBLogic.java

@Override
public int getPostStatistics(final Class<? extends Resource> resourceType, final GroupingEntity grouping,
        final String groupingName, final List<String> tags, final String hash, final Order order,
        final FilterEntity filter, final int start, final int end, final String search,
        final StatisticsConstraint constraint) {
    final DBSession session = openSession();

    try {// ww  w  .  jav a2  s .c om
        if (this.permissionDBManager.checkFilterPermissions(filter, this.loginUser)) {
            loginUser.addGroup(new Group(GroupID.PUBLIC_SPAM));
        }

        final StatisticsParam param = LogicInterfaceHelper.buildParam(StatisticsParam.class, grouping,
                groupingName, tags, hash, order, start, end, search, filter, this.loginUser);

        if (resourceType == GoldStandardPublication.class || resourceType == BibTex.class
                || resourceType == Bookmark.class || resourceType == Resource.class) {
            param.setContentTypeByClass(resourceType);
            return this.statisticsDBManager.getPostStatistics(param, session);
        }

        throw new UnsupportedResourceTypeException(
                "The requested resourcetype (" + resourceType.getClass().getName() + ") is not supported.");
    } catch (final QueryTimeoutException ex) {
        // if a query times out, we return 0 (cause we also retun empty list when a query timeout exception is thrown)
        return 0;
    } finally {
        session.close();
    }
}

From source file:org.bibsonomy.database.DBLogic.java

@Override
public List<Tag> getTags(final Class<? extends Resource> resourceType, final GroupingEntity grouping,
        final String groupingName, final String regex, final List<String> tags, final String hash,
        final Order order, final int start, final int end, final String search, final TagSimilarity relation) {
    if (GroupingEntity.ALL.equals(grouping)) {
        this.permissionDBManager.checkStartEnd(loginUser, start, end, "Tag");
    }//from   www. java2s .  c  o m

    final DBSession session = this.openSession();
    try {
        final TagParam param = LogicInterfaceHelper.buildParam(TagParam.class, grouping, groupingName, tags,
                hash, order, start, end, search, null, this.loginUser);
        param.setTagRelationType(relation);

        if (resourceType == BibTex.class || resourceType == Bookmark.class || resourceType == Resource.class) {
            // this is save because of RTTI-check of resourceType argument
            // which is of class T
            param.setRegex(regex);
            // need to switch from class to string to ensure legibility of
            // Tags.xml
            param.setContentTypeByClass(resourceType);
            return this.tagDBManager.getTags(param, session);
        }

        throw new UnsupportedResourceTypeException(
                "The requested resourcetype (" + resourceType.getClass().getName() + ") is not supported.");
    } catch (final QueryTimeoutException ex) {
        // if a query times out, we return an empty list
        return new ArrayList<Tag>();
    } finally {
        session.close();
    }
}