| | |
| | | |
| | | |
| | | import java.io.File; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.TreeSet; |
| | | import java.util.concurrent.locks.Lock; |
| | | |
| | | import org.opends.server.api.ClientConnection; |
| | | import org.opends.server.api.SynchronizationProvider; |
| | | import org.opends.server.backends.task.Task; |
| | | import org.opends.server.backends.task.TaskState; |
| | | import org.opends.server.config.ConfigException; |
| | |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.AttributeValue; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | |
| | | import org.opends.server.types.ErrorLogSeverity; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.LockManager; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.Privilege; |
| | | import org.opends.server.types.ResultCode; |
| | | import org.opends.server.types.Schema; |
| | | |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.messages.MessageHandler.*; |
| | | import static org.opends.server.messages.TaskMessages.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | |
| | |
| | | public class AddSchemaFileTask |
| | | extends Task |
| | | { |
| | | |
| | | |
| | | |
| | | // The list of files to be added to the server schema. |
| | | TreeSet<String> filesToAdd; |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_TASK_ADDSCHEMAFILE_ERROR_CHECKING_FOR_FILE; |
| | | String message = getMessage(msgID, filename, schemaDirectory, |
| | | stackTraceToSingleLineString(e)); |
| | |
| | | } |
| | | catch (ConfigException ce) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | debugCaught(DebugLogLevel.ERROR, ce); |
| | | } |
| | | |
| | | int msgID = MSGID_TASK_ADDSCHEMAFILE_ERROR_LOADING_SCHEMA_FILE; |
| | | String message = getMessage(msgID, String.valueOf(schemaFile), |
| | | ce.getMessage()); |
| | |
| | | } |
| | | catch (InitializationException ie) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | debugCaught(DebugLogLevel.ERROR, ie); |
| | | } |
| | | |
| | | int msgID = MSGID_TASK_ADDSCHEMAFILE_ERROR_LOADING_SCHEMA_FILE; |
| | | String message = getMessage(msgID, String.valueOf(schemaFile), |
| | | ie.getMessage()); |
| | |
| | | |
| | | try |
| | | { |
| | | LinkedList<Modification> mods = new LinkedList<Modification>(); |
| | | Schema schema = DirectoryServer.getSchema().duplicate(); |
| | | for (String schemaFile : filesToAdd) |
| | | { |
| | | try |
| | | { |
| | | SchemaConfigManager.loadSchemaFile(schema, schemaFile); |
| | | List<Modification> modList = |
| | | SchemaConfigManager.loadSchemaFile(schema, schemaFile); |
| | | for (Modification m : modList) |
| | | { |
| | | Attribute a = m.getAttribute(); |
| | | LinkedHashSet<AttributeValue> valuesWithFileElement = |
| | | new LinkedHashSet<AttributeValue>(); |
| | | for (AttributeValue v : a.getValues()) |
| | | { |
| | | String s = v.getStringValue(); |
| | | if (s.indexOf(SCHEMA_PROPERTY_FILENAME) < 0) |
| | | { |
| | | if (s.endsWith(" )")) |
| | | { |
| | | s = s.substring(0, s.length()-1) + SCHEMA_PROPERTY_FILENAME + |
| | | " '" + schemaFile + "' )"; |
| | | } |
| | | else if (s.endsWith(")")) |
| | | { |
| | | s = s.substring(0, s.length()-1) + " " + |
| | | SCHEMA_PROPERTY_FILENAME + " '" + schemaFile + "' )"; |
| | | } |
| | | } |
| | | |
| | | valuesWithFileElement.add(new AttributeValue(a.getAttributeType(), |
| | | s)); |
| | | } |
| | | |
| | | Attribute attrWithFile = new Attribute(a.getAttributeType(), |
| | | a.getName(), |
| | | valuesWithFileElement); |
| | | mods.add(new Modification(m.getModificationType(), attrWithFile)); |
| | | } |
| | | } |
| | | catch (ConfigException ce) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | debugCaught(DebugLogLevel.ERROR, ce); |
| | | } |
| | | |
| | | int msgID = MSGID_TASK_ADDSCHEMAFILE_ERROR_LOADING_SCHEMA_FILE; |
| | | String message = getMessage(msgID, String.valueOf(schemaFile), |
| | | ce.getMessage()); |
| | |
| | | } |
| | | catch (InitializationException ie) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | debugCaught(DebugLogLevel.ERROR, ie); |
| | | } |
| | | |
| | | int msgID = MSGID_TASK_ADDSCHEMAFILE_ERROR_LOADING_SCHEMA_FILE; |
| | | String message = getMessage(msgID, String.valueOf(schemaFile), |
| | | ie.getMessage()); |
| | |
| | | } |
| | | } |
| | | |
| | | if (! mods.isEmpty()) |
| | | { |
| | | for (SynchronizationProvider provider : |
| | | DirectoryServer.getSynchronizationProviders()) |
| | | { |
| | | try |
| | | { |
| | | provider.processSchemaChange(mods); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_TASK_ADDSCHEMAFILE_CANNOT_NOTIFY_SYNC_PROVIDER; |
| | | String message = getMessage(msgID, provider.getClass().getName(), |
| | | stackTraceToSingleLineString(e)); |
| | | logError(ErrorLogCategory.SCHEMA, ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | } |
| | | } |
| | | |
| | | Schema.writeConcatenatedSchema(); |
| | | } |
| | | |
| | | schema.setYoungestModificationTime(System.currentTimeMillis()); |
| | | DirectoryServer.setSchema(schema); |
| | | return TaskState.COMPLETED_SUCCESSFULLY; |