1 3 19 20 package com.sun.org.apache.xml.internal.resolver; 21 22 import java.util.Hashtable ; 23 import java.util.Vector ; 24 25 51 public class CatalogEntry { 52 53 protected static int nextEntry = 0; 54 55 60 protected static Hashtable entryTypes = new Hashtable (); 61 62 64 protected static Vector entryArgs = new Vector (); 65 66 77 public static int addEntryType(String name, int numArgs) { 78 entryTypes.put(name, new Integer (nextEntry)); 79 entryArgs.add(nextEntry, new Integer (numArgs)); 80 nextEntry++; 81 82 return nextEntry-1; 83 } 84 85 93 public static int getEntryType(String name) 94 throws CatalogException { 95 if (!entryTypes.containsKey(name)) { 96 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 97 } 98 99 Integer iType = (Integer ) entryTypes.get(name); 100 101 if (iType == null) { 102 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 103 } 104 105 return iType.intValue(); 106 } 107 108 116 public static int getEntryArgCount(String name) 117 throws CatalogException { 118 return getEntryArgCount(getEntryType(name)); 119 } 120 121 128 public static int getEntryArgCount(int type) 129 throws CatalogException { 130 try { 131 Integer iArgs = (Integer ) entryArgs.get(type); 132 return iArgs.intValue(); 133 } catch (ArrayIndexOutOfBoundsException e) { 134 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 135 } 136 } 137 138 139 protected int entryType = 0; 140 141 142 protected Vector args = null; 143 144 147 public CatalogEntry() {} 148 149 159 public CatalogEntry(String name, Vector args) 160 throws CatalogException { 161 Integer iType = (Integer ) entryTypes.get(name); 162 163 if (iType == null) { 164 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 165 } 166 167 int type = iType.intValue(); 168 169 try { 170 Integer iArgs = (Integer ) entryArgs.get(type); 171 if (iArgs.intValue() != args.size()) { 172 throw new CatalogException(CatalogException.INVALID_ENTRY); 173 } 174 } catch (ArrayIndexOutOfBoundsException e) { 175 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 176 } 177 178 entryType = type; 179 this.args = args; 180 } 181 182 192 public CatalogEntry(int type, Vector args) 193 throws CatalogException { 194 try { 195 Integer iArgs = (Integer ) entryArgs.get(type); 196 if (iArgs.intValue() != args.size()) { 197 throw new CatalogException(CatalogException.INVALID_ENTRY); 198 } 199 } catch (ArrayIndexOutOfBoundsException e) { 200 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 201 } 202 203 entryType = type; 204 this.args = args; 205 } 206 207 212 public int getEntryType() { 213 return entryType; 214 } 215 216 223 public String getEntryArg(int argNum) { 224 try { 225 String arg = (String ) args.get(argNum); 226 return arg; 227 } catch (ArrayIndexOutOfBoundsException e) { 228 return null; 229 } 230 } 231 232 245 public void setEntryArg(int argNum, String newspec) 246 throws ArrayIndexOutOfBoundsException { 247 args.set(argNum, newspec); 248 } 249 } 250 | Popular Tags |