List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:com.github.jakubkolar.autobuilder.impl.NamedResolver.java
private NamedResolver contributeValue(String name, @Nullable Class<?> type, Object value, Collection<Annotation> requiredAnnotations) { if (type == null || namedValues.containsKey(ImmutablePair.of(name, (Class) type))) { return this; }//from w ww . j a va 2 s .c o m NamedResolver result = new NamedResolver(namedValues, ImmutablePair.of(name, type), new RegisteredValue(value, requiredAnnotations)); result = result.contributeValue(name, type.getSuperclass(), value, requiredAnnotations); for (Class<?> iface : type.getInterfaces()) { result = result.contributeValue(name, iface, value, requiredAnnotations); } return result; }
From source file:org.openspotlight.graph.query.AbstractGeneralQueryTest.java
/** * Adds the java interface hirarchy links. * //from ww w . java 2 s. c o m * @param root the root * @param iFace the i face * @param javaInterface the java interface */ private void addJavaInterfaceHirarchyLinks(final Context root, final Class<?> iFace, final JavaInterface javaInterface) { final Class<?>[] superIFaces = iFace.getInterfaces(); for (final Class<?> superIFace : superIFaces) { final Package iFacePack = iFace.getPackage(); final JavaPackage javaPackage = writer.addNode(root, JavaPackage.class, iFacePack.getName()); // javaPackage.setCaption(iFacePack.getName()); final JavaInterface superJavaInterface = writer.addChildNode(javaPackage, JavaInterface.class, superIFace.getName()); writer.addLink(PackageContainsType.class, javaPackage, superJavaInterface); // superJavaInterface.setCaption(superIFace.getName()); writer.addLink(JavaInterfaceHierarchy.class, javaInterface, superJavaInterface); addJavaInterfaceHirarchyLinks(root, superIFace, superJavaInterface); } }
From source file:org.crazydog.util.spring.ClassUtils.java
/** * Return the number of methods with a given name (with any argument types), * for the given class and/or its superclasses. Includes non-public methods. * @param clazz the clazz to check//from ww w . j a va 2s. com * @param methodName the name of the method * @return the number of methods with the given name */ public static int getMethodCountForName(Class<?> clazz, String methodName) { org.springframework.util.Assert.notNull(clazz, "Class must not be null"); org.springframework.util.Assert.notNull(methodName, "Method name must not be null"); int count = 0; Method[] declaredMethods = clazz.getDeclaredMethods(); for (Method method : declaredMethods) { if (methodName.equals(method.getName())) { count++; } } Class<?>[] ifcs = clazz.getInterfaces(); for (Class<?> ifc : ifcs) { count += getMethodCountForName(ifc, methodName); } if (clazz.getSuperclass() != null) { count += getMethodCountForName(clazz.getSuperclass(), methodName); } return count; }
From source file:org.compass.core.converter.DefaultConverterLookup.java
private Converter actualConverterLookup(Class type) { Converter c = convertersByClass.get(type.getName()); if (c != null) { return c; }//from ww w . jav a 2 s. c o m for (Class anInterface : type.getInterfaces()) { c = convertersByClass.get(anInterface.getName()); if (c != null) { return c; } } Class superClass = type.getSuperclass(); if (superClass == null) { return null; } c = lookupConverter(superClass); if (c != null) { return c; } return null; }
From source file:org.mule.transformer.TransformerWeighting.java
/** * This is a very basic algorithm for creating a match rating for two classes. An offset weighting * can also be passed in. Where w is weighting, * if the classes are not assignable but the src is a primitive type, the w for the corresponding object type will be returned, otherwise return -1 * if the classes match exactly and dest is Object then w+3 is returned * if the classes match exactly and dest is not Object then w+1 is returned * if the classes are assignable and there is a direct equality to an interface on the class, w+2 is returned, * If there a super class, that will get matched using the above criteria but using w = w + 1 * If there is no match -1 is returned// w ww . j a v a 2s . c o m * * @param weighting an offset weighting, by default -1 should be used * @param src the src class being matched * @param dest the destination class to match to * @return a weighting where 0 would be an exact match, -1 would be no match and a positive integer that defines how close the match is */ protected int getWeighting(int weighting, Class src, Class dest) { if (!dest.isAssignableFrom(src)) { if (src.isPrimitive()) { return getWeighting(weighting, MethodUtils.getPrimitiveWrapper(src), dest); } return -1; } if (dest.equals(src)) { if (dest.equals(Object.class)) { return weighting + 3; } else { return weighting + 1; } } if (dest.isInterface() && src.getInterfaces().length > 0) { for (int i = 0; i < src.getInterfaces().length; i++) { Class aClass = src.getInterfaces()[i]; if (dest.equals(aClass)) { return weighting + 2; } } } if (src.getSuperclass() != null) { return getWeighting(weighting + 1, src.getSuperclass(), dest); } return -1; }
From source file:org.agiso.core.i18n.util.I18nUtils.java
private static String findGetterFieldCode(Class<?> c, String field, boolean reflectionCheck) throws IntrospectionException { for (PropertyDescriptor pd : Introspector.getBeanInfo(c).getPropertyDescriptors()) { if (pd.getName().equals(field)) { final Method g = pd.getReadMethod(); if (g != null) { // Jeli jest adnotacja I18n na metodzie odczytujcej pole, to pobieranie // pobieranie jej klucza (okrelonego przez 'value') lub klucza domylnego: if (g.isAnnotationPresent(I18n.class)) { if (g.getAnnotation(I18n.class).value().length() > 0) { return g.getAnnotation(I18n.class).value(); } else { return g.getDeclaringClass().getName() + CODE_SEPARATOR + field; }//from w ww .ja v a 2 s.c om } else if (reflectionCheck) { // Pole nie jest opisane adnotacj I18n. Jeli do wyszukania maj by // wykorzystane mechanizmy refleksji, to sprawdzamy interfejsy i nadklas: for (Class<?> i : c.getInterfaces()) { String i18nCode = findGetterFieldCode(i, field, false); if (i18nCode != null) { return i18nCode; } } Class<?> s = c.getSuperclass(); if (s != null) { return findGetterFieldCode(s, field, true); } } } } } if (reflectionCheck) { for (Class<?> i : c.getInterfaces()) { String i18nCode = findGetterFieldCode(i, field, false); if (i18nCode != null) { return i18nCode; } } } return null; }
From source file:com.mirth.connect.server.api.providers.MirthResourceInvocationHandlerProvider.java
@Override public InvocationHandler create(Invocable method) { return new InvocationHandler() { @Override/*from www . j ava 2 s . c o m*/ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String originalThreadName = Thread.currentThread().getName(); try { if (proxy instanceof MirthServlet) { try { MirthServlet mirthServlet = (MirthServlet) proxy; Map<Method, MethodInfo> methodMap = infoMap.get(proxy.getClass()); if (methodMap == null) { methodMap = new ConcurrentHashMap<Method, MethodInfo>(); infoMap.put(mirthServlet.getClass(), methodMap); } MethodInfo methodInfo = methodMap.get(method); if (methodInfo == null) { methodInfo = new MethodInfo(); methodMap.put(method, methodInfo); } Operation operation = methodInfo.getOperation(); if (operation == null) { /* * Get the operation from the MirthOperation annotation present on * the interface method. */ Class<?> clazz = proxy.getClass(); while (clazz != null && operation == null) { for (Class<?> interfaceClass : clazz.getInterfaces()) { if (BaseServletInterface.class.isAssignableFrom(interfaceClass)) { operation = OperationUtil.getOperation(interfaceClass, method); if (operation != null) { methodInfo.setOperation(operation); break; } } } clazz = clazz.getSuperclass(); } } mirthServlet.setOperation(operation); // Set thread name based on the servlet class and operation name Thread.currentThread().setName(mirthServlet.getClass().getSimpleName() + " Thread (" + operation.getDisplayName() + ") < " + originalThreadName); /* * If a DontCheckAuthorized annotation is present on the server * implementation method, then no auditing is done now and the servlet * is expected to call checkUserAuthorized. Two other optional * annotations determine whether the channel/user ID should be used in * the authorization check. */ Boolean checkAuthorized = methodInfo.getCheckAuthorized(); if (checkAuthorized == null) { checkAuthorized = true; Method matchingMethod = mirthServlet.getClass().getMethod(method.getName(), method.getParameterTypes()); if (matchingMethod != null) { checkAuthorized = matchingMethod .getAnnotation(DontCheckAuthorized.class) == null; methodInfo.setCheckAuthorizedChannelId( matchingMethod.getAnnotation(CheckAuthorizedChannelId.class)); methodInfo.setCheckAuthorizedUserId( matchingMethod.getAnnotation(CheckAuthorizedUserId.class)); } methodInfo.setCheckAuthorized(checkAuthorized); } if (checkAuthorized) { /* * We need to know what parameter index the channel/user ID resides * at so we can correctly include it with the authorization request. */ Integer channelIdIndex = methodInfo.getChannelIdIndex(); Integer userIdIndex = methodInfo.getUserIdIndex(); if (args.length > 0) { List<String> paramNames = methodInfo.getParamNames(); if (paramNames == null) { paramNames = new ArrayList<String>(); List<Integer> notFoundIndicies = new ArrayList<Integer>(); /* * The Param annotation lets us know at runtime the name to * use when adding entries into the parameter map, which * will eventually be stored in the event logs. */ int count = 0; for (Annotation[] paramAnnotations : method.getParameterAnnotations()) { boolean found = false; for (Annotation annotation : paramAnnotations) { if (annotation instanceof Param) { Param param = (Param) annotation; // Set the name to null if we're not including it in the parameter map paramNames.add(param.excludeFromAudit() ? null : param.value()); found = true; break; } } if (!found) { notFoundIndicies.add(count); paramNames.add(null); } count++; } // For each parameter name that wasn't found, replace it with a default name to use in the parameter map if (CollectionUtils.isNotEmpty(notFoundIndicies)) { for (Integer index : notFoundIndicies) { paramNames.set(index, getDefaultParamName(paramNames)); } } methodInfo.setParamNames(paramNames); } // Add all arguments to the parameter map, except those that had excludeFromAudit enabled. for (int i = 0; i < args.length; i++) { String paramName = paramNames.get(i); if (paramName != null) { mirthServlet.addToParameterMap(paramNames.get(i), args[i]); } } if (channelIdIndex == null) { channelIdIndex = -1; if (methodInfo.getCheckAuthorizedChannelId() != null) { channelIdIndex = paramNames .indexOf(methodInfo.getCheckAuthorizedChannelId().paramName()); } methodInfo.setChannelIdIndex(channelIdIndex); } if (userIdIndex == null) { userIdIndex = -1; if (methodInfo.getCheckAuthorizedUserId() != null) { userIdIndex = paramNames .indexOf(methodInfo.getCheckAuthorizedUserId().paramName()); } methodInfo.setUserIdIndex(userIdIndex); } } // Authorize the request if (channelIdIndex != null && channelIdIndex >= 0) { mirthServlet.checkUserAuthorized((String) args[channelIdIndex]); } else if (userIdIndex != null && userIdIndex >= 0) { mirthServlet.checkUserAuthorized((Integer) args[userIdIndex], methodInfo.getCheckAuthorizedUserId().auditCurrentUser()); } else { mirthServlet.checkUserAuthorized(); } } } catch (Throwable t) { Throwable converted = convertThrowable(t, new HashSet<Throwable>()); if (converted != null) { t = converted; } if (!(t instanceof WebApplicationException)) { t = new MirthApiException(t); } throw new InvocationTargetException(t); } } try { return method.invoke(proxy, args); } catch (InvocationTargetException e) { Throwable converted = convertThrowable(e, new HashSet<Throwable>()); if (converted != null && converted instanceof InvocationTargetException) { e = (InvocationTargetException) converted; } throw e; } } finally { Thread.currentThread().setName(originalThreadName); } } }; }
From source file:android.bus.EventBus.java
/** Looks up all Class objects including super classes and interfaces. Should also work for interfaces. */ private List<Class<?>> lookupAllEventTypes(Class<?> eventClass) { synchronized (eventTypesCache) { List<Class<?>> eventTypes = eventTypesCache.get(eventClass); if (eventTypes == null) { eventTypes = new ArrayList<Class<?>>(); Class<?> clazz = eventClass; while (clazz != null) { eventTypes.add(clazz);/* ww w. ja v a 2 s. com*/ addInterfaces(eventTypes, clazz.getInterfaces()); clazz = clazz.getSuperclass(); } eventTypesCache.put(eventClass, eventTypes); } return eventTypes; } }
From source file:com.opensymphony.xwork2.util.LocalizedTextUtil.java
/** * Traverse up class hierarchy looking for message. Looks at class, then implemented interface, * before going up hierarchy./*w w w . jav a 2s.com*/ */ private static String findMessage(Class clazz, String key, String indexedKey, Locale locale, Object[] args, Set<String> checked, ValueStack valueStack) { if (checked == null) { checked = new TreeSet<String>(); } else if (checked.contains(clazz.getName())) { return null; } // look in properties of this class String msg = getMessage(clazz.getName(), locale, key, valueStack, args); if (msg != null) { return msg; } if (indexedKey != null) { msg = getMessage(clazz.getName(), locale, indexedKey, valueStack, args); if (msg != null) { return msg; } } // look in properties of implemented interfaces Class[] interfaces = clazz.getInterfaces(); for (Class anInterface : interfaces) { msg = getMessage(anInterface.getName(), locale, key, valueStack, args); if (msg != null) { return msg; } if (indexedKey != null) { msg = getMessage(anInterface.getName(), locale, indexedKey, valueStack, args); if (msg != null) { return msg; } } } // traverse up hierarchy if (clazz.isInterface()) { interfaces = clazz.getInterfaces(); for (Class anInterface : interfaces) { msg = findMessage(anInterface, key, indexedKey, locale, args, checked, valueStack); if (msg != null) { return msg; } } } else { if (!clazz.equals(Object.class) && !clazz.isPrimitive()) { return findMessage(clazz.getSuperclass(), key, indexedKey, locale, args, checked, valueStack); } } return null; }
From source file:gov.va.vinci.leo.ae.LeoBaseAnnotator.java
/** * Returns parameters defined in a static class named Param with static ConfigurationParameter objects. * <p/>//from w w w . j a v a 2 s.c o m * For Example: * <p/> * <pre> * {@code * protected String parameterName = "parameter value"; * * public static class Param { * public static ConfigurationParameter PARAMETER_NAME * = new ConfigurationParameterImpl( * "parameterName", "Description", "String", false, true, new String[] {} * ); * } * }</pre> * * @return the annotator parameters this annotator can accept. * @throws IllegalAccessException if there is an exception trying to get annotator parameters via reflection. */ protected ConfigurationParameter[] getAnnotatorParams() throws IllegalAccessException { ConfigurationParameter params[] = null; for (Class c : this.getClass().getDeclaredClasses()) { if (c.isEnum() && Arrays.asList(c.getInterfaces()).contains(ConfigurationParameter.class)) { params = new ConfigurationParameter[EnumSet.allOf(c).size()]; int counter = 0; for (Object o : EnumSet.allOf(c)) { params[counter] = ((ConfigurationParameter) o); counter++; } break; } else if (c.getCanonicalName().endsWith(".Param")) { Field[] fields = c.getFields(); List<ConfigurationParameter> paramList = new ArrayList<ConfigurationParameter>(); for (Field f : fields) { if (ConfigurationParameter.class.isAssignableFrom(f.getType())) { paramList.add((ConfigurationParameter) f.get(null)); } } params = paramList.toArray(new ConfigurationParameter[paramList.size()]); } } return params; }