Factory (Runtime API)

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

Factory

Use the Factory to create instances of Resource: transactions, participants and assets.

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

Details

  • Module runtime

Method Summary

Name Returns Description
newConcept Concept Create a new concept with a given namespace, type, and identifier
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
newResource Resource Create a new resource (an instance of an asset, participant, or transaction)

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.

Returns

Resource - The new instance of the resource.

Parameters

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

Example

// Get the factory.
var factory = getFactory();
// Create a new vehicle.
var vehicle = factory.newResource('org.example', '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.example', type 'Vehicle' and identifier 'VEHICLE_1' creates` a pointer that points at an existing instance of org.example.Vehicle with the identifier 'VEHICLE_1'.

Returns

Relationship - The new instance of the relationship.

Parameters

Name Type Mandatory Description
ns string Yes The namespace of the resource referenced by the relationship.
type string Yes The type of the resource referenced by the relationship.
id string Yes 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.example', '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

Returns

Concept - The new instance of the concept.

Parameters

Name Type Mandatory Description
ns string Yes The namespace of the concept.
type string Yes 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.example', '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 Mandatory Description
ns string Yes The namespace of the event.
type string Yes The type of the event.

Inherited methods