Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * JBoss, Home of Professional Open Source.
   * Copyright 2009, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site:
Setter based resource injection. To access a resource a developer declares a setter method and annotates it as being a resource reference. The name and type of resource maybe inferred by inspecting the method declaration if necessary. The name of the resource, if not declared, is the name of the JavaBeans property as determined starting from the name of the setter method in question. The setter method must follow the standard JavaBeans convention - name starts with a 'set', void return type and only one parameter. Additionally, the type of the parameter must be compatible with the type specified as a property of the Resource if present.

Richard Opalka
 public final class ResourceMethodFinder

Parameter type to accept/ignore.
    private final Class<?> accept;
If accept field is not null then:
  • true means include only methods with accept parameter,
  • false means exclude all methods with accept parameter
    private final boolean include;


accept filtering class
include whether include/exclude filtering class
    public ResourceMethodFinder(final Class<?> acceptboolean include)
       this. = accept;
       this. = include;
    public void validate(Method method)
       // Ensure all method preconditions
       Class<Resourceannotation = getAnnotation();
    public boolean matches(Method method)
       final boolean matches = super.matches(method);
       if (matches)
          // processing @Resource annotated method
          if (this. != null)
            // filtering
            if (method.getParameterTypes().length == 1)
               final Class<?> param = method.getParameterTypes()[0];
               final boolean parameterMatch = this..equals(param);
               // include/exclude filtering
               return this. ? parameterMatch : !parameterMatch;
      return matches;
New to GrepCode? Check out our FAQ X