1
2
3
4
5
6
7
8 package nl.tudelft.simulation.introspection;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 /***
14 * The AbstractSupressIntrospector.
15 * <p>
16 * (c) copyright 2002-2005-2004 <a href="http://www.simulation.tudelft.nl">Delft
17 * University of Technology </a>, the Netherlands. <br>
18 * See for project information <a
19 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
20 * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
21 * General Public License (LGPL) </a>, no warranty.
22 *
23 * @author <a
24 * href="http://web.eur.nl/fbk/dep/dep1/Introduction/Staff/People/Lang">Niels
25 * Lang </a><a href="http://www.peter-jacobs.com/index.htm">Peter
26 * Jacobs </a>
27 * @version 1.1 Apr 15, 2004
28 * @since 1.5
29 */
30 public abstract class AbstractSuppressIntrospector implements Introspector
31 {
32 /*** the parent introspector */
33 protected Introspector parent;
34
35 /***
36 * Constructor for AbstractSuppressIntrospector.
37 *
38 * @param parent the parent introspector
39 */
40 public AbstractSuppressIntrospector(final Introspector parent)
41 {
42 super();
43 this.parent = parent;
44 }
45
46 /***
47 * @see nl.tudelft.simulation.introspection.Introspector#getProperties(Object)
48 */
49 public Property[] getProperties(final Object arg0)
50 {
51 Property[] original = this.parent.getProperties(arg0);
52 List<Property> result = new ArrayList<Property>();
53 for (int i = 0; i < original.length; i++)
54 {
55 if (!this.suppress(original[i].getType())
56 && !this.suppress(original[i].getName()))
57 {
58 result.add(original[i]);
59 }
60 }
61 return result.toArray(new Property[0]);
62 }
63
64 /***
65 * @see nl.tudelft.simulation.introspection.Introspector#getPropertyNames(Object)
66 */
67 public String[] getPropertyNames(final Object arg0)
68 {
69 Property[] properties = this.getProperties(arg0);
70 String[] result = new String[properties.length];
71 for (int i = 0; i < properties.length; i++)
72 {
73 result[i] = properties[i].getName();
74 }
75 return result;
76 }
77
78 /***
79 * @see nl.tudelft.simulation.introspection.Introspector#getProperty(Object,
80 * String)
81 */
82 public Property getProperty(final Object arg0, final String arg1)
83 {
84 Property[] properties = this.getProperties(arg0);
85 for (int i = 0; i < properties.length; i++)
86 {
87 if (properties[i].getName().equals(arg1))
88 {
89 return properties[i];
90 }
91 }
92 return null;
93 }
94
95 /***
96 * Method suppress.
97 *
98 * @param type the type of tyhe class
99 * @return boolean whether to supress
100 */
101 protected boolean suppress(final Class type)
102 {
103 if (type.equals(Class.class))
104 {
105 return true;
106 }
107 return false;
108 }
109
110 /***
111 * Method suppress.
112 *
113 * @param propertyName the propertyName
114 * @return whether to supress
115 */
116 protected abstract boolean suppress(final String propertyName);
117 }