Class SchemaHandler
- java.lang.Object
-
- org.opends.server.schema.SchemaHandler
-
- All Implemented Interfaces:
ConfigurationAddListener<SchemaProviderCfg>
,ConfigurationDeleteListener<SchemaProviderCfg>
public final class SchemaHandler extends Object implements ConfigurationAddListener<SchemaProviderCfg>, ConfigurationDeleteListener<SchemaProviderCfg>
Responsible for access to the server's schema.The schema handler initializes the schema in four steps :
- Start from the core schema.
- Add server specific syntaxes and matching rules
- Load schema elements from the schema providers defined in configuration.
- Load all schema files located in the schema directory.
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SchemaHandler.SchemaUpdater
Interface to update a schema provided a schema builder.
-
Constructor Summary
Constructors Constructor Description SchemaHandler()
Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.Path
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(Path schemaFile, SchemaBuilder schemaBuilder, Schema readSchema)
Loads the contents of the provided schema file into the provided schema builder.List<Modification>
loadSchemaFileIntoSchemaBuilderAndReturnModifications(Path 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.
-
-
-
Method Detail
-
getYoungestModificationTime
public long getYoungestModificationTime()
Returns the youngest modification time for schema files.- Returns:
- the youngest modification time for any schema configuration file
-
getOldestModificationTime
public long getOldestModificationTime()
Returns the oldest modification time for schema files.- Returns:
- the oldest modification time for any schema configuration file
-
initialize
public void initialize(ServerContext serverContext) throws InitializationException, ConfigException
Initializes this schema handler.- Parameters:
serverContext
- The server context.- Throws:
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.
-
isConfigurationAddAcceptable
public boolean isConfigurationAddAcceptable(SchemaProviderCfg config, List<LocalizableMessage> unacceptableReasons)
Description copied from interface:ConfigurationAddListener
Indicates whether the proposed addition of a new configuration is acceptable to this add listener.- Specified by:
isConfigurationAddAcceptable
in interfaceConfigurationAddListener<SchemaProviderCfg>
- Parameters:
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.- Returns:
- Returns
true
if the proposed addition is acceptable, orfalse
if it is not.
-
applyConfigurationAdd
public ConfigChangeResult applyConfigurationAdd(SchemaProviderCfg config)
Description copied from interface:ConfigurationAddListener
Adds a new configuration to this add listener.- Specified by:
applyConfigurationAdd
in interfaceConfigurationAddListener<SchemaProviderCfg>
- Parameters:
config
- The configuration that will be added.- Returns:
- Returns information about the result of adding the configuration.
-
isConfigurationDeleteAcceptable
public boolean isConfigurationDeleteAcceptable(SchemaProviderCfg config, List<LocalizableMessage> unacceptableReasons)
Description copied from interface:ConfigurationDeleteListener
Indicates whether the proposed deletion of an existing configuration is acceptable to this delete listener.- Specified by:
isConfigurationDeleteAcceptable
in interfaceConfigurationDeleteListener<SchemaProviderCfg>
- Parameters:
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.- Returns:
- Returns
true
if the proposed deletion is acceptable, orfalse
if it is not.
-
applyConfigurationDelete
public ConfigChangeResult applyConfigurationDelete(SchemaProviderCfg config)
Description copied from interface:ConfigurationDeleteListener
Deletes an existing configuration from this delete listener.- Specified by:
applyConfigurationDelete
in interfaceConfigurationDeleteListener<SchemaProviderCfg>
- Parameters:
config
- The existing configuration that will be deleted.- Returns:
- Returns information about the result of deleting the configuration.
-
detectChangesOnInitialization
public void detectChangesOnInitialization() throws InitializationException
Detects offline schema changes by comparing schema files and concatenated schema.Updates the concatenated schema if changes are detected.
- Throws:
InitializationException
- If an error occurs while updating the concatenated schema
-
getSchema
public Schema getSchema()
Returns the schema.- Returns:
- the schema
-
getSchemaDirectoryPath
public Path getSchemaDirectoryPath() throws InitializationException
Retrieves the path to the directory containing the server schema files.- Returns:
- The path to the directory containing the server schema files.
- Throws:
InitializationException
- If the directory path does not exists or is not a directory
-
getOfflineSchemaModifications
public List<Modification> getOfflineSchemaModifications()
Returns the list of offline modifications made to the schema, which is built once when initializing the schema.- Returns:
- the offline schema modifications list
-
updateSchema
public void updateSchema(SchemaHandler.SchemaUpdater updater) throws LdapException
Updates the schema using the provided schema updater.The schema files are not updated.
- Parameters:
updater
- the updater that performs modifications on the schema builder- Throws:
LdapException
- if there is any problem updating the schema
-
updateSchema
public void updateSchema(Schema schema) throws LdapException
Replaces the schema with the provided schema.The schema files are not updated.
- Parameters:
schema
- the new schema to use- Throws:
LdapException
- if the provided schema contains warnings
-
updateSchemaAndSchemaFiles
public void updateSchemaAndSchemaFiles(Schema newSchema, Map<String,Attribute> newExtraAttributes, SortedSet<String> modifiedSchemaFileNames, AlertGenerator alertGenerator) throws LdapException
Replaces the schema with the provided schema and updates the provided set of schema files.The concatenated schema file is updated as well.
- Parameters:
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 alerts- Throws:
LdapException
- If an error occurs during update of schema or schema files
-
updateSchemaAndConcatenatedSchemaFile
public void updateSchemaAndConcatenatedSchemaFile(Schema newSchema) throws LdapException
Replaces the schema with the provided schema and update the concatenated schema file.- Parameters:
newSchema
- The new schema to use- Throws:
LdapException
- If an error occurs during update of schema or schema files
-
updateSchemaOption
public <T> void updateSchemaOption(Option<T> option, T newValue) throws LdapException
Updates the schema option if the new value differs from the old value.- Type Parameters:
T
- the schema option's type- Parameters:
option
- the schema option to updatenewValue
- the new value for the schema option- Throws:
LdapException
- if there is any problem updating the schema
-
getExtraAttributes
public Map<String,Attribute> getExtraAttributes()
Returns the mapping (oid, attribute) for extra attributes stored in this schema handler.- Returns:
- The map of extra attributes
-
destroy
public void destroy()
Destroys the structures maintained by this handler so that they are no longer usable.This should only be called at the end of the server shutdown process, and it can help detect inappropriate cached references.
-
importEntry
public void importEntry(Entry newSchemaEntry, AlertGenerator alertGenerator) throws LdapException
Imports the provided schema entry in the schema.The behavior is:
- iterate over each element of the newSchemaEntry and compare with the existing schema
- if the new schema element does not exist in current schema, add it to the schema
- if an element of current schema is not in the new schema entry: delete it
FIXME: currently, attributeTypes and objectClasses are the only elements taken into account.
- Parameters:
newSchemaEntry
- The schema entry to be imported.alertGenerator
- Alert generator to use.- Throws:
LdapException
- If an error occurs during the import
-
loadSchemaFileIntoSchemaBuilder
public void loadSchemaFileIntoSchemaBuilder(Path schemaFile, SchemaBuilder schemaBuilder, Schema readSchema) throws InitializationException, ConfigException
Loads the contents of the provided schema file into the provided schema builder.This method has no effect on the current schema.
- Parameters:
schemaFile
- The schema file to load.schemaBuilder
- The schema builder to update.readSchema
- The schema used to read the schema file.- Throws:
InitializationException
- If a problem occurs when reading the schema file.ConfigException
- If a problem occurs when updating the schema builder.
-
loadSchemaFileIntoSchemaBuilderAndReturnModifications
public List<Modification> loadSchemaFileIntoSchemaBuilderAndReturnModifications(Path schemaFile, SchemaBuilder schemaBuilder, Schema readSchema) throws InitializationException, ConfigException
Loads the contents of the provided schema file into the provided schema builder and returns the list of modifications.This method has no effect on the current schema.
- Parameters:
schemaFile
- The schema file to load.schemaBuilder
- The schema builder to update.readSchema
- The schema used to read the schema file.- Returns:
- A list of the modifications that could be performed in order to obtain the contents of the file.
- Throws:
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.
-
isSchemaAttribute
public static boolean isSchemaAttribute(String attrOid)
Checks if a given attribute oid corresponds to an attribute that is used by the definition of the schema.- Parameters:
attrOid
- The oid of the attribute to be checked.- Returns:
true
if the attribute is part of the schema definition, false otherwise
-
-