Message message = WARN_CONFIG_SCHEMA_CANNOT_OPEN_FILE.get(
schemaFile, schemaDirPath, getExceptionMessage(e));
if (failOnError)
{
throw new ConfigException(message);
}
else
{
logError(message);
return null;
}
}
// Read the LDIF entry from the file and close the file.
Entry entry;
try
{
entry = reader.readEntry(false);
if (entry == null)
{
// The file was empty -- skip it.
reader.close();
return new LinkedList<Modification>();
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_READ_LDIF_ENTRY.get(
schemaFile, schemaDirPath, getExceptionMessage(e));
if (failOnError)
{
throw new InitializationException(message, e);
}
else
{
logError(message);
return null;
}
}
// If there are any more entries in the file, then print a warning message.
try
{
Entry e = reader.readEntry(false);
if (e != null)
{
Message message = WARN_CONFIG_SCHEMA_MULTIPLE_ENTRIES_IN_FILE.get(
schemaFile, schemaDirPath);
logError(message);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = WARN_CONFIG_SCHEMA_UNPARSEABLE_EXTRA_DATA_IN_FILE.get(
schemaFile, schemaDirPath, getExceptionMessage(e));
logError(message);
}
try
{
reader.close();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
// Get the attributeTypes attribute from the entry.
LinkedList<Modification> mods = new LinkedList<Modification>();
//parse the syntaxes first because attributes rely on these.
LDAPSyntaxDescriptionSyntax ldapSyntax;
try
{
ldapSyntax = (LDAPSyntaxDescriptionSyntax) schema.getSyntax(
SYNTAX_LDAP_SYNTAX_OID);
if (ldapSyntax == null)
{
ldapSyntax = new LDAPSyntaxDescriptionSyntax();
ldapSyntax.initializeSyntax(null);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
ldapSyntax = new LDAPSyntaxDescriptionSyntax();
ldapSyntax.initializeSyntax(null);
}
AttributeType ldapSyntaxAttrType =
schema.getAttributeType(ATTR_LDAP_SYNTAXES_LC);
if (ldapSyntaxAttrType == null)
{
ldapSyntaxAttrType =
DirectoryServer.getDefaultAttributeType(ATTR_LDAP_SYNTAXES,
ldapSyntax);
}
List<Attribute> ldapSyntaxList = entry.getAttribute(ldapSyntaxAttrType);
if ((ldapSyntaxList != null) && (! ldapSyntaxList.isEmpty()))
{
for (Attribute a : ldapSyntaxList)
{
mods.add(new Modification(ModificationType.ADD, a));
}
}
AttributeTypeSyntax attrTypeSyntax;
try
{
attrTypeSyntax = (AttributeTypeSyntax)
schema.getSyntax(SYNTAX_ATTRIBUTE_TYPE_OID);
if (attrTypeSyntax == null)
{
attrTypeSyntax = new AttributeTypeSyntax();
attrTypeSyntax.initializeSyntax(null);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
attrTypeSyntax = new AttributeTypeSyntax();
attrTypeSyntax.initializeSyntax(null);
}
AttributeType attributeAttrType =
schema.getAttributeType(ATTR_ATTRIBUTE_TYPES_LC);
if (attributeAttrType == null)
{
attributeAttrType =
DirectoryServer.getDefaultAttributeType(ATTR_ATTRIBUTE_TYPES,
attrTypeSyntax);
}
List<Attribute> attrList = entry.getAttribute(attributeAttrType);
if ((attrList != null) && (! attrList.isEmpty()))
{
for (Attribute a : attrList)
{
mods.add(new Modification(ModificationType.ADD, a));
}
}
// Get the objectClasses attribute from the entry.
ObjectClassSyntax ocSyntax;
try
{
ocSyntax = (ObjectClassSyntax) schema.getSyntax(SYNTAX_OBJECTCLASS_OID);
if (ocSyntax == null)
{
ocSyntax = new ObjectClassSyntax();
ocSyntax.initializeSyntax(null);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
ocSyntax = new ObjectClassSyntax();
ocSyntax.initializeSyntax(null);
}
AttributeType objectclassAttrType =
schema.getAttributeType(ATTR_OBJECTCLASSES_LC);
if (objectclassAttrType == null)
{
objectclassAttrType =
DirectoryServer.getDefaultAttributeType(ATTR_OBJECTCLASSES,
ocSyntax);
}
List<Attribute> ocList = entry.getAttribute(objectclassAttrType);
if ((ocList != null) && (! ocList.isEmpty()))
{
for (Attribute a : ocList)
{
mods.add(new Modification(ModificationType.ADD, a));
}
}
// Get the name forms attribute from the entry.
NameFormSyntax nfSyntax;
try
{
nfSyntax = (NameFormSyntax) schema.getSyntax(SYNTAX_NAME_FORM_OID);
if (nfSyntax == null)
{
nfSyntax = new NameFormSyntax();
nfSyntax.initializeSyntax(null);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
nfSyntax = new NameFormSyntax();
nfSyntax.initializeSyntax(null);
}
AttributeType nameFormAttrType =
schema.getAttributeType(ATTR_NAME_FORMS_LC);
if (nameFormAttrType == null)
{
nameFormAttrType =
DirectoryServer.getDefaultAttributeType(ATTR_NAME_FORMS, nfSyntax);
}
List<Attribute> nfList = entry.getAttribute(nameFormAttrType);
if ((nfList != null) && (! nfList.isEmpty()))
{
for (Attribute a : nfList)
{
mods.add(new Modification(ModificationType.ADD, a));
}
}
// Get the DIT content rules attribute from the entry.
DITContentRuleSyntax dcrSyntax;
try
{
dcrSyntax = (DITContentRuleSyntax)
schema.getSyntax(SYNTAX_DIT_CONTENT_RULE_OID);
if (dcrSyntax == null)
{
dcrSyntax = new DITContentRuleSyntax();
dcrSyntax.initializeSyntax(null);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
dcrSyntax = new DITContentRuleSyntax();
dcrSyntax.initializeSyntax(null);
}
AttributeType dcrAttrType =
schema.getAttributeType(ATTR_DIT_CONTENT_RULES_LC);
if (dcrAttrType == null)
{
dcrAttrType =
DirectoryServer.getDefaultAttributeType(ATTR_DIT_CONTENT_RULES,
dcrSyntax);
}
List<Attribute> dcrList = entry.getAttribute(dcrAttrType);
if ((dcrList != null) && (! dcrList.isEmpty()))
{
for (Attribute a : dcrList)
{
mods.add(new Modification(ModificationType.ADD, a));
}
}
// Get the DIT structure rules attribute from the entry.
DITStructureRuleSyntax dsrSyntax;
try
{
dsrSyntax = (DITStructureRuleSyntax)
schema.getSyntax(SYNTAX_DIT_STRUCTURE_RULE_OID);
if (dsrSyntax == null)
{
dsrSyntax = new DITStructureRuleSyntax();
dsrSyntax.initializeSyntax(null);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
dsrSyntax = new DITStructureRuleSyntax();
dsrSyntax.initializeSyntax(null);
}
AttributeType dsrAttrType =
schema.getAttributeType(ATTR_DIT_STRUCTURE_RULES_LC);
if (dsrAttrType == null)
{
dsrAttrType =
DirectoryServer.getDefaultAttributeType(ATTR_DIT_STRUCTURE_RULES,
dsrSyntax);
}
List<Attribute> dsrList = entry.getAttribute(dsrAttrType);
if ((dsrList != null) && (! dsrList.isEmpty()))
{
for (Attribute a : dsrList)
{
mods.add(new Modification(ModificationType.ADD, a));
}
}
// Get the matching rule uses attribute from the entry.
MatchingRuleUseSyntax mruSyntax;
try
{
mruSyntax = (MatchingRuleUseSyntax)
schema.getSyntax(SYNTAX_MATCHING_RULE_USE_OID);
if (mruSyntax == null)
{
mruSyntax = new MatchingRuleUseSyntax();
mruSyntax.initializeSyntax(null);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
mruSyntax = new MatchingRuleUseSyntax();
mruSyntax.initializeSyntax(null);
}
AttributeType mruAttrType =
schema.getAttributeType(ATTR_MATCHING_RULE_USE_LC);
if (mruAttrType == null)
{
mruAttrType =
DirectoryServer.getDefaultAttributeType(ATTR_MATCHING_RULE_USE,
mruSyntax);
}
List<Attribute> mruList = entry.getAttribute(mruAttrType);
if ((mruList != null) && (! mruList.isEmpty()))
{
for (Attribute a : mruList)
{
mods.add(new Modification(ModificationType.ADD, a));
}
}
// Loop on all the attribute of the schema entry to
// find the extra attribute that shoule be loaded in the Schema.
for (Attribute attribute : entry.getAttributes())
{
if (!isSchemaAttribute(attribute))
{
schema.addExtraAttribute(attribute.getName(), attribute);
}
}
// Parse the ldapsyntaxes definitions if there are any.
if (ldapSyntaxList != null)
{
for (Attribute a : ldapSyntaxList)
{
for (AttributeValue v : a)
{
LDAPSyntaxDescription syntaxDescription = null;
try
{
syntaxDescription = LDAPSyntaxDescriptionSyntax.decodeLDAPSyntax(
v.getValue(),schema,false);
syntaxDescription.setExtraProperty(
SCHEMA_PROPERTY_FILENAME, (String) null);
syntaxDescription.setSchemaFile(schemaFile);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_LDAP_SYNTAX.get(
schemaFile,
de.getMessageObject());
if (failOnError)
{
throw new ConfigException(message, de);
}
else
{
logError(message);
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_LDAP_SYNTAX.get(
schemaFile,
v.getValue().toString() + ": " + getExceptionMessage(e));
if (failOnError)
{
throw new ConfigException(message, e);
}
else
{
logError(message);
continue;
}
}
// Register it with the schema. We will allow duplicates, with the
// later definition overriding any earlier definition, but we want
// to trap them and log a warning.
try
{
schema.registerLdapSyntaxDescription(
syntaxDescription, failOnError);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CONFLICTING_LDAP_SYNTAX.get(
schemaFile, de.getMessageObject());
logError(message);
try
{
schema.registerLdapSyntaxDescription(syntaxDescription, true);
}
catch (Exception e)
{
// This should never happen.
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
}
}
}
}
// Parse the attribute type definitions if there are any.
if (attrList != null)
{
for (Attribute a : attrList)
{
for (AttributeValue v : a)
{
// Parse the attribute type.
AttributeType attrType;
try
{
attrType = AttributeTypeSyntax.decodeAttributeType(v.getValue(),
schema, false);
attrType.setExtraProperty(SCHEMA_PROPERTY_FILENAME, (String) null);
attrType.setSchemaFile(schemaFile);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_ATTR_TYPE.get(
schemaFile, de.getMessageObject());
if (failOnError)
{
throw new ConfigException(message, de);
}
else
{
logError(message);
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_ATTR_TYPE.get(
schemaFile, v.getValue().toString() + ": " +
getExceptionMessage(e));
if (failOnError)
{
throw new ConfigException(message, e);
}
else
{
logError(message);
continue;
}
}
// Register it with the schema. We will allow duplicates, with the
// later definition overriding any earlier definition, but we want
// to trap them and log a warning.
try
{
schema.registerAttributeType(attrType, failOnError);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CONFLICTING_ATTR_TYPE.get(
schemaFile, de.getMessageObject());
logError(message);
try
{
schema.registerAttributeType(attrType, true);
}
catch (Exception e)
{
// This should never happen.
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
}
}
}
}
// Parse the objectclass definitions if there are any.
if (ocList != null)
{
for (Attribute a : ocList)
{
for (AttributeValue v : a)
{
// Parse the objectclass.
ObjectClass oc;
try
{
oc =
ObjectClassSyntax.decodeObjectClass(v.getValue(), schema, false);
oc.setExtraProperty(SCHEMA_PROPERTY_FILENAME, (String) null);
oc.setSchemaFile(schemaFile);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_OC.get(
schemaFile,
de.getMessageObject());
if (failOnError)
{
throw new ConfigException(message, de);
}
else
{
logError(message);
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_OC.get(
schemaFile,
v.getValue().toString() + ": " + getExceptionMessage(e));
if (failOnError)
{
throw new ConfigException(message, e);
}
else
{
logError(message);
continue;
}
}
// Register it with the schema. We will allow duplicates, with the
// later definition overriding any earlier definition, but we want
// to trap them and log a warning.
try
{
schema.registerObjectClass(oc, failOnError);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CONFLICTING_OC.get(
schemaFile, de.getMessageObject());
logError(message);
try
{
schema.registerObjectClass(oc, true);
}
catch (Exception e)
{
// This should never happen.
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
}
}
}
}
// Parse the name form definitions if there are any.
if (nfList != null)
{
for (Attribute a : nfList)
{
for (AttributeValue v : a)
{
// Parse the name form.
NameForm nf;
try
{
nf = NameFormSyntax.decodeNameForm(v.getValue(), schema, false);
nf.getExtraProperties().remove(SCHEMA_PROPERTY_FILENAME);
nf.setSchemaFile(schemaFile);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_NAME_FORM.get(
schemaFile, de.getMessageObject());
if (failOnError)
{
throw new ConfigException(message, de);
}
else
{
logError(message);
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_NAME_FORM.get(
schemaFile, v.getValue().toString() + ": " +
getExceptionMessage(e));
if (failOnError)
{
throw new ConfigException(message, e);
}
else
{
logError(message);
continue;
}
}
// Register it with the schema. We will allow duplicates, with the
// later definition overriding any earlier definition, but we want
// to trap them and log a warning.
try
{
schema.registerNameForm(nf, failOnError);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CONFLICTING_NAME_FORM.get(
schemaFile, de.getMessageObject());
logError(message);
try
{
schema.registerNameForm(nf, true);
}
catch (Exception e)
{
// This should never happen.
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
}
}
}
}
// Parse the DIT content rule definitions if there are any.
if (dcrList != null)
{
for (Attribute a : dcrList)
{
for (AttributeValue v : a)
{
// Parse the DIT content rule.
DITContentRule dcr;
try
{
dcr = DITContentRuleSyntax.decodeDITContentRule(
v.getValue(), schema, false);
dcr.getExtraProperties().remove(SCHEMA_PROPERTY_FILENAME);
dcr.setSchemaFile(schemaFile);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_DCR.get(
schemaFile, de.getMessageObject());
if (failOnError)
{
throw new ConfigException(message, de);
}
else
{
logError(message);
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_DCR.get(
schemaFile,v.getValue().toString() + ": " +
getExceptionMessage(e));
if (failOnError)
{
throw new ConfigException(message, e);
}
else
{
logError(message);
continue;
}
}
// Register it with the schema. We will allow duplicates, with the
// later definition overriding any earlier definition, but we want
// to trap them and log a warning.
try
{
schema.registerDITContentRule(dcr, failOnError);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CONFLICTING_DCR.get(
schemaFile, de.getMessageObject());
logError(message);
try
{
schema.registerDITContentRule(dcr, true);
}
catch (Exception e)
{
// This should never happen.
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
}
}
}
}
// Parse the DIT structure rule definitions if there are any.
if (dsrList != null)
{
for (Attribute a : dsrList)
{
for (AttributeValue v : a)
{
// Parse the DIT content rule.
DITStructureRule dsr;
try
{
dsr = DITStructureRuleSyntax.decodeDITStructureRule(
v.getValue(), schema, false);
dsr.getExtraProperties().remove(SCHEMA_PROPERTY_FILENAME);
dsr.setSchemaFile(schemaFile);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_DSR.get(
schemaFile, de.getMessageObject());
if (failOnError)
{
throw new ConfigException(message, de);
}
else
{
logError(message);
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_DSR.get(
schemaFile, v.getValue().toString() + ": " +
getExceptionMessage(e));
if (failOnError)
{
throw new ConfigException(message, e);
}
else
{
logError(message);
continue;
}
}
// Register it with the schema. We will allow duplicates, with the
// later definition overriding any earlier definition, but we want
// to trap them and log a warning.
try
{
schema.registerDITStructureRule(dsr, failOnError);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CONFLICTING_DSR.get(
schemaFile, de.getMessageObject());
logError(message);
try
{
schema.registerDITStructureRule(dsr, true);
}
catch (Exception e)
{
// This should never happen.
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
}
}
}
}
}
// Parse the matching rule use definitions if there are any.
if (mruList != null)
{
for (Attribute a : mruList)
{
for (AttributeValue v : a)
{
// Parse the matching rule use definition.
MatchingRuleUse mru;
try
{
mru = MatchingRuleUseSyntax.decodeMatchingRuleUse(
v.getValue(), schema, false);
mru.getExtraProperties().remove(SCHEMA_PROPERTY_FILENAME);
mru.setSchemaFile(schemaFile);
}
catch (DirectoryException de)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, de);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_MRU.get(
schemaFile, de.getMessageObject());
if (failOnError)
{
throw new ConfigException(message, de);
}
else
{
logError(message);
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_MRU.get(
schemaFile,
v.getValue().toString() + ": " +
getExceptionMessage(e));
if (failOnError)
{
throw new ConfigException(message, e);
}
else
{
logError(message);
continue;