| | |
| | | return subschemaDN; |
| | | } |
| | | |
| | | /** Allows to perform modifications on element's builders before adding the result to this schema builder. */ |
| | | public interface SchemaBuilderHook { |
| | | /** |
| | | * Allow to modify the builder before its inclusion in schema. |
| | | * |
| | | * @param builder |
| | | * Schema's element builder. |
| | | */ |
| | | public void beforeAddSyntax(Syntax.Builder builder); |
| | | |
| | | /** |
| | | * Allow to modify the builder before its inclusion in schema. |
| | | * |
| | | * @param builder |
| | | * Schema's element builder. |
| | | */ |
| | | public void beforeAddAttribute(AttributeType.Builder builder); |
| | | |
| | | /** |
| | | * Allow to modify the builder before its inclusion in schema. |
| | | * |
| | | * @param builder |
| | | * Schema's element builder. |
| | | */ |
| | | public void beforeAddObjectClass(ObjectClass.Builder builder); |
| | | |
| | | /** |
| | | * Allow to modify the builder before its inclusion in schema. |
| | | * |
| | | * @param builder |
| | | * Schema's element builder. |
| | | */ |
| | | public void beforeAddMatchingRuleUse(MatchingRuleUse.Builder builder); |
| | | |
| | | /** |
| | | * Allow to modify the builder before its inclusion in schema. |
| | | * |
| | | * @param builder |
| | | * Schema's element builder. |
| | | */ |
| | | public void beforeAddMatchingRule(MatchingRule.Builder builder); |
| | | |
| | | /** |
| | | * Allow to modify the builder before its inclusion in schema. |
| | | * |
| | | * @param builder |
| | | * Schema's element builder. |
| | | */ |
| | | public void beforeAddDitContentRule(DITContentRule.Builder builder); |
| | | |
| | | /** |
| | | * Allow to modify the builder before its inclusion in schema. |
| | | * |
| | | * @param builder |
| | | * Schema's element builder. |
| | | */ |
| | | public void beforeAddDitStructureRule(DITStructureRule.Builder builder); |
| | | |
| | | /** |
| | | * Allow to modify the builder before its inclusion in schema. |
| | | * |
| | | * @param builder |
| | | * Schema's element builder. |
| | | */ |
| | | public void beforeAddNameForm(NameForm.Builder builder); |
| | | } |
| | | |
| | | private Map<Integer, DITStructureRule> id2StructureRules; |
| | | private Map<String, List<AttributeType>> name2AttributeTypes; |
| | | private Map<String, List<DITContentRule>> name2ContentRules; |
| | |
| | | */ |
| | | public SchemaBuilder(final Entry entry) { |
| | | preLazyInitBuilder(entry.getName().toString(), null); |
| | | addSchema(entry, true); |
| | | addSchema(entry, true, null); |
| | | } |
| | | |
| | | /** |
| | |
| | | * If {@code definition} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addAttributeType(final String definition, final boolean overwrite) { |
| | | return addAttributeType(definition, overwrite, null); |
| | | } |
| | | |
| | | SchemaBuilder addAttributeType(final String definition, final boolean overwrite, SchemaBuilderHook hook) { |
| | | Reject.ifNull(definition); |
| | | |
| | | lazyInitBuilder(); |
| | |
| | | atBuilder.superiorType(superiorType) |
| | | .syntax(syntax); |
| | | |
| | | if (hook != null) { |
| | | hook.beforeAddAttribute(atBuilder); |
| | | } |
| | | return atBuilder.addToSchema(overwrite); |
| | | } catch (final DecodeException e) { |
| | | final LocalizableMessage msg = ERR_ATTR_SYNTAX_ATTRTYPE_INVALID1.get(definition, e.getMessageObject()); |
| | |
| | | * If {@code definition} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addDITContentRule(final String definition, final boolean overwrite) { |
| | | return addDITContentRule(definition, overwrite, null); |
| | | } |
| | | |
| | | SchemaBuilder addDITContentRule(final String definition, final boolean overwrite, SchemaBuilderHook hook) { |
| | | Reject.ifNull(definition); |
| | | |
| | | lazyInitBuilder(); |
| | |
| | | } |
| | | } |
| | | |
| | | if (hook != null) { |
| | | hook.beforeAddDitContentRule(contentRuleBuilder); |
| | | } |
| | | return contentRuleBuilder.addToSchema(overwrite); |
| | | } catch (final DecodeException e) { |
| | | final LocalizableMessage msg = ERR_ATTR_SYNTAX_DCR_INVALID1.get(definition, e.getMessageObject()); |
| | |
| | | * If {@code definition} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addDITStructureRule(final String definition, final boolean overwrite) { |
| | | return addDITStructureRule(definition, overwrite, null); |
| | | } |
| | | |
| | | SchemaBuilder addDITStructureRule(final String definition, final boolean overwrite, SchemaBuilderHook hook) { |
| | | Reject.ifNull(definition); |
| | | |
| | | lazyInitBuilder(); |
| | |
| | | } |
| | | ruleBuilder.nameForm(nameForm); |
| | | |
| | | if (hook != null) { |
| | | hook.beforeAddDitStructureRule(ruleBuilder); |
| | | } |
| | | return ruleBuilder.addToSchema(overwrite); |
| | | } catch (final DecodeException e) { |
| | | final LocalizableMessage msg = ERR_ATTR_SYNTAX_DSR_INVALID1.get(definition, e.getMessageObject()); |
| | |
| | | * If {@code definition} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addMatchingRule(final String definition, final boolean overwrite) { |
| | | return addMatchingRule(definition, overwrite, null); |
| | | } |
| | | |
| | | SchemaBuilder addMatchingRule(final String definition, final boolean overwrite, SchemaBuilderHook hook) { |
| | | Reject.ifNull(definition); |
| | | |
| | | lazyInitBuilder(); |
| | |
| | | if (syntax == null) { |
| | | throw new LocalizedIllegalArgumentException(ERR_ATTR_SYNTAX_MR_NO_SYNTAX.get(definition)); |
| | | } |
| | | if (hook != null) { |
| | | hook.beforeAddMatchingRule(matchingRuleBuilder); |
| | | } |
| | | matchingRuleBuilder.addToSchema(overwrite); |
| | | } catch (final DecodeException e) { |
| | | final LocalizableMessage msg = |
| | |
| | | * If {@code definition} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addMatchingRuleUse(final String definition, final boolean overwrite) { |
| | | return addMatchingRuleUse(definition, overwrite, null); |
| | | } |
| | | |
| | | SchemaBuilder addMatchingRuleUse(final String definition, final boolean overwrite, SchemaBuilderHook hook) { |
| | | Reject.ifNull(definition); |
| | | |
| | | lazyInitBuilder(); |
| | |
| | | } |
| | | useBuilder.attributes(attributes); |
| | | |
| | | if (hook != null) { |
| | | hook.beforeAddMatchingRuleUse(useBuilder); |
| | | } |
| | | return useBuilder.addToSchema(overwrite); |
| | | } catch (final DecodeException e) { |
| | | final LocalizableMessage msg = ERR_ATTR_SYNTAX_MRUSE_INVALID1.get(definition, e.getMessageObject()); |
| | |
| | | * If {@code definition} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addNameForm(final String definition, final boolean overwrite) { |
| | | return addNameForm(definition, overwrite, null); |
| | | } |
| | | |
| | | SchemaBuilder addNameForm(final String definition, final boolean overwrite, SchemaBuilderHook hook) { |
| | | Reject.ifNull(definition); |
| | | |
| | | lazyInitBuilder(); |
| | |
| | | throw new LocalizedIllegalArgumentException(ERR_ATTR_SYNTAX_NAME_FORM_NO_REQUIRED_ATTR.get(definition)); |
| | | } |
| | | |
| | | if (hook != null) { |
| | | hook.beforeAddNameForm(nameFormBuilder); |
| | | } |
| | | nameFormBuilder.addToSchema(overwrite); |
| | | } catch (final DecodeException e) { |
| | | final LocalizableMessage msg = |
| | |
| | | * If {@code definition} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addObjectClass(final String definition, final boolean overwrite) { |
| | | return addObjectClass(definition, overwrite, null); |
| | | } |
| | | |
| | | SchemaBuilder addObjectClass(final String definition, final boolean overwrite, SchemaBuilderHook hook) { |
| | | Reject.ifNull(definition); |
| | | |
| | | lazyInitBuilder(); |
| | |
| | | ERR_ATTR_SYNTAX_OBJECTCLASS_ILLEGAL_TOKEN1.get(definition, tokenName)); |
| | | } |
| | | } |
| | | if (hook != null) { |
| | | hook.beforeAddObjectClass(ocBuilder); |
| | | } |
| | | |
| | | if (EXTENSIBLE_OBJECT_OBJECTCLASS_OID.equals(oid)) { |
| | | addObjectClass(newExtensibleObjectObjectClass( |
| | |
| | | // The call to addSchema will perform copyOnWrite. |
| | | final SearchRequest request = getReadSchemaSearchRequest(name); |
| | | final Entry entry = connection.searchSingleEntry(request); |
| | | return addSchema(entry, overwrite); |
| | | return addSchema(entry, overwrite, null); |
| | | } |
| | | |
| | | /** |
| | |
| | | * If {@code entry} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addSchema(final Entry entry, final boolean overwrite) { |
| | | return addSchema(entry, overwrite, null); |
| | | } |
| | | |
| | | /** |
| | | * Adds all of the schema elements contained in the provided subschema |
| | | * subentry to this schema builder. Any problems encountered while parsing |
| | | * the entry can be retrieved using the returned schema's |
| | | * {@link Schema#getWarnings()} method. |
| | | * |
| | | * @param entry |
| | | * The subschema subentry to be parsed. |
| | | * @param overwrite |
| | | * {@code true} if existing schema elements with the same |
| | | * conflicting OIDs should be overwritten. |
| | | * @param hook |
| | | * Allows to perform modifications on element's builders before adding the result to this schema builder. |
| | | * @return A reference to this schema builder. |
| | | * @throws NullPointerException |
| | | * If {@code entry} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addSchema(final Entry entry, final boolean overwrite, SchemaBuilderHook hook) { |
| | | Reject.ifNull(entry); |
| | | |
| | | lazyInitBuilder(); |
| | |
| | | if (attr != null) { |
| | | for (final ByteString def : attr) { |
| | | try { |
| | | addSyntax(def.toString(), overwrite); |
| | | addSyntax(def.toString(), overwrite, hook); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | warnings.add(e.getMessageObject()); |
| | | } |
| | |
| | | if (attr != null) { |
| | | for (final ByteString def : attr) { |
| | | try { |
| | | addAttributeType(def.toString(), overwrite); |
| | | addAttributeType(def.toString(), overwrite, hook); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | warnings.add(e.getMessageObject()); |
| | | } |
| | |
| | | if (attr != null) { |
| | | for (final ByteString def : attr) { |
| | | try { |
| | | addObjectClass(def.toString(), overwrite); |
| | | addObjectClass(def.toString(), overwrite, hook); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | warnings.add(e.getMessageObject()); |
| | | } |
| | |
| | | if (attr != null) { |
| | | for (final ByteString def : attr) { |
| | | try { |
| | | addMatchingRuleUse(def.toString(), overwrite); |
| | | addMatchingRuleUse(def.toString(), overwrite, hook); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | warnings.add(e.getMessageObject()); |
| | | } |
| | |
| | | if (attr != null) { |
| | | for (final ByteString def : attr) { |
| | | try { |
| | | addMatchingRule(def.toString(), overwrite); |
| | | addMatchingRule(def.toString(), overwrite, hook); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | warnings.add(e.getMessageObject()); |
| | | } |
| | |
| | | if (attr != null) { |
| | | for (final ByteString def : attr) { |
| | | try { |
| | | addDITContentRule(def.toString(), overwrite); |
| | | addDITContentRule(def.toString(), overwrite, hook); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | warnings.add(e.getMessageObject()); |
| | | } |
| | |
| | | if (attr != null) { |
| | | for (final ByteString def : attr) { |
| | | try { |
| | | addDITStructureRule(def.toString(), overwrite); |
| | | addDITStructureRule(def.toString(), overwrite, hook); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | warnings.add(e.getMessageObject()); |
| | | } |
| | |
| | | if (attr != null) { |
| | | for (final ByteString def : attr) { |
| | | try { |
| | | addNameForm(def.toString(), overwrite); |
| | | addNameForm(def.toString(), overwrite, hook); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | warnings.add(e.getMessageObject()); |
| | | } |
| | |
| | | new Function<SearchResultEntry, SchemaBuilder, LdapException>() { |
| | | @Override |
| | | public SchemaBuilder apply(SearchResultEntry result) throws LdapException { |
| | | addSchema(result, overwrite); |
| | | addSchema(result, overwrite, null); |
| | | return SchemaBuilder.this; |
| | | } |
| | | }); |
| | |
| | | * If {@code definition} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addSyntax(final String definition, final boolean overwrite) { |
| | | return addSyntax(definition, overwrite, null); |
| | | } |
| | | |
| | | SchemaBuilder addSyntax(final String definition, final boolean overwrite, SchemaBuilderHook hook) { |
| | | Reject.ifNull(definition); |
| | | |
| | | lazyInitBuilder(); |
| | |
| | | } |
| | | } |
| | | |
| | | if (hook != null) { |
| | | hook.beforeAddSyntax(syntaxBuilder); |
| | | } |
| | | syntaxBuilder.addToSchema(overwrite); |
| | | } catch (final DecodeException e) { |
| | | final LocalizableMessage msg = |