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:be.fedict.eid.dss.model.bean.ConfigurationBean.java

/**
 * {@inheritDoc}//ww w .ja  va2  s .c o  m
 */
public void setValue(ConfigProperty configProperty, String index, Object value) {

    String propertyValue;
    if (null != value) {
        Class<?> expectedType = configProperty.getType();
        Class<?> type = value.getClass();
        if (!expectedType.isAssignableFrom(type)) {
            throw new IllegalArgumentException("value has incorrect type: " + type.getClass().getName());
        }
        Object castedValue = expectedType.cast(value);
        if (expectedType.isEnum()) {
            Enum<?> enumValue = (Enum<?>) castedValue;
            propertyValue = enumValue.name();
        } else {
            propertyValue = castedValue.toString();
            if (propertyValue.trim().isEmpty()) {
                propertyValue = null;
            }
        }
    } else {
        propertyValue = null;
    }

    String propertyName = getPropertyName(configProperty, index);
    ConfigPropertyEntity configPropertyEntity = this.entityManager.find(ConfigPropertyEntity.class,
            propertyName);
    if (null == configPropertyEntity) {
        configPropertyEntity = new ConfigPropertyEntity(propertyName, propertyValue);
        this.entityManager.persist(configPropertyEntity);
    } else {
        configPropertyEntity.setValue(propertyValue);
    }
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.util.RepoRepositoryService.java

@Override
public <K extends Resource> K getResource(String uri, Class<K> resourceType) {
    PersistenceService persistenceService = persistenceServices.get(resourceType);
    if (persistenceService == null) {
        if (log.isDebugEnabled()) {
            log.debug("Unknown resource type " + resourceType.getClass().getName() + " requested");
        }//from  w w  w  . ja  va  2  s .  co  m
        return null;
    }

    @SuppressWarnings("unchecked")
    K resource = (K) persistenceService.load(uri, this);
    return resource;
}

From source file:org.dasein.cloud.utils.requester.streamprocessors.JsonStreamToObjectProcessor.java

public @Nullable T read(InputStream inputStream, Class<T> classType) throws StreamReadException {
    try {//from   ww  w  . j  av a  2 s.c  o m
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.readValue(inputStream, classType);
    } catch (Exception ex) {
        throw new StreamReadException("Error deserializing input stream into object", tryGetString(inputStream),
                ((ParameterizedType) classType.getClass().getGenericSuperclass()).getActualTypeArguments()[0]);
    }
}

From source file:org.jadira.scanner.classpath.types.JType.java

@Override
public <A extends java.lang.annotation.Annotation> JAnnotation<A> getAnnotation(Class<A> annotation)
        throws ClasspathAccessException {

    Set<JAnnotation<?>> inspAnnotations = getAnnotations();
    for (JAnnotation<?> next : inspAnnotations) {
        if (next.getName().equals(annotation.getName())
                && (next.getActualAnnotation().annotationType().getClass().equals(annotation.getClass()))) {
            @SuppressWarnings("unchecked")
            JAnnotation<A> retVal = (JAnnotation<A>) next;
            return retVal;
        }/* w ww.  j a  va 2 s  .co  m*/
    }
    return null;
}

From source file:com.chiralbehaviors.CoRE.workspace.WorkspaceAuthorization.java

public static String getWorkspaceAuthorizationColumnName(Class<?> ruleform) {
    StringBuilder builder = new StringBuilder();
    String simpleName = ruleform.getClass().getSimpleName();
    builder.append(Character.toLowerCase(simpleName.charAt(0)));
    int i = 1;//from  w  w  w.jav  a 2  s . c  o  m
    for (char c = simpleName.charAt(i); i < simpleName.length(); i++) {
        if (Character.isUpperCase(c)) {
            builder.append('_');
            builder.append(Character.toLowerCase(c));
        }
    }
    return builder.toString();
}

From source file:org.tinygroup.validate.impl.XmlValidatorManagerImpl.java

private Field getFiled(String fieldName, Class exactlyClazz, Class clazz, boolean includeParentClass) {
    try {/* w  w  w  .  j a v  a  2  s .c o  m*/
        Field field = clazz.getDeclaredField(fieldName);
        return field;
    } catch (Exception e) {
        if (clazz.getSuperclass() == null) {
            throw new RuntimeException("" + exactlyClazz.getClass() + "" + fieldName);
        }
        return getFiled(fieldName, exactlyClazz, clazz.getSuperclass(), true);
    }
}

From source file:org.dasein.cloud.utils.requester.streamprocessors.StreamToStringProcessor.java

@Nullable
@Override/*from  ww  w .  ja  v  a  2s .  c om*/
public String read(InputStream inputStream, Class<String> classType) throws StreamReadException {
    try {
        StringWriter stringWriter = new StringWriter();
        IOUtils.copy(inputStream, stringWriter);
        return stringWriter.toString();
    } catch (IOException ex) {
        throw new StreamReadException("Error deserializing input stream into object", tryGetString(inputStream),
                ((ParameterizedType) classType.getClass().getGenericSuperclass()).getActualTypeArguments()[0]);
    }
}

From source file:org.kuali.kpme.core.service.module.KpmeModuleService.java

@Override
public List<List<String>> listAlternatePrimaryKeyFieldNames(Class businessObjectInterfaceClass) {
    List<List<String>> retList = new ArrayList<List<String>>();
    List<String> keyList = new ArrayList<String>();
    try {//from   w ww . j  a v a2 s.  co m
        keyList.addAll((java.util.List<String>) businessObjectInterfaceClass.getDeclaredField("BUSINESS_KEYS")
                .get(businessObjectInterfaceClass));
    } catch (NoSuchFieldException e) {
        LOG.warn(businessObjectInterfaceClass.getClass().getName() + " does not contain a BUSINESS_KEYS list");
    } catch (IllegalAccessException e) {
        LOG.warn(businessObjectInterfaceClass.getClass().getName() + " does not contain a BUSINESS_KEYS list");
    }

    if (HrBusinessObject.class.isAssignableFrom(businessObjectInterfaceClass)) {
        keyList.add(HrConstants.EFFECTIVE_DATE_FIELD);
    }
    if (CollectionUtils.isNotEmpty(keyList)) {
        retList.add(keyList);
        return retList;
    }
    return super.listAlternatePrimaryKeyFieldNames(businessObjectInterfaceClass);
}

From source file:org.dasein.cloud.utils.requester.streamprocessors.StreamToJSONObjectProcessor.java

@Nullable
@Override//from w ww  .  j  ava2 s . co m
public JSONObject read(InputStream inputStream, Class<JSONObject> classType) throws StreamReadException {
    try {
        StringWriter stringWriter = new StringWriter();
        IOUtils.copy(inputStream, stringWriter);
        return new JSONObject(stringWriter.toString());
    } catch (Exception ex) {
        throw new StreamReadException("Error deserializing input stream into object", tryGetString(inputStream),
                ((ParameterizedType) classType.getClass().getGenericSuperclass()).getActualTypeArguments()[0]);
    }
}

From source file:com.ms.commons.summer.web.handler.DataBinderUtil.java

/**
 * ?//from w  w w. j  a  v  a  2s . co m
 * 
 * @param method
 * @param model
 * @param request
 * @param response
 * @param c
 * @return
 */
@SuppressWarnings("unchecked")
public static Object[] getArgs(Method method, Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response, Class<?> c) {
    Class<?>[] paramTypes = method.getParameterTypes();
    Object[] args = new Object[paramTypes.length];
    Map<String, Object> argMap = new HashMap<String, Object>(args.length);
    Map<String, String> pathValues = null;
    PathPattern pathPattern = method.getAnnotation(PathPattern.class);
    if (pathPattern != null) {
        String path = request.getRequestURI();
        int index = path.lastIndexOf('.');
        if (index != -1) {
            path = path.substring(0, index);
            String[] patterns = pathPattern.patterns();
            pathValues = getPathValues(patterns, path);
        }
    }
    MapBindingResult errors = new MapBindingResult(argMap, "");
    ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
    for (int i = 0; i < paramTypes.length; i++) {
        Class<?> paramType = paramTypes[i];

        MethodParameter methodParam = new MethodParameter(method, i);
        methodParam.initParameterNameDiscovery(parameterNameDiscoverer);
        GenericTypeResolver.resolveParameterType(methodParam, c.getClass());

        String paramName = methodParam.getParameterName();
        // map
        if (Map.class.isAssignableFrom(paramType)) {
            args[i] = model;
        }
        // HttpServletRequest
        else if (HttpServletRequest.class.isAssignableFrom(paramType)) {
            args[i] = request;
        }
        // HttpServletResponse
        else if (HttpServletResponse.class.isAssignableFrom(paramType)) {
            args[i] = response;
        }
        // HttpSession
        else if (HttpSession.class.isAssignableFrom(paramType)) {
            args[i] = request.getSession();
        }
        // Errors
        else if (Errors.class.isAssignableFrom(paramType)) {
            args[i] = errors;
        }
        // MultipartFile
        else if (MultipartFile.class.isAssignableFrom(paramType)) {
            MultipartFile[] files = resolveMultipartFiles(request, errors, paramName);
            if (files != null && files.length > 0) {
                args[i] = files[0];
            }
        }
        // MultipartFile[]
        else if (MultipartFile[].class.isAssignableFrom(paramType)) {
            args[i] = resolveMultipartFiles(request, errors, paramName);
        } else {
            // ??
            if (BeanUtils.isSimpleProperty(paramType)) {
                SimpleTypeConverter converter = new SimpleTypeConverter();
                Object value;
                // ?
                if (paramType.isArray()) {
                    value = request.getParameterValues(paramName);
                } else {
                    Object[] parameterAnnotations = methodParam.getParameterAnnotations();
                    value = null;
                    if (parameterAnnotations != null && parameterAnnotations.length > 0) {
                        if (pathValues != null && pathValues.size() > 0) {
                            for (Object object : parameterAnnotations) {
                                if (PathVariable.class.isInstance(object)) {
                                    PathVariable pv = (PathVariable) object;
                                    if (StringUtils.isEmpty(pv.value())) {
                                        value = pathValues.get(paramName);
                                    } else {
                                        value = pathValues.get(pv.value());
                                    }
                                    break;
                                }
                            }
                        }
                    } else {
                        value = request.getParameter(paramName);
                    }
                }
                try {
                    args[i] = converter.convertIfNecessary(value, paramType, methodParam);
                    model.put(paramName, args[i]);
                } catch (TypeMismatchException e) {
                    errors.addError(new FieldError(paramName, paramName, e.getMessage()));
                }
            } else {
                // ???POJO
                if (paramType.isArray()) {
                    ObjectArrayDataBinder binder = new ObjectArrayDataBinder(paramType.getComponentType(),
                            paramName);
                    args[i] = binder.bind(request);
                    model.put(paramName, args[i]);
                } else {
                    Object bindObject = BeanUtils.instantiateClass(paramType);
                    SummerServletRequestDataBinder binder = new SummerServletRequestDataBinder(bindObject,
                            paramName);
                    binder.bind(request);
                    BindException be = new BindException(binder.getBindingResult());
                    List<FieldError> fieldErrors = be.getFieldErrors();
                    for (FieldError fieldError : fieldErrors) {
                        errors.addError(fieldError);
                    }
                    args[i] = binder.getTarget();
                    model.put(paramName, args[i]);
                }
            }
        }
    }
    return args;
}