-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathConstructorArgumentsElementMappingHandlerList.ts
More file actions
45 lines (43 loc) · 1.54 KB
/
ConstructorArgumentsElementMappingHandlerList.ts
File metadata and controls
45 lines (43 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { Resource } from 'rdf-object';
import type { GenericsContext } from '../GenericsContext';
import type { IConstructorArgumentsElementMappingHandler } from './IConstructorArgumentsElementMappingHandler';
import type { IConstructorArgumentsMapper } from './IConstructorArgumentsMapper';
/**
* Handler for an RDF list.
*/
export class ConstructorArgumentsElementMappingHandlerList implements IConstructorArgumentsElementMappingHandler {
public canHandle(
configRoot: Resource,
constructorArgs: Resource,
configElement: Resource,
mapper: IConstructorArgumentsMapper,
): boolean {
return Boolean(constructorArgs.list);
}
public handle(
configRoot: Resource,
constructorArgs: Resource,
configElement: Resource,
mapper: IConstructorArgumentsMapper,
genericsContext: GenericsContext,
): Resource {
// Recursively handle all field values.
const ret = mapper.objectLoader.createCompactedResource({});
ret.list = [];
for (const argument of constructorArgs.list!) {
if (argument.property.fields || argument.property.elements) {
ret.list.push(mapper
.applyConstructorArgumentsParameters(configRoot, argument, configElement, genericsContext));
} else {
const value = mapper
.getParameterValue(configRoot, argument, configElement, false, genericsContext);
if (value) {
ret.list.push(value);
} else {
ret.list.push(mapper.objectLoader.createCompactedResource({ undefined: true }));
}
}
}
return ret;
}
}