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 | /**
|
18 | *
|
19 | * Provides access to the structure of transactions, assets and participants.
|
20 | *
|
21 | * @class
|
22 | * @memberof module:concerto-core
|
23 | */
|
24 | class Introspector {
|
25 | /**
|
26 | * Create the Introspector.
|
27 | * @param {ModelManager} modelManager - the ModelManager that backs this Introspector
|
28 | */
|
29 | constructor(modelManager) {
|
30 | this.modelManager = modelManager;
|
31 | }
|
32 |
|
33 | /**
|
34 | * Visitor design pattern
|
35 | * @param {Object} visitor - the visitor
|
36 | * @param {Object} parameters - the parameter
|
37 | * @return {Object} the result of visiting or null
|
38 | * @private
|
39 | */
|
40 | accept(visitor,parameters) {
|
41 | return visitor.visit(this, parameters);
|
42 | }
|
43 |
|
44 | /**
|
45 | * Returns all the class declarations for the business network.
|
46 | * @return {ClassDeclaration[]} the array of class declarations
|
47 | */
|
48 | getClassDeclarations() {
|
49 | let result = [];
|
50 | const modelFiles = this.modelManager.getModelFiles();
|
51 | for(let n=0; n < modelFiles.length; n++) {
|
52 | const modelFile = modelFiles[n];
|
53 | result = result.concat(modelFile.getAllDeclarations());
|
54 | }
|
55 | return result;
|
56 | }
|
57 |
|
58 | /**
|
59 | * Returns the class declaration with the given fully qualified name.
|
60 | * Throws an error if the class declaration does not exist.
|
61 | * @param {String} fullyQualifiedTypeName - the fully qualified name of the type
|
62 | * @return {ClassDeclaration} the class declaration
|
63 | * @throws {Error} if the class declaration does not exist
|
64 | */
|
65 | getClassDeclaration(fullyQualifiedTypeName) {
|
66 | return this.modelManager.getType(fullyQualifiedTypeName);
|
67 | }
|
68 |
|
69 | /**
|
70 | * Returns the backing ModelManager
|
71 | * @return {ModelManager} the backing ModelManager
|
72 | * @private
|
73 | */
|
74 | getModelManager() {
|
75 | return this.modelManager;
|
76 | }
|
77 | }
|
78 |
|
79 | module.exports = Introspector;
|