001/*
002 * Copyright 2015-2017 UnboundID Corp.
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2017 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk;
022
023
024
025import java.util.ArrayList;
026import java.util.Collection;
027import java.util.Collections;
028import java.util.List;
029
030import com.unboundid.util.StaticUtils;
031import com.unboundid.util.ThreadSafety;
032import com.unboundid.util.ThreadSafetyLevel;
033
034
035
036/**
037 * This class provides an implementation of a post-connect processor that makes
038 * it possible to invoke multiple post-connect processors as a single unit.
039 */
040@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
041public final class AggregatePostConnectProcessor
042       implements PostConnectProcessor
043{
044  // The list of post-connect processors to be invoked.
045  private final List<PostConnectProcessor> processors;
046
047
048
049  /**
050   * Creates a new aggregate post-connect processor that will invoke the given
051   * set of post-connect processors in the order they are listed.
052   *
053   * @param  processors  The set of post-connect processors to be invoked.
054   */
055  public AggregatePostConnectProcessor(final PostConnectProcessor... processors)
056  {
057    this(StaticUtils.toList(processors));
058  }
059
060
061
062  /**
063   * Creates a new aggregate post-connect processor that will invoke the given
064   * set of post-connect processors in the order they are listed.
065   *
066   * @param  processors  The set of post-connect processors to be invoked.
067   */
068  public AggregatePostConnectProcessor(
069              final Collection<? extends PostConnectProcessor> processors)
070  {
071    if (processors == null)
072    {
073      this.processors = Collections.emptyList();
074    }
075    else
076    {
077      this.processors = Collections.unmodifiableList(
078           new ArrayList<PostConnectProcessor>(processors));
079    }
080  }
081
082
083
084  /**
085   * {@inheritDoc}
086   */
087  public void processPreAuthenticatedConnection(final LDAPConnection connection)
088         throws LDAPException
089  {
090    for (final PostConnectProcessor p : processors)
091    {
092      p.processPreAuthenticatedConnection(connection);
093    }
094  }
095
096
097
098  /**
099   * {@inheritDoc}
100   */
101  public void processPostAuthenticatedConnection(
102                   final LDAPConnection connection)
103         throws LDAPException
104  {
105    for (final PostConnectProcessor p : processors)
106    {
107      p.processPostAuthenticatedConnection(connection);
108    }
109  }
110}