001package edu.wpi.first.wpilibj.networktables;
002
003import java.util.*;
004
005import edu.wpi.first.wpilibj.networktables2.*;
006import edu.wpi.first.wpilibj.tables.*;
007
008/**
009 * Provides a {@link NetworkTable} for a given {@link NetworkTableNode}
010 * 
011 * @author Mitchell
012 *
013 */
014public class NetworkTableProvider implements ITableProvider{
015        private final NetworkTableNode node;
016        private final Hashtable tables = new Hashtable();
017
018        /**
019         * Create a new NetworkTableProvider for a given NetworkTableNode
020         * @param node the node that handles the actual network table 
021         */
022        public NetworkTableProvider(NetworkTableNode node){
023                this.node = node;
024        }
025        
026        public ITable getRootTable(){
027                return getTable("");
028        }
029
030        public ITable getTable(String key) {
031                if (tables.containsKey(key)) {
032                        return (NetworkTable) tables.get(key);
033                } else {
034                        NetworkTable table = new NetworkTable(key, this);
035                        tables.put(key, table);
036                        return table;
037                }
038        }
039
040        /**
041         * @return the Network Table node that backs the Tables returned by this provider
042         */
043        public NetworkTableNode getNode() {
044                return node;
045        }
046
047        /**
048         * close the backing network table node
049         */
050        public void close() {
051                node.close();
052        }
053}