package de.spieleck.config;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Iterator;
public class ConfigSafeNode
implements ConfigNode
{
protected ConfigNode root;
protected ConfigNode cn;
public ConfigSafeNode(ConfigNode cn)
{
this(cn, cn);
}
public ConfigSafeNode(ConfigNode cn, ConfigNode root)
{
this.root = root;
this.cn = cn;
}
public ConfigNode node(String path)
{
return new ConfigSafeNode(cn.node(path), root);
}
public ConfigNode nodeInh(String path)
{
return cn.node(path);
}
public ConfigFileNode getBranchNode()
{
return null;
}
public String getName()
{
return cn.getName();
}
public String getPath()
{
return cn.getName();
}
public ConfigNode getParent()
{
if ( cn == root )
return null;
else
return new ConfigSafeNode(cn.getParent(), root);
}
public boolean getBoolean()
{
return cn.getBoolean();
}
public int getInt()
{
return cn.getInt();
}
public double getDouble()
{
return cn.getDouble();
}
public String getString()
{
return cn.getString();
}
public boolean getBoolean(String path, boolean deflt)
{
return cn.getBoolean(path, deflt);
}
public int getInt(String path, int deflt)
{
return cn.getInt(path, deflt);
}
public double getDouble(String path, double deflt)
{
return cn.getDouble(path, deflt);
}
public String getString(String path, String deflt)
{
return cn.getString(path, deflt);
}
public boolean getInhBoolean(String path, boolean deflt)
{
return getBoolean(path, deflt);
}
public int getInhInt(String path, int deflt)
{
return getInt(path, deflt);
}
public double getInhDouble(String path, double deflt)
{
return getDouble(path, deflt);
}
public String getInhString(String path, String deflt)
{
return getString(path, deflt);
}
public int countChildren()
{
return cn.countChildren();
}
public Iterator children()
{
return new SafeIterator(cn.children(), root);
}
public Iterator childrenNamed(String key)
{
return new SafeIterator(cn.childrenNamed(key), root);
}
public int countChildrenNamed(String key)
{
return cn.countChildrenNamed(key);
}
public void print(PrintWriter os)
throws IOException
{
cn.print(os);
}
protected static class SafeIterator
implements Iterator
{
Iterator it;
ConfigNode root;
public SafeIterator(Iterator it, ConfigNode root)
{
this.it = it;
this.root = root;
}
public boolean hasNext()
{
return it.hasNext();
}
public void remove()
{
it.remove();
}
public Object next()
{
return new ConfigSafeNode((ConfigNode)it.next(), root);
}
}
}