FileDocCategorySizeDatePackage
CatalogEntry.javaAPI DocJava SE 6 API7665Tue Jun 10 00:22:58 BST 2008com.sun.org.apache.xml.internal.resolver

CatalogEntry

public class CatalogEntry extends Object
Represents a Catalog entry.

Instances of this class represent individual entries in a Catalog.

Each catalog entry has a unique name and is associated with an arbitrary number of arguments (all strings). For example, the TR9401 catalog entry "PUBLIC" has two arguments, a public identifier and a system identifier. Each entry has a unique numeric type, assigned automatically when the entry type is created.

The number and type of catalog entries is maintained statically. Catalog classes, or their subclasses, can add new entry types, but all Catalog objects share the same global pool of types.

Initially there are no valid entries.

see
Catalog
author
Norman Walsh Norman.Walsh@Sun.COM
version
1.0

Fields Summary
protected static int
nextEntry
The nextEntry is the ordinal number of the next entry type.
protected static Hashtable
entryTypes
The entryTypes vector maps catalog entry names (e.g., 'BASE' or 'SYSTEM') to their type (1, 2, etc.). Names are case sensitive.
protected static Vector
entryArgs
The entryTypes vector maps catalog entry types to the number of arguments they're required to have.
protected int
entryType
The entry type of this entry
protected Vector
args
The arguments associated with this entry
Constructors Summary
public CatalogEntry()
Null constructor; something for subclasses to call.


            
    
public CatalogEntry(String name, Vector args)
Construct a catalog entry of the specified type.

param
name The name of the entry type
param
args A String Vector of arguments
throws
InvalidCatalogEntryTypeException if no such entry type exists.
throws
InvalidCatalogEntryException if the wrong number of arguments is passed.

    Integer iType = (Integer) entryTypes.get(name);

    if (iType == null) {
      throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE);
    }

    int type = iType.intValue();

    try {
      Integer iArgs = (Integer) entryArgs.get(type);
      if (iArgs.intValue() != args.size()) {
	throw new CatalogException(CatalogException.INVALID_ENTRY);
      }
    } catch (ArrayIndexOutOfBoundsException e) {
      throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE);
    }

    entryType = type;
    this.args = args;
  
public CatalogEntry(int type, Vector args)
Construct a catalog entry of the specified type.

param
type The entry type
param
args A String Vector of arguments
throws
InvalidCatalogEntryTypeException if no such entry type exists.
throws
InvalidCatalogEntryException if the wrong number of arguments is passed.

    try {
      Integer iArgs = (Integer) entryArgs.get(type);
      if (iArgs.intValue() != args.size()) {
	throw new CatalogException(CatalogException.INVALID_ENTRY);
      }
    } catch (ArrayIndexOutOfBoundsException e) {
      throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE);
    }

    entryType = type;
    this.args = args;
  
Methods Summary
public static intaddEntryType(java.lang.String name, int numArgs)
Adds a new catalog entry type.

param
name The name of the catalog entry type. This must be unique among all types and is case-sensitive. (Adding a duplicate name effectively replaces the old type with the new type.)
param
numArgs The number of arguments that this entry type is required to have. There is no provision for variable numbers of arguments.
return
The type for the new entry.


                                                                         
         
    entryTypes.put(name, new Integer(nextEntry));
    entryArgs.add(nextEntry, new Integer(numArgs));
    nextEntry++;

    return nextEntry-1;
  
public java.lang.StringgetEntryArg(int argNum)
Get an entry argument.

param
argNum The argument number (arguments are numbered from 0).
return
The specified argument or null if an invalid argNum is provided.

    try {
      String arg = (String) args.get(argNum);
      return arg;
    } catch (ArrayIndexOutOfBoundsException e) {
      return null;
    }
  
public static intgetEntryArgCount(java.lang.String name)
Find out how many arguments an entry is required to have.

param
name The name of the catalog entry type.
return
The number of arguments that entry type is required to have.
throws
InvalidCatalogEntryTypeException if no entry has the specified name.

    return getEntryArgCount(getEntryType(name));
  
public static intgetEntryArgCount(int type)
Find out how many arguments an entry is required to have.

param
type A valid catalog entry type.
return
The number of arguments that entry type is required to have.
throws
InvalidCatalogEntryTypeException if the type is invalid.

    try {
      Integer iArgs = (Integer) entryArgs.get(type);
      return iArgs.intValue();
    } catch (ArrayIndexOutOfBoundsException e) {
      throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE);
    }
  
public static intgetEntryType(java.lang.String name)
Lookup an entry type

param
name The name of the catalog entry type.
return
The type of the catalog entry with the specified name.
throws
InvalidCatalogEntryTypeException if no entry has the specified name.

    if (!entryTypes.containsKey(name)) {
      throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE);
    }

    Integer iType = (Integer) entryTypes.get(name);

    if (iType == null) {
      throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE);
    }

    return iType.intValue();
  
public intgetEntryType()
Get the entry type.

return
The entry type of the CatalogEntry

    return entryType;
  
public voidsetEntryArg(int argNum, java.lang.String newspec)
Set an entry argument.

Catalogs sometimes need to adjust the catlog entry parameters, for example to make a relative URI absolute with respect to the current base URI. But in general, this function should only be called shortly after object creation to do some sort of cleanup. Catalog entries should not mutate over time.

param
argNum The argument number (arguments are numbered from 0).
throws
ArrayIndexOutOfBoundsException if an invalid argument number is provided.

    args.set(argNum, newspec);