@@ -10,15 +10,30 @@ interface NamedComponent {
10
10
component : jsonConfig . Component ;
11
11
}
12
12
13
+ /**
14
+ * [[BeanDefinitionMethod]] does not include the name of the method or the name of the class it is defined in; these are provided by the context.
15
+ *
16
+ * This class therefore combines these bits of information to act as the value to be used in a map from calculated identifiers to bean definition
17
+ * methods.
18
+ */
13
19
interface NamedBeanDefinitionMethod {
14
20
className : string ;
15
21
name : string ;
16
22
method : jsonConfig . BeanDefinitionMethod ;
17
23
}
18
24
25
+ // A map from identifiers to components discovered in the JSON file.
19
26
const componentsById = new Map < string , NamedComponent > ( ) ;
27
+ // A map from identifiers to bean definition methods discovered in the JSON file.
20
28
const beansById = new Map < string , NamedBeanDefinitionMethod > ( ) ;
21
29
30
+ /**
31
+ * Collect beans from the JSON configuration file without parsing them.
32
+ *
33
+ * This allows us to set up objects that can be used to resolve circular references discovered later during parsing.
34
+ * @param filePath The path to the configuration file to read the input from
35
+ * @returns Paths to other config files to also include
36
+ */
22
37
export async function collectBeansFromConfigFile ( filePath : string ) : Promise < string [ ] > {
23
38
let json : string ;
24
39
try {
@@ -60,7 +75,12 @@ export async function collectBeansFromConfigFile(filePath: string): Promise<stri
60
75
return [ ] ;
61
76
}
62
77
63
- // Check for duplicate ids from other beans
78
+ /**
79
+ * Check for duplicate ids from other beans or aliases
80
+ * @param id The bean identifier to check
81
+ * @param location The location to include in the text of any thrown exception
82
+ * @throws [[ConfigParseError]] If the bean identifier has already been used
83
+ */
64
84
function checkBeanId ( id : string , location : string ) : void {
65
85
if ( componentsById . has ( id ) )
66
86
throw new ConfigParseError ( `${ location } : There is an existing component with id '${ id } '` ) ;
@@ -71,10 +91,18 @@ function checkBeanId(id: string, location: string): void {
71
91
throw new ConfigParseError ( `${ location } : There is an existing alias with identifier '${ aliasedBeanId } '` ) ;
72
92
}
73
93
94
+ /**
95
+ * Check whether a bean identifier is already implemented by an element from the JSON configuration
96
+ * @param id The bean identifier to check
97
+ * @returns True if the bean identifier is already registered
98
+ */
74
99
export function beanWithIdExists ( id : string ) : boolean {
75
100
return componentsById . has ( id ) || beansById . has ( id ) ;
76
101
}
77
102
103
+ /**
104
+ * Create the model for each bean discovered during the execution of [[collectBeansFromConfigFile]]
105
+ */
78
106
export function parseAllBeans ( ) : void {
79
107
for ( const [ beanId , component ] of componentsById ) {
80
108
if ( model . Bean . tryGet ( beanId ) !== undefined )
@@ -90,6 +118,11 @@ export function parseAllBeans(): void {
90
118
}
91
119
}
92
120
121
+ /**
122
+ * Create the model for a bean with the given identifier
123
+ * @param id The identifier of a bean implemented by a component or bean definition method
124
+ * @returns The model for the bean
125
+ */
93
126
export function parseBean ( id : string ) : model . Bean {
94
127
const component = componentsById . get ( id ) ;
95
128
if ( component !== undefined )
@@ -100,6 +133,12 @@ export function parseBean(id: string): model.Bean {
100
133
throw new Error ( "Called parseBean on a bean that did not exist" ) ;
101
134
}
102
135
136
+ /**
137
+ * Create the model for a bean with the given identifier defined by a component from the JSON configuration file
138
+ * @param id The identifier of a bean implemented by a component
139
+ * @param namedBean The component definition from the JSON configuration file
140
+ * @returns The model for the bean
141
+ */
103
142
function parseJsonComponent ( id : string , namedBean : NamedComponent ) : model . Bean {
104
143
const component = namedBean . component ;
105
144
const properties : model . BeanProperty [ ] = [ ] ;
@@ -115,6 +154,12 @@ function parseJsonComponent(id: string, namedBean: NamedComponent): model.Bean {
115
154
return new model . Bean ( undefined , id , namedBean . qualifiedClassName , false , [ ] , properties ) ;
116
155
}
117
156
157
+ /**
158
+ * Create the model for a bean with the given identifier defined by a component from the JSON configuration file
159
+ * @param id The identifier of a bean implemented by a bean definition method
160
+ * @param namedMethod The bean definition method definition from the JSON configuration file
161
+ * @returns The model for the bean
162
+ */
118
163
function parseJsonBean ( id : string , namedMethod : NamedBeanDefinitionMethod ) : model . Bean {
119
164
const fieldBeanId = model . Bean . tryGetIdByClass ( namedMethod . className ) ;
120
165
if ( fieldBeanId === undefined )
0 commit comments