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 reader change record
038 * translator that can be used to invoke multiple LDIF reader change record
039 * translators for each record to be processed.
040 */
041 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
042 public final class AggregateLDIFReaderChangeRecordTranslator
043 implements LDIFReaderChangeRecordTranslator
044 {
045 // The set of LDIF reader change record translators to be invoked for each
046 // record to process.
047 private final List<LDIFReaderChangeRecordTranslator> translators;
048
049
050
051 /**
052 * Creates a new aggregate LDIF reader 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 reader change record translators to be
056 * invoked for each record to be processed.
057 */
058 public AggregateLDIFReaderChangeRecordTranslator(
059 final LDIFReaderChangeRecordTranslator... translators)
060 {
061 this(StaticUtils.toList(translators));
062 }
063
064
065
066 /**
067 * Creates a new aggregate LDIF reader 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 reader change record translators to be
071 * invoked for each record to be processed.
072 */
073 public AggregateLDIFReaderChangeRecordTranslator(
074 final Collection<? extends LDIFReaderChangeRecordTranslator> translators)
075 {
076 if (translators == null)
077 {
078 this.translators = Collections.emptyList();
079 }
080 else
081 {
082 this.translators = Collections.unmodifiableList(
083 new ArrayList<LDIFReaderChangeRecordTranslator>(translators));
084 }
085 }
086
087
088
089 /**
090 * {@inheritDoc}
091 */
092 public LDIFChangeRecord translate(final LDIFChangeRecord original,
093 final long firstLineNumber)
094 throws LDIFException
095 {
096 if (original == null)
097 {
098 return null;
099 }
100
101 LDIFChangeRecord r = original;
102 for (final LDIFReaderChangeRecordTranslator t : translators)
103 {
104 r = t.translate(r, firstLineNumber);
105 if (r == null)
106 {
107 return null;
108 }
109 }
110
111 return r;
112 }
113 }