package jsci.chemistry;

import java.io.IOException;
import java.lang.Double;
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import javax.xml.parsers.*;

import jsci.chemistry.periodictable.*;

import org.w3c.dom.*;
import org.xml.sax.SAXException;

/**
* This class provides access to the elements of the periodic table.
* @version 0.2
* @author Mark Hale
*/
public final class PeriodicTable {
        private static final Map table = new HashMap();
        private static Map symbols;

        private PeriodicTable() {}
        /**
        * Returns the name for a symbol.
        */
        public static String getName(String symbol) {
                if(symbols == null)
                        symbols = loadIndex();
                return (String)symbols.get(symbol);
        }
        /**
        * Returns an element.
        */
        public static Element getElement(String name) {
                name = name.toLowerCase();
                Element element = (Element) table.get(name);
                if(element == null) {
                        element = loadElement("periodictable/"+name+".xml");
                        if(element != null)
                                table.put(name, element);
                }
                return element;
        }
        /**
        * Loads the XML index.
        */
        private static Map loadIndex() {
                DocumentBuilderFactory docFactory=DocumentBuilderFactory.newInstance();
                try {
                        DocumentBuilder docBuilder=docFactory.newDocumentBuilder();
                        Document doc=docBuilder.parse(PeriodicTable.class.getResource("periodictable/index.xml").toString());
                        Node root=doc.getDocumentElement();
                        NodeList nl=root.getChildNodes();
                        Map index = new HashMap();
                        for(int i=0; i 

Ads help maintain this website.