Class: Factory

composer-common. Factory

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


new Factory(modelManager)

Create the factory.


Note: Only to be called by framework code. Applications should
retrieve instances from Fabric-Composer

Parameters:
Name Type Description
modelManager ModelManager

The ModelManager to use for this registry

Source:

Methods


newConcept(ns, type [, options])

Create a new Resource with a given namespace, type name and id

Parameters:
Name Type Argument Description
ns string

the namespace of the Resource

type string

the type of the Resource

options Object <optional>

an optional set of options

Properties
Name Type Argument Description
disableValidation boolean <optional>

pass true if you want the factory to
return a Resource instead of a ValidatedResource. Defaults to false.

generate boolean <optional>

pass true if you want the factory to return a
resource instance with generated sample data.

Source:
Throws:

if the type is not registered with the ModelManager

Type
ModelException
Returns:

the new instance

Type
Resource

newInstance(ns, type, id [, options])

Create a new Resource with a given namespace, type name and id

Parameters:
Name Type Argument Description
ns string

the namespace of the Resource

type string

the type of the Resource

id string

the identifier

options Object <optional>

an optional set of options

Properties
Name Type Argument Description
disableValidation boolean <optional>

pass true if you want the factory to
return a Resource instead of a ValidatedResource. Defaults to false.

generate boolean <optional>

pass true if you want the factory to return a
resource instance with generated sample data.

Deprecated:
  • - use newResource instead
Source:
Throws:

if the type is not registered with the ModelManager

Type
ModelException
Returns:

the new instance

Type
Resource

newRelationship(ns, type, id)

Create a new Relationship with a given namespace, type and identifier.
* A relationship is a typed pointer to an instance. I.e the relationship with namespace = 'org.acme', type = 'Vehicle' and id = 'ABC' creates
a pointer that points at an instance of org.acme.Vehicle with the id
ABC.

Parameters:
Name Type Description
ns string

the namespace of the Resource

type string

the type of the Resource

id string

the identifier

Source:
Throws:

if the type is not registered with the ModelManager

Type
ModelException
Returns:
  • the new relationship instance
Type
Relationship

newResource(ns, type, id [, options])

Create a new Resource with a given namespace, type name and id

Parameters:
Name Type Argument Description
ns string

the namespace of the Resource

type string

the type of the Resource

id string

the identifier

options Object <optional>

an optional set of options

Properties
Name Type Argument Description
disableValidation boolean <optional>

pass true if you want the factory to
return a Resource instead of a ValidatedResource. Defaults to false.

generate boolean <optional>

pass true if you want the factory to return a
resource instance with generated sample data.

Source:
Throws:

if the type is not registered with the ModelManager

Type
ModelException
Returns:

the new instance

Type
Resource

newTransaction(ns, type [, id] [, options])

Create a new transaction object. The identifier of the transaction is
set to a UUID.

Parameters:
Name Type Argument Description
ns string

the namespace of the transaction.

type string

the type of the transaction.

id string <optional>

an optional identifier for the transaction; if you do not specify
one then an identifier will be automatically generated.

options Object <optional>

an optional set of options

Properties
Name Type Argument Description
generate boolean <optional>

pass true if you want the factory to return a
resource instance with generated sample data.

Source:
Returns:

A resource for the new transaction.

Type
Resource

toJSON()

Stop serialization of this object.

Source:
Returns:

An empty object.

Type
Object