1 | /*
|
2 | * Licensed under the Apache License, Version 2.0 (the "License");
|
3 | * you may not use this file except in compliance with the License.
|
4 | * You may obtain a copy of the License at
|
5 | *
|
6 | * http://www.apache.org/licenses/LICENSE-2.0
|
7 | *
|
8 | * Unless required by applicable law or agreed to in writing, software
|
9 | * distributed under the License is distributed on an "AS IS" BASIS,
|
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11 | * See the License for the specific language governing permissions and
|
12 | * limitations under the License.
|
13 | */
|
14 |
|
15 | ;
|
16 |
|
17 | const ClassDeclaration = require('./classdeclaration');
|
18 |
|
19 | /**
|
20 | * AssetDeclaration defines the schema (aka model or class) for
|
21 | * an Asset. It extends ClassDeclaration which manages a set of
|
22 | * fields, a super-type and the specification of an
|
23 | * identifying field.
|
24 | *
|
25 | * @extends ClassDeclaration
|
26 | * @see See {@link ClassDeclaration}
|
27 | * @class
|
28 | * @memberof module:concerto-core
|
29 | */
|
30 | class AssetDeclaration extends ClassDeclaration {
|
31 |
|
32 | /**
|
33 | * Create an AssetDeclaration.
|
34 | * @param {ModelFile} modelFile the ModelFile for this class
|
35 | * @param {Object} ast - The AST created by the parser
|
36 | * @throws {IllegalModelException}
|
37 | */
|
38 | constructor(modelFile, ast) {
|
39 | super(modelFile, ast);
|
40 | this._isAssetDeclaration = true;
|
41 | }
|
42 |
|
43 | /**
|
44 | * Returns true if this class can be pointed to by a relationship
|
45 | *
|
46 | * @return {boolean} true if the class may be pointed to by a relationship
|
47 | */
|
48 | isRelationshipTarget() {
|
49 | return true;
|
50 | }
|
51 |
|
52 | /**
|
53 | * Returns the base system type for Assets from the system namespace
|
54 | *
|
55 | * @return {string} the short name of the base system type
|
56 | */
|
57 | getSystemType() {
|
58 | let systemType = this.modelFile.getModelManager().getSystemModelTable().get('Asset');
|
59 | return systemType !== undefined ? systemType : null;
|
60 | }
|
61 |
|
62 | /**
|
63 | * Alternative instanceof that is reliable across different module instances
|
64 | * @see https://github.com/hyperledger/composer-concerto/issues/47
|
65 | *
|
66 | * @param {object} object - The object to test against
|
67 | * @returns {boolean} - True, if the object is an instance of a AssetDeclaration
|
68 | */
|
69 | static [Symbol.hasInstance](object){
|
70 | return typeof object !== 'undefined' && object !== null && Boolean(object._isAssetDeclaration);
|
71 | }
|
72 | }
|
73 |
|
74 | module.exports = AssetDeclaration;
|