SimpleNameInterceptorFilter.java :  » Web-Services » crispy » net » sf » crispy » filter » Java Open Source

Java Open Source » Web Services » crispy 
crispy » net » sf » crispy » filter » SimpleNameInterceptorFilter.java
package net.sf.crispy.filter;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

import net.sf.crispy.InterceptorFilterContext;

public class SimpleNameInterceptorFilter extends AbstractInterceptorFilter {

  private Set filterObjects = null;

  
  public SimpleNameInterceptorFilter(Class pvFilterClass) {
    filterObjects = new HashSet(1);
    filterObjects.add(pvFilterClass.getName());
    filterObjectsType = FILTER_TYPE_CLASS;
  }

  public SimpleNameInterceptorFilter(Class pvFilterClass[]) {
    filterObjects = new HashSet (pvFilterClass.length);
    filterObjectsType = FILTER_TYPE_CLASS;
    for (int i = 0; i < pvFilterClass.length; i++) {
      filterObjects.add(pvFilterClass[i].getName());  
    }      
  }
  
  public SimpleNameInterceptorFilter(Method pvFilterMethod) {
    filterObjects = new HashSet(1);
    filterObjects.add(pvFilterMethod.getName());
    filterObjectsType = FILTER_TYPE_METHOD;
  }

  public SimpleNameInterceptorFilter(Method pvFilterMethod[]) {
    filterObjects = new HashSet (pvFilterMethod.length);
    filterObjectsType = FILTER_TYPE_METHOD;
    for (int i = 0; i < pvFilterMethod.length; i++) {
      filterObjects.add(pvFilterMethod[i].getName());  
    }      
  }

  public SimpleNameInterceptorFilter(Throwable pvFilterThrowable) {
    filterObjects = new HashSet(1);
    filterObjects.add(pvFilterThrowable.getClass().getName());
    filterObjectsType = FILTER_TYPE_THROWABLE;
  }

  public SimpleNameInterceptorFilter(Throwable pvFilterThrowable[]) {
    filterObjects = new HashSet (pvFilterThrowable.length);
    filterObjectsType = FILTER_TYPE_THROWABLE;
    for (int i = 0; i < pvFilterThrowable.length; i++) {
      filterObjects.add(pvFilterThrowable[i].getClass().getName());  
    }      
  }
  

  public SimpleNameInterceptorFilter(String pvFilterNames, int pvFilterType) {
    filterObjects = new HashSet(1);
    filterObjects.add(pvFilterNames);
    filterObjectsType = pvFilterType;
  }

  public SimpleNameInterceptorFilter(String pvFilterNames[], int pvFilterType) {
    filterObjects = new HashSet (pvFilterNames.length);
    filterObjectsType = pvFilterType;
    for (int i = 0; i < pvFilterNames.length; i++) {
      filterObjects.add(pvFilterNames[i]);  
    }      
  }
  

  
  public boolean accept(InterceptorFilterContext pvContext) {
    boolean ret = false;
    switch (filterObjectsType) {
      case FILTER_TYPE_METHOD:
        if (pvContext.getMethod() != null) {
          ret = filterObjects.contains(pvContext.getMethod().getName());
        }
        break;
      case FILTER_TYPE_CLASS:
        if (pvContext.getInvocationClass() != null) {
          ret = filterObjects.contains(pvContext.getInvocationClass().getName());
        }
        break;
      case FILTER_TYPE_THROWABLE:
        if (pvContext.getThrowable() != null) {
          ret = filterObjects.contains(pvContext.getThrowable().getClass().getName());
        }
        break;
      default:
        ret = false;
        break;
    }
    return negate(ret);
  }
  

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.