WARNING: This server provides a static reference view of the NetKernel documentation. Links to dynamic content do not work. For the best experience we recommend you install NetKernel and view the documentation in the live system .

Endpoint
Name:JavascriptPrototype
Description:
Id:JavascriptPrototype
Category:accessor prototype

JavascriptPrototype is an accessor that must be instantiated from a prototype. You must instantiate the prototype in your module to create an accessor that can receive requests.

Parameters

The JavascriptPrototype prototype has the following initialisation parameters:

NameRulesTypingDefaultDescription
scriptMandatoryIdentifier or XML(none)
Javascript to execute
grammarMandatoryXML(none)
An identifier grammar definition.
verbsOptionalStringSOURCE
comma separated list of supported verbs
privateOptionalBooleanfalse
If included this parameter will mark the endpoint as private and it will not be exposed outside module.
idOptionalStringnull
An identifier for created logical endpoint, if omitted a unique auto-generated value it will be used.
fromRepresentationAny quantityStringnull
used when creating transreptor
toRepresentationAny quantityStringnull
used when creating transreptor
metaOptionalXMLnull(no description available)

Here is an auto-generated example of how to instantiate an instance of JavascriptPrototype:

<accessor>
  <prototype>JavascriptPrototype</prototype>
  <script>Javascript to execute</script>
  <grammar>an identifier grammar definition</grammar>
</accessor>
Import Requirements

To use JavascriptPrototype accessor prototype you must import the module urn:org:netkernel:lang:javascript:

<import>
  <uri>urn:org:netkernel:lang:javascript</uri>
</import>

The Javascript language prototype is an alternate way of using the javascript functionality to the runtime. The prototype allows the instantiation of a javascript implemented accessor within your application without the need to [map requests to it. This has benefits of compactness and the ability to implement transreptors.

Verbs

The comma separate list of verbs defines which verbs will be supported by the instantiated javascript accessor. This defaults to just "SOURCE". See the mapper verbs document for examples of how to set this string.

The runtime contains documentation on how to differentiate handling of different verbs.

Example

Implementing a transreptor in javascript is easy, you need to declare the instantiation of the prototype in your space:

<transreptor>
  <verbs>TRANSREPT</verbs>
  <prototype>JavascriptPrototype</prototype>
  <grammar>
    <regex type="anything" />
  </grammar>
  <fromRepresentation>java.lang.Object</fromRepresentation>
  <toRepresentation>org.ten60.netkernel.lang.javascript.test.MyRep</toRepresentation>
  <script>res:/test/integration/transrept.js</script>
</transreptor>
Then create a static resource containing your javascript:
// Javascript code to implement simple transreptor
primary = context.sourcePrimary(java.lang.Object);
rep = new org.ten60.netkernel.lang.javascript.test.MyRep(primary);
context.createResponseFrom(rep);