Question
Must comment on the code at every /* Comment Here */ section about what the code is doing. import java.io.*; import org.xml.sax.*; import org.xml.sax.helpers.DefaultHandler; import
Must comment on the code at every "/* Comment Here */" section about what the code is doing.
import java.io.*;
import org.xml.sax.*; import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser;
import java.util.Map; import java.util.HashMap;
public class Configuration extends DefaultHandler { private Map map; private String configurationFile;
/* Comment Here */ public Configuration(String configurationFile) throws ConfigurationException { this.configurationFile = configurationFile;
map = new HashMap();
try { // Use the default (non-validating) parser SAXParserFactory factory = SAXParserFactory.newInstance();
// Parse the input SAXParser saxParser = factory.newSAXParser(); saxParser.parse( new File(configurationFile), this); } catch (javax.xml.parsers.ParserConfigurationException pce) { throw new ConfigurationException("javax.xml.parsers.ParserConfigurationException"); } catch (org.xml.sax.SAXException se) { throw new ConfigurationException("org.xml.sax.SAXException"); } catch (java.io.IOException ioe) { throw new ConfigurationException("java.io.IOException"); } }
/* Comment Here */ public void startElement(String namespaceURI, String lName, String qName, Attributes attrs) throws SAXException { String elementName = lName; // element name if ("".equals(elementName)) elementName = qName; // namespaceAware = false
/* Comment Here */ if (attrs != null) { for (int i = 0; i < attrs.getLength(); i++) { String aName = attrs.getLocalName(i); // Attr name if ("".equals(aName)) aName = attrs.getQName(i);
/* Comment Here */ map.put(elementName+"."+aName,attrs.getValue(i)); } } }
/* Comment Here */ public String getLogFile() { return (String)map.get("logfile.log"); }
/* Comment Here */ public String getDocBase() { return (String)map.get("context.docBase"); }
/* Comment Here */ public String getServerName() { return (String)map.get("webserver.title"); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started