package edu.vt.marian.server; import java.io.*; import java.net.*; import java.lang.*; import java.util.*; import edu.vt.marian.common.*; /** class name: class_dir_table class description: this class represents a table of class names and their corresponding directory names, this class is used by configuration object to manage system class directories. uses the services of class(es): class_dir designer(s): Jianxin Zhao (jxzhao@csgrad.cs.vt.edu) implementator(s): Ning Chai (nchai@csgrad.cs.vt.edu) finished time: Nov 23, 1998 known bugs: JDK version: 1.1.5 side effects: */ public class class_dir_table { public final static int OK = 0; public final static int NULL_DIR_NAME_NEG= -1; public final static int NULL_CLASS_NAME = 1; public final static int NULL_DIR_NAME = 2; public final static int CLASS_ALREADY_EXISTS = 3; public final static int CLASS_DOESNT_EXIST = 4; private Vector class_dirs; //Used to hold the dir included in dir table /** this is just used for debugging */ Debug debug; /** method description: this constructor will create a class dir table object, the table is empty upon creation uses the services of class(es): input parameter(s): debug -- used for debugging output parameter(s): none return value: none synchronization:none */ public class_dir_table(Debug debug) { this.debug = debug; class_dirs = new Vector(); } /** method description: this method will add the specified class name and directory name pair to the table uses the services of class(es): none input parameter(s): class_name -- this is the name of a class, class name must be uniq in the table (currently we don't allow one class has more than one directories) dir_name -- this is the directory name corresponds to the class name output parameter(s): none return value: 0 -- the class name and directory name pair has been added into the table correctly 1 -- the class name is null 2 -- the directory name is null 3 -- duplicated class name identified synchronization:synchronized */ public synchronized int add(String class_name, String dir_name) { int i; class_dir class_dir_obj = null; if ((class_name == null) || class_name.equals("")) { debug.dumpTrace("Class: class_dir_table Method:add Class name is null or empty."); return NULL_CLASS_NAME; } if ((dir_name == null)||dir_name.equals("")) { debug.dumpTrace("Class: class_dir_table Method:add Dir name is null or empty."); return NULL_DIR_NAME; } for (i = 0; i < class_dirs.size(); i++) { class_dir_obj = (class_dir)(class_dirs.elementAt(i)); if (class_dir_obj.get_class_name().equals(class_name)) { debug.dumpTrace("Class: class_dir_table Method:add Class already exists.\n"); return CLASS_ALREADY_EXISTS; } } //Insert class_dir into class_dirs class_dir_obj = new class_dir(class_name,dir_name,debug); class_dirs.addElement(class_dir_obj); return OK; } /** method description: this method will return the directory name corresponds to the specified class name in the table uses the services of class(es): none input parameter(s): class_name -- this will be used to search the table output parameter(s): none return value: null -- class name is null or didn't find an entry in the table with the same class name synchronization:synchronized */ public synchronized String get_dir_name(String class_name) { int i; class_dir class_dir_obj =null; if ((class_name == null)||class_name.equals("")) { debug.dumpTrace("Class: class_dir_table Method:get_dir_name Class name is null or empty."); return null; } for (i = 0; i < class_dirs.size(); i++) { class_dir_obj = (class_dir)(class_dirs.elementAt(i)); if (class_dir_obj.get_class_name().equals(class_name)) { return class_dir_obj.get_dir_name(); } } debug.dumpTrace("Class: class_dir_table Method: get_dir_name Can't find a dir with name'" + class_name + "'."); return null; } /** method description: this method will delete the entry in the table with the specified class name uses the services of class(es): input parameter(s): class_name -- the entry with the same class name will be deleted from teh table output parameter(s): none return value: 0 -- the entry has been deleted correctly 1 -- class name is null 4 -- there is no entry in the table with the specified class name synchronization:synchronized */ public synchronized int delete_by_class(String class_name) { int i; class_dir class_dir_obj = null; if ((class_name == null)||class_name.equals("")) { debug.dumpTrace("Class:class_dir_name Method:delete_by_class Class name is null or empty."); return NULL_CLASS_NAME; } for (i=0; i= 0; i--) { class_dir_obj = (class_dir)(class_dirs.elementAt(i)); if (class_dir_obj.get_dir_name().startsWith(dir_name)) { class_dirs.removeElementAt(i); number_deleted++; } } return number_deleted; } /** method description: this method will return the class name(s) whose corresponding directory name is the same as the specified value in the table uses the services of class(es): input parameter(s): dir_name -- this will be used to search the table output parameter(s): none return value: null -- the directory name is null a vector -- contains all the class names match the directory name in the table synchronization:none */ public Vector get_class_names(String dir_name) { int i; class_dir class_dir_obj = null; if ((dir_name == null) || dir_name.equals("")) { debug.dumpTrace("Class:class_dir_name Method:get_class_name Dir name is null or empty."); return null; } Vector class_names = new Vector(); for (i=0; i