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