Source Code Cross Referenced for FilterList.java in  » Testing » jacareto » jacareto » filter » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jacareto » jacareto.filter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.system.Customization;
027:        import jacareto.system.Environment;
028:        import jacareto.system.Language;
029:        import jacareto.toolkit.EnhancedHashtable;
030:
031:        import org.apache.log4j.Logger;
032:
033:        import java.lang.reflect.Constructor;
034:        import java.lang.reflect.InvocationTargetException;
035:
036:        import java.util.Enumeration;
037:
038:        import javax.swing.DefaultListModel;
039:
040:        /**
041:         * The list of filters.
042:         *
043:         * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
044:         * @version 1.0
045:         */
046:        public class FilterList extends DefaultListModel {
047:            /** The env. */
048:            private Environment env;
049:
050:            /**
051:             * Creates a new filter list with the filters contained in the customization map given by the
052:             * customization key and the given class loader which should load the filter classes.
053:             *
054:             * @param env the environment
055:             * @param customizationKey the customization key
056:             * @param classLoader the classLoader
057:             */
058:            public FilterList(Environment env, String customizationKey,
059:                    ClassLoader classLoader) {
060:                this .env = env;
061:
062:                if (customizationKey != null) {
063:                    loadFilters(customizationKey, classLoader);
064:                }
065:            }
066:
067:            /**
068:             * Creates a new filter list with the filters contained in the customization map given by the
069:             * customization key and the default class loader
070:             *
071:             * @param env the environment
072:             * @param customizationKey the customization key
073:             */
074:            public FilterList(Environment env, String customizationKey) {
075:                this (env, customizationKey, null);
076:            }
077:
078:            /**
079:             * Creates an empty filter list.
080:             *
081:             * @param env the environment
082:             */
083:            public FilterList(Environment env) {
084:                this (env, null);
085:            }
086:
087:            /**
088:             * Loads the filters from the customization with the default class loader
089:             *
090:             * @param customizationKey DOCUMENT ME!
091:             */
092:            private void loadFilters(String customizationKey) {
093:                loadClassFilters(customizationKey + ".ClassFilters");
094:                loadNonClassFilters(customizationKey + ".NonClassFilters");
095:            }
096:
097:            /**
098:             * Loads the filters from the customization with the specified class loader.
099:             *
100:             * @param customizationKey DOCUMENT ME!
101:             * @param classLoader DOCUMENT ME!
102:             */
103:            private void loadFilters(String customizationKey,
104:                    ClassLoader classLoader) {
105:                loadClassFilters(customizationKey + ".ClassFilters",
106:                        classLoader);
107:                loadNonClassFilters(customizationKey + ".NonClassFilters",
108:                        classLoader);
109:            }
110:
111:            /**
112:             * Adds an element sorted.
113:             *
114:             * @param element DOCUMENT ME!
115:             */
116:            public void addSorted(Object element) {
117:                boolean inserted = false;
118:
119:                for (int i = 0; i < size(); i++) {
120:                    if (getElementAt(i).toString()
121:                            .compareTo(element.toString()) >= 0) {
122:                        insertElementAt(element, i);
123:                        inserted = true;
124:
125:                        break;
126:                    }
127:                }
128:
129:                if (!inserted) {
130:                    addElement(element);
131:                }
132:            }
133:
134:            /**
135:             * Loads the class filters from the customization with the default class loader.
136:             *
137:             * @param customizationKey DOCUMENT ME!
138:             */
139:            private void loadClassFilters(String customizationKey) {
140:                loadClassFilters(customizationKey, null);
141:            }
142:
143:            /**
144:             * Loads the class filters from the customization with the given class loader
145:             *
146:             * @param customizationKey DOCUMENT ME!
147:             * @param classLoader DOCUMENT ME!
148:             */
149:            private void loadClassFilters(String customizationKey,
150:                    ClassLoader classLoader) {
151:                Logger logger = env.getLogger();
152:                Language language = env.getLanguage();
153:                Customization customization = env.getCustomization();
154:
155:                if (classLoader == null) {
156:                    classLoader = ClassLoader.getSystemClassLoader();
157:                }
158:
159:                try {
160:                    // some reflection instances
161:                    Class classFilterClass = Class.forName(
162:                            "jacareto.filter.ClassFilter", true, classLoader);
163:                    Class[] parameterTypes = new Class[3];
164:                    parameterTypes[0] = Class.forName(
165:                            "jacareto.system.Environment", true, classLoader);
166:                    parameterTypes[1] = Class.forName("java.lang.String", true,
167:                            classLoader);
168:                    parameterTypes[2] = Class.forName("java.lang.ClassLoader",
169:                            true, classLoader);
170:
171:                    Object[] parameters = new Object[3];
172:                    Constructor filterConstructor = classFilterClass
173:                            .getConstructor(parameterTypes);
174:
175:                    parameters[0] = env;
176:                    parameters[2] = classLoader;
177:
178:                    // load the map of class filters
179:                    EnhancedHashtable classFiltersMap = customization.getMap(
180:                            customizationKey, new EnhancedHashtable());
181:                    Enumeration enumeration = classFiltersMap.keys();
182:
183:                    while (enumeration.hasMoreElements()) {
184:                        try {
185:                            parameters[1] = (String) enumeration.nextElement();
186:                            logger
187:                                    .debug(language
188:                                            .getString("Filters.FilterList.Msg.LoadingClassFilter")
189:                                            + " " + parameters[1]);
190:
191:                            Object filterToAdd = filterConstructor
192:                                    .newInstance(parameters);
193:
194:                            if (filterToAdd != null) {
195:                                addSorted(filterToAdd);
196:                            }
197:                        } catch (InstantiationException inst) {
198:                            logger
199:                                    .debug(
200:                                            language
201:                                                    .getString("Filters.FilterList.Error.Construction"),
202:                                            inst);
203:                        } catch (IllegalAccessException ill) {
204:                            logger
205:                                    .debug(
206:                                            language
207:                                                    .getString("Filters.FilterList.Error.Construction"),
208:                                            ill);
209:                        } catch (IllegalArgumentException ila) {
210:                            logger
211:                                    .debug(
212:                                            language
213:                                                    .getString("Filters.FilterList.Error.Construction"),
214:                                            ila);
215:                        } catch (InvocationTargetException inv) {
216:                            logger
217:                                    .debug(
218:                                            language
219:                                                    .getString("Filters.FilterList.Error.Construction"),
220:                                            inv);
221:                        }
222:                    }
223:                } catch (ClassNotFoundException c) {
224:                    logger
225:                            .error(
226:                                    language
227:                                            .getString("Filters.FilterList.Error.MissingClass"),
228:                                    c);
229:                } catch (NoSuchMethodException n) {
230:                    logger
231:                            .error(
232:                                    language
233:                                            .getString("Filters.FilterList.Error.MissingConstructor"),
234:                                    n);
235:                }
236:            }
237:
238:            /**
239:             * Loads the filters from the customization which are no classfilters with the default class
240:             * loader.
241:             *
242:             * @param customizationKey DOCUMENT ME!
243:             */
244:            private void loadNonClassFilters(String customizationKey) {
245:                loadNonClassFilters(customizationKey, null);
246:            }
247:
248:            /**
249:             * Loads the filters from the customization which are no classfilters with the given class
250:             * loader.
251:             *
252:             * @param customizationKey DOCUMENT ME!
253:             * @param classLoader DOCUMENT ME!
254:             */
255:            private void loadNonClassFilters(String customizationKey,
256:                    ClassLoader classLoader) {
257:                Logger logger = env.getLogger();
258:                Language language = env.getLanguage();
259:                Customization customization = env.getCustomization();
260:
261:                if (classLoader == null) {
262:                    classLoader = ClassLoader.getSystemClassLoader();
263:                }
264:
265:                try {
266:                    // some reflection instances
267:                    Class filterClass = Class.forName("jacareto.filter.Filter",
268:                            true, classLoader);
269:                    Class[] parameterTypes = new Class[1];
270:                    parameterTypes[0] = Class.forName(
271:                            "jacareto.system.Environment", true, classLoader);
272:
273:                    Object[] parameters = new Object[1];
274:                    parameters[0] = env;
275:
276:                    // load the map of filters
277:                    EnhancedHashtable filtersMap = customization.getMap(
278:                            customizationKey, new EnhancedHashtable());
279:                    Enumeration enumeration = filtersMap.keys();
280:
281:                    while (enumeration.hasMoreElements()) {
282:                        try {
283:                            String mapFilterClassName = (String) enumeration
284:                                    .nextElement();
285:                            Class mapFilterClass = Class.forName(
286:                                    mapFilterClassName, true, classLoader);
287:
288:                            if (!filterClass.isAssignableFrom(mapFilterClass)) {
289:                                throw new InstantiationException();
290:                            }
291:
292:                            Constructor filterConstructor = mapFilterClass
293:                                    .getConstructor(parameterTypes);
294:                            logger
295:                                    .debug(language
296:                                            .getString("Filters.FilterList.Msg.Loading")
297:                                            + " " + mapFilterClassName);
298:                            addSorted(filterConstructor.newInstance(parameters));
299:                        } catch (InstantiationException inst) {
300:                            logger
301:                                    .error(
302:                                            language
303:                                                    .getString("Filters.FilterList.Error.Construction"),
304:                                            inst);
305:                        } catch (IllegalAccessException ill) {
306:                            logger
307:                                    .error(
308:                                            language
309:                                                    .getString("Filters.FilterList.Error.Construction"),
310:                                            ill);
311:                        } catch (IllegalArgumentException ila) {
312:                            logger
313:                                    .error(
314:                                            language
315:                                                    .getString("Filters.FilterList.Error.Construction"),
316:                                            ila);
317:                        } catch (InvocationTargetException inv) {
318:                            logger
319:                                    .error(
320:                                            language
321:                                                    .getString("Filters.FilterList.Error.Construction"),
322:                                            inv);
323:                        }
324:                    }
325:                } catch (ClassNotFoundException c) {
326:                    logger
327:                            .error(
328:                                    language
329:                                            .getString("Filters.FilterList.Error.MissingClass"),
330:                                    c);
331:                } catch (NoSuchMethodException n) {
332:                    logger
333:                            .error(
334:                                    language
335:                                            .getString("Filters.FilterList.Error.MissingConstructor"),
336:                                    n);
337:                }
338:            }
339:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.