|
16 | 16 | import java.io.FileNotFoundException;
|
17 | 17 | import java.util.Collections;
|
18 | 18 | import java.util.HashSet;
|
| 19 | +import java.util.List; |
19 | 20 | import java.util.Map;
|
20 | 21 | import java.util.Set;
|
21 | 22 | import java.util.Stack;
|
@@ -97,7 +98,19 @@ private static Try<String> resolveBammUrn( final String urn ) {
|
97 | 98 | * @return The resolved model on success
|
98 | 99 | */
|
99 | 100 | public Try<VersionedModel> resolveAspectModel( final ResolutionStrategy resolver, final AspectModelUrn input ) {
|
100 |
| - final Try<Model> mergedModel = resolve( input.toString(), resolver ); |
| 101 | + return resolveAspectModel( resolver, List.of( input ) ); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Method to resolve multiple {@link AspectModelUrn}s using a suitable {@link ResolutionStrategy}. |
| 106 | + * This creates the closure (merged model) of all referenced models and the corresponding meta model. |
| 107 | + * |
| 108 | + * @param resolver The strategy to resolve input URNs to RDF models |
| 109 | + * @param input The input to be resolved by the strategy |
| 110 | + * @return The resolved model on success |
| 111 | + */ |
| 112 | + public Try<VersionedModel> resolveAspectModel( final ResolutionStrategy resolver, final List<AspectModelUrn> input ) { |
| 113 | + final Try<Model> mergedModel = resolve( input.stream().map( AspectModelUrn::toString ).toList(), resolver ); |
101 | 114 |
|
102 | 115 | if ( mergedModel.isFailure() ) {
|
103 | 116 | if ( mergedModel.getCause() instanceof FileNotFoundException ) {
|
@@ -151,18 +164,20 @@ public static boolean containsDefinition( final Model model, final AspectModelUr
|
151 | 164 | }
|
152 | 165 |
|
153 | 166 | /**
|
154 |
| - * The main model resolution method that takes an Aspect Model element URN and a resolution strategy as input. |
155 |
| - * The strategy is applied to the URN to load a model, and then repeated for all URNs in the loaded model that |
| 167 | + * The main model resolution method that takes Aspect Model element URNs and a resolution strategy as input. |
| 168 | + * The strategy is applied to the URNs to load a model, and then repeated for all URNs in the loaded model that |
156 | 169 | * have not yet been loaded.
|
157 |
| - * @param urn the Aspect Model element URN |
| 170 | + * @param urns the Aspect Model element URNs |
158 | 171 | * @param resolutionStrategy the resolution strategy that knowns how to turn a URN into a Model
|
159 | 172 | * @return the fully resolved model, or a failure if one of the transitively referenced elements can't be found
|
160 | 173 | */
|
161 |
| - private Try<Model> resolve( final String urn, final ResolutionStrategy resolutionStrategy ) { |
| 174 | + private Try<Model> resolve( final List<String> urns, final ResolutionStrategy resolutionStrategy ) { |
162 | 175 | final Model result = ModelFactory.createDefaultModel();
|
163 | 176 | final Stack<String> unresolvedUrns = new Stack<>();
|
164 | 177 | final Set<Model> mergedModels = new HashSet<>();
|
165 |
| - unresolvedUrns.push( urn ); |
| 178 | + for ( final String urn : urns ) { |
| 179 | + unresolvedUrns.push( urn ); |
| 180 | + } |
166 | 181 |
|
167 | 182 | while ( !unresolvedUrns.isEmpty() ) {
|
168 | 183 | final String urnToResolve = unresolvedUrns.pop();
|
|
0 commit comments