001package org.biopax.paxtools.controller; 002 003import org.biopax.paxtools.model.BioPAXElement; 004import org.biopax.paxtools.util.ClassFilterSet; 005import org.biopax.paxtools.util.IllegalBioPAXArgumentException; 006 007import java.util.Set; 008 009/** 010 * This class is a decorating property accessor that filters values with a given class. It is used, for example, to 011 * implement restrictions for pattern editors. 012 */ 013public class FilteredPropertyAccessor<D extends BioPAXElement, R> extends DecoratingPropertyAccessor<D,R> 014{ 015 private Class filter; 016 017 private FilteredPropertyAccessor(PropertyAccessor<D, R> impl, Class filter) 018 { 019 super(impl); 020 this.filter=filter; 021 } 022 023 @Override public Set<? extends R> getValueFromBean(D bean) throws IllegalBioPAXArgumentException 024 { 025 return new ClassFilterSet(impl.getValueFromBean(bean), filter); 026 } 027 028 /** 029 * FactoryMethod that creates a filtered property accessor by decorating a given accessor with a class filter. 030 * @param pa to be decorated 031 * @param filter Class to be filtered, must extend from R. 032 * @param <D> Domain of the original accessor 033 * @param <R> Range of the original accessor 034 * @return A filtered accessor. 035 */ 036 public static <D extends BioPAXElement, R> PropertyAccessor<D,R> create(PropertyAccessor<D,R> pa, 037 Class filter) 038 { 039 return new FilteredPropertyAccessor<D, R>(pa, filter); 040 } 041}