Example usage for java.lang Class getSimpleName

List of usage examples for java.lang Class getSimpleName

Introduction

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

Prototype

public String getSimpleName() 

Source Link

Document

Returns the simple name of the underlying class as given in the source code.

Usage

From source file:adalid.core.XS1.java

static boolean checkFieldAnnotation(boolean log, Field field, Class<? extends Annotation> annotation,
        Class<?>[] validTypes) {
    String name = field.getName();
    Class<?> type = field.getDeclaringClass();
    String string;//from  w  ww .  j a v a2  s.  com
    int modifiers = field.getModifiers();
    if (Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers)) {
        string = "field " + name + " has static and/or final modifier";
        if (log) {
            logFieldAnnotationErrorMessage(name, type, annotation, string);
        }
        return false;
    }
    int length = validTypes == null ? 0 : validTypes.length;
    if (length < 1) {
        return true;
    }
    Class<?> ft = getTrueType(field.getType());
    String[] strings = new String[length];
    int i = 0;
    for (Class<?> vt : validTypes) {
        if (vt.isAssignableFrom(ft)) {
            return true;
        }
        strings[i++] = vt.getSimpleName();
    }
    string = "type of " + name + " is not " + StringUtils.join(strings, " or ");
    if (log) {
        logFieldAnnotationErrorMessage(name, type, annotation, string);
    }
    return false;
}

From source file:adalid.core.XS1.java

private static void checkAbstractClassReference(Field declaringField, Class<?> type) {
    if (type.isAnnotationPresent(AbstractClass.class)) {
        String message = "Abstract Class Reference: " + declaringField + "; " + type.getSimpleName()
                + " is annotated with AbstractClass";
        if (type.isAnnotationPresent(InheritanceMapping.class)) {
            InheritanceMapping annotation = type.getAnnotation(InheritanceMapping.class);
            message += " and its inheritance mapping strategy is " + annotation.strategy();
            if (InheritanceMappingStrategy.TABLE_PER_CLASS.equals(annotation.strategy())) {
                TLC.getProject().getParser().error(message);
            }//from  w  w  w  . ja  va  2 s. co m
        }
    }
}

From source file:com.flexive.faces.FxJsfUtils.java

/**
 * Returns the managed beans of the given class. Works only for flexive beans that
 * have the full class name and a "fx" prefix by convention. For example,
 * the ContentEditorBean is registered with JSF as "fxContentEditorBean".
 *
 * @param beanClass the beans class/*from   w w  w .j av  a 2  s  .  com*/
 * @return the managed beans of the given class, or null if none exists
 */
public static <T> T getManagedBean(Class<T> beanClass) {
    return beanClass.cast(getManagedBean("fx" + beanClass.getSimpleName()));
}

From source file:com.feilong.commons.core.lang.ClassUtil.java

/**
 *  class info map for log./*  w ww  .j a v a 2s  .  c om*/
 *
 * @param klass
 *            the clz
 * @return the map for log
 */
public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) {

    Map<String, Object> map = new LinkedHashMap<String, Object>();

    //"clz.getCanonicalName()": "com.feilong.commons.core.date.DatePattern",
    //"clz.getName()": "com.feilong.commons.core.date.DatePattern",
    //"clz.getSimpleName()": "DatePattern",

    // getCanonicalName ( Java Language Specification ??) && getName
    //??class?array?
    // getName[[Ljava.lang.String?getCanonicalName?
    map.put("clz.getCanonicalName()", klass.getCanonicalName());
    map.put("clz.getName()", klass.getName());
    map.put("clz.getSimpleName()", klass.getSimpleName());

    map.put("clz.getComponentType()", klass.getComponentType());
    // ?? voidboolean?byte?char?short?int?long?float  double?
    map.put("clz.isPrimitive()", klass.isPrimitive());

    // ??,
    map.put("clz.isLocalClass()", klass.isLocalClass());
    // ????,??????
    map.put("clz.isMemberClass()", klass.isMemberClass());

    //isSynthetic()?Class????java??false?trueJVM???java??????
    map.put("clz.isSynthetic()", klass.isSynthetic());
    map.put("clz.isArray()", klass.isArray());
    map.put("clz.isAnnotation()", klass.isAnnotation());

    //??true
    map.put("clz.isAnonymousClass()", klass.isAnonymousClass());
    map.put("clz.isEnum()", klass.isEnum());

    return map;
    //      Class<?> klass = this.getClass();
    //
    //      TypeVariable<?>[] typeParameters = klass.getTypeParameters();
    //      TypeVariable<?> typeVariable = typeParameters[0];
    //
    //      Type[] bounds = typeVariable.getBounds();
    //
    //      Type bound = bounds[0];
    //
    //      if (log.isDebugEnabled()){
    //         log.debug("" + (bound instanceof ParameterizedType));
    //      }
    //
    //      Class<T> modelClass = ReflectUtil.getGenericModelClass(klass);
    //      return modelClass;
}

From source file:com.actionbarsherlock.ActionBarSherlock.java

/**
 * Wrap an activity with an action bar abstraction which will enable the
 * use of a custom implementation on platforms where a native version does
 * not exist.//from  www  .j  a va  2s . c  o  m
 *
 * @param activity Owning activity.
 * @param flags Option flags to control behavior.
 * @return Instance to interact with the action bar.
 */
public static ActionBarSherlock wrap(Activity activity, int flags) {
    //Create a local implementation map we can modify
    HashMap<Implementation, Class<? extends ActionBarSherlock>> impls = new HashMap<Implementation, Class<? extends ActionBarSherlock>>(
            IMPLEMENTATIONS);
    boolean hasQualfier;

    /* DPI FILTERING */
    hasQualfier = false;
    for (Implementation key : impls.keySet()) {
        //Only honor TVDPI as a specific qualifier
        if (key.dpi() == DisplayMetrics.DENSITY_TV) {
            hasQualfier = true;
            break;
        }
    }
    if (hasQualfier) {
        final boolean isTvDpi = activity.getResources()
                .getDisplayMetrics().densityDpi == DisplayMetrics.DENSITY_TV;
        for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext();) {
            int keyDpi = keys.next().dpi();
            if ((isTvDpi && keyDpi != DisplayMetrics.DENSITY_TV)
                    || (!isTvDpi && keyDpi == DisplayMetrics.DENSITY_TV)) {
                keys.remove();
            }
        }
    }

    /* API FILTERING */
    hasQualfier = false;
    for (Implementation key : impls.keySet()) {
        if (key.api() != Implementation.DEFAULT_API) {
            hasQualfier = true;
            break;
        }
    }
    if (hasQualfier) {
        final int runtimeApi = Build.VERSION.SDK_INT;
        int bestApi = 0;
        for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext();) {
            int keyApi = keys.next().api();
            if (keyApi > runtimeApi) {
                keys.remove();
            } else if (keyApi > bestApi) {
                bestApi = keyApi;
            }
        }
        for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext();) {
            if (keys.next().api() != bestApi) {
                keys.remove();
            }
        }
    }

    if (impls.size() > 1) {
        throw new IllegalStateException("More than one implementation matches configuration.");
    }
    if (impls.isEmpty()) {
        throw new IllegalStateException("No implementations match configuration.");
    }
    Class<? extends ActionBarSherlock> impl = impls.values().iterator().next();
    if (DEBUG)
        Log.i(TAG, "Using implementation: " + impl.getSimpleName());

    try {
        Constructor<? extends ActionBarSherlock> ctor = impl.getConstructor(CONSTRUCTOR_ARGS);
        return ctor.newInstance(activity, flags);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.actionbarsherlock.ActionBarSherlock.java

/**
 * Register an ActionBarSherlock implementation.
 *
 * @param implementationClass Target implementation class which extends
 * {@link ActionBarSherlock}. This class must also be annotated with
 * {@link Implementation}./*from  w ww  . ja  v  a2 s  . c om*/
 */
public static void registerImplementation(Class<? extends ActionBarSherlock> implementationClass) {
    if (!implementationClass.isAnnotationPresent(Implementation.class)) {
        throw new IllegalArgumentException(
                "Class " + implementationClass.getSimpleName() + " is not annotated with @Implementation");
    } else if (IMPLEMENTATIONS.containsValue(implementationClass)) {
        if (DEBUG)
            Log.w(TAG, "Class " + implementationClass.getSimpleName() + " already registered");
        return;
    }

    Implementation impl = implementationClass.getAnnotation(Implementation.class);
    if (DEBUG)
        Log.i(TAG, "Registering " + implementationClass.getSimpleName() + " with qualifier " + impl);
    IMPLEMENTATIONS.put(impl, implementationClass);
}

From source file:com.evolveum.midpoint.gui.api.util.WebModelServiceUtils.java

public static <T extends ObjectType> List<PrismObject<T>> searchObjects(Class<T> type, ObjectQuery query,
        Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result, PageBase page,
        PrismObject<UserType> principal) {
    LOGGER.debug("Searching {} with oid {}, options {}", new Object[] { type.getSimpleName(), query, options });

    OperationResult subResult;//from  ww w.ja  v  a 2  s.c o m
    if (result != null) {
        subResult = result.createMinorSubresult(OPERATION_SEARCH_OBJECTS);
    } else {
        subResult = new OperationResult(OPERATION_SEARCH_OBJECTS);
    }
    List<PrismObject<T>> objects = new ArrayList<>();
    try {
        Task task = createSimpleTask(subResult.getOperation(), principal, page.getTaskManager());
        List<PrismObject<T>> list = page.getModelService().searchObjects(type, query, options, task, subResult);
        if (list != null) {
            objects.addAll(list);
        }
    } catch (Exception ex) {
        subResult.recordFatalError("WebModelUtils.couldntSearchObjects", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't search objects", ex);
    } finally {
        subResult.computeStatus();
    }

    if (result == null && WebComponentUtil.showResultInPage(subResult)) {
        page.showResult(subResult);
    }

    LOGGER.debug("Loaded ({}) with result {}", new Object[] { objects.size(), subResult });

    return objects;
}

From source file:net.centro.rtb.monitoringcenter.MonitoringCenter.java

/**
 * Retrieves a {@link MetricCollector} with a given namespace. The metric collector's namespace will be constructed
 * from the simple name of the provided class and the optional additional namespaces.
 * <br><br>/*  w  w w  . jav a 2 s  .  c o m*/
 * The additional namespaces will be sanitized as described in {@link MetricNamingUtil#join(String, String...)}.
 * <br><br>
 * This method triggers the MonitoringCenter auto-configuration, if the {@link #configure(MonitoringCenterConfig)}
 * has not been called explicitly.
 *
 * @param clazz class, whose simple name will serve as the main namespace for the metric collector.
 * @param namespaces supplementary namespaces to use for the metric collector.
 * @return a new or cached metric collector with the provided namespace.
 * @throws NullPointerException if <tt>clazz</tt> is <tt>null</tt>.
 */
public static MetricCollector getMetricCollector(final Class<?> clazz, String... namespaces) {
    Preconditions.checkNotNull(clazz, "class cannot be null");
    return getMetricCollector(clazz.getSimpleName(), namespaces);
}

From source file:com.evolveum.midpoint.gui.api.util.WebModelServiceUtils.java

@Nullable
public static <T extends ObjectType> PrismObject<T> loadObject(Class<T> type, String oid,
        Collection<SelectorOptions<GetOperationOptions>> options, boolean allowNotFound, PageBase page,
        Task task, OperationResult result) {
    LOGGER.debug("Loading {} with oid {}, options {}", type.getSimpleName(), oid, options);

    OperationResult subResult;//from ww w .j  av a 2s .  c  om
    if (result != null) {
        subResult = result.createMinorSubresult(OPERATION_LOAD_OBJECT);
    } else {
        subResult = new OperationResult(OPERATION_LOAD_OBJECT);
    }
    PrismObject<T> object = null;
    try {
        if (options == null) {
            options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
        } else {
            GetOperationOptions getOpts = SelectorOptions.findRootOptions(options);
            if (getOpts == null) {
                options.add(new SelectorOptions<>(GetOperationOptions.createResolveNames()));
            } else {
                getOpts.setResolveNames(Boolean.TRUE);
            }
        }
        object = page.getModelService().getObject(type, oid, options, task, subResult);
    } catch (AuthorizationException e) {
        // Not authorized to access the object. This is probably caused by a reference that
        // point to an object that the current user cannot read. This is no big deal.
        // Just do not display that object.
        subResult.recordHandledError(e);
        LOGGER.debug("User {} is not authorized to read {} {}",
                task.getOwner() != null ? task.getOwner().getName() : null, type.getSimpleName(), oid);
        return null;
    } catch (ObjectNotFoundException e) {
        if (allowNotFound) {
            // Object does not exist. It was deleted in the meanwhile, or not created yet. This could happen quite often.
            subResult.recordHandledError(e);
            LOGGER.debug("{} {} does not exist", type.getSimpleName(), oid, e);
            return null;
        } else {
            subResult.recordFatalError("WebModelUtils.couldntLoadObject", e);
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", e);
        }
    } catch (Exception ex) {
        subResult.recordFatalError("WebModelUtils.couldntLoadObject", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
    } finally {
        subResult.computeStatus();
    }
    // TODO reconsider this part: until recently, the condition was always 'false'
    if (WebComponentUtil.showResultInPage(subResult)) {
        page.showResult(subResult);
    }

    LOGGER.debug("Loaded {} with result {}", object, subResult);

    return object;
}

From source file:org.grails.datastore.mapping.query.jpa.JpaQueryBuilder.java

private static PersistentProperty validateProperty(PersistentEntity entity, String name, Class criterionType) {
    if (entity.getIdentity().getName().equals(name))
        return entity.getIdentity();
    PersistentProperty prop = entity.getPropertyByName(name);
    if (prop == null) {
        throw new InvalidDataAccessResourceUsageException("Cannot use [" + criterionType.getSimpleName()
                + "] criterion on non-existent property: " + name);
    }//  ww w  . j a v a2 s.co  m
    return prop;
}