01: /*
02: * XML 2 Java Binding (X2JB) - the excellent Java tool.
03: * Copyright 2007, by Richard Opalka.
04: *
05: * This is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU Lesser General Public License as
07: * published by the Free Software Foundation; either version 2.1 of
08: * the License, or (at your option) any later version.
09: *
10: * This software is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this software; if not see the FSF site:
17: * http://www.fsf.org/ and search for the LGPL License document there.
18: */
19: package webapp;
20:
21: import org.w3c.dom.Element;
22: import org.w3c.dom.Node;
23: import org.w3c.dom.Text;
24: import org.x2jb.bind.BindingException;
25: import org.x2jb.bind.handler.ElementHandler;
26:
27: /**
28: * Web app sample
29: *
30: * @author <a href="mailto:richard_opalka@yahoo.com">Richard Opalka</a>
31: * @version 1.0
32: */
33: public final class Handler implements ElementHandler {
34:
35: public Object bind(Element element, Class clazz)
36: throws BindingException {
37: if (clazz.equals(Dispatcher.class)) {
38: return Dispatcher.valueOf(getTextContent(element));
39: }
40:
41: throw new BindingException("Handler doesn't support '"
42: + clazz.getName() + "' class");
43: }
44:
45: private static String getTextContent(Element e)
46: throws BindingException {
47: Node childNode = e.getFirstChild();
48: if ((childNode == null) || (!(childNode instanceof Text))) {
49: throw new BindingException(
50: "Text node expected but not found");
51: } else {
52: return ((Text) childNode).getData();
53: }
54: }
55:
56: public final Object getDefault(Class clazz) throws BindingException {
57: return null;
58: }
59:
60: }
|