Example usage for java.lang.reflect Type equals

List of usage examples for java.lang.reflect Type equals

Introduction

In this page you can find the example usage for java.lang.reflect Type equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:org.brutusin.rpc.websocket.WebsocketEndpoint.java

/**
 *
 * @param request/*  w  w  w  . j  a va2 s  .c  om*/
 * @return
 */
private Object execute(RpcRequest request, RpcSpringContext rpcCtx) throws Exception {
    if (!"2.0".equals(request.getJsonrpc())) {
        throw new InvalidRequestException("Only jsonrpc 2.0 supported");
    }
    String serviceId = request.getMethod();
    Map<String, WebsocketAction> services = rpcCtx.getWebSocketServices();
    if (serviceId == null || !services.containsKey(serviceId)) {
        throw new ServiceNotFoundException();
    }
    WebsocketAction service = services.get(serviceId);
    Object input;
    if (request.getParams() == null) {
        input = null;
    } else {
        Type inputType = service.getInputType();
        JsonSchema inputSchema = JsonCodec.getInstance().getSchema(inputType);
        inputSchema.validate(request.getParams());
        if (inputType.equals(Object.class)) {
            input = request.getParams();
        } else {
            input = JsonCodec.getInstance().load(request.getParams(), Miscellaneous.getClass(inputType));
        }
    }
    return service.execute(input);
}

From source file:org.evosuite.testcase.fm.MethodDescriptor.java

public Object executeMatcher(int i) throws IllegalArgumentException {
    if (i < 0 || i >= getNumberOfInputParameters()) {
        throw new IllegalArgumentException("Invalid index: " + i);
    }/*from   ww  w .ja  v a  2 s  .  c o  m*/

    Type[] types = method.getParameterTypes();
    Type type = types[i];

    try {
        if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
            return Mockito.anyInt();
        } else if (type.equals(Long.TYPE) || type.equals(Long.class)) {
            return Mockito.anyLong();
        } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
            return Mockito.anyBoolean();
        } else if (type.equals(Double.TYPE) || type.equals(Double.class)) {
            return Mockito.anyDouble();
        } else if (type.equals(Float.TYPE) || type.equals(Float.class)) {
            return Mockito.anyFloat();
        } else if (type.equals(Short.TYPE) || type.equals(Short.class)) {
            return Mockito.anyShort();
        } else if (type.equals(Character.TYPE) || type.equals(Character.class)) {
            return Mockito.anyChar();
        } else if (type.equals(String.class)) {
            return Mockito.anyString();
        } else {
            return Mockito.any(type.getClass());
        }
    } catch (Exception e) {
        logger.error("Failed to executed Mockito matcher n{} of type {} in {}.{}: {}", i, type, className,
                methodName, e.getMessage());
        throw new EvosuiteError(e);
    }
}

From source file:org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.java

private Type determineInferredType(Method method) {
    if (method == null) {
        return null;
    }/*from  ww w.ja  v  a 2s.c  om*/

    Type genericParameterType = null;
    boolean hasAck = false;

    for (int i = 0; i < method.getParameterTypes().length; i++) {
        MethodParameter methodParameter = new MethodParameter(method, i);
        /*
         * We're looking for a single non-annotated parameter, or one annotated with @Payload.
         * We ignore parameters with type Message because they are not involved with conversion.
         */
        if (eligibleParameter(methodParameter) && (methodParameter.getParameterAnnotations().length == 0
                || methodParameter.hasParameterAnnotation(Payload.class))) {
            if (genericParameterType == null) {
                genericParameterType = methodParameter.getGenericParameterType();
                if (genericParameterType instanceof ParameterizedType) {
                    ParameterizedType parameterizedType = (ParameterizedType) genericParameterType;
                    if (parameterizedType.getRawType().equals(Message.class)) {
                        genericParameterType = ((ParameterizedType) genericParameterType)
                                .getActualTypeArguments()[0];
                    } else if (parameterizedType.getRawType().equals(List.class)
                            && parameterizedType.getActualTypeArguments().length == 1) {
                        Type paramType = parameterizedType.getActualTypeArguments()[0];
                        this.isConsumerRecordList = paramType.equals(ConsumerRecord.class)
                                || (paramType instanceof ParameterizedType && ((ParameterizedType) paramType)
                                        .getRawType().equals(ConsumerRecord.class));
                        this.isMessageList = paramType.equals(Message.class)
                                || (paramType instanceof ParameterizedType
                                        && ((ParameterizedType) paramType).getRawType().equals(Message.class));
                    }
                }
            } else {
                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("Ambiguous parameters for target payload for method " + method
                            + "; no inferred type available");
                }
                break;
            }
        } else if (methodParameter.getGenericParameterType().equals(Acknowledgment.class)) {
            hasAck = true;
        }
    }
    Assert.state(
            !this.isConsumerRecordList || method.getParameterTypes().length == 1
                    || (method.getGenericParameterTypes().length == 2 && hasAck),
            "A parameter of type 'List<ConsumerRecord>' must be the only parameter "
                    + "(except for an optional 'Acknowledgment')");
    Assert.state(
            !this.isMessageList || method.getParameterTypes().length == 1
                    || (method.getGenericParameterTypes().length == 2 && hasAck),
            "A parameter of type 'List<Message<?>>' must be the only parameter "
                    + "(except for an optional 'Acknowledgment')");

    return genericParameterType;
}

From source file:dstrelec.nats.listener.adapter.MessagingMessageListenerAdapter.java

/**
 * Subclasses can override this method to use a different mechanism to determine
 * the target type of the payload conversion.
 * @param method the method.//from ww w.jav a 2  s .  c  om
 * @return the type.
 */
protected Type determineInferredType(Method method) {
    if (method == null) {
        return null;
    }

    Type genericParameterType = null;

    for (int i = 0; i < method.getParameterTypes().length; i++) {
        MethodParameter methodParameter = new MethodParameter(method, i);
        /*
         * We're looking for a single non-annotated parameter, or one annotated with @Payload.
         * We ignore parameters with type Message because they are not involved with conversion.
         */
        if (eligibleParameter(methodParameter) && (methodParameter.getParameterAnnotations().length == 0
                || methodParameter.hasParameterAnnotation(Payload.class))) {
            if (genericParameterType == null) {
                genericParameterType = methodParameter.getGenericParameterType();
                if (genericParameterType instanceof ParameterizedType) {
                    ParameterizedType parameterizedType = (ParameterizedType) genericParameterType;
                    if (parameterizedType.getRawType().equals(Message.class)) {
                        genericParameterType = ((ParameterizedType) genericParameterType)
                                .getActualTypeArguments()[0];
                    } else if (parameterizedType.getRawType().equals(List.class)
                            && parameterizedType.getActualTypeArguments().length == 1) {
                        Type paramType = parameterizedType.getActualTypeArguments()[0];
                        this.isConsumerRecordList = paramType.equals(io.nats.client.Message.class)
                                || (paramType instanceof ParameterizedType && ((ParameterizedType) paramType)
                                        .getRawType().equals(io.nats.client.Message.class));
                        this.isMessageList = paramType.equals(Message.class)
                                || (paramType instanceof ParameterizedType
                                        && ((ParameterizedType) paramType).getRawType().equals(Message.class));
                    }
                }
            } else {
                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("Ambiguous parameters for target payload for method " + method
                            + "; no inferred type available");
                }
                break;
            }
        }
    }
    Assert.state(!this.isConsumerRecordList || method.getParameterTypes().length == 1,
            "A parameter of type 'List<ConsumerRecord>' must be the only parameter");
    Assert.state(!this.isMessageList || method.getParameterTypes().length == 1,
            "A parameter of type 'List<Message<?>>' must be the only parameter");

    return genericParameterType;
}

From source file:io.mandrel.common.schema.SchemaTest.java

public void inspect(int level, Type clazz, String name) {

    if (level > 6)
        return;/* w w w.  j  a v a 2s.c  o m*/
    if (clazz instanceof Class && clazz.equals(LinkFilter.class))
        return;

    if (clazz instanceof Class && !((Class<?>) clazz).isEnum() && ((Class<?>) clazz).getPackage() != null
            && ((Class<?>) clazz).getPackage().getName().startsWith("io.mandrel")) {
        int newLevel = level + 1;

        List<Field> fields = new ArrayList<Field>();
        Class<?> i = ((Class<?>) clazz);
        while (i != null && i != Object.class) {
            fields.addAll(Arrays.asList(i.getDeclaredFields()));
            i = i.getSuperclass();
        }

        for (Field field : fields) {
            Class<?> fieldType = field.getType();
            String text;
            if (!field.isAnnotationPresent(JsonIgnore.class) && !Modifier.isStatic(field.getModifiers())) {
                if (List.class.equals(fieldType) || Map.class.equals(fieldType)) {
                    Type type = field.getGenericType();
                    if (type instanceof ParameterizedType) {
                        ParameterizedType pType = (ParameterizedType) type;
                        for (Type paramType : pType.getActualTypeArguments()) {
                            if (paramType instanceof Class
                                    && NamedDefinition.class.isAssignableFrom((Class) paramType)) {
                                text = field.getName() + "(container of " + paramType + " oneOf)";
                                System.err.println(
                                        StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                                Class<? extends NamedDefinition> nd = (Class<? extends NamedDefinition>) field
                                        .getType();
                                Map<String, ? extends NamedDefinition> map = NamedProviders.get(nd);
                                map.forEach((k, v) -> {
                                    String text2 = k;
                                    System.err.println(StringUtils.leftPad(text2, text2.length() + newLevel * 5,
                                            "\t-   "));
                                    inspect(newLevel, v.getClass(), field.getName());
                                });
                            } else if (paramType instanceof ParameterizedType && NamedDefinition.class
                                    .isAssignableFrom((Class) ((ParameterizedType) paramType).getRawType())) {
                                text = field.getName() + "(container of " + paramType + " oneOf2)";
                                System.err.println(
                                        StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                                Class<? extends NamedDefinition> nd = (Class<? extends NamedDefinition>) ((ParameterizedType) paramType)
                                        .getRawType();
                                Map<String, ? extends NamedDefinition> map = NamedProviders.get(nd);
                                map.forEach((k, v) -> {
                                    String text2 = k;
                                    System.err.println(StringUtils.leftPad(text2, text2.length() + newLevel * 5,
                                            "\t-   "));
                                    inspect(newLevel, v.getClass(), field.getName());
                                });
                            } else if (paramType instanceof WildcardType) {
                                for (Type wildType : ((WildcardType) paramType).getUpperBounds()) {
                                    if (wildType instanceof Class
                                            && NamedDefinition.class.isAssignableFrom((Class) wildType)) {
                                        text = field.getName() + "(container of " + wildType + " oneOf)";
                                        System.err.println(StringUtils.leftPad(text,
                                                text.length() + newLevel * 5, "\t-   "));
                                        Class<? extends NamedDefinition> nd = (Class<? extends NamedDefinition>) field
                                                .getType();
                                        Map<String, ? extends NamedDefinition> map = NamedProviders.get(nd);
                                        map.forEach((k, v) -> {
                                            String text2 = k;
                                            System.err.println(StringUtils.leftPad(text2,
                                                    text2.length() + newLevel * 5, "\t-   "));
                                            inspect(newLevel, v.getClass(), field.getName());
                                        });
                                    } else if (wildType instanceof ParameterizedType
                                            && NamedDefinition.class.isAssignableFrom(
                                                    (Class) ((ParameterizedType) wildType).getRawType())) {
                                        text = field.getName() + "(container of " + wildType + " oneOf2)";
                                        System.err.println(StringUtils.leftPad(text,
                                                text.length() + newLevel * 5, "\t-   "));
                                        Class<? extends NamedDefinition> nd = (Class<? extends NamedDefinition>) ((ParameterizedType) wildType)
                                                .getRawType();
                                        Map<String, ? extends NamedDefinition> map = NamedProviders.get(nd);
                                        map.forEach((k, v) -> {
                                            String text2 = k;
                                            System.err.println(StringUtils.leftPad(text2,
                                                    text2.length() + newLevel * 5, "\t-   "));
                                            inspect(newLevel, v.getClass(), field.getName());
                                        });
                                    }
                                }
                            } else {
                                text = field.getName() + "(container of " + paramType + ")";
                                System.err.println(
                                        StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                                inspect(newLevel, paramType, "");
                            }
                        }
                    }
                } else {
                    if (NamedDefinition.class.isAssignableFrom(field.getType())) {
                        text = field.getName() + " oneOf";
                        System.err.println(StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                        Class<? extends NamedDefinition> nd = (Class<? extends NamedDefinition>) field
                                .getType();
                        Map<String, ? extends NamedDefinition> map = NamedProviders.get(nd);
                        map.forEach((k, v) -> {
                            String text2 = k;
                            System.err.println(
                                    StringUtils.leftPad(text2, text2.length() + newLevel * 5, "\t-   "));
                            inspect(newLevel, v.getClass(), field.getName());
                        });
                    } else {
                        text = field.getName()
                                + (field.getType().isPrimitive() || field.getType().equals(String.class)
                                        || field.getType().equals(LocalDateTime.class)
                                                ? " (" + field.getType().getName() + ")"
                                                : "");
                        System.err.println(StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                        inspect(newLevel, fieldType, field.getName());
                    }
                }

                // JsonSubTypes subtype =
                // fieldType.getAnnotation(JsonSubTypes.class);
                // if (subtype != null) {
                // int subLevel = level + 2;
                // text = "subtypes:";
                // System.err.println(StringUtils.leftPad(text,
                // text.length() + subLevel * 5, "\t-   "));
                // for (JsonSubTypes.Type type : subtype.value()) {
                // text = "subtype:" + type.name();
                // System.err.println(StringUtils.leftPad(text,
                // text.length() + (subLevel + 1) * 5, "\t-   "));
                // inspect((subLevel + 1), type.value(), type.name());
                // }
                // }
            }
        }

        JsonSubTypes subtype = ((Class<?>) clazz).getAnnotation(JsonSubTypes.class);
        if (subtype != null) {
            int subLevel = level + 1;
            String text = "subtypes:";
            System.err.println(StringUtils.leftPad(text, text.length() + subLevel * 5, "\t-   "));
            for (JsonSubTypes.Type type : subtype.value()) {
                text = "subtype:" + type.name();
                System.err.println(StringUtils.leftPad(text, text.length() + (subLevel + 1) * 5, "\t-   "));
                inspect((subLevel + 1), type.value(), type.name());
            }
        }
    }
}

From source file:org.apache.hadoop.yarn.api.TestPBImplRecords.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static Object genTypeValue(Type type) {
    Object ret = typeValueCache.get(type);
    if (ret != null) {
        return ret;
    }//from   w  ww  . ja  va 2 s  .  c  o m
    // only use positive primitive values
    if (type.equals(boolean.class)) {
        return rand.nextBoolean();
    } else if (type.equals(byte.class)) {
        return bytes[rand.nextInt(4)];
    } else if (type.equals(int.class)) {
        return rand.nextInt(1000000);
    } else if (type.equals(long.class)) {
        return Long.valueOf(rand.nextInt(1000000));
    } else if (type.equals(float.class)) {
        return rand.nextFloat();
    } else if (type.equals(double.class)) {
        return rand.nextDouble();
    } else if (type.equals(String.class)) {
        return String.format("%c%c%c", 'a' + rand.nextInt(26), 'a' + rand.nextInt(26), 'a' + rand.nextInt(26));
    } else if (type instanceof Class) {
        Class clazz = (Class) type;
        if (clazz.isArray()) {
            Class compClass = clazz.getComponentType();
            if (compClass != null) {
                ret = Array.newInstance(compClass, 2);
                Array.set(ret, 0, genTypeValue(compClass));
                Array.set(ret, 1, genTypeValue(compClass));
            }
        } else if (clazz.isEnum()) {
            Object[] values = clazz.getEnumConstants();
            ret = values[rand.nextInt(values.length)];
        } else if (clazz.equals(ByteBuffer.class)) {
            // return new ByteBuffer every time
            // to prevent potential side effects
            ByteBuffer buff = ByteBuffer.allocate(4);
            rand.nextBytes(buff.array());
            return buff;
        }
    } else if (type instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) type;
        Type rawType = pt.getRawType();
        Type[] params = pt.getActualTypeArguments();
        // only support EnumSet<T>, List<T>, Set<T>, Map<K,V>
        if (rawType.equals(EnumSet.class)) {
            if (params[0] instanceof Class) {
                Class c = (Class) (params[0]);
                return EnumSet.allOf(c);
            }
        }
        if (rawType.equals(List.class)) {
            ret = Lists.newArrayList(genTypeValue(params[0]));
        } else if (rawType.equals(Set.class)) {
            ret = Sets.newHashSet(genTypeValue(params[0]));
        } else if (rawType.equals(Map.class)) {
            Map<Object, Object> map = Maps.newHashMap();
            map.put(genTypeValue(params[0]), genTypeValue(params[1]));
            ret = map;
        }
    }
    if (ret == null) {
        throw new IllegalArgumentException("type " + type + " is not supported");
    }
    typeValueCache.put(type, ret);
    return ret;
}

From source file:org.jspare.forvertx.web.handler.DefaultHandler.java

/**
 * Resolve parameter./*  w  w w . j av  a2  s  .co m*/
 *
 * @param parameter
 *            the parameter
 * @param routingContext
 *            the routing context
 * @return the object
 */
@SuppressWarnings("unchecked")
protected Object resolveParameter(Parameter parameter, RoutingContext routingContext) {

    if (parameter.getType().equals(RoutingContext.class)) {

        return routingContext;
    }
    if (parameter.getType().equals(HttpServerRequest.class)) {

        return routingContext.request();
    }

    if (parameter.getType().equals(HttpServerResponse.class)) {

        return routingContext.response();
    }
    if (StringUtils.isNotEmpty(routingContext.request().getParam(parameter.getName()))) {

        return routingContext.request().getParam(parameter.getName());
    }

    if (parameter.isAnnotationPresent(ArrayModel.class)) {

        ArrayModel am = parameter.getAnnotation(ArrayModel.class);
        Class<? extends Collection<?>> collection = (Class<? extends Collection<?>>) am.collectionClass();
        Class<?> clazz = am.value();
        return ArrayModelParser.toList(routingContext.getBody().toString(), collection, clazz);
    }

    if (parameter.isAnnotationPresent(MapModel.class)) {

        MapModel mm = parameter.getAnnotation(MapModel.class);
        Class<?> mapClazz = mm.mapClass();
        Class<?> key = mm.key();
        Class<?> value = mm.value();
        return MapModelParser.toMap(routingContext.getBody().toString(), mapClazz, key, value);
    }

    if (parameter.getType().getPackage().getName().endsWith(".model")
            || parameter.getType().isAnnotationPresent(Model.class)
            || parameter.isAnnotationPresent(Model.class)) {

        try {
            if (routingContext.getBody() == null) {

                return null;
            }
            return my(Json.class).fromJSON(routingContext.getBody().toString(), parameter.getType());
        } catch (SerializationException e) {

            log.debug("Invalid content of body for class [{}] on parameter [{}]", parameter.getClass(),
                    parameter.getName());
            return null;
        }
    }
    if (parameter.isAnnotationPresent(org.jspare.forvertx.web.mapping.handling.Parameter.class)) {

        String parameterName = parameter.getAnnotation(org.jspare.forvertx.web.mapping.handling.Parameter.class)
                .value();
        // Test types
        Type typeOfParameter = parameter.getType();
        if (typeOfParameter.equals(Integer.class)) {
            return Integer.parseInt(routingContext.request().getParam(parameterName));
        }
        if (typeOfParameter.equals(Double.class)) {
            return Double.parseDouble(routingContext.request().getParam(parameterName));
        }
        if (typeOfParameter.equals(Long.class)) {
            return Long.parseLong(routingContext.request().getParam(parameterName));
        }
        return routingContext.request().getParam(parameterName);
    }
    if (parameter.isAnnotationPresent(org.jspare.forvertx.web.mapping.handling.Header.class)) {

        String headerName = parameter.getAnnotation(org.jspare.forvertx.web.mapping.handling.Header.class)
                .value();
        return routingContext.request().getHeader(headerName);
    }

    return null;
}

From source file:org.evosuite.testcase.fm.MethodDescriptor.java

private String initMatchers(GenericMethod method, GenericClass retvalType) {

    String matchers = "";
    Type[] types = method.getParameterTypes();
    List<GenericClass> parameterClasses = method.getParameterClasses();
    for (int i = 0; i < types.length; i++) {
        if (i > 0) {
            matchers += " , ";
        }/*w  ww .j a  va  2 s  . co  m*/

        Type type = types[i];
        GenericClass genericParameter = parameterClasses.get(i);
        if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
            matchers += "anyInt()";
        } else if (type.equals(Long.TYPE) || type.equals(Long.class)) {
            matchers += "anyLong()";
        } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
            matchers += "anyBoolean()";
        } else if (type.equals(Double.TYPE) || type.equals(Double.class)) {
            matchers += "anyDouble()";
        } else if (type.equals(Float.TYPE) || type.equals(Float.class)) {
            matchers += "anyFloat()";
        } else if (type.equals(Short.TYPE) || type.equals(Short.class)) {
            matchers += "anyShort()";
        } else if (type.equals(Character.TYPE) || type.equals(Character.class)) {
            matchers += "anyChar()";
        } else if (type.equals(String.class)) {
            matchers += "anyString()";
        } else {
            if (type.getTypeName().equals(Object.class.getName())) {
                /*
                Ideally here we should use retvalType to understand if the target class
                is using generics and if this method parameters would need to be handled
                accordingly. However, doing it does not seem so trivial...
                so a current workaround is that, when a method takes an Object as input (which is
                that would happen in case of Generics T), we use the undetermined "any()"
                 */
                matchers += "any()";
            } else {
                if (type instanceof Class) {
                    matchers += "any(" + ((Class) type).getCanonicalName() + ".class)";
                } else {
                    //what to do here? is it even possible?
                    matchers += "any(" + genericParameter.getRawClass().getCanonicalName() + ".class)";
                    // matchers += "any(" + type.getTypeName() + ".class)";
                }
            }
        }
    }

    return matchers;
}

From source file:org.wrml.runtime.syntax.DefaultSyntaxLoader.java

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public final <T> T parseSyntacticText(final String text, final java.lang.reflect.Type targetType) {

    if (text == null) {
        return null;
    }//from   w w w  .j av a 2s  . c  om

    if (targetType == null || targetType.equals(String.class)) {
        return (T) text;
    }

    if (targetType.equals(Integer.TYPE) || targetType.equals(Integer.class)) {
        return (T) new Integer(text);
    }

    if (targetType.equals(Boolean.TYPE) || targetType.equals(Boolean.class)) {
        return (T) (text.equals("true") ? Boolean.TRUE : Boolean.FALSE);
    }

    if (targetType.equals(Long.TYPE) || targetType.equals(Long.class)) {
        return (T) new Long(text);
    }

    if (targetType.equals(Double.TYPE) || targetType.equals(Double.class)) {
        return (T) new Double(text);
    }

    if (TypeUtils.isAssignable(targetType, Enum.class)) {
        return (T) Enum.valueOf((Class<Enum>) targetType, text);
    }

    if (targetType instanceof Class<?>) {

        final SyntaxHandler<?> syntaxHandler = getSyntaxHandler((Class<?>) targetType);

        if (syntaxHandler != null) {
            return (T) syntaxHandler.parseSyntacticText(text);
        }
    }

    throw new SyntaxRegistryException(
            "Failed to transform text: \"" + text + "\" value to target type: " + targetType, null, this);

}

From source file:cn.chenlichao.web.ssm.service.impl.BaseServiceImpl.java

@SuppressWarnings("unchecked")
public BaseServiceImpl() {
    //  Class  (, ?, void)  Type
    Type genType = getClass().getGenericSuperclass();

    // ??, , ?//  w w w .  j  a v  a 2s  .c  o m
    while (!genType.equals(Object.class)) {
        if (genType instanceof ParameterizedType) {
            ParameterizedType superType = (ParameterizedType) genType;
            Type[] params = superType.getActualTypeArguments();
            if (params.length == 2 && params[0] instanceof Class) {
                entityClass = (Class<E>) params[0];
                pkClass = (Class<PK>) params[1];
                break;
            }
        }
        if (genType instanceof Class) {
            genType = ((Class) genType).getGenericSuperclass();
        } else {
            break;
        }
    }
    LOGGER.debug("Entity Class: {}, PK class: {}", entityClass.getSimpleName(), pkClass.getSimpleName());
}