001: /*
002: * Copyright (C) 2004 TiongHiang Lee
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Email: thlee@onemindsoft.org
019: */
020:
021: package org.onemind.jxp.config;
022:
023: import java.util.HashMap;
024: import java.util.Map;
025: import org.onemind.commons.java.datastructure.XmlPropertyElementDigester;
026: import org.onemind.commons.java.util.ObjectUtils;
027: import org.onemind.commons.java.xml.digest.*;
028: import org.onemind.jxp.*;
029: import org.xml.sax.Attributes;
030: import org.xml.sax.SAXException;
031:
032: /**
033: * JxpConfigDigester digest jxp configuration
034: * @author TiongHiang Lee (thlee@onemindsoft.org)
035: */
036: public class JxpConfigDigester extends AbstractElementCreatorDigester
037: implements ElementListener {
038:
039: /** the processor **/
040: private JxpProcessor _processor;
041:
042: /** the environment **/
043: private Map _env;
044:
045: /** do method statistics **/
046: private boolean _doMethodStats;
047:
048: /**
049: * Constructor
050: */
051: public JxpConfigDigester() {
052: super ("jxp");
053: }
054:
055: /**
056: * {@inheritDoc}
057: */
058: public void startDigest(SaxDigesterHandler handler, Attributes attr)
059: throws SAXException {
060: _doMethodStats = ObjectUtils.toBool(attr
061: .getValue("methodstats"), false);
062: _env = new HashMap();
063: XmlPropertyElementDigester pDig = new XmlPropertyElementDigester(
064: "var", _env);
065: handler.addSubDigester("env", pDig);
066: String pageSourcePath = "pagesources";
067: MultiSourceDigester dig = new MultiSourceDigester();
068: dig.addListener(this );
069: handler.addSubDigester(pageSourcePath, dig);
070: FileSourceDigester fdig = new FileSourceDigester();
071: fdig.addListener(this );
072: handler.addSubDigester(pageSourcePath, fdig);
073: StreamSourceDigester sdig = new StreamSourceDigester();
074: sdig.addListener(this );
075: handler.addSubDigester(pageSourcePath, sdig);
076: }
077:
078: /**
079: * {@inheritDoc}
080: */
081: public void objectCreated(Object obj) {
082: _processor = new JxpProcessor(new JxpContext(
083: (JxpPageSource) obj, _env));
084: _processor.setDoMethodStats(_doMethodStats);
085: setCreatedElement(_processor);
086: }
087:
088: /**
089: * Return the created processor
090: * @return the processor
091: */
092: public JxpProcessor getProcessor() {
093: return _processor;
094: }
095:
096: /**
097: * {@inheritDoc}
098: */
099: public void endDigest(SaxDigesterHandler handler)
100: throws SAXException {
101: if (_processor == null) {
102: throw new SAXException(
103: "Jxp processor config is missing in the config");
104: }
105: }
106: }
|