View Javadoc

1   /*
2    * $Id: ElementTypeVisitor.java,v 1.5 2004/09/02 20:45:52 jlerner Exp $
3    * Created on May 21, 2004
4    *
5    * Copyright (c) 1999-2004, BBN Technologies, LLC.
6    * All rights reserved.
7    * http://www.daml.org/legal/opensource/bbn_license.html
8    */
9   
10  package com.bbn.swede.core;
11  
12  import java.util.List;
13  
14  /***
15   * An OWL element visitor for collecting OWL resources of a specific type.
16   * The visit(IOWLElement) method simply checks the current element against the
17   * type specified at construction and appends it to the list if it matches.
18   * @author tself
19   */
20  public class ElementTypeVisitor implements IOWLElementVisitor
21  {
22     private Class _c;
23     private List _list;
24  
25     /***
26      * Constructs a new ElementTypeVisitor.  Elements that match the specified
27      * type will be appended to the supplied list.
28      * @param c The Java class to match against
29      * @param list The list to populate with matching elements
30      */
31     public ElementTypeVisitor(Class c, List list)
32     {
33        _list = list;
34        _c = c;
35     }
36  
37     /* (non-Javadoc)
38      * @see com.bbn.swede.core.IOWLElementVisitor#visit(com.bbn.swede.core.IOWLElement)
39      */
40     public boolean visit(IOWLElement element)
41     {
42        if (_list == null)
43        {
44           return false;
45        }
46        if (_c.isInstance(element))
47        {
48           _list.add(element);
49        }
50        return true;
51     }
52  }