public final class SchemaHandler extends Object implements ConfigurationAddListener<SchemaProviderCfg>, ConfigurationDeleteListener<SchemaProviderCfg>
The schema handler initializes the schema in four steps :
The schema handler provides read and write access to the schema.
As schema is immutable, there is no risk to alter it outside this handler. However, no long-lived reference should be kept on the schema because further schema updates would be missed. It is advised to retrieve the server's schema from the handler for any operation.
The server's schema can be updated using one of the updateSchema()
method.
Modifier and Type | Class and Description |
---|---|
static interface |
SchemaHandler.SchemaUpdater
Interface to update a schema provided a schema builder.
|
Constructor and Description |
---|
SchemaHandler()
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
ConfigChangeResult |
applyConfigurationAdd(SchemaProviderCfg config)
Adds a new configuration to this add listener.
|
ConfigChangeResult |
applyConfigurationDelete(SchemaProviderCfg config)
Deletes an existing configuration from this delete listener.
|
void |
destroy()
Destroys the structures maintained by this handler so that they are no longer usable.
|
void |
detectChangesOnInitialization()
Detects offline schema changes by comparing schema files and concatenated schema.
|
Map<String,Attribute> |
getExtraAttributes()
Returns the mapping (oid, attribute) for extra attributes stored in this schema handler.
|
List<Modification> |
getOfflineSchemaModifications()
Returns the list of offline modifications made to the schema, which is built once when initializing the schema.
|
long |
getOldestModificationTime()
Returns the oldest modification time for schema files.
|
Schema |
getSchema()
Returns the schema.
|
File |
getSchemaDirectoryPath()
Retrieves the path to the directory containing the server schema files.
|
long |
getYoungestModificationTime()
Returns the youngest modification time for schema files.
|
void |
importEntry(Entry newSchemaEntry,
AlertGenerator alertGenerator)
Imports the provided schema entry in the schema.
|
void |
initialize(ServerContext serverContext)
Initializes this schema handler.
|
boolean |
isConfigurationAddAcceptable(SchemaProviderCfg config,
List<LocalizableMessage> unacceptableReasons)
Indicates whether the proposed addition of a new configuration is
acceptable to this add listener.
|
boolean |
isConfigurationDeleteAcceptable(SchemaProviderCfg config,
List<LocalizableMessage> unacceptableReasons)
Indicates whether the proposed deletion of an existing configuration is
acceptable to this delete listener.
|
static boolean |
isSchemaAttribute(String attrOid)
Checks if a given attribute oid corresponds to an attribute that is used by the definition of the schema.
|
void |
loadSchemaFileIntoSchemaBuilder(File schemaFile,
SchemaBuilder schemaBuilder,
Schema readSchema)
Loads the contents of the provided schema file into the provided schema builder.
|
List<Modification> |
loadSchemaFileIntoSchemaBuilderAndReturnModifications(File schemaFile,
SchemaBuilder schemaBuilder,
Schema readSchema)
Loads the contents of the provided schema file into the provided schema builder and returns the list of
modifications.
|
void |
updateSchema(Schema schema)
Replaces the schema with the provided schema.
|
void |
updateSchema(SchemaHandler.SchemaUpdater updater)
Updates the schema using the provided schema updater.
|
void |
updateSchemaAndConcatenatedSchemaFile(Schema newSchema)
Replaces the schema with the provided schema and update the concatenated schema file.
|
void |
updateSchemaAndSchemaFiles(Schema newSchema,
Map<String,Attribute> newExtraAttributes,
SortedSet<String> modifiedSchemaFileNames,
AlertGenerator alertGenerator)
Replaces the schema with the provided schema and updates the provided set of schema files.
|
<T> void |
updateSchemaOption(Option<T> option,
T newValue)
Updates the schema option if the new value differs from the old value.
|
public long getYoungestModificationTime()
public long getOldestModificationTime()
public void initialize(ServerContext serverContext) throws InitializationException, ConfigException
serverContext
- The server context.ConfigException
- If a configuration problem arises in the process of performing the initialization.InitializationException
- If a problem that is not configuration-related occurs during initialization.public boolean isConfigurationAddAcceptable(SchemaProviderCfg config, List<LocalizableMessage> unacceptableReasons)
ConfigurationAddListener
isConfigurationAddAcceptable
in interface ConfigurationAddListener<SchemaProviderCfg>
config
- The configuration that will be added.unacceptableReasons
- A list that can be used to hold messages about why the
provided configuration is not acceptable.true
if the proposed addition is acceptable,
or false
if it is not.public ConfigChangeResult applyConfigurationAdd(SchemaProviderCfg config)
ConfigurationAddListener
applyConfigurationAdd
in interface ConfigurationAddListener<SchemaProviderCfg>
config
- The configuration that will be added.public boolean isConfigurationDeleteAcceptable(SchemaProviderCfg config, List<LocalizableMessage> unacceptableReasons)
ConfigurationDeleteListener
isConfigurationDeleteAcceptable
in interface ConfigurationDeleteListener<SchemaProviderCfg>
config
- The configuration that will be deleted.unacceptableReasons
- A list that can be used to hold messages about why the
provided configuration is not acceptable.true
if the proposed deletion is acceptable,
or false
if it is not.public ConfigChangeResult applyConfigurationDelete(SchemaProviderCfg config)
ConfigurationDeleteListener
applyConfigurationDelete
in interface ConfigurationDeleteListener<SchemaProviderCfg>
config
- The existing configuration that will be deleted.public void detectChangesOnInitialization() throws InitializationException
Updates the concatenated schema if changes are detected.
InitializationException
- If an error occurs while updating the concatenated schemapublic Schema getSchema()
public File getSchemaDirectoryPath() throws InitializationException
InitializationException
- If the directory path does not exists or is not a directorypublic List<Modification> getOfflineSchemaModifications()
public void updateSchema(SchemaHandler.SchemaUpdater updater) throws LdapException
The schema files are not updated.
updater
- the updater that performs modifications on the schema builderLdapException
- if there is any problem updating the schemapublic void updateSchema(Schema schema) throws LdapException
The schema files are not updated.
schema
- the new schema to useLdapException
- if the provided schema contains warningspublic void updateSchemaAndSchemaFiles(Schema newSchema, Map<String,Attribute> newExtraAttributes, SortedSet<String> modifiedSchemaFileNames, AlertGenerator alertGenerator) throws LdapException
The concatenated schema file is updated as well.
newSchema
- The new schema to usenewExtraAttributes
- The new map of extra attributesmodifiedSchemaFileNames
- The set of names of schema files that need to be updatedalertGenerator
- The generator to use for alertsLdapException
- If an error occurs during update of schema or schema filespublic void updateSchemaAndConcatenatedSchemaFile(Schema newSchema) throws LdapException
newSchema
- The new schema to useLdapException
- If an error occurs during update of schema or schema filespublic <T> void updateSchemaOption(Option<T> option, T newValue) throws LdapException
T
- the schema option's typeoption
- the schema option to updatenewValue
- the new value for the schema optionLdapException
- if there is any problem updating the schemapublic Map<String,Attribute> getExtraAttributes()
public void destroy()
This should only be called at the end of the server shutdown process, and it can help detect inappropriate cached references.
public void importEntry(Entry newSchemaEntry, AlertGenerator alertGenerator) throws LdapException
The behavior is:
FIXME: currently, attributeTypes and objectClasses are the only elements taken into account.
newSchemaEntry
- The schema entry to be imported.alertGenerator
- Alert generator to use.LdapException
- If an error occurs during the importpublic void loadSchemaFileIntoSchemaBuilder(File schemaFile, SchemaBuilder schemaBuilder, Schema readSchema) throws InitializationException, ConfigException
This method has no effect on the current schema.
schemaFile
- The schema file to load.schemaBuilder
- The schema builder to update.readSchema
- The schema used to read the schema file.InitializationException
- If a problem occurs when reading the schema file.ConfigException
- If a problem occurs when updating the schema builder.public List<Modification> loadSchemaFileIntoSchemaBuilderAndReturnModifications(File schemaFile, SchemaBuilder schemaBuilder, Schema readSchema) throws InitializationException, ConfigException
This method has no effect on the current schema.
schemaFile
- The schema file to load.schemaBuilder
- The schema builder to update.readSchema
- The schema used to read the schema file.ConfigException
- If a configuration problem causes the schema element initialization to fail.InitializationException
- If a problem occurs while initializing the schema elements that is not related to the server
configuration.public static boolean isSchemaAttribute(String attrOid)
attrOid
- The oid of the attribute to be checked.true
if the attribute is part of the schema definition, false otherwiseCopyright 2010-2022 ForgeRock AS.