Package ome.util

Class ContextFilter

  • All Implemented Interfaces:
    Filter
    Direct Known Subclasses:
    ModelMapper, RdfPrinter

    public class ContextFilter
    extends java.lang.Object
    implements Filter
    modified (hierarchical) visitor pattern. See http://c2.com/cgi/wiki?HierarchicalVisitorPattern for more information. (A better name may be "contextual visitor pattern" for graph traversing.) The modifications to Visitor make use of a model graph (here: the ome generated model classes) implementing Filterable. As documented in Filterable, model objects are responsible for calling filter.filter(someField) for all fields and setting the value of that field to the return value of the method call. The Filter itself is responsible for returning a compatible object and (optionally) stepping into objects and keeping up with context. Note: This class is not thread-safe. template method to filter domain objects. The standard idiom is:
     
      if (m != null && hasntSeen(m)){
          enter(m); // Provides context
          addSeen(m); // Prevents looping
          m.acceptFilter(this); // Visits all fields
          exit(m); // Remove from context
      }
    
     
    Implementation notes: - nulls are already "seen"
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map _cache  
      protected java.util.LinkedList _context  
    • Constructor Summary

      Constructors 
      Constructor Description
      ContextFilter()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addSeen​(java.lang.Object o)  
      protected void afterFilter​(java.lang.String fieldId, java.lang.Object o)  
      protected void beforeFilter​(java.lang.String fieldId, java.lang.Object o)  
      java.lang.Object currentContext()  
      protected void doFilter​(java.lang.String fieldId, java.lang.Object o)  
      protected void doFilter​(java.lang.String fieldId, java.util.Collection c)  
      protected void doFilter​(java.lang.String fieldId, Filterable f)  
      boolean enter​(java.lang.Object o)  
      boolean exit​(java.lang.Object o)  
      java.lang.Object filter​(java.lang.String fieldId, java.lang.Object o)
      used when type is unknown.
      java.util.Collection filter​(java.lang.String fieldId, java.util.Collection c)
      iterates over the contents of the collection and filters each.
      java.util.Map filter​(java.lang.String fieldId, java.util.Map m)
      filters both the key and value sets of the map.
      protected ome.util.ContextFilter.Entry filter​(java.lang.String fieldId, ome.util.ContextFilter.Entry entry)
      doesn't return a new entry.
      Filterable filter​(java.lang.String fieldId, Filterable f)  
      protected boolean hasntSeen​(java.lang.Object o)  
      protected void pop​(java.lang.Object o)  
      java.lang.Object previousContext​(int index)  
      protected void push​(java.lang.Object o)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _cache

        protected java.util.Map _cache
      • _context

        protected java.util.LinkedList _context
    • Constructor Detail

      • ContextFilter

        public ContextFilter()
    • Method Detail

      • beforeFilter

        protected void beforeFilter​(java.lang.String fieldId,
                                    java.lang.Object o)
      • doFilter

        protected void doFilter​(java.lang.String fieldId,
                                java.lang.Object o)
      • doFilter

        protected void doFilter​(java.lang.String fieldId,
                                Filterable f)
      • doFilter

        protected void doFilter​(java.lang.String fieldId,
                                java.util.Collection c)
      • afterFilter

        protected void afterFilter​(java.lang.String fieldId,
                                   java.lang.Object o)
      • filter

        public java.util.Collection filter​(java.lang.String fieldId,
                                           java.util.Collection c)
        iterates over the contents of the collection and filters each. Adds itself to the context. This is somewhat dangerous.
        Specified by:
        filter in interface Filter
      • filter

        public java.util.Map filter​(java.lang.String fieldId,
                                    java.util.Map m)
        filters both the key and value sets of the map. Adds itself to the context. Somewhat dangerous.
        Specified by:
        filter in interface Filter
      • filter

        public java.lang.Object filter​(java.lang.String fieldId,
                                       java.lang.Object o)
        used when type is unknown. this is possibly omittable with generics
        Specified by:
        filter in interface Filter
      • filter

        protected ome.util.ContextFilter.Entry filter​(java.lang.String fieldId,
                                                      ome.util.ContextFilter.Entry entry)
        doesn't return a new entry. only changes key and value
      • enter

        public boolean enter​(java.lang.Object o)
      • exit

        public boolean exit​(java.lang.Object o)
      • currentContext

        public java.lang.Object currentContext()
      • previousContext

        public java.lang.Object previousContext​(int index)
      • push

        protected void push​(java.lang.Object o)
      • pop

        protected void pop​(java.lang.Object o)
      • addSeen

        protected void addSeen​(java.lang.Object o)
      • hasntSeen

        protected boolean hasntSeen​(java.lang.Object o)