Fan

 

abstract const class

sys::UriSpace

sys::Obj
  sys::UriSpace

UriSpace models a Uri to Obj map. UriSpaces provide a unified CRUD (create/read/update/delete) interface for managing objects keyed by a Uri. The root space is accessed via UriSpace.root provides a thread-safe memory database. Custom spaces can be mounted into the system via the UriSpace.mount method.

See docLang::UriSpaces for details.

Slots

createSource

virtual Uri create(Uri? uri, Obj obj)

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

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

The default implementation for subclasses is to throw UnsupportedErr.

deleteSource

virtual Void delete(Uri uri)

Delete the object mapped by the specified uri. If the uri isn't mapped then throw UnresolvedErr. Throw ArgErr if uri returns false for isPathOnly.

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

The default implementation for subclasses is to throw UnsupportedErr.

findSource

static UriSpace find(Uri uri)

Get the uri space instance which manages the specified uri or fallback to root uri space.

getSource

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. Throw ArgErr if uri returns false for isPathOnly.

makeDirSource

static UriSpace makeDir(File dir)

Create a UriSpace which maps Uris to a directory tree. The resulting uri space may then be mounted via UriSpace.mount to alias uri space 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:

UriSpace.mount(`/foo/`, UriSpace.makeDir(`/pub/`.toFile))
UriSpace.root[`/foo/file.html`]  =>  `/pub/file.html`
mountSource

static Void mount(Uri uri, UriSpace ns)

Mount a uri space under the specified Uri. All requests to process uris contained by the specified uri are routed to the uri space instance for processing. Throw ArgErr if the uri is already or mounted by another uri space. Throw ArgErr if the uri isn't path absolute, has a query, or has fragment.

putSource

virtual Void put(Uri uri, Obj obj)

Update the object mapped by the specified uri. If the uri isn't mapped then throw UnresolvedErr. Throw ArgErr if uri returns false for isPathOnly.

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

The default implementation for subclasses is to throw UnsupportedErr.

rootSource

static UriSpace root()

Get the root uri space.

unmountSource

static Void unmount(Uri uri)

Unmount a uri space which was previously mounted by the mount method. Throw UnresolvedErr is uri doesn't directly map to a mounted uri space.

uriSource

Uri? uri()

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