Factory (Runtime API)

Overview - Common API - Client API - Admin API - Runtime API

Factory

Do not attempt to create an instance of this class.
You must use the getFactory method instead.

Details

  • Module runtime

See also

Method Summary

Name Returns Description
newConcept Concept Create a new concept with a given namespace, type, and identifier. A concept is an advanced data structure
newEvent Resource Create a new type with a given namespace and type
newRelationship Relationship Create a new relationship with a given namespace, type, and identifier. A relationship is a typed pointer to an instance. For example, a new relationship with namespace 'org.acme', type 'Vehicle' and identifier 'VEHICLE_1' creates` a pointer that points at an existing instance of org.acme.Vehicle with the identifier 'VEHICLE_1'.
newResource Resource Create a new resource (an instance of an asset, participant, or transaction). The properties of the new instance should be set as standard JavaScript object properties. The new instance can then be stored in a registry using the appropriate registry APIs, for example AssetRegistry.

Method Details

newResource

Resource newResource( string ns, string type, string id )

Create a new resource (an instance of an asset, participant, or transaction). The properties of the new instance should be set as standard JavaScript object properties. The new instance can then be stored in a registry using the appropriate registry APIs, for example AssetRegistry.

Example

// Get the factory.
var factory = getFactory();
// Create a new vehicle.
var vehicle = factory.newResource('org.acme', 'Vehicle', 'VEHICLE_1');
// Set the properties of the new vehicle.
vehicle.colour = 'BLUE';
vehicle.manufacturer = 'Toyota';

Returns

Resource - The new instance of the resource.

Parameters

Name Type Optional Description
ns string false The namespace of the resource to create.
type string false The type of the resource to create.
id string false The identifier of the new resource.

Example

// Get the factory.
var factory = getFactory();
// Create a new vehicle.
var vehicle = factory.newResource('org.acme', 'Vehicle', 'VEHICLE_1');
// Set the properties of the new vehicle.
vehicle.colour = 'BLUE';
vehicle.manufacturer = 'Toyota';

newRelationship

Relationship newRelationship( string ns, string type, string id )

Create a new relationship with a given namespace, type, and identifier. A relationship is a typed pointer to an instance. For example, a new relationship with namespace 'org.acme', type 'Vehicle' and identifier 'VEHICLE_1' creates` a pointer that points at an existing instance of org.acme.Vehicle with the identifier 'VEHICLE_1'.

Example

// The existing driver of the vehicle.
var driver;
// Get the factory.
var factory = getFactory();
// Create a new relationship to the vehicle.
var vehicle = factory.newRelationship('org.acme', 'Vehicle', 'VEHICLE_1');
// Set the relationship as the value of the vehicle property of the driver.
driver.vehicle = vehicle;

Returns

Relationship - The new instance of the relationship.

Parameters

Name Type Optional Description
ns string false The namespace of the resource referenced by the relationship.
type string false The type of the resource referenced by the relationship.
id string false The identifier of the resource referenced by the relationship.

Example

// The existing driver of the vehicle.
var driver;
// Get the factory.
var factory = getFactory();
// Create a new relationship to the vehicle.
var vehicle = factory.newRelationship('org.acme', 'Vehicle', 'VEHICLE_1');
// Set the relationship as the value of the vehicle property of the driver.
driver.vehicle = vehicle;

newConcept

Concept newConcept( string ns, string type )

Create a new concept with a given namespace, type, and identifier. A concept is an advanced data structure

Example

// The existing driver of the vehicle.
var person;
// Get the factory.
var factory = getFactory();
// Create a new relationship to the vehicle.
var record = factory.newConcept('org.acme', 'Record');
// Add the record to the persons array of records.
person.records.push(record);

Returns

Concept - The new instance of the concept.

Parameters

Name Type Optional Description
ns string false The namespace of the concept.
type string false The type of the concept.

Example

// The existing driver of the vehicle.
var person;
// Get the factory.
var factory = getFactory();
// Create a new relationship to the vehicle.
var record = factory.newConcept('org.acme', 'Record');
// Add the record to the persons array of records.
person.records.push(record);

newEvent

Resource newEvent( string ns, string type )

Create a new type with a given namespace and type

Returns

Resource - The new instance of the event.

Parameters

Name Type Optional Description
ns string false The namespace of the event.
type string false The type of the event.