Question: Java: Briefly explain the code in each area with /*comment*/ above it 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: Briefly explain the code in each area with /*comment*/ above it

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!