/** * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ /******************************************************************************\ * * This product was developed by * * SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), * * a government company established under Brazilian law (5.615/70), * at Department of Development of Porto Alegre. * \******************************************************************************/ package serpro.mailarchiver.domain.metaarchive; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.jdo.JDOHelper; import javax.jdo.annotations.NotPersistent; import javax.jdo.annotations.PersistenceCapable; import org.apache.james.mime4j.codec.EncoderUtil; import serpro.mailarchiver.util.Logger; @PersistenceCapable public class AddressListField_Group extends AddressListField_Address { @NotPersistent private static final Logger log = Logger.getLocalLogger(); //**** P E R S I S T E N T **** private ArrayList mailboxList = new ArrayList(); //***************************** public final List getMailboxList() { return Collections.unmodifiableList(mailboxList); } public final int indexOf(AddressListField_Group_Mailbox mailbox) { return mailboxList.indexOf(mailbox); } public final void addMailbox(AddressListField_Group_Mailbox mailbox) { if(mailbox != null) { mailbox.setGroup(this); } } final void internal_addMailbox(AddressListField_Group_Mailbox mailbox) { mailboxList.add(mailbox); } public final void removeMailbox(AddressListField_Group_Mailbox mailbox) { if((mailbox != null) && (mailbox.getGroup() == this)) { mailbox.setGroup(null); } } final void internal_removeMailbox(AddressListField_Group_Mailbox mailbox) { mailboxList.remove(mailbox); } //---------------------------------------------------------------------- @Override public final String toDisplayString(boolean includeRoute) { String name = getName(); StringBuilder sb = new StringBuilder(); sb.append(name); sb.append(":"); boolean first = true; for(AddressListField_Group_Mailbox mailbox : getMailboxList()) { if(first) { first = false; } else { sb.append(","); } sb.append(" "); sb.append(mailbox.toDisplayString(includeRoute)); } sb.append(";"); return sb.toString(); } @Override public final String toEncodedString() { String name = getName(); StringBuilder sb = new StringBuilder(); sb.append(EncoderUtil.encodeAddressDisplayName(name)); sb.append(":"); boolean first = true; for(AddressListField_Group_Mailbox mailbox : getMailboxList()) { if (first) { first = false; } else { sb.append(","); } sb.append(" "); sb.append(mailbox.toEncodedString()); } sb.append(";"); return sb.toString(); } //---------------------------------------------------------------------- @Override final void dumpTree(StringBuilder sb, String pad) { int size = mailboxList.size(); sb.append(toString(pad + ((size > 0) ? "| " : " "))); for(int i = 0; i < size; i++) { sb.append("\n") .append(pad).append("|\n"); if(i < (size - 1)) { sb.append(pad).append("+---"); mailboxList.get(i).dumpTree(sb, pad + "| "); } else { sb.append(pad).append("+---"); mailboxList.get(i).dumpTree(sb, pad + " "); } } } @Override final String toString(String pad) { String idx = (getField() == null) ? "" : ("[" + String.valueOf(getFieldIdx()) + "]"); return String.format( "AddressListField_Group %1$s%n" + "%2$sjdoState: %3$s%n" + "%2$soid: %4$s%n" + "%2$shash: %5$x%n" + "%2$sname: %6$s" , idx , pad , JDOHelper.getObjectState(this) , getOid() , hashCode() , getName()); } }