| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.config; |
| | |
| | | */ |
| | | public final class ManagedObjectPath<C extends ConfigurationClient, S extends Configuration> { |
| | | |
| | | /** |
| | | * A serialize which is used to generate the toDN representation. |
| | | */ |
| | | /** A serialize which is used to generate the toDN representation. */ |
| | | private static final class DNSerializer implements ManagedObjectPathSerializer { |
| | | |
| | | /** The current DN. */ |
| | |
| | | this.profile = LDAPProfile.getInstance(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | InstantiableRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d, |
| | | String name) { |
| | |
| | | dn = dn.child(new RDN(attrType, name)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | SetRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | // Add the RDN sequence representing the relation. |
| | |
| | | dn = dn.child(new RDN(attrType, d.getName())); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | OptionalRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | // Add the RDN sequence representing the relation. |
| | | appendManagedObjectPathElement(r); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> void appendManagedObjectPathElement( |
| | | SingletonRelationDefinition<? super C, ? super S> r, AbstractManagedObjectDefinition<C, S> d) { |
| | | // Add the RDN sequence representing the relation. |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Abstract path element. |
| | | */ |
| | | /** Abstract path element. */ |
| | | private static abstract class Element<C extends ConfigurationClient, S extends Configuration> { |
| | | |
| | | /** The type of managed object referenced by this element. */ |
| | |
| | | public abstract void serialize(ManagedObjectPathSerializer serializer); |
| | | } |
| | | |
| | | /** |
| | | * A path element representing an instantiable managed object. |
| | | */ |
| | | /** A path element representing an instantiable managed object. */ |
| | | private static final class InstantiableElement<C extends ConfigurationClient, S extends Configuration> extends |
| | | Element<C, S> { |
| | | |
| | |
| | | this.name = name; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public InstantiableRelationDefinition<? super C, ? super S> getRelationDefinition() { |
| | | return r; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void serialize(ManagedObjectPathSerializer serializer) { |
| | | serializer.appendManagedObjectPathElement(r, getManagedObjectDefinition(), name); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * A path element representing an optional managed object. |
| | | */ |
| | | /** A path element representing an optional managed object. */ |
| | | private static final class OptionalElement<C extends ConfigurationClient, S extends Configuration> extends |
| | | Element<C, S> { |
| | | |
| | |
| | | this.r = r; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public OptionalRelationDefinition<? super C, ? super S> getRelationDefinition() { |
| | | return r; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void serialize(ManagedObjectPathSerializer serializer) { |
| | | serializer.appendManagedObjectPathElement(r, getManagedObjectDefinition()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * A path element representing an set managed object. |
| | | */ |
| | | /** A path element representing an set managed object. */ |
| | | private static final class SetElement<C extends ConfigurationClient, S extends Configuration> extends |
| | | Element<C, S> { |
| | | |
| | |
| | | this.r = r; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public SetRelationDefinition<? super C, ? super S> getRelationDefinition() { |
| | | return r; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void serialize(ManagedObjectPathSerializer serializer) { |
| | | serializer.appendManagedObjectPathElement(r, getManagedObjectDefinition()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * A path element representing a singleton managed object. |
| | | */ |
| | | /** A path element representing a singleton managed object. */ |
| | | private static final class SingletonElement<C extends ConfigurationClient, S extends Configuration> extends |
| | | Element<C, S> { |
| | | |
| | |
| | | this.r = r; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public SingletonRelationDefinition<? super C, ? super S> getRelationDefinition() { |
| | | return r; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void serialize(ManagedObjectPathSerializer serializer) { |
| | | serializer.appendManagedObjectPathElement(r, getManagedObjectDefinition()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * A serialize which is used to generate the toString representation. |
| | | */ |
| | | /** A serialize which is used to generate the toString representation. */ |
| | | private static final class StringSerializer implements ManagedObjectPathSerializer { |
| | | |
| | | /** Serialize to this string builder. */ |
| | |
| | | this.builder = builder; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <M extends ConfigurationClient, N extends Configuration> void appendManagedObjectPathElement( |
| | | InstantiableRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d, |
| | | String name) { |
| | |
| | | builder.append(name.replace("/", "//")); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <M extends ConfigurationClient, N extends Configuration> void appendManagedObjectPathElement( |
| | | OptionalRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | serializeElement(r, d); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <M extends ConfigurationClient, N extends Configuration> void appendManagedObjectPathElement( |
| | | SingletonRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | serializeElement(r, d); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <M extends ConfigurationClient, N extends Configuration> void appendManagedObjectPathElement( |
| | | SetRelationDefinition<? super M, ? super N> r, AbstractManagedObjectDefinition<M, N> d) { |
| | | serializeElement(r, d); |
| | |
| | | return create(elements, lastElement); |
| | | } |
| | | |
| | | /** |
| | | * Factory method required in order to allow generic wild-card |
| | | * construction of new paths. |
| | | */ |
| | | /** Factory method required in order to allow generic wild-card construction of new paths. */ |
| | | private static <C extends ConfigurationClient, S extends Configuration> ManagedObjectPath<C, S> create( |
| | | LinkedList<Element<?, ?>> elements, Element<C, S> lastElement) { |
| | | return new ManagedObjectPath<>(elements, lastElement.getRelationDefinition(), |
| | |
| | | return child(r, r.getChildDefinition()); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (obj == this) { |
| | |
| | | return r; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int hashCode() { |
| | | return toString().hashCode(); |
| | |
| | | return serializer.toDN(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String toString() { |
| | | StringBuilder builder = new StringBuilder(); |