001: /*
002: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package de.odysseus.calyxo.control.conf.impl;
017:
018: import java.net.URL;
019:
020: import org.apache.commons.digester.Digester;
021: import org.apache.commons.digester.Rule;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import de.odysseus.calyxo.base.ModuleContext;
026: import de.odysseus.calyxo.base.conf.ConfigException;
027: import de.odysseus.calyxo.base.conf.impl.RootConfigImpl;
028: import de.odysseus.calyxo.base.conf.impl.RootConfigImplParser;
029: import de.odysseus.calyxo.control.conf.ControlConfig;
030:
031: /**
032: * Control configuration parser.
033: *
034: * @author Christoph Beck
035: */
036: public class ControlConfigParser extends RootConfigImplParser {
037: private static final Log log = LogFactory
038: .getLog(ControlConfigParser.class);
039:
040: private static final SchemaResolver SCHEMA_RESOLVER = new SchemaResolver(
041: "/de/odysseus/calyxo/control/conf/impl/calyxo-control-config.xsd");
042:
043: private static final DTDResolver DTD_RESOLVER = new DTDResolver(
044: "-//Odysseus Software GmbH//DTD Calyxo Control 0.9//EN",
045: "/de/odysseus/calyxo/control/conf/impl/calyxo-control-config.dtd");
046:
047: private final Rule exceptionId = new UniqueIdRule("ex", "id");
048:
049: /**
050: * Constructor.
051: */
052: public ControlConfigParser(ModuleContext context) {
053: super (context);
054: }
055:
056: /*
057: * (non-Javadoc)
058: * @see de.odysseus.calyxo.base.conf.impl.RootConfigImplParser#createRoot()
059: */
060: protected RootConfigImpl createRoot() {
061: return new ControlConfigImpl();
062: }
063:
064: /* (non-Javadoc)
065: * @see org.apache.commons.digester.RuleSet#addRuleInstances(org.apache.commons.digester.Digester)
066: */
067: public void addRuleInstances(Digester digester) {
068: digester
069: .setRuleNamespaceURI("http://calyxo.odysseus.de/xml/ns/control");
070:
071: // Handle exceptions element
072: digester.addObjectCreate("*/exception-handlers",
073: ExceptionHandlersConfigImpl.class.getName());
074: digester.addSetProperties("*/exception-handlers");
075: digester.addSetNext("*/exception-handlers",
076: "setExceptionsConfig",
077: ExceptionHandlersConfigImpl.class.getName());
078:
079: // Handle exception elements
080: digester.addObjectCreate("*/exception-handler",
081: ExceptionHandlerConfigImpl.class.getName());
082: digester.addSetProperties("*/exception-handler", "class",
083: "className");
084: digester.addRule("*/exception-handler", exceptionId);
085: digester.addSetNext("*/exception-handler", "add",
086: ExceptionHandlerConfigImpl.class.getName());
087:
088: // Handle dispatches element
089: digester.addObjectCreate("*/dispatches",
090: DispatchesConfigImpl.class.getName());
091: digester.addSetProperties("*/dispatches");
092: digester.addSetNext("*/dispatches", "setDispatchesConfig",
093: DispatchesConfigImpl.class.getName());
094:
095: // Handle actions element
096: digester.addObjectCreate("*/actions", ActionsConfigImpl.class
097: .getName());
098: digester.addSetProperties("*/actions");
099: digester.addSetNext("*/actions", "setActionsConfig",
100: ActionsConfigImpl.class.getName());
101:
102: // Handle action elements
103: digester.addObjectCreate("*/action", ActionConfigImpl.class
104: .getName());
105: digester.addSetProperties("*/action", "class", "className");
106: digester.addSetNext("*/action", "add", ActionConfigImpl.class
107: .getName());
108:
109: // Handle params elements
110: digester.addObjectCreate("*/filter", FilterConfigImpl.class
111: .getName());
112: digester.addSetProperties("*/filter", "class", "className");
113: digester.addSetNext("*/filter", "add", FilterConfigImpl.class
114: .getName());
115:
116: // Handle dispatch elements
117: digester.addObjectCreate("*/dispatch", DispatchConfigImpl.class
118: .getName());
119: digester.addSetProperties("*/dispatch");
120: digester.addSetNext("*/dispatch", "add",
121: DispatchConfigImpl.class.getName());
122:
123: // Handle plugins element
124: digester.addObjectCreate("*/plugins", PluginsConfigImpl.class
125: .getName());
126: digester.addSetProperties("*/plugins");
127: digester.addSetNext("*/plugins", "setPluginsConfig",
128: PluginsConfigImpl.class.getName());
129:
130: // Handle plugin elements
131: digester.addObjectCreate("*/plugin", PluginConfigImpl.class
132: .getName());
133: digester.addSetProperties("*/plugin", "class", "className");
134: digester.addSetNext("*/plugin", "add", PluginConfigImpl.class
135: .getName());
136:
137: // Handle params elements
138: digester.addObjectCreate("*/params", ParamsConfigImpl.class
139: .getName());
140: digester.addSetProperties("*/params");
141: digester.addSetNext("*/params", "add", ParamsConfigImpl.class
142: .getName());
143:
144: // Handle param elements
145: digester.addObjectCreate("*/param", ParamConfigImpl.class
146: .getName());
147: digester.addSetProperties("*/param");
148: digester.addSetNext("*/param", "add", ParamConfigImpl.class
149: .getName());
150: }
151:
152: /**
153: * Parse control configuration files..
154: * @param urls pointing to xml configuration files
155: * @return Control configuration
156: * @throws ConfigException on error during parse or initialization
157: */
158: public ControlConfig parse(URL[] urls) throws ConfigException {
159: return (ControlConfig) parseAll(urls);
160: }
161:
162: /* (non-Javadoc)
163: * @see de.odysseus.calyxo.base.conf.impl.RootConfigImplParser#getDtdResolver()
164: */
165: protected DTDResolver getDtdResolver() {
166: return DTD_RESOLVER;
167: }
168:
169: /**
170: * Answer <code>null</code>
171: * @see de.odysseus.calyxo.base.conf.impl.RootConfigImplParser#getSchemaResolver()
172: */
173: protected SchemaResolver getSchemaResolver() {
174: return SCHEMA_RESOLVER;
175: }
176:
177: /*
178: * (non-Javadoc)
179: * @see de.odysseus.calyxo.base.conf.impl.RootConfigImplParser#getLog()
180: */
181: protected Log getLog() {
182: return log;
183: }
184: }
|