/*
 *
 */
package de.spieleck.config;

import java.io.*;
import java.util.Set;
import java.util.HashSet;

import de.spieleck.net.URLTools;

/**
 * A ConfigNode that is responsible for actually holding nodes
 * from a file. <B>Note:</B> Due to independance of logical and
 * file structure these nodes are only spurious in the logical part
 * of the tree. They are kept however to hold propper dependencies
 * of nodes on files. 
 * @author FSN
 */
public class ConfigFileNode
 extends ConfigNodeImpl
 implements ConfigNode
{
    protected String fName;
    protected File inFile           = null;
    protected long lastModified     = -1;
    protected Set subReadNodes = null;

    /* package */ ConfigFileNode(String name, String value, String fName,
                      ConfigParamMap pm)
    {
        super(name, value, pm);
        this.fName = fName;
        if (fName != null)
        {
            fName  = URLTools.getFileString(fName);
            inFile = new File(fName);
            if (inFile != null)
                lastModified = inFile.lastModified();
        }
    }

    protected void setParent(ConfigNode p)
    {
        super.setParent(p);
        if (p != null)
            p.getBranchNode().addSubReader(this);
    }

    protected void addSubReader(ConfigNode subReader)
    {
        if (subReadNodes == null)
            subReadNodes = new HashSet(8);
        subReadNodes.add(subReader);
    }

    public String getSourceFileName()
    {
        return fName;
    }

    public ConfigFileNode getBranchNode()
    {
        return this;
    }

}
//
//    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
//