001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.filter;
025:
026: import jacareto.struct.StructureElement;
027: import jacareto.system.Environment;
028:
029: /**
030: * A structure element matches this filter if it is of a special class.
031: *
032: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
033: * @version 1.0
034: */
035: public class ClassFilter extends Filter {
036: /** The class name. */
037: private String className;
038:
039: /** The class for matching tests. */
040: private Class matchingClass;
041:
042: /** The class loader which loads the filter class. */
043: private ClassLoader classLoader;
044:
045: /**
046: * Creates a new class filter with the default class loader.
047: *
048: * @param env the environment
049: * @param className the classname of structure elements which match the filter
050: *
051: * @throws ClassNotFoundException DOCUMENT ME!
052: */
053: public ClassFilter(Environment env, String className)
054: throws ClassNotFoundException {
055: this (env, className, ClassLoader.getSystemClassLoader());
056: }
057:
058: /**
059: * Creates a new class filter with the specified class loader.
060: *
061: * @param env the environment
062: * @param className the classname of structure elements which match the filter
063: * @param classLoader DOCUMENT ME!
064: *
065: * @throws ClassNotFoundException DOCUMENT ME!
066: */
067: public ClassFilter(Environment env, String className,
068: ClassLoader classLoader) throws ClassNotFoundException {
069: super (env);
070: setClassLoader(classLoader);
071: setClassName(className);
072: }
073:
074: /**
075: * Sets the classname.
076: *
077: * @param className DOCUMENT ME!
078: *
079: * @throws ClassNotFoundException DOCUMENT ME!
080: */
081: public void setClassName(String className)
082: throws ClassNotFoundException {
083: this .matchingClass = null;
084: this .className = className;
085: this .matchingClass = Class
086: .forName(className, true, classLoader);
087: }
088:
089: /**
090: * Returns the name.
091: *
092: * @return DOCUMENT ME!
093: */
094: public String getName() {
095: return language.getString("Filters.ClassFilter.Names."
096: + className);
097: }
098:
099: /**
100: * Returns the classname.
101: *
102: * @return DOCUMENT ME!
103: */
104: public String getClassName() {
105: return className;
106: }
107:
108: /**
109: * Sets the class loader.
110: *
111: * @param classLoader DOCUMENT ME!
112: */
113: public void setClassLoader(ClassLoader classLoader) {
114: this .classLoader = classLoader;
115: }
116:
117: /**
118: * Returns <code>true</code> when a given structure elements is of the class specified by the
119: * classname
120: *
121: * @param element DOCUMENT ME!
122: *
123: * @return DOCUMENT ME!
124: */
125: public boolean matches(StructureElement element) {
126: return (matchingClass != null)
127: && matchingClass.isInstance(element);
128: }
129: }
|