gnu.mapping

Class Namespace

Implemented Interfaces:
Externalizable, HasNamedParts
Known Direct Subclasses:
ClassNamespace, LispPackage, XmlNamespace

public class Namespace
extends java.lang.Object
implements Externalizable, HasNamedParts

A mapping from strings ("print names") to Symbols. Namespaces are normally named and can be accessed from a global table. They correspond to Common Lisp "packages" (which are implemented using gnu.kawa.lispexpr.LispPackage, which extends Namespace). A Namespace is a "weak" mapping in the sense that a Symbol can be garbage collected even though it is referenced from a Namespace.

Field Summary

static Namespace
EmptyNamespace
The Namespace with the empty name.
protected static Hashtable
nsTable
Map namepsace names (and nick-names) to Namespaces.
protected String
prefix
protected gnu.mapping.SymbolRef[]
table

Constructor Summary

Namespace()
Namespace(int capacity)

Method Summary

Symbol
add(Symbol sym, int hash)
Object
get(String key)
static Namespace
getDefault()
static Symbol
getDefaultSymbol(String name)
static Namespace
getInstance(String name)
String
getName()
Get the name of this Namespace.
Symbol
getSymbol(String key)
Get a Symbol matching the given name.
boolean
isConstant(String key)
Symbol
lookup(String key)
Get a Symbol matching the given name.
Symbol
lookup(String key, int hash, boolean create)
protected Symbol
lookupInternal(String key, int hash)
static Namespace
make(String name)
static Namespace
make(String uri, String prefix)
static Namespace
makeUnknownNamespace(String prefix)
Create a "placeholder" for a namespace with a known prefix but unknown uri.
void
readExternal(ObjectInput in)
Object
readResolve()
protected void
rehash()
boolean
remove(Symbol symbol)
void
setName(String name)
Set the name of this Namespace.
String
toString()
void
writeExternal(ObjectOutput out)

Field Details

EmptyNamespace

public static final Namespace EmptyNamespace
The Namespace with the empty name.

nsTable

protected static final Hashtable nsTable
Map namepsace names (and nick-names) to Namespaces.

prefix

protected String prefix

table

protected gnu.mapping.SymbolRef[] table

Constructor Details

Namespace

public Namespace()

Namespace

public Namespace(int capacity)

Method Details

add

public Symbol add(Symbol sym,
                  int hash)

get

public Object get(String key)
Specified by:
get in interface HasNamedParts

getDefault

public static Namespace getDefault()

getDefaultSymbol

public static Symbol getDefaultSymbol(String name)

getInstance

public static Namespace getInstance(String name)

getName

public final String getName()
Get the name of this Namespace.

getSymbol

public Symbol getSymbol(String key)
Get a Symbol matching the given name. Creates a new Symbol if one is not found. Equivalent to Common Lisp's "intern" function.

isConstant

public boolean isConstant(String key)
Specified by:
isConstant in interface HasNamedParts

lookup

public Symbol lookup(String key)
Get a Symbol matching the given name. Returns null if one is not found.

lookup

public Symbol lookup(String key,
                     int hash,
                     boolean create)

lookupInternal

protected final Symbol lookupInternal(String key,
                                      int hash)

make

public static Namespace make(String name)

make

public static Namespace make(String uri,
                             String prefix)

makeUnknownNamespace

public static Namespace makeUnknownNamespace(String prefix)
Create a "placeholder" for a namespace with a known prefix but unknown uri.

readExternal

public void readExternal(ObjectInput in)
            throws IOException,
                   ClassNotFoundException

readResolve

public Object readResolve()
            throws ObjectStreamException

rehash

protected void rehash()

remove

public boolean remove(Symbol symbol)

setName

public final void setName(String name)
Set the name of this Namespace.

toString

public String toString()

writeExternal

public void writeExternal(ObjectOutput out)
            throws IOException