logo

abstract const class

sys::Namespace

sys::Obj
  sys::Namespace

Namespace models a Uri to Obj map. Namespaces provide a unified CRUD (create/read/update/delete) interface for managing objects keyed by a Uri. The root namespace accessed via Sys.ns provides a thread-safe memory database. Custom namespaces can be mounted into the system via the Sys.mount method.

See docLang::Namespaces for details.

Slots

create

virtual Uri create(Uri uri, Obj obj)

Create the specified uri/object pair in this namespace. Pass null for uri if the namespace should generate a new uri automatically. Return the newly created uri. If the uri is already mapped, then throw ArgErr.

The root namespace stores the object in the memory database - the object must be immutable or serializable.

The default implementation for subclasses is to throw UnsupportedErr.

delete

virtual Void delete(Uri uri)

Delete the object mapped by the specified uri. If the uri isn't mapped then throw UnresolvedErr.

The root namespace removes the uri/object pair from the memory database.

The default implementation for subclasses is to throw UnsupportedErr.

get

abstract Obj get(Uri uri, Bool checked := true)

Get the object mapped by the specified Uri. If the Uri doesn't map to a valid object and checked is false then return null, otherwise throw UnresolvedErr.

makeDir

static Namespace makeDir(File dir)

Create a Namespace which maps Uris to a directory tree. The resulting namespace may then be mounted via Sys.mount to alias namespace Uris to files within the directory. Throw ArgErr if dir does not map to an existing directory. Note that uris will resolve successfully directories without a trailing slash.

Example:

Sys.mount(`/foo/`, Namespace.makeDir(`/pub/`.toFile))
Sys.ns[`/foo/file.html`]  =>  `/pub/file.html`
put

virtual Void put(Uri uri, Obj obj)

Update the object mapped by the specified uri. If the uri isn't mapped then throw UnresolvedErr.

The root namespace stores the object back to the memory database - the object must be immutable or serializable.

The default implementation for subclasses is to throw UnsupportedErr.

uri

Uri uri()

Get the Uri that this Namespace is mounted under or null if not mounted.