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 | /** Class representing the definition of an Event.
|
20 | * @extends ClassDeclaration
|
21 | * @see See {@link ClassDeclaration}
|
22 | * @class
|
23 | * @memberof module:concerto-core
|
24 | */
|
25 | class EventDeclaration extends ClassDeclaration {
|
26 | /**
|
27 | * Create an EventDeclaration.
|
28 | * @param {ModelFile} modelFile the ModelFile for this class
|
29 | * @param {Object} ast - The AST created by the parser
|
30 | * @throws {IllegalModelException}
|
31 | */
|
32 | constructor(modelFile, ast) {
|
33 | super(modelFile, ast);
|
34 | this._isEventDeclaration = true;
|
35 | }
|
36 |
|
37 | /**
|
38 | * Process the AST and build the model
|
39 | *
|
40 | * @throws {IllegalModelException}
|
41 | * @private
|
42 | */
|
43 | process() {
|
44 | super.process();
|
45 | this.addTimestampField();
|
46 | }
|
47 |
|
48 | /**
|
49 | * Returns the base system type for Events from the system namespace
|
50 | *
|
51 | * @return {string} the short name of the base system type
|
52 | */
|
53 | getSystemType() {
|
54 | let systemType = this.modelFile.getModelManager().getSystemModelTable().get('Event');
|
55 | return systemType !== undefined ? systemType : null;
|
56 | }
|
57 |
|
58 | /**
|
59 | * Returns true if this class is the definition of an event
|
60 | *
|
61 | * @return {boolean} true if the class is an event
|
62 | */
|
63 | isEvent() {
|
64 | return true;
|
65 | }
|
66 |
|
67 | /**
|
68 | * Alternative instanceof that is reliable across different module instances
|
69 | * @see https://github.com/hyperledger/composer-concerto/issues/47
|
70 | *
|
71 | * @param {object} object - The object to test against
|
72 | * @returns {boolean} - True, if the object is an instance of a EventDeclaration
|
73 | */
|
74 | static [Symbol.hasInstance](object){
|
75 | return typeof object !== 'undefined' && object !== null && Boolean(object._isEventDeclaration);
|
76 | }
|
77 | }
|
78 |
|
79 | module.exports = EventDeclaration;
|