8,8 → 8,19 |
import ak.hostadmiral.util.ModelSecurityException; |
|
public class MailboxManager |
implements |
UserBeforeDeleteListener, |
SystemUserBeforeDeleteListener, |
InetDomainBeforeDeleteListener |
{ |
private static MailboxManager mailboxManager = null; |
private static boolean registered = false; |
|
public static MailboxManager getInstance() |
{ |
return mailboxManager; |
} |
|
protected static void register() |
{ |
synchronized(MailboxManager.class) { |
19,6 → 30,8 |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/hostadmiral/core/model/Mailbox.hbm.xml"); |
|
mailboxManager = new MailboxManager(); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
31,8 → 44,13 |
register(); |
} |
|
private Collection beforeDeleteListeners = new ArrayList(); |
|
private MailboxManager() |
{ |
UserManager.getInstance().addBeforeDeleteListener(this); |
SystemUserManager.getInstance().addBeforeDeleteListener(this); |
InetDomainManager.getInstance().addBeforeDeleteListener(this); |
} |
|
public Mailbox create(User editor) |
130,6 → 148,31 |
} |
} |
|
public void addBeforeDeleteListener(MailboxBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.add(listener); |
} |
|
public void removeBeforeDeleteListener(MailboxBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.remove(listener); |
} |
|
public Collection beforeDelete(User editor, Mailbox mailbox, Collection known) |
throws ModelException |
{ |
Collection cascade = new ArrayList(); |
|
for(Iterator i = beforeDeleteListeners.iterator(); i.hasNext(); ) { |
MailboxBeforeDeleteListener listener = (MailboxBeforeDeleteListener)i.next(); |
Collection subcascade = listener.mailboxBeforeDelete(editor, mailbox, known); |
if(subcascade != null) |
cascade.addAll(subcascade); |
} |
|
return cascade; |
} |
|
public void delete(User editor, Mailbox mailbox) |
throws ModelException |
{ |
188,16 → 231,83 |
} |
} |
|
private static MailboxManager mailboxManager = null; |
public Collection userBeforeDelete(User editor, User user, Collection known) |
throws ModelException |
{ |
Collection mailboxes; |
|
public static MailboxManager getInstance() |
try { |
mailboxes = HibernateUtil.currentSession().find( |
"from Mailbox where owner = ?", |
user, Hibernate.entity(User.class) ); |
} |
catch(HibernateException ex) |
{ |
if(mailboxManager == null) |
mailboxManager = new MailboxManager(); |
throw new ModelException(ex); |
} |
|
return mailboxManager; |
return iterateBeforeDelete(editor, mailboxes, known); |
} |
|
public Collection inetDomainBeforeDelete(User editor, InetDomain domain, Collection known) |
throws ModelException |
{ |
Collection mailboxes; |
|
try { |
mailboxes = HibernateUtil.currentSession().find( |
"from Mailbox where domain = ?", |
domain, Hibernate.entity(InetDomain.class) ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
|
return iterateBeforeDelete(editor, mailboxes, known); |
} |
|
public Collection systemUserBeforeDelete(User editor, SystemUser user, Collection known) |
throws ModelException |
{ |
Collection mailboxes; |
|
try { |
mailboxes = HibernateUtil.currentSession().find( |
"from Mailbox where systemUser = ?", |
user, Hibernate.entity(SystemUser.class) ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
|
return iterateBeforeDelete(editor, mailboxes, known); |
} |
|
private Collection iterateBeforeDelete(User editor, Collection mailboxes, Collection known) |
throws ModelException |
{ |
Collection cascade = new ArrayList(); |
for(Iterator i = mailboxes.iterator(); i.hasNext(); ) { |
Mailbox mailbox = (Mailbox)i.next(); |
if(mailbox.viewableBy(editor)) { |
if(mailbox.deleteableBy(editor)) |
cascade.add(new CascadeDeleteElement(mailbox, CascadeDeleteElement.DELETE, |
this.beforeDelete(editor, mailbox, known))); |
else |
cascade.add(new CascadeDeleteElement(mailbox, CascadeDeleteElement.FORBIDDEN, |
null)); |
} |
else { |
cascade.add(new CascadeDeleteElement(Mailbox.createLimitedCopy(mailbox), |
CascadeDeleteElement.FORBIDDEN, null)); |
} |
} |
|
return cascade; |
} |
|
public static final Comparator LOGIN_COMPARATOR = new LoginComparator(); |
|
private static class LoginComparator |