/** * @param method the method * @return the corresponding element name */ public static String getElementName(Method method) { Name name = method.getAnnotation(Name.class); if (name != null) { return name.value(); } return getElementName(method.getName()); }
/** * @param method the method * @param searchTopMethod search for top most overridden method * @return the corresponding element name */ public static String getElementName(Method method, boolean searchTopMethod) { Method topMethod = method; if (searchTopMethod) { // Get top most method declaration Set<Method> hierarchy = MethodUtils.getOverrideHierarchy(method, Interfaces.INCLUDE); topMethod = IterableUtils.get(hierarchy, hierarchy.size() - 1); } // Get element name from method return getElementName(topMethod); }
/** * @param type the class of the filter * @return the descriptor of the filter * @throws IncompatibleFilterException when several methods/events are incompatibles */ private FilterDescriptor createDescriptor(Class<?> type) throws IncompatibleFilterException { // Proxy "loose" various reflection informations (like method parameter names) if (Proxy.isProxyClass(type)) { return getFilterDescriptor(type.getInterfaces()); } else { FilterDescriptor descriptor = new FilterDescriptor(); for (Method method : type.getMethods()) { // Get top most method declaration Set<Method> hierarchy = MethodUtils.getOverrideHierarchy(method, Interfaces.INCLUDE); Method topMethod = IterableUtils.get(hierarchy, hierarchy.size() - 1); // Get element name from method String elementName = getElementName(topMethod); // If a name can be found, continue if (elementName != null) { addElement(elementName, descriptor, topMethod); } } return descriptor; } }
private static void invokeUnkown(Object filter, FilterDescriptor descriptor, Method method, Object[] args) throws FilterException { String id = DefaultFilterDescriptorManager.getElementName(method); if (id != null) { FilterElementDescriptor element = descriptor.getElement(id); if (element != null) { FilterEventParameters metadata = new FilterEventParameters(); for (FilterElementParameterDescriptor<?> parameter : element.getParameters()) { metadata.put( parameter.getName() != null ? parameter.getName() : String.valueOf(parameter.getIndex()), args[parameter.getIndex()]); } UnknownFilter unknownFilter = (UnknownFilter) filter; if (method.getName().startsWith(DefaultFilterDescriptorManager.PREFIX_BEGIN)) { unknownFilter.beginUnknwon(id, metadata); } else if (method.getName().startsWith(DefaultFilterDescriptorManager.PREFIX_END)) { unknownFilter.endUnknwon(id, metadata); } else if (method.getName().startsWith(DefaultFilterDescriptorManager.PREFIX_ON)) { unknownFilter.onUnknwon(id, metadata); } } } } }