Representations and Aspects
A resource is an entity which is located by a URI - with NetKernel's concept of active URIs this includes
dynamically generated resources. In practical terms a resource cannot simply correspond one-to-one with a Java
object (for example a String or a ByteArray).
We can see this if we consider a URI to an XML resource.
file:/example.xml. Though we conceptually understand that this is an XML document we might want to access this
resource in any one of a number of forms - for example a stream of characters, as a stream of SAX events, DOM, JDOM etc etc.
So a resource is a single abstract entity which may have a number of concrete forms.
The design of NetKernel's resource object model realises this reality.
NetKernel calls a resource's abstract entity its Representation. This holds its metadata, such
as its dependency hierarchy. The representation also contains a collection of Aspects which are the concrete forms
of the resource.
The aspects of a representation obtained for a URI are immutable (ie once
sourced or generated they cannot be changed). However the representation can be invalidated - in which case its data is
declared to be out of date. Whilst aspects are immutable, new aspects can be dynamically added to a representation.
Transreptors
A request for a resource is made using its URI, in addition the request must specify the aspect of the resource that it requires.
If the aspect which is requested is not found in the resulting representation, the Kernel
tries to locate a registered converter from an aspect of the representation which is present to the aspect which was requested.
The components which convert one aspect to another are called
Tranrepresentors (or Transreptors for short).
This is not a pretentious made up name for a transformer! A transform is an explicit operation on a resource to
change it from one thing to another. A transrepresentation never changes the resource, it only ever changes from one concrete form to another concrete form -
transrepresentation is lossless and reversible.
We can illustrate by returning to the XML document example. Suppose that initially the XML document is obtained from the filesystem in it's lowest form, as a stream of bytes.
However an Accessor requests that the resource URI be returned with a DOM Aspect. NetKernel looks to find a binary-stream to DOM converter, more commonly recognised as a DOM Parser.
It issues a request to the DOMParser Transreptor to tranrepresent the binary-stream to DOM. Finally the accessor receives the XML document in the DOM form it requested. The
transrepresentation process is completely transparent to the accessor.
The Representation, Aspect, Transreptor architecture is very powerful. It means that accessors do not need to implement common functionality and the execution of
aspect conversion is always transparently performed by NetKernel - in practical terms an XML process does not need to be concerned with parsing or serialization, unless it
really needs to. It also means that since the URI is unique and the resource at that URI is immutable the URI can be used as a primary key to the cached resource and
further the cached representation need only maintain the most commonly used forms of the resource.