| File was renamed from opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPNameBuilder.java |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.config.client.ldap; |
| | |
| | | /** |
| | | * A strategy for creating <code>DN</code>s from managed object paths. |
| | | */ |
| | | final class LDAPNameBuilder implements ManagedObjectPathSerializer { |
| | | final class DNBuilder implements ManagedObjectPathSerializer { |
| | | |
| | | /** |
| | | * Creates a new DN representing the specified managed object path. |
| | |
| | | * The LDAP profile which should be used to construct LDAP names. |
| | | * @return Returns a new DN representing the specified managed object path. |
| | | */ |
| | | public static DN create(ManagedObjectPath<?, ?> path, LDAPProfile profile) { |
| | | LDAPNameBuilder builder = new LDAPNameBuilder(profile); |
| | | static DN create(ManagedObjectPath<?, ?> path, LDAPProfile profile) { |
| | | DNBuilder builder = new DNBuilder(profile); |
| | | path.serialize(builder); |
| | | return builder.getInstance(); |
| | | return builder.build(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return Returns a new DN representing the specified managed object path |
| | | * and instantiable relation. |
| | | */ |
| | | public static DN create(ManagedObjectPath<?, ?> path, InstantiableRelationDefinition<?, ?> relation, |
| | | LDAPProfile profile) { |
| | | LDAPNameBuilder builder = new LDAPNameBuilder(profile); |
| | | static DN create(ManagedObjectPath<?, ?> path, |
| | | InstantiableRelationDefinition<?, ?> relation, LDAPProfile profile) { |
| | | DNBuilder builder = new DNBuilder(profile); |
| | | path.serialize(builder); |
| | | builder.appendManagedObjectPathElement(relation); |
| | | return builder.getInstance(); |
| | | return builder.build(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return Returns a new DN representing the specified managed object path |
| | | * and set relation. |
| | | */ |
| | | public static DN create(ManagedObjectPath<?, ?> path, SetRelationDefinition<?, ?> relation, LDAPProfile profile) { |
| | | LDAPNameBuilder builder = new LDAPNameBuilder(profile); |
| | | static DN create(ManagedObjectPath<?, ?> path, SetRelationDefinition<?, ?> relation, |
| | | LDAPProfile profile) { |
| | | DNBuilder builder = new DNBuilder(profile); |
| | | path.serialize(builder); |
| | | builder.appendManagedObjectPathElement(relation); |
| | | return builder.getInstance(); |
| | | return builder.build(); |
| | | } |
| | | |
| | | /** The list of RDNs in big-endian order. */ |
| | |
| | | * @param profile |
| | | * The LDAP profile which should be used to construct DNs. |
| | | */ |
| | | public LDAPNameBuilder(LDAPProfile profile) { |
| | | private DNBuilder(LDAPProfile profile) { |
| | | this.rdns = new LinkedList<RDN>(); |
| | | this.profile = profile; |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | InstantiableRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d, |
| | | String name) { |
| | | InstantiableRelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d, String name) { |
| | | // Add the RDN sequence representing the relation. |
| | | appendManagedObjectPathElement(r); |
| | | |
| | |
| | | * @param r |
| | | * The relation definition. |
| | | */ |
| | | public void appendManagedObjectPathElement(RelationDefinition<?, ?> r) { |
| | | private void appendManagedObjectPathElement(RelationDefinition<?, ?> r) { |
| | | // Add the RDN sequence representing the relation. |
| | | DN dn = DN.valueOf(profile.getRelationRDNSequence(r)); |
| | | List<RDN> rdnsOfDn = getRdnsInBigEndianOrder(dn); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | OptionalRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | OptionalRelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d) { |
| | | // Add the RDN sequence representing the relation. |
| | | appendManagedObjectPathElement(r); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | SingletonRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | SingletonRelationDefinition<? super C, ? super S> r, |
| | | AbstractManagedObjectDefinition<C, S> d) { |
| | | // Add the RDN sequence representing the relation. |
| | | appendManagedObjectPathElement(r); |
| | | } |
| | |
| | | * |
| | | * @return Returns the new DN instance. |
| | | */ |
| | | public DN getInstance() { |
| | | private DN build() { |
| | | DN dn = DN.rootDN(); |
| | | for (RDN rdn : rdns) { |
| | | dn = dn.child(rdn); |