/** * Default constructor. */ private ConfigurationKeyContextManager() { this.context = createContext(); }
/** * Constructs an instance based on the given matchers. * * @param configurationKey the configuration key the matcher is responsible * for. * @param matchers the matchers to use for matching. * @return the constructed instance. */ public static PathMatcher forMatchers( final ConfigurationKey<?> configurationKey, final List<Matcher> matchers) { return new PathMatcher(configurationKey, matchers); }
/** * Constructs an instance based on the given paths. * * @param configurationKey the configuration key the matcher is responsible * for. * @param paths the list of paths to match. A path may end with <code>*</code> * signaling a wildcard match. * @return the constructed instance. */ public static PathMatcher forPaths( final ConfigurationKey<?> configurationKey, final List<String> paths) { return forMatchers(configurationKey, convertToMatchers(paths)); }
private static ConfigurationKey<?> createKey(final ApplicationId applicationId) { return ConfigurationKeyContextManager.INSTANCE.context() .configurationKeyFactory().createKey(applicationId); }
/** * Returns the definition information for the given class loader. * * @param context the class loader and the root folder to read the * <code>{@value de.smartics.properties.api.core.domain.PropertiesContext#DEFINITION_FILE_NAME}</code> * . * @return the definition helper if there is a * <code>{@value de.smartics.properties.api.core.domain.PropertiesContext#DEFINITION_FILE_NAME}</code> * or at least * {@value de.smartics.properties.api.core.domain.PropertiesContext#META_INF_HOME} * , <code>null</code> otherwise. */ @CheckForNull DefinitionKeyHelper getDefinition(final ClassPathContext context) { DefinitionKeyHelper definition = definitionCache.get(context); if (definition == null) { final DefinitionConfigParser<?> parser = ConfigurationKeyContextManager.INSTANCE.context() .definitionConfigParser(); final PropertiesDefinitionContext definitionContext = parser.parse(context); definition = ConfigurationKeyContextManager.INSTANCE.context() .definitionKeyHelper(definitionContext); definitionCache.put(context, definition); } return definition; }
/** * Expected to be called with write lock acquired. */ private ConfigurationPropertiesManagement constructConfigurationWithDefaults( final ConfigurationKey<?> key) { final KeyListBuilder builder = ConfigurationKeyContextManager.INSTANCE.context().keyListBuilder(); final List<ConfigurationKey<?>> keySet = builder.createKeyList(key); final List<ConfigurationPropertiesManagement> defaults = new ArrayList<ConfigurationPropertiesManagement>(keySet.size()); for (final ConfigurationKey<?> current : keySet) { final ConfigurationPropertiesManagement config = getCachedOrCreate(current); if (config != null) { defaults.add(config); } } if (defaults.isEmpty()) { return null; } if (defaults.size() == 1) { return defaults.get(0); } return new ConfigurationPropertiesManagementWithDefaults(defaults); }
final PathMatcher.Matcher matcher = new PathMatcher.Matcher(text); pathMatcher.add(matcher); PathMatcher.forMatchers(key, pathMatcher); matchers.add(matcher); return new PropertyResourceMatchers(anyKey, matchers);
/** * Returns the key for the given resource identifier. * * @param resourceId the identifier of a resource. Usually the path to a * properties file within an archive. * @return the configuration key the resource is associated with or the * default {@code anyKey} if none is registered for the given * {@code resourceId}. The default key may be <code>null</code>. */ public ConfigurationKey<?> getKey(final String resourceId) { for (final PropertiesResourceMatcher matcher : matchers) { if (matcher.match(resourceId)) { return matcher.getConfigurationKey(); } } return anyKey; }
/** * Returns the configuration key associated with the given {@code path}. * * @param path the path to fetch its configuration key. Note that a * <code>null</code> value is allowed. * @return the configuration key for the given {@code path} or * <code>null</code> if no key is associated with it. */ @CheckForNull public final ConfigurationKey<?> getKey(final String path) { return matchers.getKey(path); }
private static List<Matcher> convertToMatchers(final List<String> paths) { final List<Matcher> matchers = new ArrayList<Matcher>(paths.size()); for (final String path : paths) { final Matcher matcher = new Matcher(path); matchers.add(matcher); } return matchers; }
/** * Default constructor. * * @param tlds the collection of top-level-domains (tlds). * @param environments the collection of registered environment names. * @param nodes the collection of registered node names. * @param groups the collection of registered group names. * @param matchers the matcher of properties file path names to a associated * configuration key. */ public AbstractPropertiesDefinitionContext(final Set<String> tlds, final Set<String> environments, final Set<String> nodes, final Set<String> groups, final PropertyResourceMatchers matchers) { this.tlds = create(tlds); this.environments = create(environments); this.nodes = create(nodes); this.groups = create(groups); this.matchers = (matchers != null ? matchers : new PropertyResourceMatchers()); }
/** * Default constructor. * * @param registry the registry to resolve property descriptors. * @param decrypter the helper to decrypt secured property values. * @throws NullArgumentException if {@code registry} or {@code decrypter} is * <code>null</code>. */ public BootConfigurationProperties(final PropertyDescriptorRegistry registry, final PropertyValueSecurity decrypter) throws NullArgumentException { super(ConfigurationKeyContextManager.INSTANCE.context() .configurationKeyFactory().createUniqueKey("smartics-boot"), registry, decrypter); }
@Override public final ConfigurationPropertiesManagement createDefaultManagement() { final ConfigurationKey<?> key = ConfigurationKeyContextManager.INSTANCE.context() .configurationKeyFactory().createDefaultKey(); return createManagement(key); }
@Override public final T createDefault() { final ConfigurationKey<?> key = ConfigurationKeyContextManager.INSTANCE.context() .configurationKeyFactory().createDefaultKey(); return create(key); }
/** * Convenience constructor allowing to control the need of existing properties * files on the classpath, using its own registry and an artificial key. * * @param requiresDefaultOnClassPath the flag controls the behavior on not * finding default properties on the classpath. If the value is * <code>true</code> not finding the properties file on the class * path signals an exception, if set to <code>false</code> the * properties are not required to exist. In the latter case the * properties may be set purely programatically. * @param decrypter the helper to decrypt secured property values. * @throws NullArgumentException if {@code decrypter} is <code>null</code>. */ public ClasspathConfigurationProperties( final boolean requiresDefaultOnClassPath, final PropertyValueSecurity decrypter) throws NullArgumentException { super(ConfigurationKeyContextManager.INSTANCE.context() .configurationKeyFactory().createDefaultKey(), new InMemoryPropertyDescriptorRegistry(), requiresDefaultOnClassPath, decrypter); }
@Override public void clear() throws TransferException { try { FileUtils.cleanDirectory(targetFolder); } catch (final IOException e) { final ConfigurationKey<?> key = ConfigurationKeyContextManager.INSTANCE.context() .configurationKeyFactory().createDefaultKey(); throw new TransferException(new TransferMessageBean( TransferFileCode.FAILED_TO_CLEAN, e, key, targetFolder)); } }
private static void initialize() { final ConfigurationPropertiesFactory factory = ConfigurationPropertiesFactoryFactory .createFactory(PropertiesConfigurationPropertiesFactory.class); final ConfigurationKey<?> key = ConfigurationKeyContextManager.INSTANCE.context() .configurationKeyFactory().createDefaultKey(); final ConfigurationPropertiesManagement propertiesConfiguration = factory.createManagement(key); INSTANCE = propertiesConfiguration .getProperties(ResourceRepositoryProperties.class); }
private ConfigurationKey<?> parseKey(final String key) { final ConfigurationKeyFactory<?> factory = ConfigurationKeyContextManager.INSTANCE.context() .configurationKeyFactory(); try { final ConfigurationKey<?> configurationKey = factory.createKeyFromString(key); return configurationKey; } catch (final IllegalArgumentException e) { final DataSourceConfigurationMessageBean message = new DataSourceConfigurationMessageBean( DataSourceCode.INVALID_CONFIGURATION_KEY, e, manager.getDataSourceId(), null); throw new DataSourceException(message); // NOPMD } }
return ConfigurationKeyContextManager.INSTANCE.context() .configurationKeyFactory().createDefaultKey();
return ConfigurationKeyContextManager.INSTANCE.context() .configurationKeyFactory().createDefaultKey();