01: /*
02: * transformica 2
03: * Code generator
04: * Copyright (C) 2004 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.pavelvlasov.com/pv/content/menu.show@id=products.transformica.html
21: * e-Mail: support@hammurapi.biz
22: */
23: package biz.hammurapi.transformica;
24:
25: import java.io.Writer;
26: import java.util.HashSet;
27: import java.util.Set;
28:
29: import org.apache.tools.ant.BuildException;
30:
31: import biz.hammurapi.util.Visitor;
32:
33: /**
34: * @author Pavel Vlasov
35: * @version $Revision: 1.1 $
36: */
37: public class IncludeVisitor implements Visitor {
38: public static final Set RESERVED_NAMES = new HashSet();
39:
40: static {
41: RESERVED_NAMES.add("element");
42: RESERVED_NAMES.add("session");
43: RESERVED_NAMES.add("jxpath");
44: RESERVED_NAMES.add("ognl");
45: }
46:
47: public static void validateEntryName(String name)
48: throws BuildException {
49: if (RESERVED_NAMES.contains(name)) {
50: throw new BuildException("'" + name
51: + "' context entry name is reserved.");
52: }
53: }
54:
55: private TransformSession session;
56: private Writer writer;
57: private Channel channel;
58:
59: /**
60: *
61: */
62: public IncludeVisitor(TransformSession session, Channel channel,
63: Writer writer) {
64: this .session = session;
65: this .channel = channel;
66: this .writer = writer;
67: }
68:
69: public boolean visit(Object element) {
70: session.verbose("Including "
71: + Channel.getObjectIdString(element));
72:
73: try {
74: if (channel.getCompositeAcceptor().accept(element)) {
75: channel.process(element, writer);
76: }
77: } catch (TransformicaException e) {
78: session.error("Exception " + e + " while including "
79: + Channel.getObjectIdString(element));
80: throw new TransformicaRuntimeException(e);
81: }
82: return true;
83: }
84: }
|