1 /*
2 * SPDX-FileCopyrightText: none
3 * SPDX-License-Identifier: CC0-1.0
4 */
5
6 package dev.metaschema.core.testsupport.builder;
7
8 import java.net.URI;
9 import java.util.List;
10
11 import dev.metaschema.core.model.IAssemblyDefinition;
12 import dev.metaschema.core.model.IAssemblyInstanceAbsolute;
13 import dev.metaschema.core.model.IModule;
14 import dev.metaschema.core.qname.IEnhancedQName;
15 import dev.metaschema.core.util.ObjectUtils;
16 import edu.umd.cs.findbugs.annotations.NonNull;
17 import edu.umd.cs.findbugs.annotations.Nullable;
18
19 /**
20 * Represents a Metaschema module-based model builder for producing assembly
21 * definitions and instances.
22 */
23 public interface IAssemblyBuilder extends IModelBuilder<IAssemblyBuilder> {
24
25 /**
26 * Create a new builder using the provided mocking context.
27 *
28 * @return the new builder
29 */
30 @NonNull
31 static IAssemblyBuilder builder() {
32 return new AssemblyBuilder().reset();
33 }
34
35 /**
36 * Apply the provided root namespace for use by this builder.
37 *
38 * @param name
39 * the namespace to use
40 * @return this builder
41 */
42 @NonNull
43 IAssemblyBuilder rootNamespace(@NonNull String name);
44
45 /**
46 * Apply the provided root namespace for use by this builder.
47 *
48 * @param name
49 * the namespace to use
50 * @return this builder
51 */
52 @NonNull
53 default IAssemblyBuilder rootNamespace(@NonNull URI name) {
54 return rootNamespace(ObjectUtils.notNull(name.toASCIIString()));
55 }
56
57 /**
58 * Apply the provided root name for use by this builder.
59 *
60 * @param name
61 * the name to use
62 * @return this builder
63 */
64 @NonNull
65 IAssemblyBuilder rootName(@NonNull String name);
66
67 /**
68 * Apply the provided root qualified name for use by this builder.
69 *
70 * @param qname
71 * the qualified name to use
72 * @return this builder
73 */
74 @NonNull
75 IAssemblyBuilder rootQName(@NonNull IEnhancedQName qname);
76
77 /**
78 * Use the provided model instances for built fields.
79 *
80 * @param modelInstances
81 * the model instances to use
82 * @return this builder
83 */
84 IAssemblyBuilder modelInstances(@Nullable List<? extends IModelBuilder<?>> modelInstances);
85
86 @Override
87 @NonNull
88 IAssemblyInstanceAbsolute toInstance(@NonNull IAssemblyDefinition parent);
89
90 /**
91 * Build a mocked assembly instance, using the provided definition, as a child
92 * of the provided parent.
93 *
94 * @param parent
95 * the parent containing the new instance
96 * @param definition
97 * the definition to base the instance on
98 * @return the new mocked instance
99 */
100 @NonNull
101 IAssemblyInstanceAbsolute toInstance(@NonNull IAssemblyDefinition parent, @NonNull IAssemblyDefinition definition);
102
103 /**
104 * Build a mocked assembly definition.
105 *
106 * @return the new mocked definition
107 */
108 @NonNull
109 IAssemblyDefinition toDefinition();
110
111 /**
112 * Build a mocked assembly definition associated with the given module.
113 *
114 * @param module
115 * the containing module
116 * @return the new mocked definition
117 */
118 @NonNull
119 IAssemblyDefinition toDefinition(@NonNull IModule module);
120 }