001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE 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
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package de.schlund.pfixxml.config.impl;
020:
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: import org.xml.sax.Attributes;
025: import org.xml.sax.SAXException;
026:
027: import de.schlund.pfixcore.generator.IWrapper;
028: import de.schlund.pfixxml.config.ContextXMLServletConfig;
029:
030: public class PagerequestInputInterfaceRule extends CheckedRule {
031: public PagerequestInputInterfaceRule(ContextXMLServletConfig config) {
032: }
033:
034: public void begin(String namespace, String name,
035: Attributes attributes) throws Exception {
036: check(namespace, name, attributes);
037: PageRequestConfigImpl pageConfig = (PageRequestConfigImpl) this
038: .getDigester().peek();
039: IWrapperConfigImpl wrapperConfig = new IWrapperConfigImpl();
040: String prefix = attributes.getValue("prefix");
041: if (prefix == null) {
042: throw new SAXException(
043: "Mandatory attribute \"prefix\" is missing!");
044: }
045: wrapperConfig.setPrefix(prefix);
046: String className = attributes.getValue("class");
047: if (className == null) {
048: throw new SAXException(
049: "Mandatory attribute \"class\" is missing!");
050: }
051: Class<?> wrapperClass;
052: try {
053: wrapperClass = Class.forName(className);
054: } catch (ClassNotFoundException e) {
055: throw new SAXException("Could not load wrapper class \""
056: + className + "\"!");
057: }
058: if (!IWrapper.class.isAssignableFrom(wrapperClass)) {
059: throw new SAXException("Input wrapper class "
060: + wrapperClass + " on page "
061: + pageConfig.getPageName() + " does not implement "
062: + IWrapper.class + " interface!");
063: }
064: wrapperConfig.setWrapperClass(wrapperClass
065: .asSubclass(IWrapper.class));
066: String activeignore = attributes.getValue("activeignore");
067: if (activeignore != null) {
068: wrapperConfig.setActiveIgnore(Boolean
069: .parseBoolean(activeignore));
070: } else {
071: wrapperConfig.setActiveIgnore(false);
072: }
073: String doContinue = attributes.getValue("continue");
074: if (doContinue != null) {
075: wrapperConfig.setContinue(Boolean.parseBoolean(doContinue));
076: } else {
077: wrapperConfig.setContinue(false);
078: }
079: String alwaysretrieve = attributes.getValue("alwaysretrieve");
080: if (alwaysretrieve != null) {
081: wrapperConfig.setAlwaysRetrieve(Boolean
082: .parseBoolean(alwaysretrieve));
083: } else {
084: wrapperConfig.setAlwaysRetrieve(false);
085: }
086: String dologging = attributes.getValue("logging");
087: if (dologging != null) {
088: wrapperConfig.setLogging(Boolean.parseBoolean(dologging));
089: } else {
090: wrapperConfig.setLogging(false);
091: }
092: pageConfig.addIWrapper(wrapperConfig);
093: }
094:
095: protected Map<String, Boolean> wantsAttributes() {
096: HashMap<String, Boolean> atts = new HashMap<String, Boolean>();
097: atts.put("class", true);
098: atts.put("prefix", true);
099: atts.put("activeignore", false);
100: atts.put("continue", false);
101: atts.put("alwaysretrieve", false);
102: atts.put("logging", false);
103: return atts;
104: }
105: }
|