pnuts.lang
Class Package

java.lang.Object
  |
  +--pnuts.lang.Package
Direct Known Subclasses:
ProtectedPackage, PSEPackage

public class Package
extends java.lang.Object
implements Property, java.io.Serializable, java.lang.Cloneable

This class represents a Pnuts package (not Java's).

See Also:
Serialized Form

Field Summary
 pnuts.lang.SymbolTable autoloadTable
          This represents a set of names which are registered as autoloaded.
protected  java.util.Vector children
           
static Package globalPackage
          The package with name "".
protected  java.lang.String name
          The name of the package.
protected static java.util.Hashtable packages
          All packages with a non-null name
protected  Package parent
           
protected  pnuts.lang.SymbolTable requireTable
          This represents a set of loaded script names.
protected  pnuts.lang.SymbolTable table
           
protected  pnuts.lang.SymbolTable unitTable
          This represents a set of registered QuantityFactory.
 
Constructor Summary
  Package()
          creates a package that is not visible from other packages
protected Package(java.lang.String name)
          creates a package and register it in a static hashtable.
 
Method Summary
 void clear(java.lang.String symbol)
          Delete a symbol from the package
 void clear(java.lang.String symbol, Context context)
          Delete a symbol from the package
 java.lang.Object clone()
           
 boolean defined(java.lang.String name)
           
 boolean defined(java.lang.String name, Context context)
           
 java.util.Enumeration elements()
          enumerates sub-packages
static Package find(java.lang.String pkg)
           
 java.lang.Object get(java.lang.String symbol)
          This method defines the behavior of the following expression.
 java.lang.Object get(java.lang.String name, Context context)
          Get the value of a symbol in the package.
static Package getGlobalPackage()
           
 java.lang.String getName()
           
static Package getPackage(java.lang.String pkg)
          If package "pkg" exists returns that, otherwise creates and returns one.
protected  void init()
          This method is called by the constructors.
protected  void init(Context context)
          This method is called when the package become the current package with package() function.
 java.util.Enumeration keys()
          Returns an enumeration of the names in the package.
protected  Value lookup(java.lang.String symbol, Context context)
          lookup the symbol in the package
static void registerQuantityFactory(java.lang.String unit, QuantityFactory fac)
           
static void remove(java.lang.String name)
          Remove the specified package
static void reset()
          Remove all packages
 void save(java.io.OutputStream s)
          save the package to an outputStream.
 void set(java.lang.String symbol, java.lang.Object obj)
          Set a value of a symbol in the package.
 void set(java.lang.String symbol, java.lang.Object obj, Context context)
          Set a value of a symbol in the package.
static void setPackageFactory(PackageFactory factory)
          When an instance of PackageFactory is registered by this method, the package() builtin function calls its PackageFactory.createPackage() method.
 int size()
          the number of symbols
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

packages

protected static java.util.Hashtable packages
All packages with a non-null name

globalPackage

public static Package globalPackage
The package with name "".

table

protected transient pnuts.lang.SymbolTable table

children

protected transient java.util.Vector children

parent

protected transient Package parent

name

protected java.lang.String name
The name of the package.

autoloadTable

public pnuts.lang.SymbolTable autoloadTable
This represents a set of names which are registered as autoloaded. This is only for global package.

unitTable

protected pnuts.lang.SymbolTable unitTable
This represents a set of registered QuantityFactory. This is only for global package.

requireTable

protected pnuts.lang.SymbolTable requireTable
This represents a set of loaded script names. This is only for global package.
Constructor Detail

Package

public Package()
creates a package that is not visible from other packages

Package

protected Package(java.lang.String name)
creates a package and register it in a static hashtable.
Method Detail

getGlobalPackage

public static Package getGlobalPackage()
Returns:
the global package

setPackageFactory

public static void setPackageFactory(PackageFactory factory)
When an instance of PackageFactory is registered by this method, the package() builtin function calls its PackageFactory.createPackage() method.
Since:
Pnuts 1.0beta3

getPackage

public static Package getPackage(java.lang.String pkg)
If package "pkg" exists returns that, otherwise creates and returns one.

defined

public boolean defined(java.lang.String name)
Returns:
true if name is defined in the package.

defined

public boolean defined(java.lang.String name,
                       Context context)
Returns:
true if name is defined in the package.
Since:
Pnuts 1.0beta3

get

public java.lang.Object get(java.lang.String symbol)
Description copied from interface: Property
This method defines the behavior of the following expression.
    aProperty . name
 
Specified by:
get in interface Property
Returns:
the value of specified variable in the package.

get

public java.lang.Object get(java.lang.String name,
                            Context context)
Get the value of a symbol in the package.
Parameters:
symbol - a name in the package
context - the context in which the symbol is referenced. null means "not specified".
Returns:
the value of specified variable in the package.
Since:
Pnuts 1.0beta3

set

public void set(java.lang.String symbol,
                java.lang.Object obj)
Set a value of a symbol in the package.
Specified by:
set in interface Property
Parameters:
sym - a name of variable
obj - the value of the variable

set

public void set(java.lang.String symbol,
                java.lang.Object obj,
                Context context)
Set a value of a symbol in the package.
Parameters:
symbol - a name of variable
obj - the value of the variable
Since:
Pnuts 1.0beta3

clear

public void clear(java.lang.String symbol)
Delete a symbol from the package
Parameters:
symbol - a name of variable to be deleted

clear

public void clear(java.lang.String symbol,
                  Context context)
Delete a symbol from the package
Parameters:
symbol - a name of variable to be deleted

remove

public static void remove(java.lang.String name)
Remove the specified package

find

public static Package find(java.lang.String pkg)
Parameters:
pkg - a name of package to look
Returns:
a package with name "pkg" if it exits.

reset

public static void reset()
Remove all packages

init

protected void init()
This method is called by the constructors.

init

protected void init(Context context)
This method is called when the package become the current package with package() function. This method in a subclass must call super.init(context) first.
Since:
Pnuts 1.0beta3

getName

public java.lang.String getName()
Returns:
the name of the package

keys

public java.util.Enumeration keys()
Returns an enumeration of the names in the package.

size

public int size()
the number of symbols

lookup

protected Value lookup(java.lang.String symbol,
                       Context context)
lookup the symbol in the package
Parameters:
symbol - intern'ed string

save

public void save(java.io.OutputStream s)
save the package to an outputStream. If a value of a symbol can not be serialized, the symbol is ignored.

elements

public java.util.Enumeration elements()
enumerates sub-packages

registerQuantityFactory

public static void registerQuantityFactory(java.lang.String unit,
                                           QuantityFactory fac)

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object