001 /*
002 * Copyright 2016 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2016 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 */
021 package com.unboundid.ldif;
022
023
024
025 import java.util.ArrayList;
026 import java.util.Collection;
027 import java.util.Collections;
028 import java.util.List;
029
030 import com.unboundid.util.StaticUtils;
031 import com.unboundid.util.ThreadSafety;
032 import com.unboundid.util.ThreadSafetyLevel;
033
034
035
036 /**
037 * This class provides an implementation of an LDIF writer change record
038 * translator that can be used to invoke multiple LDIF writer change record
039 * translators for each record to be processed.
040 */
041 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
042 public final class AggregateLDIFWriterChangeRecordTranslator
043 implements LDIFWriterChangeRecordTranslator
044 {
045 // The set of LDIF writer change record translators to be invoked for each
046 // record to process.
047 private final List<LDIFWriterChangeRecordTranslator> translators;
048
049
050
051 /**
052 * Creates a new aggregate LDIF writer change record translator that will
053 * invoke all of the provided translators for each record to be processed.
054 *
055 * @param translators The set of LDIF writer change record translators to be
056 * invoked for each record to be processed.
057 */
058 public AggregateLDIFWriterChangeRecordTranslator(
059 final LDIFWriterChangeRecordTranslator... translators)
060 {
061 this(StaticUtils.toList(translators));
062 }
063
064
065
066 /**
067 * Creates a new aggregate LDIF writer change record translator that will
068 * invoke all of the provided translators for each record to be processed.
069 *
070 * @param translators The set of LDIF writer change record translators to be
071 * invoked for each record to be processed.
072 */
073 public AggregateLDIFWriterChangeRecordTranslator(
074 final Collection<? extends LDIFWriterChangeRecordTranslator> translators)
075 {
076 if (translators == null)
077 {
078 this.translators = Collections.emptyList();
079 }
080 else
081 {
082 this.translators = Collections.unmodifiableList(
083 new ArrayList<LDIFWriterChangeRecordTranslator>(translators));
084 }
085 }
086
087
088
089 /**
090 * {@inheritDoc}
091 */
092 public LDIFChangeRecord translateChangeRecordToWrite(
093 final LDIFChangeRecord original)
094 {
095 if (original == null)
096 {
097 return null;
098 }
099
100 LDIFChangeRecord r = original;
101 for (final LDIFWriterChangeRecordTranslator t : translators)
102 {
103 r = t.translateChangeRecordToWrite(r);
104 if (r == null)
105 {
106 return null;
107 }
108 }
109
110 return r;
111 }
112 }