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.xmi.model.XmiProject.java

private void pcx(VelocityContext context, Class clazz) {
    context.put(clazz.getSimpleName(), clazz);
}

From source file:com.logsniffer.web.controller.exception.ResourceNotFoundException.java

public ResourceNotFoundException(final Class<?> resourceType, final Object id) {
    super(resourceType.getSimpleName() + " not found for id: " + id);
    this.resourceType = resourceType;
    this.id = id;
}

From source file:springfox.documentation.spring.web.SpringGroupingStrategy.java

private String getDescription(Class<?> controllerClass) {
    return splitCamelCase(controllerClass.getSimpleName(), " ");
}

From source file:free.yhc.netmbuddy.utils.Utils.java

private static void log(Class<?> cls, LogLV lv, String msg) {
    if (null == msg)
        return;/*from w w  w  . j  ava2s .com*/

    StackTraceElement ste = Thread.currentThread().getStackTrace()[5];
    msg = ste.getClassName() + "/" + ste.getMethodName() + "(" + ste.getLineNumber() + ") : " + msg;

    if (!LOGF) {
        switch (lv) {
        case V:
            Log.v(cls.getSimpleName(), msg);
            break;
        case D:
            Log.d(cls.getSimpleName(), msg);
            break;
        case I:
            Log.i(cls.getSimpleName(), msg);
            break;
        case W:
            Log.w(cls.getSimpleName(), msg);
            break;
        case E:
            Log.e(cls.getSimpleName(), msg);
            break;
        case F:
            Log.wtf(cls.getSimpleName(), msg);
            break;
        }
    } else {
        long timems = System.currentTimeMillis();
        sLogWriter.printf("<%s:%03d> [%s] %s\n", sLogTimeDateFormat.format(new Date(timems)), timems % 1000,
                lv.name(), msg);
        sLogWriter.flush();
    }
}

From source file:edu.usu.sdl.openstorefront.doc.JaxrsProcessor.java

public static APIResourceModel processRestClass(Class resource, String rootPath) {
    APIResourceModel resourceModel = new APIResourceModel();

    resourceModel.setClassName(resource.getName());
    resourceModel.setResourceName(/* ww  w  .  j a v a 2  s .  c o m*/
            String.join(" ", StringUtils.splitByCharacterTypeCamelCase(resource.getSimpleName())));

    APIDescription aPIDescription = (APIDescription) resource.getAnnotation(APIDescription.class);
    if (aPIDescription != null) {
        resourceModel.setResourceDescription(aPIDescription.value());
    }

    Path path = (Path) resource.getAnnotation(Path.class);
    if (path != null) {
        resourceModel.setResourcePath(rootPath + "/" + path.value());
    }

    RequireAdmin requireAdmin = (RequireAdmin) resource.getAnnotation(RequireAdmin.class);
    if (requireAdmin != null) {
        resourceModel.setRequireAdmin(true);
    }

    //class parameters
    mapParameters(resourceModel.getResourceParams(), resource.getDeclaredFields());

    //methods
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    int methodId = 0;
    for (Method method : resource.getDeclaredMethods()) {

        APIMethodModel methodModel = new APIMethodModel();
        methodModel.setId(methodId++);

        //rest method
        List<String> restMethods = new ArrayList<>();
        GET getMethod = (GET) method.getAnnotation(GET.class);
        POST postMethod = (POST) method.getAnnotation(POST.class);
        PUT putMethod = (PUT) method.getAnnotation(PUT.class);
        DELETE deleteMethod = (DELETE) method.getAnnotation(DELETE.class);
        if (getMethod != null) {
            restMethods.add("GET");
        }
        if (postMethod != null) {
            restMethods.add("POST");
        }
        if (putMethod != null) {
            restMethods.add("PUT");
        }
        if (deleteMethod != null) {
            restMethods.add("DELETE");
        }
        methodModel.setRestMethod(String.join(",", restMethods));

        if (restMethods.isEmpty()) {
            //skip non-rest methods
            continue;
        }

        //produces
        Produces produces = (Produces) method.getAnnotation(Produces.class);
        if (produces != null) {
            methodModel.setProducesTypes(String.join(",", produces.value()));
        }

        //consumes
        Consumes consumes = (Consumes) method.getAnnotation(Consumes.class);
        if (consumes != null) {
            methodModel.setConsumesTypes(String.join(",", consumes.value()));
        }

        aPIDescription = (APIDescription) method.getAnnotation(APIDescription.class);
        if (aPIDescription != null) {
            methodModel.setDescription(aPIDescription.value());
        }

        path = (Path) method.getAnnotation(Path.class);
        if (path != null) {
            methodModel.setMethodPath(path.value());
        }

        requireAdmin = (RequireAdmin) method.getAnnotation(RequireAdmin.class);
        if (requireAdmin != null) {
            methodModel.setRequireAdmin(true);
        }

        try {
            if (!(method.getReturnType().getSimpleName().equalsIgnoreCase(Void.class.getSimpleName()))) {
                APIValueModel valueModel = new APIValueModel();
                DataType dataType = (DataType) method.getAnnotation(DataType.class);

                boolean addResponseObject = true;
                if ("javax.ws.rs.core.Response".equals(method.getReturnType().getName()) && dataType == null) {
                    addResponseObject = false;
                }

                if (addResponseObject) {
                    valueModel.setValueObjectName(method.getReturnType().getSimpleName());
                    ReturnType returnType = (ReturnType) method.getAnnotation(ReturnType.class);
                    Class returnTypeClass;
                    if (returnType != null) {
                        returnTypeClass = returnType.value();
                    } else {
                        returnTypeClass = method.getReturnType();
                    }

                    if (!"javax.ws.rs.core.Response".equals(method.getReturnType().getName())) {
                        if (ReflectionUtil.isCollectionClass(method.getReturnType()) == false) {
                            try {
                                valueModel.setValueObject(
                                        objectMapper.writeValueAsString(returnTypeClass.newInstance()));
                                mapValueField(valueModel.getValueFields(),
                                        ReflectionUtil.getAllFields(returnTypeClass).toArray(new Field[0]));
                                mapComplexTypes(valueModel.getAllComplexTypes(),
                                        ReflectionUtil.getAllFields(returnTypeClass).toArray(new Field[0]),
                                        false);

                                aPIDescription = (APIDescription) returnTypeClass
                                        .getAnnotation(APIDescription.class);
                                if (aPIDescription != null) {
                                    valueModel.setValueDescription(aPIDescription.value());
                                }
                            } catch (InstantiationException iex) {
                                log.log(Level.WARNING, MessageFormat.format(
                                        "Unable to instantiated type: {0} make sure the type is not abstract.",
                                        returnTypeClass));
                            }
                        }
                    }

                    if (dataType != null) {
                        String typeName = dataType.value().getSimpleName();
                        if (StringUtils.isNotBlank(dataType.actualClassName())) {
                            typeName = dataType.actualClassName();
                        }
                        valueModel.setTypeObjectName(typeName);
                        try {
                            valueModel.setTypeObject(
                                    objectMapper.writeValueAsString(dataType.value().newInstance()));
                            mapValueField(valueModel.getTypeFields(),
                                    ReflectionUtil.getAllFields(dataType.value()).toArray(new Field[0]));
                            mapComplexTypes(valueModel.getAllComplexTypes(),
                                    ReflectionUtil.getAllFields(dataType.value()).toArray(new Field[0]), false);

                            aPIDescription = (APIDescription) dataType.value()
                                    .getAnnotation(APIDescription.class);
                            if (aPIDescription != null) {
                                valueModel.setTypeDescription(aPIDescription.value());
                            }

                        } catch (InstantiationException iex) {
                            log.log(Level.WARNING, MessageFormat.format(
                                    "Unable to instantiated type: {0} make sure the type is not abstract.",
                                    dataType.value()));
                        }
                    }

                    methodModel.setResponseObject(valueModel);
                }
            }
        } catch (IllegalAccessException | JsonProcessingException ex) {
            log.log(Level.WARNING, null, ex);
        }

        //method parameters
        mapMethodParameters(methodModel.getMethodParams(), method.getParameters());

        //Handle Consumed Objects
        mapConsumedObjects(methodModel, method.getParameters());

        resourceModel.getMethods().add(methodModel);
    }
    Collections.sort(resourceModel.getMethods(), new ApiMethodComparator<>());
    return resourceModel;
}

From source file:org.homiefund.test.config.AbstractDAOTest.java

protected String message(String key, Class clazz) {
    return MessageFormat.format(key, clazz.getSimpleName());
}

From source file:org.hawkular.datamining.api.json.ConceptDriftTypeResolver.java

@Override
public String idFromValueAndType(Object value, Class<?> suggestedType) {
    String simpleName = suggestedType.getSimpleName();

    return simpleName;
}

From source file:org.github.aenygmatic.payroll.usecases.postprocessors.PaymentComponentEnumPostProcessor.java

@Override
protected String generateName(Class<?> interfaceType) {
    String s = PayType.class.getSimpleName() + interfaceType.getSimpleName() + "Proxy";
    return Character.toLowerCase(s.charAt(0)) + s.substring(1);
}

From source file:de.openknowledge.cdi.monitoring.ComponentStatus.java

public ComponentStatus(Class aClazz) {
    this(aClazz.getSimpleName());
}

From source file:com.senacor.core.manager.LocalManagerFactory.java

public <T extends Manager> T getManager(Class<T> clazz) {
    Object bean = applicationContext.getBean(StringUtils.uncapitalize(clazz.getSimpleName()));
    assert bean != null : ManagerError.NO_EXACT_MANAGER_DEFINITION_FOUND.getDescription();
    return (T) bean;
}