package de.spieleck.config;

import java.io.PrintWriter;
import java.io.IOException;

import java.util.Iterator;

import de.spieleck.util.EmptyIterator;

/**
 * An ConfigNode, that contains nothing.
 * Might sometimes be a better return than a null for
 * a ConfigNode returning device.
 */
public class EmptyConfigNode
    implements ConfigNode
{
    private static ConfigNode instance = new EmptyConfigNode();

    // This is a Singleton
    private EmptyConfigNode() { };

    public static ConfigNode getInstance()
    {
        return instance;
    }

    public ConfigNode node(String path)
    {
        return null; // XXX or this??
    }

    public ConfigNode nodeInh(String path)
    {
        return null; // XXX or this??
    }

    public ConfigFileNode getBranchNode()
    {
        return null; // XXX or this??
    }

    public String getName()
    {
        return "empty"; // XXX or null??
    }

    public String getPath()
    {
        return null; // XXX or what?
    }

    public ConfigNode getParent()
    {
        return null; // XXX or what?
    }

    public boolean getBoolean()
    {
        return false;
    }

    public int getInt()
    {
        return 0;
    }

    public double getDouble()
    {
        return 0.0;
    }

    public String getString()
    {
        return "";
    }

    public boolean getBoolean(String path, boolean deflt)
    {
        return deflt;
    }

    public int getInt(String path, int deflt)
    {
        return deflt;
    }

    public double getDouble(String path, double deflt)
    {
        return deflt;
    }

    public String getString(String path, String deflt)
    {
        return deflt;
    }

    public boolean getInhBoolean(String path, boolean deflt)
    {
        return deflt;
    }

    public int getInhInt(String path, int deflt)
    {
        return deflt;
    }

    public double getInhDouble(String path, double deflt)
    {
        return deflt;
    }

    public String getInhString(String path, String deflt)
    {
        return deflt;
    }

    public int countChildren()
    {
        return 0;
    }

    public Iterator children()
    {
        return EmptyIterator.getInstance();
    }

    public Iterator childrenNamed(String key)
    {
        return EmptyIterator.getInstance();
    }

    public int countChildrenNamed(String key)
    {
        return 0;
    }

    public void print(PrintWriter os)
     throws IOException
    {
        os.print("<empty/>");
    }
}
//
//    Jacson - Text Filtering with Java.
//    Copyright (C) 2002 Frank S. Nestel (nestefan -at- users.sourceforge.net)
//
//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License as published by the Free Software Foundation; either
//    version 2.1 of the License, or (at your option) any later version.
//
//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public
//    License along with this library; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//