1 3 56 57 package org.jboss.util.xml.catalog; 58 59 import java.util.Hashtable ; 60 import java.util.Vector ; 61 62 88 public class CatalogEntry { 89 90 protected static int nextEntry = 0; 91 92 97 protected static Hashtable entryTypes = new Hashtable (); 98 99 101 protected static Vector entryArgs = new Vector (); 102 103 114 public static int addEntryType(String name, int numArgs) { 115 entryTypes.put(name, new Integer (nextEntry)); 116 entryArgs.add(nextEntry, new Integer (numArgs)); 117 nextEntry++; 118 119 return nextEntry-1; 120 } 121 122 130 public static int getEntryType(String name) 131 throws CatalogException { 132 if (!entryTypes.containsKey(name)) { 133 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 134 } 135 136 Integer iType = (Integer ) entryTypes.get(name); 137 138 if (iType == null) { 139 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 140 } 141 142 return iType.intValue(); 143 } 144 145 153 public static int getEntryArgCount(String name) 154 throws CatalogException { 155 return getEntryArgCount(getEntryType(name)); 156 } 157 158 165 public static int getEntryArgCount(int type) 166 throws CatalogException { 167 try { 168 Integer iArgs = (Integer ) entryArgs.get(type); 169 return iArgs.intValue(); 170 } catch (ArrayIndexOutOfBoundsException e) { 171 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 172 } 173 } 174 175 176 protected int entryType = 0; 177 178 179 protected Vector args = null; 180 181 184 public CatalogEntry() {} 185 186 196 public CatalogEntry(String name, Vector args) 197 throws CatalogException { 198 Integer iType = (Integer ) entryTypes.get(name); 199 200 if (iType == null) { 201 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 202 } 203 204 int type = iType.intValue(); 205 206 try { 207 Integer iArgs = (Integer ) entryArgs.get(type); 208 if (iArgs.intValue() != args.size()) { 209 throw new CatalogException(CatalogException.INVALID_ENTRY); 210 } 211 } catch (ArrayIndexOutOfBoundsException e) { 212 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 213 } 214 215 entryType = type; 216 this.args = args; 217 } 218 219 229 public CatalogEntry(int type, Vector args) 230 throws CatalogException { 231 try { 232 Integer iArgs = (Integer ) entryArgs.get(type); 233 if (iArgs.intValue() != args.size()) { 234 throw new CatalogException(CatalogException.INVALID_ENTRY); 235 } 236 } catch (ArrayIndexOutOfBoundsException e) { 237 throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); 238 } 239 240 entryType = type; 241 this.args = args; 242 } 243 244 249 public int getEntryType() { 250 return entryType; 251 } 252 253 260 public String getEntryArg(int argNum) { 261 try { 262 String arg = (String ) args.get(argNum); 263 return arg; 264 } catch (ArrayIndexOutOfBoundsException e) { 265 return null; 266 } 267 } 268 269 282 public void setEntryArg(int argNum, String newspec) 283 throws ArrayIndexOutOfBoundsException { 284 args.set(argNum, newspec); 285 } 286 } 287 | Popular Tags |