org.hibernate.search.engine.cfg.spi.ConfigurationScope Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-search-engine Show documentation
Show all versions of hibernate-search-engine Show documentation
Hibernate Search engine, always required
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.search.engine.cfg.spi;
import java.util.Objects;
import java.util.function.Predicate;
import org.hibernate.search.util.common.annotation.Incubating;
/**
Holds a configuration scope.
*
* It is not expected for service implementors to create the scopes.
* Hibernate Search will create the scope itself, and it will pass a corresponding scope to the {@link ConfigurationProvider}
* whenever it is required.
*
* Scope always starts as the global scope.
* This global scope should always be reachable through recursively accessing the {@link #parent() parent scope},
* unless the current scope is already a global scope.
*
* An example of a scope sequence:
*
* - {@code [namespace:global]} -- scope always starts with the global scope
* -
* {@code [namespace:backend name:backend-name]} -- next a backend scope with an optional backend named.
* If the name is not present, it means that scope represents a default backend.
*
* - {@code [namespace:index name:index-name]} -- next is a scope specific to an index
*
* @see ConfigurationScopeNamespaces
* @see ConfigurationProvider
*/
@Incubating
public final class ConfigurationScope {
public static final ConfigurationScope GLOBAL = new ConfigurationScope( null, ConfigurationScopeNamespaces.GLOBAL, null );
private final ConfigurationScope parent;
private final String namespace;
private final String name;
private ConfigurationScope(ConfigurationScope parent, String namespace, String name) {
this.parent = parent;
this.namespace = namespace;
this.name = name;
}
public ConfigurationScope reduce(String namespace, String name) {
return new ConfigurationScope( this, namespace, name );
}
public boolean matchAny(String namespace) {
return this.namespace.equals( namespace );
}
public boolean matchExact(String namespace) {
return matchExact( namespace, null );
}
public boolean matchExact(String namespace, String name) {
return matchAny( namespace ) && Objects.equals( this.name, name );
}
public boolean match(Predicate predicate) {
return predicate.test( this );
}
public ConfigurationScope parent() {
return parent;
}
public String namespace() {
return namespace;
}
public String name() {
return name;
}
@Override
public String toString() {
return ( parent == null ? "" : parent + ": " ) + namespace + ( name == null ? "" : "(" + name + ")" );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy