List of usage examples for java.lang Class getGenericInterfaces
public Type[] getGenericInterfaces()
From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java
/** * Handles all the clean up activities when a Manager is stopped It clears the distributed mbeans * and underlying data structures/*www. j a v a2s . c o m*/ */ public void handleManagerStop() throws ManagementException { if (!isServiceInitialised("handleManagerStop")) { return; } MBeanJMXAdapter jmxAdapter = service.getJMXAdapter(); Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean(); ObjectName aggregatemMBeanPattern; try { aggregatemMBeanPattern = new ObjectName(ManagementConstants.AGGREGATE_MBEAN_PATTERN); } catch (MalformedObjectNameException | NullPointerException e1) { throw new ManagementException(e1); } MemberMXBean localMember = service.getMemberMXBean(); ObjectName memberObjectName = MBeanJMXAdapter .getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember()); FederationComponent removedComp = service.getLocalManager().getFedComponents().get(memberObjectName); service.afterRemoveProxy(memberObjectName, MemberMXBean.class, localMember, removedComp); for (ObjectName objectName : registeredMBeans.keySet()) { if (objectName.equals(memberObjectName)) { continue; } if (aggregatemMBeanPattern.apply(objectName)) { continue; } Object object = registeredMBeans.get(objectName); ObjectInstance instance; try { instance = mbeanServer.getObjectInstance(objectName); String className = instance.getClassName(); Class cls = ClassLoadUtil.classFromName(className); Type[] intfTyps = cls.getGenericInterfaces(); FederationComponent oldObj = service.getLocalManager().getFedComponents().get(objectName); for (Type intfTyp1 : intfTyps) { Class intfTyp = (Class) intfTyp1; service.afterRemoveProxy(objectName, intfTyp, object, oldObj); } } catch (InstanceNotFoundException | ClassNotFoundException e) { logger.warn("Failed to invoke aggregator for {} with exception {}", objectName, e.getMessage(), e); } } service.removeProxyListener(this.aggregator); this.aggregator = null; }
From source file:org.devproof.portal.core.config.factory.DevproofClassPathBeanDefinitionScanner.java
/** * Entity class is always the first generic type * @param clazz type/*from ww w .j a v a 2 s . c om*/ * @return entity class */ private Class<?> getEntityClazz(Class<?> clazz) { Type[] types = clazz.getGenericInterfaces(); ParameterizedType type = (ParameterizedType) types[0]; return (Class<?>) type.getActualTypeArguments()[0]; }
From source file:org.jcurl.core.ui.TaskExecutor.java
/** Find the presence of a generic type parameter. */ @SuppressWarnings("unchecked") static Class<Executor> findMessageTypeParam(final Class<? extends Task> clz) { if (Object.class.equals(clz.getGenericSuperclass())) { final ParameterizedType pt = (ParameterizedType) clz.getGenericInterfaces()[0]; return (Class<Executor>) pt.getActualTypeArguments()[0]; }//from w w w . ja va 2 s . com final ParameterizedType pt = (ParameterizedType) clz.getGenericSuperclass(); return (Class<Executor>) pt.getActualTypeArguments()[0]; }
From source file:org.jgentleframework.utils.ReflectUtils.java
/** * Returns the all {@link Type Types} representing the interfaces * implemented by the class or interface represented by given object class. * // ww w . jav a2 s . com * @param clazz * the given object class * @param superClass * if <b>true</b>, the result will includes all types of super * classes and super interfaces of given object class. * @return an {@link ArrayList} containing returned types if they exist, * otherwise, returns an empty {@link ArrayList}. */ public static List<Type> getAllGenericInterfaces(Class<?> clazz, boolean superClass) { Assertor.notNull(clazz); List<Type> result = new ArrayList<Type>(); for (Type type : clazz.getGenericInterfaces()) { if (!result.contains(type)) { int i = 0; for (Type resultType : result) { if (resultType.toString().equals(type.toString())) { i++; } } if (i == 0) { result.add(type); } } } // Tm trn tt c cc interfaces ca clazz hin hnh Set<Class<?>> listInterfaces = ReflectUtils.getAllInterfaces(clazz, superClass); for (Class<?> interfaze : listInterfaces) { for (Type type : interfaze.getGenericInterfaces()) { if (!result.contains(type)) { int i = 0; for (Type resultType : result) { if (resultType.toString().equals(type.toString())) { i++; } } if (i == 0) { result.add(type); } } } } // Tm trn tt c cc superClass ca clazz hin hnh List<Class<?>> listClass = ReflectUtils.getAllSuperClass(clazz, false); for (Class<?> current : listClass) { for (Type type : current.getGenericInterfaces()) { if (!result.contains(type)) { int i = 0; for (Type resultType : result) { if (resultType.toString().equals(type.toString())) { i++; } } if (i == 0) { result.add(type); } } } } return result; }
From source file:org.jiemamy.utils.reflect.GenericUtil.java
/** * ??(???)??????{@link Map}??/* ww w .j a v a 2s .c o m*/ * * @param clazz ??(???) * @return ????????{@link Map} * @throws IllegalArgumentException ?{@code null}??? */ public static Map<TypeVariable<?>, Type> getTypeVariableMap(Class<?> clazz) { Validate.notNull(clazz); Map<TypeVariable<?>, Type> map = Maps.newLinkedHashMap(); Class<?> superClass = clazz.getSuperclass(); Type superClassType = clazz.getGenericSuperclass(); if (superClass != null) { gatherTypeVariables(superClass, superClassType, map); } Class<?>[] interfaces = clazz.getInterfaces(); Type[] interfaceTypes = clazz.getGenericInterfaces(); for (int i = 0; i < interfaces.length; ++i) { gatherTypeVariables(interfaces[i], interfaceTypes[i], map); } return map; }
From source file:org.jiemamy.utils.reflect.GenericUtil.java
/** * ??(???)???????{@code map}??//w w w. j ava2 s . c o m * * @param clazz * @param type * @param map ????????{@link Map} */ protected static void gatherTypeVariables(Class<?> clazz, Type type, Map<TypeVariable<?>, Type> map) { if (clazz == null) { return; } gatherTypeVariables(type, map); Class<?> superClass = clazz.getSuperclass(); Type superClassType = clazz.getGenericSuperclass(); if (superClass != null) { gatherTypeVariables(superClass, superClassType, map); } Class<?>[] interfaces = clazz.getInterfaces(); Type[] interfaceTypes = clazz.getGenericInterfaces(); for (int i = 0; i < interfaces.length; ++i) { gatherTypeVariables(interfaces[i], interfaceTypes[i], map); } }
From source file:org.jmingo.mapping.convert.ConverterService.java
private Set<Class<?>> getConverters(final Class<?> aClass) { Set<Class<?>> suitableConverters = new HashSet<>(); for (Class<?> converterClass : convertersClasses) { if (converterClass.getGenericInterfaces().length > 0 && converterClass.getGenericInterfaces()[0] instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) converterClass.getGenericInterfaces()[0]; if (pt.getActualTypeArguments().length > 0 && pt.getActualTypeArguments()[0] instanceof Class) { Class<?> at = (Class<?>) pt.getActualTypeArguments()[0]; if (aClass.equals(at)) { suitableConverters.add(converterClass); }/*from w w w.j a v a 2s . co m*/ } } } return suitableConverters; }
From source file:org.kuali.rice.krad.uif.util.ObjectPropertyUtils.java
/** * Locate the generic type declaration for a given target class in the generic type hierarchy of * the source class./* w w w. ja v a 2s . c o m*/ * * @param sourceClass The class representing the generic type hierarchy to scan. * @param targetClass The class representing the generic type declaration to locate within the * source class' hierarchy. * @return The generic type representing the target class within the source class' generic * hierarchy. */ public static Type findGenericType(Class<?> sourceClass, Class<?> targetClass) { if (!targetClass.isAssignableFrom(sourceClass)) { throw new IllegalArgumentException(targetClass + " is not assignable from " + sourceClass); } if (sourceClass.equals(targetClass)) { return sourceClass; } @SuppressWarnings("unchecked") Queue<Type> typeQueue = RecycleUtils.getInstance(LinkedList.class); typeQueue.offer(sourceClass); while (!typeQueue.isEmpty()) { Type type = typeQueue.poll(); Class<?> upperBound = getUpperBound(type); if (targetClass.equals(upperBound)) { return type; } Type genericSuper = upperBound.getGenericSuperclass(); if (genericSuper != null) { typeQueue.offer(genericSuper); } Type[] genericInterfaces = upperBound.getGenericInterfaces(); for (int i = 0; i < genericInterfaces.length; i++) { if (genericInterfaces[i] != null) { typeQueue.offer(genericInterfaces[i]); } } } throw new IllegalStateException(targetClass + " is assignable from " + sourceClass + " but could not be found in the generic type hierarchy"); }
From source file:org.matonto.jaas.rest.providers.GroupProvider.java
private boolean isGroup(Class<?> someClass, Type type) { return type == Group.class || Arrays.asList(someClass.getGenericInterfaces()).contains(Group.class); }
From source file:org.matonto.jaas.rest.providers.UserProvider.java
private boolean isUser(Class<?> someClass, Type type) { return type == User.class || Arrays.asList(someClass.getGenericInterfaces()).contains(User.class); }