01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package de.schlund.pfixxml.config.impl;
20:
21: import java.util.HashMap;
22: import java.util.Map;
23:
24: import org.xml.sax.Attributes;
25: import org.xml.sax.SAXException;
26:
27: import de.schlund.pfixcore.workflow.ContextInterceptor;
28:
29: public class ContextInterceptorRule extends CheckedRule {
30:
31: private ContextXMLServletConfigImpl config;
32: private String type;
33:
34: public ContextInterceptorRule(ContextXMLServletConfigImpl config,
35: String type) {
36: this .config = config;
37: if (!(type.equals("start") || type.equals("end"))) {
38: throw new IllegalArgumentException("\"" + type
39: + "\" is not a valid context interceptor type!");
40: }
41: this .type = type;
42: }
43:
44: public void begin(String namespace, String name,
45: Attributes attributes) throws Exception {
46: check(namespace, name, attributes);
47: // Use properties until interceptors have been added to XSD
48: String classname = attributes.getValue("class");
49: Class<?> clazz;
50: try {
51: clazz = Class.forName(classname);
52: } catch (ClassNotFoundException e) {
53: throw new SAXException("Could not load interceptor class "
54: + classname, e);
55: }
56: if (!ContextInterceptor.class.isAssignableFrom(clazz)) {
57: throw new SAXException("Context interceptor " + clazz
58: + " does not implmement "
59: + ContextInterceptor.class + " interface!");
60: }
61: if (type.equals("start")) {
62: config.getContextConfig().addStartInterceptor(
63: clazz.asSubclass(ContextInterceptor.class));
64: }
65: if (type.equals("end")) {
66: config.getContextConfig().addEndInterceptor(
67: clazz.asSubclass(ContextInterceptor.class));
68: }
69: }
70:
71: protected Map<String, Boolean> wantsAttributes() {
72: HashMap<String, Boolean> atts = new HashMap<String, Boolean>();
73: atts.put("class", true);
74: return atts;
75: }
76:
77: }
|