| | |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import org.opends.server.api.AttributeSyntax; |
| | | import org.opends.server.api.ConfigAddListener; |
| | | import org.opends.server.api.ConfigChangeListener; |
| | | import org.opends.server.api.ConfigDeleteListener; |
| | |
| | | public void initializeAttributeSyntaxes() |
| | | throws ConfigException, InitializationException |
| | | { |
| | | // First, get the attribute syntax configuration base entry. |
| | | ConfigEntry syntaxBaseEntry; |
| | | try |
| | | { |
| | | DN syntaxBaseDN = DN.decode(DN_SYNTAX_CONFIG_BASE); |
| | | syntaxBaseEntry = configHandler.getConfigEntry(syntaxBaseDN); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_CONFIG_SCHEMA_CANNOT_GET_SYNTAX_BASE; |
| | | String message = getMessage(msgID, String.valueOf(e)); |
| | | throw new ConfigException(msgID, message, e); |
| | | } |
| | | |
| | | if (syntaxBaseEntry == null) |
| | | { |
| | | // The syntax base entry does not exist. This is not acceptable, so throw |
| | | // an exception. |
| | | int msgID = MSGID_CONFIG_SCHEMA_SYNTAX_BASE_DOES_NOT_EXIST; |
| | | String message = getMessage(msgID); |
| | | throw new ConfigException(msgID, message); |
| | | } |
| | | |
| | | |
| | | // Register add and delete listeners with the syntax base entry. We don't |
| | | // care about modifications to it. |
| | | syntaxBaseEntry.registerAddListener(this); |
| | | syntaxBaseEntry.registerDeleteListener(this); |
| | | |
| | | |
| | | // See if the syntax base has any children. If not, then this is very |
| | | // bad, since we won't know how to deal with any attribute types. |
| | | if (! syntaxBaseEntry.hasChildren()) |
| | | { |
| | | int msgID = MSGID_CONFIG_SCHEMA_NO_SYNTAXES; |
| | | String message = getMessage(msgID); |
| | | throw new ConfigException(msgID, message); |
| | | } |
| | | |
| | | |
| | | // Iterate through the child entries and process them as syntax entries. |
| | | for (ConfigEntry childEntry : syntaxBaseEntry.getChildren().values()) |
| | | { |
| | | DN syntaxEntryDN = childEntry.getDN(); |
| | | |
| | | |
| | | // Register as a change listener for this syntax entry so that we will be |
| | | // notified of any changes that may be made to it. |
| | | childEntry.registerChangeListener(this); |
| | | |
| | | |
| | | // Check to see if this entry appears to contain an attribute syntax |
| | | // configuration. If not, log a warning and skip it. |
| | | if (! childEntry.hasObjectClass(OC_ATTRIBUTE_SYNTAX)) |
| | | { |
| | | int msgID = MSGID_CONFIG_SCHEMA_ENTRY_DOES_NOT_HAVE_SYNTAX_CONFIG; |
| | | String message = getMessage(msgID, String.valueOf(syntaxEntryDN)); |
| | | logError(ErrorLogCategory.CONFIGURATION, |
| | | ErrorLogSeverity.SEVERE_WARNING, message, msgID); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | // See if the entry contains an attribute that indicates whether the |
| | | // syntax should be enabled. If it does not, or if it is not set to |
| | | // "true", then skip it. |
| | | int msgID = MSGID_CONFIG_SCHEMA_SYNTAX_ATTR_DESCRIPTION_ENABLED; |
| | | BooleanConfigAttribute enabledStub = |
| | | new BooleanConfigAttribute(ATTR_SYNTAX_ENABLED, getMessage(msgID), |
| | | false); |
| | | try |
| | | { |
| | | BooleanConfigAttribute enabledAttr = |
| | | (BooleanConfigAttribute) |
| | | childEntry.getConfigAttribute(enabledStub); |
| | | if (enabledAttr == null) |
| | | { |
| | | // The attribute is not present, so this syntax will be disabled. Log |
| | | // a message and continue. |
| | | msgID = MSGID_CONFIG_SCHEMA_SYNTAX_NO_ENABLED_ATTR; |
| | | String message = getMessage(msgID, String.valueOf(syntaxEntryDN)); |
| | | logError(ErrorLogCategory.CONFIGURATION, |
| | | ErrorLogSeverity.SEVERE_WARNING, message, msgID); |
| | | continue; |
| | | } |
| | | else if (! enabledAttr.activeValue()) |
| | | { |
| | | // The syntax is explicitly disabled. Log a mild warning and |
| | | // continue. |
| | | msgID = MSGID_CONFIG_SCHEMA_SYNTAX_DISABLED; |
| | | String message = getMessage(msgID, String.valueOf(syntaxEntryDN)); |
| | | logError(ErrorLogCategory.CONFIGURATION, |
| | | ErrorLogSeverity.INFORMATIONAL, message, msgID); |
| | | continue; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | msgID = MSGID_CONFIG_SCHEMA_SYNTAX_UNABLE_TO_DETERMINE_ENABLED_STATE; |
| | | String message = getMessage(msgID, String.valueOf(syntaxEntryDN), |
| | | getExceptionMessage(e)); |
| | | logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | // See if the entry contains an attribute that specifies the class name |
| | | // for the syntax implementation. If it does, then load it and make sure |
| | | // that it's a valid syntax implementation. If there is no such |
| | | // attribute, the specified class cannot be loaded, or it does not contain |
| | | // a valid syntax implementation, then log an error and skip it. |
| | | String className; |
| | | msgID = MSGID_CONFIG_SCHEMA_SYNTAX_ATTR_DESCRIPTION_CLASS; |
| | | StringConfigAttribute classStub = |
| | | new StringConfigAttribute(ATTR_SYNTAX_CLASS, getMessage(msgID), |
| | | true, false, true); |
| | | try |
| | | { |
| | | StringConfigAttribute classAttr = |
| | | (StringConfigAttribute) |
| | | childEntry.getConfigAttribute(classStub); |
| | | if (classAttr == null) |
| | | { |
| | | msgID = MSGID_CONFIG_SCHEMA_SYNTAX_NO_CLASS_ATTR; |
| | | String message = getMessage(msgID, String.valueOf(syntaxEntryDN)); |
| | | logError(ErrorLogCategory.CONFIGURATION, |
| | | ErrorLogSeverity.SEVERE_ERROR, message, msgID); |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | className = classAttr.activeValue(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | msgID = MSGID_CONFIG_SCHEMA_SYNTAX_CANNOT_GET_CLASS; |
| | | String message = getMessage(msgID, String.valueOf(syntaxEntryDN), |
| | | getExceptionMessage(e)); |
| | | logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | continue; |
| | | } |
| | | |
| | | AttributeSyntax syntax; |
| | | try |
| | | { |
| | | Class syntaxClass = DirectoryServer.loadClass(className); |
| | | syntax = (AttributeSyntax) syntaxClass.newInstance(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | msgID = MSGID_CONFIG_SCHEMA_SYNTAX_CANNOT_INSTANTIATE; |
| | | String message = getMessage(msgID, String.valueOf(className), |
| | | String.valueOf(syntaxEntryDN), |
| | | getExceptionMessage(e)); |
| | | logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | // Perform the necessary initialization for the syntax. |
| | | try |
| | | { |
| | | syntax.initializeSyntax(childEntry); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | msgID = MSGID_CONFIG_SCHEMA_SYNTAX_CANNOT_INITIALIZE; |
| | | String message = getMessage(msgID, String.valueOf(className), |
| | | String.valueOf(syntaxEntryDN), |
| | | getExceptionMessage(e)); |
| | | logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | // Register the syntax with the server schema. |
| | | try |
| | | { |
| | | schema.registerSyntax(syntax, false); |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, de); |
| | | } |
| | | |
| | | msgID = MSGID_CONFIG_SCHEMA_SYNTAX_CONFLICTING_SYNTAX; |
| | | String message = getMessage(msgID, String.valueOf(syntaxEntryDN), |
| | | de.getErrorMessage()); |
| | | logError(ErrorLogCategory.CONFIGURATION, |
| | | ErrorLogSeverity.SEVERE_WARNING, message, msgID); |
| | | continue; |
| | | } |
| | | } |
| | | AttributeSyntaxConfigManager syntaxConfigManager = |
| | | new AttributeSyntaxConfigManager(); |
| | | syntaxConfigManager.initializeAttributeSyntaxes(); |
| | | } |
| | | |
| | | |