/** * Create a new builder instance using the specified default {@link Charset}. * * @param defaultCharset the default charset to use * @return a new {@link ConfigurationMetadataRepositoryJsonBuilder} instance. */ public static CasConfigurationMetadataRepositoryJsonBuilder create(final Charset defaultCharset) { return new CasConfigurationMetadataRepositoryJsonBuilder(defaultCharset); } }
@SneakyThrows public CasConfigurationMetadataRepository(final Resource resource) { val builder = CasConfigurationMetadataRepositoryJsonBuilder.create(); try (val in = resource.getInputStream()) { builder.withJsonResource(in); } repository = builder.build(); }
/** * Create a new builder instance using {@link StandardCharsets#UTF_8} as the default * charset and the specified json resource. * * @param inputStreams the source input streams * @return a new {@link ConfigurationMetadataRepositoryJsonBuilder} instance. * @throws IOException on error */ public static CasConfigurationMetadataRepositoryJsonBuilder create(final InputStream... inputStreams) throws IOException { var builder = create(); for (val inputStream : inputStreams) { builder = builder.withJsonResource(inputStream); } return builder; }
private static SimpleConfigurationMetadataRepository create(final RawConfigurationMetadata metadata) { val repository = new SimpleConfigurationMetadataRepository(); repository.add(metadata.getSources()); for (val item : metadata.getItems()) { val source = getSource(metadata, item); repository.add(item, source); } val allProperties = repository.getAllProperties(); for (val hint : metadata.getHints()) { var property = allProperties.get(hint.getId()); if (property != null) { addValueHints(property, hint); } else { val id = hint.resolveId(); property = allProperties.get(id); if (property != null) { if (hint.isMapKeyHints()) { addMapHints(property, hint); } else { addValueHints(property, hint); } } } } return repository; }
/** * Create a new builder instance using {@link StandardCharsets#UTF_8} as the default * charset. * * @return a new {@link ConfigurationMetadataRepositoryJsonBuilder} instance. */ public static CasConfigurationMetadataRepositoryJsonBuilder create() { return create(StandardCharsets.UTF_8); }
/** * Add the content of a {@link ConfigurationMetadataRepository} defined by the * specified {@link InputStream} json document using the default charset. If this * metadata repository holds items that were loaded previously, these are ignored. * <p> * Leaves the stream open when done. * * @param inputStream the source input stream * @return this builder */ public CasConfigurationMetadataRepositoryJsonBuilder withJsonResource(final InputStream inputStream) { return withJsonResource(inputStream, this.defaultCharset); }
/** * Add the content of a {@link ConfigurationMetadataRepository} defined by the * specified {@link InputStream} json document using the specified {@link Charset}. If * this metadata repository holds items that were loaded previously, these are * ignored. * <p> * Leaves the stream open when done. * * @param inputStream the source input stream * @param charset the charset of the input * @return this builder */ public CasConfigurationMetadataRepositoryJsonBuilder withJsonResource(final InputStream inputStream, final Charset charset) { if (inputStream == null) { throw new IllegalArgumentException("InputStream must not be null."); } this.repositories.add(add(inputStream, charset)); return this; }
private SimpleConfigurationMetadataRepository add(final InputStream in, final Charset charset) { try { val metadata = this.reader.read(in, charset); return create(metadata); } catch (final Exception ex) { throw new IllegalStateException("Failed to read configuration metadata", ex); } }
/** * Instantiates a new Cas configuration metadata repository. * Scans the context looking for spring configuration metadata * resources and then loads them all into a repository instance. * * @param resource the resource */ @SneakyThrows public CasConfigurationMetadataRepository(final String resource) { val resources = new PathMatchingResourcePatternResolver().getResources(resource); val builder = CasConfigurationMetadataRepositoryJsonBuilder.create(); Arrays.stream(resources).forEach(Unchecked.consumer(r -> { try (val in = r.getInputStream()) { builder.withJsonResource(in); } })); repository = builder.build(); }