List of usage examples for java.lang Class getGenericInterfaces
public Type[] getGenericInterfaces()
From source file:com.msopentech.odatajclient.proxy.api.impl.EntityTypeInvocationHandler.java
private Object getNavigationPropertyValue(final NavigationProperty property, final Method getter) { final Class<?> type = getter.getReturnType(); final Class<?> collItemType; if (AbstractEntityCollection.class.isAssignableFrom(type)) { final Type[] entityCollectionParams = ((ParameterizedType) type.getGenericInterfaces()[0]) .getActualTypeArguments(); collItemType = (Class<?>) entityCollectionParams[0]; } else {/*from w w w .j a v a2 s . co m*/ collItemType = type; } final Object navPropValue; if (linkChanges.containsKey(property)) { navPropValue = linkChanges.get(property); } else { final ODataLink link = EngineUtils.getNavigationLink(property.name(), entity); if (link instanceof ODataInlineEntity) { // return entity navPropValue = getEntityProxy(((ODataInlineEntity) link).getEntity(), property.targetContainer(), property.targetEntitySet(), type, false); } else if (link instanceof ODataInlineEntitySet) { // return entity set navPropValue = getEntityCollection(collItemType, type, property.targetContainer(), ((ODataInlineEntitySet) link).getEntitySet(), link.getLink(), false); } else { // navigate final URI uri = URIUtils.getURI(containerHandler.getFactory().getServiceRoot(), link.getLink().toASCIIString()); if (AbstractEntityCollection.class.isAssignableFrom(type)) { navPropValue = getEntityCollection(collItemType, type, property.targetContainer(), client.getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody(), uri, true); } else { final ODataRetrieveResponse<ODataEntity> res = client.getRetrieveRequestFactory() .getEntityRequest(uri).execute(); navPropValue = getEntityProxy(res.getBody(), property.targetContainer(), property.targetEntitySet(), type, res.getEtag(), true); } } if (navPropValue != null) { int checkpoint = linkChanges.hashCode(); linkChanges.put(property, navPropValue); updateLinksTag(checkpoint); } } return navPropValue; }
From source file:com.msopentech.odatajclient.proxy.api.impl.EntitySetInvocationHandler.java
@SuppressWarnings("unchecked") private EntitySetInvocationHandler(final Class<?> ref, final EntityContainerInvocationHandler containerHandler) { super(containerHandler.getClient(), containerHandler); final Annotation annotation = ref.getAnnotation(EntitySet.class); if (!(annotation instanceof EntitySet)) { throw new IllegalArgumentException( "Return type " + ref.getName() + " is not annotated as @" + EntitySet.class.getSimpleName()); }//ww w .ja v a2 s .com this.entitySetName = ((EntitySet) annotation).name(); final Type[] abstractEntitySetParams = ((ParameterizedType) ref.getGenericInterfaces()[0]) .getActualTypeArguments(); this.typeRef = (Class<T>) abstractEntitySetParams[0]; if (typeRef.getAnnotation(EntityType.class) == null) { throw new IllegalArgumentException("Invalid entity '" + typeRef.getSimpleName() + "'"); } this.collTypeRef = (Class<EC>) abstractEntitySetParams[2]; final URIBuilder uriBuilder = client.getURIBuilder(containerHandler.getFactory().getServiceRoot()); if (!containerHandler.isDefaultEntityContainer()) { uriBuilder.appendStructuralSegment(containerHandler.getEntityContainerName()) .appendStructuralSegment("."); } uriBuilder.appendEntitySetSegment(entitySetName); this.uri = uriBuilder.build(); }
From source file:com.searchbox.framework.web.ApplicationConversionService.java
@Override public void afterPropertiesSet() throws Exception { LOGGER.info("Scanning for SearchComponents"); Map<Class<?>, String> conditionUrl = new HashMap<Class<?>, String>(); ClassPathScanningCandidateComponentProvider scanner; // Getting all the SearchElements scanner = new ClassPathScanningCandidateComponentProvider(false); scanner.addIncludeFilter(new AnnotationTypeFilter(SearchCondition.class)); for (BeanDefinition bean : scanner.findCandidateComponents("com.searchbox")) { try {/*from w w w. ja va2 s . c o m*/ Class<?> clazz = Class.forName(bean.getBeanClassName()); String urlParam = clazz.getAnnotation(SearchCondition.class).urlParam(); conditionUrl.put(clazz, urlParam); } catch (Exception e) { LOGGER.error("Could not introspect SearchElement: " + bean, e); } } // Getting all converters for SearchConditions scanner = new ClassPathScanningCandidateComponentProvider(false); scanner.addIncludeFilter(new AnnotationTypeFilter(SearchConverter.class)); for (BeanDefinition bean : scanner.findCandidateComponents("com.searchbox")) { try { Class<?> clazz = Class.forName(bean.getBeanClassName()); for (Type i : clazz.getGenericInterfaces()) { ParameterizedType pi = (ParameterizedType) i; for (Type piarg : pi.getActualTypeArguments()) { if (AbstractSearchCondition.class.isAssignableFrom(((Class<?>) piarg))) { Class<?> conditionClass = ((Class<?>) piarg); searchConditions.put(conditionUrl.get(conditionClass), ((Class<?>) piarg)); this.addConverter((Converter<?, ?>) clazz.newInstance()); LOGGER.info("Registered Converter " + clazz.getSimpleName() + " for " + ((Class<?>) piarg).getSimpleName() + " with prefix: " + conditionUrl.get(conditionClass)); } } } } catch (Exception e) { LOGGER.error("Could not create Converter for: " + bean.getBeanClassName(), e); } } this.addConverter(new Converter<String, SearchboxEntity>() { @Override public SearchboxEntity convert(String slug) { return searchboxRepository.findBySlug(slug); } }); this.addConverter(new Converter<SearchboxEntity, String>() { @Override public String convert(SearchboxEntity searchbox) { return searchbox.getSlug(); } }); this.addConverter(new Converter<Long, SearchboxEntity>() { @Override public SearchboxEntity convert(java.lang.Long id) { return searchboxRepository.findOne(id); } }); this.addConverter(new Converter<SearchboxEntity, Long>() { @Override public Long convert(SearchboxEntity searchbox) { return searchbox.getId(); } }); this.addConverter(new Converter<String, PresetEntity>() { @Override public PresetEntity convert(String slug) { return presetRepository.findPresetDefinitionBySlug(slug); } }); this.addConverter(new Converter<Long, PresetEntity>() { @Override public PresetEntity convert(java.lang.Long id) { return presetRepository.findOne(id); } }); this.addConverter(new Converter<PresetEntity, String>() { @Override public String convert(PresetEntity presetDefinition) { return new StringBuilder().append(presetDefinition.getSlug()).toString(); } }); this.addConverter(new Converter<Class<?>, String>() { @Override public String convert(Class<?> source) { return source.getName(); } }); this.addConverter(new Converter<String, Class<?>>() { @Override public Class<?> convert(String source) { try { // TODO Such a bad hack... if (source.contains("class")) { source = source.replace("class", "").trim(); } return context.getClassLoader().loadClass(source); // Class.forName(source); } catch (ClassNotFoundException e) { LOGGER.error("Could not convert \"" + source + "\" to class.", e); } return null; } }); }
From source file:com.link_intersystems.lang.reflect.Class2.java
private Type findBoundTypeInGenericInterfaces(Class<?> typeClass, TypeVariable<?> typeVariable) { Type boundType = null;/* w ww .j a v a 2 s .c o m*/ Type[] genericInterfaces = typeClass.getGenericInterfaces(); for (Type genericInterface : genericInterfaces) { if (genericInterface instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) genericInterface; boundType = doGetBoundType(parameterizedType, typeVariable); if (boundType != null) { break; } } } return boundType; }
From source file:pl.bristleback.server.bristle.conf.resolver.action.ActionResolver.java
private boolean isDefaultRemoteAction(Class clazz, Method action) { if (!DefaultAction.class.isAssignableFrom(clazz)) { // this action class does not have default action return false; }/*from ww w . ja v a 2 s .c o m*/ Method defaultMethod = DefaultAction.class.getMethods()[0]; if (!defaultMethod.getName().equals(action.getName())) { return false; } Class[] defaultParameterTypes = defaultMethod.getParameterTypes(); if (defaultParameterTypes.length != action.getParameterTypes().length) { return false; } int parametersLength = defaultParameterTypes.length; for (int i = 0; i < parametersLength - 1; i++) { Class defaultParameterType = defaultParameterTypes[i]; if (!defaultParameterType.isAssignableFrom(action.getParameterTypes()[i])) { return false; } } Type requiredLastParameterType = action.getGenericParameterTypes()[parametersLength - 1]; Type actualLastParameterType = null; for (int i = 0; i < clazz.getInterfaces().length; i++) { Class interfaceOfClass = clazz.getInterfaces()[i]; if (DefaultAction.class.equals(interfaceOfClass)) { Type genericInterface = clazz.getGenericInterfaces()[i]; if (genericInterface instanceof ParameterizedType) { actualLastParameterType = ((ParameterizedType) (genericInterface)).getActualTypeArguments()[1]; } else { actualLastParameterType = Object.class; } } } return requiredLastParameterType.equals(actualLastParameterType); }
From source file:co.paralleluniverse.galaxy.core.Cache.java
private static boolean isVoidLineFunction(Class<?> clazz) { if (clazz == null) return false; for (java.lang.reflect.Type iface : clazz.getGenericInterfaces()) { if (iface instanceof java.lang.reflect.ParameterizedType) { java.lang.reflect.ParameterizedType pt = (java.lang.reflect.ParameterizedType) iface; if (pt.getRawType() == LineFunction.class) return (pt.getActualTypeArguments()[0] == Void.class); boolean r = isVoidLineFunction((Class) pt.getRawType()); if (r) return true; } else if (iface == LineFunction.class) return false; boolean r = isVoidLineFunction((Class) iface); if (r)// w w w .jav a 2 s .c o m return true; } return isVoidLineFunction(clazz.getSuperclass()); }
From source file:com.clark.func.Functions.java
/** * <p>/* ww w.j a va2 s . c o m*/ * Closest parent type? Closest to what? The closest parent type to the * super class specified by <code>superClass</code>. * </p> * * @param cls * @param superClass * @return */ private static Type getClosestParentType(Class<?> cls, Class<?> superClass) { // only look at the interfaces if the super class is also an interface if (superClass.isInterface()) { // get the generic interfaces of the subject class Type[] interfaceTypes = cls.getGenericInterfaces(); // will hold the best generic interface match found Type genericInterface = null; // find the interface closest to the super class for (int i = 0; i < interfaceTypes.length; i++) { Type midType = interfaceTypes[i]; Class<?> midClass = null; if (midType instanceof ParameterizedType) { midClass = getRawType((ParameterizedType) midType); } else if (midType instanceof Class<?>) { midClass = (Class<?>) midType; } else { throw new IllegalStateException("Unexpected generic" + " interface type found: " + midType); } // check if this interface is further up the inheritance chain // than the previously found match if (isAssignable(midClass, superClass) && isAssignable(genericInterface, (Type) midClass)) { genericInterface = midType; } } // found a match? if (genericInterface != null) { return genericInterface; } } // none of the interfaces were descendants of the target class, so the // super class has to be one, instead return cls.getGenericSuperclass(); }
From source file:nl.luminis.test.util.annotations.HierarchyDiscovery.java
private void discoverFromClass(Class<?> clazz) { discoverTypes(resolveType(type, type, clazz.getGenericSuperclass())); for (Type c : clazz.getGenericInterfaces()) { discoverTypes(resolveType(type, type, c)); }/*from w ww . j ava2 s . c om*/ }
From source file:org.apache.flink.api.java.typeutils.TypeExtractor.java
private static Type getParameterType(Class<?> baseClass, ArrayList<Type> typeHierarchy, Class<?> clazz, int pos) { if (typeHierarchy != null) { typeHierarchy.add(clazz);/* w ww . java 2 s . co m*/ } Type[] interfaceTypes = clazz.getGenericInterfaces(); // search in interfaces for base class for (Type t : interfaceTypes) { Type parameter = getParameterTypeFromGenericType(baseClass, typeHierarchy, t, pos); if (parameter != null) { return parameter; } } // search in superclass for base class Type t = clazz.getGenericSuperclass(); Type parameter = getParameterTypeFromGenericType(baseClass, typeHierarchy, t, pos); if (parameter != null) { return parameter; } throw new InvalidTypesException("The types of the interface " + baseClass.getName() + " could not be inferred. " + "Support for synthetic interfaces, lambdas, and generic or raw types is limited at this point"); }
From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java
/** * Handles all the distributed mbean creation part when a Manager is started */// www . j ava 2 s . c o m public void handleManagerStart() throws ManagementException { if (!isServiceInitialised("handleManagerStart")) { return; } MBeanJMXAdapter jmxAdapter = service.getJMXAdapter(); Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean(); DistributedSystemBridge dsBridge = new DistributedSystemBridge(service); this.aggregator = new MBeanAggregator(dsBridge); // register the aggregator for Federation framework to use service.addProxyListener(aggregator); /* * get the local member mbean as it need to be provided to aggregator first */ MemberMXBean localMember = service.getMemberMXBean(); ObjectName memberObjectName = MBeanJMXAdapter .getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember()); FederationComponent addedComp = service.getLocalManager().getFedComponents().get(memberObjectName); service.afterCreateProxy(memberObjectName, MemberMXBean.class, localMember, addedComp); for (ObjectName objectName : registeredMBeans.keySet()) { if (objectName.equals(memberObjectName)) { 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 newObj = service.getLocalManager().getFedComponents().get(objectName); for (Type intfTyp1 : intfTyps) { Class intfTyp = (Class) intfTyp1; service.afterCreateProxy(objectName, intfTyp, object, newObj); } } catch (InstanceNotFoundException e) { if (logger.isDebugEnabled()) { logger.debug("Failed in Registering distributed mbean "); } throw new ManagementException(e); } catch (ClassNotFoundException e) { if (logger.isDebugEnabled()) { logger.debug("Failed in Registering distributed mbean"); } throw new ManagementException(e); } } }