/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/Mailbox.java |
---|
0,0 → 1,321 |
package ak.hostadmiral.core.model; |
import java.util.Iterator; |
import java.util.Collection; |
import java.util.HashSet; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="mailboxes" |
*/ |
public class Mailbox |
extends GeneralModelObject |
{ |
private String login; |
private Collection passwords; // Collection(PasswordStore) |
private InetDomain domain; |
private User owner; |
private Boolean virusCheck; |
private Boolean spamCheck; |
private SystemUser systemUser; |
private Mailbox origin; // save original object state before any changes |
protected Mailbox() |
{ |
} |
protected Mailbox(Mailbox origin) |
{ |
super(origin); |
this.login = origin.login; |
if(origin.passwords == null) |
this.passwords = null; |
else |
this.passwords = new HashSet(origin.passwords); |
this.domain = origin.domain; |
this.owner = origin.owner; |
this.virusCheck = origin.virusCheck; |
this.spamCheck = origin.spamCheck; |
this.systemUser = origin.systemUser; |
} |
protected Mailbox getOrigin() |
{ |
return origin; |
} |
protected void backupMe() |
{ |
if(origin == null) |
origin = new Mailbox(this); |
} |
protected void resetOrigin() |
{ |
origin = null; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getLogin() |
{ |
return login; |
} |
protected void setLogin(String login) |
{ |
this.login = login; |
} |
public void setLogin(User editor, String login) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.login = login; |
} |
protected void addPasswordStore(PasswordStore ps) |
{ |
if(passwords == null) passwords = new HashSet(); |
passwords.add(ps); |
} |
public String getPassword(User editor, String digest) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
for(Iterator i = passwords.iterator(); i.hasNext(); ) { |
Object o = i.next(); |
if(!(o instanceof PasswordStore)) |
throw new ModelException("It's not a password store"); |
PasswordStore ps = (PasswordStore)o; |
if(ps.getDigest().equals(digest)) { |
return ps.getPassword(); |
} |
} |
throw new ModelException("Digest " + digest + " not found"); |
} |
public void setPassword(User editor, String password) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
if(password == null) |
throw new NullPointerException("Null password"); |
backupMe(); |
for(Iterator i = passwords.iterator(); i.hasNext(); ) { |
Object o = i.next(); |
if(!(o instanceof PasswordStore)) |
throw new ModelException("It's not a password store"); |
((PasswordStore)o).setNewPassword(password); |
} |
} |
/** |
* |
* @hibernate.set cascade="all" |
* @hibernate.collection-key column="obj" |
* @hibernate.collection-one-to-many class="ak.hostadmiral.core.model.PasswordStoreAbstract" |
*/ |
protected Collection getPasswords() |
{ |
return passwords; |
} |
protected void setPasswords(Collection passwords) |
{ |
this.passwords = passwords; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public InetDomain getDomain() |
{ |
return domain; |
} |
protected void setDomain(InetDomain domain) |
{ |
this.domain = domain; |
} |
public void setDomain(User editor, InetDomain domain) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.domain = domain; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getOwner() |
{ |
return owner; |
} |
protected void setOwner(User owner) |
{ |
this.owner = owner; |
} |
public void setOwner(User editor, User owner) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.owner = owner; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Boolean getVirusCheck() |
{ |
return virusCheck; |
} |
protected void setVirusCheck(Boolean virusCheck) |
{ |
this.virusCheck = virusCheck; |
} |
public void setVirusCheck(User editor, Boolean virusCheck) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.virusCheck = virusCheck; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Boolean getSpamCheck() |
{ |
return spamCheck; |
} |
protected void setSpamCheck(Boolean spamCheck) |
{ |
this.spamCheck = spamCheck; |
} |
public void setSpamCheck(User editor, Boolean spamCheck) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.spamCheck = spamCheck; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public SystemUser getSystemUser() |
{ |
return systemUser; |
} |
protected void setSystemUser(SystemUser systemUser) |
{ |
this.systemUser = systemUser; |
} |
public void setSystemUser(User editor, SystemUser systemUser) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.systemUser = systemUser; |
} |
public String getTypeKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.TYPE_MAILBOX; |
} |
public String getIdentKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.IDENT_MAILBOX; |
} |
public Object[] getIdentParams() |
{ |
return new Object[] { getLogin(), getDomain().getName() }; |
} |
public boolean viewableBy(User user) |
{ |
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner); |
} |
public boolean editableBy(User user) |
{ |
return user.isSuperuser() |
|| (domain == null) // just created |
|| user.equals(domain.getOwner()); |
} |
public boolean deleteableBy(User user) |
{ |
return user.isSuperuser() || user.equals(domain.getOwner()); |
} |
protected static boolean allowedToCreate(MailboxManager manager, User editor) |
throws ModelException |
{ |
return editor.isSuperuser() |
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor); |
} |
protected static Mailbox createLimitedCopy(Mailbox origin) |
{ |
Mailbox m = new Mailbox(); |
m.setLogin(origin.getLogin()); |
m.setDomain(origin.getDomain()); |
m.setOwner(origin.getOwner()); |
return m; |
} |
public String toString() |
{ |
return "Mailbox id=[" + getId() + "] login=[" + login + "@" |
+ (domain == null ? "_none_" : domain.getName()) + "]"; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailAlias.java |
---|
0,0 → 1,210 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="mailaliases" |
*/ |
public class MailAlias |
extends GeneralModelObject |
{ |
private String address; |
private InetDomain domain; |
private User owner; |
private Collection destinations; // Collection(MailAliasDestintion) |
private MailAlias origin; // save original object state before any changes |
protected MailAlias() |
{ |
} |
protected MailAlias(MailAlias origin) |
{ |
super(origin); |
this.address = origin.address; |
this.domain = origin.domain; |
this.owner = origin.owner; |
this.destinations = origin.destinations; // FIXME: or make a copy? |
} |
protected MailAlias getOrigin() |
{ |
return origin; |
} |
protected void backupMe() |
{ |
if(origin == null) |
origin = new MailAlias(this); |
} |
protected void resetOrigin() |
{ |
origin = null; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getAddress() |
{ |
return address; |
} |
protected void setAddress(String address) |
{ |
this.address = address; |
} |
public void setAddress(User editor, String address) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
this.address = address; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public InetDomain getDomain() |
{ |
return domain; |
} |
protected void setDomain(InetDomain domain) |
{ |
this.domain = domain; |
} |
public void setDomain(User editor, InetDomain domain) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
this.domain = domain; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getOwner() |
{ |
return owner; |
} |
protected void setOwner(User owner) |
{ |
this.owner = owner; |
} |
public void setOwner(User editor, User owner) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
this.owner = owner; |
} |
/** |
* @return Collection(MailAliasDestination) |
* |
* @hibernate.bag inverse="true" cascade="all-delete-orphan" |
* @hibernate.collection-key column="alias" |
* @hibernate.collection-one-to-many class="ak.hostadmiral.core.model.MailAliasDestination" |
*/ |
protected Collection getDestinations() |
{ |
return destinations; |
} |
/** |
* @return Collection(MailAliasDestination) |
*/ |
public Collection getDestinations(User editor) |
throws ModelException |
{ |
if(mayChangeDestinations(editor)) |
return destinations; |
else if(viewableBy(editor)) |
return java.util.Collections.unmodifiableCollection(destinations); |
else |
throw new ModelSecurityException(); |
} |
/** |
* @param destinations Collection(MailAliasDestination) |
*/ |
protected void setDestinations(Collection destinations) |
{ |
this.destinations = destinations; |
} |
public String getTypeKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.TYPE_MAIL_ALIAS; |
} |
public String getIdentKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.IDENT_MAIL_ALIAS; |
} |
public Object[] getIdentParams() |
{ |
return new Object[] { getAddress(), getDomain().getName() }; |
} |
public boolean viewableBy(User user) |
{ |
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner); |
} |
public boolean editableBy(User user) |
{ |
return user.isSuperuser() |
|| (domain == null) // just created |
|| user.equals(domain.getOwner()); |
} |
public boolean mayChangeDestinations(User user) |
{ |
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner); |
} |
public boolean deleteableBy(User user) |
{ |
return user.isSuperuser() || user.equals(domain.getOwner()); |
} |
protected static boolean allowedToCreate(MailAliasManager manager, User editor) |
throws ModelException |
{ |
return editor.isSuperuser() |
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor); |
} |
protected static MailAlias createLimitedCopy(MailAlias origin) |
{ |
MailAlias m = new MailAlias(); |
m.setAddress(origin.getAddress()); |
m.setDomain(origin.getDomain()); |
m.setOwner(origin.getOwner()); |
return m; |
} |
public String toString() |
{ |
return "MailAlias id=[" + getId() + "] address=[" + address + "@" |
+ (domain == null ? "_none_" : domain.getName()) + "]"; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/User.java |
---|
0,0 → 1,401 |
package ak.hostadmiral.core.model; |
import java.util.Iterator; |
import java.util.Collection; |
import java.util.Collections; |
import java.util.HashSet; |
import java.util.Locale; |
import java.util.StringTokenizer; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="users" |
*/ |
public class User |
extends GeneralModelObject |
{ |
public static final String DEFAULT_PASSWORD_STORE = "MD5"; |
private String login; |
private Collection passwords; // Collection(PasswordStore) |
private User boss; |
private Boolean superuser; |
private Locale locale = Locale.getDefault(); |
private Collection loginHistory; |
private User origin; // save original object state before any changes |
protected User() |
{ |
} |
protected User(User origin) |
{ |
super(origin); |
this.login = origin.login; |
if(origin.passwords == null) |
this.passwords = null; |
else |
this.passwords = new HashSet(origin.passwords); |
this.boss = origin.boss; |
this.superuser = origin.superuser; |
this.locale = origin.locale; |
if(origin.loginHistory == null) |
this.loginHistory = null; |
else |
this.loginHistory = new HashSet(origin.loginHistory); |
} |
protected User getOrigin() |
{ |
return origin; |
} |
protected void backupMe() |
{ |
if(origin == null) |
origin = new User(this); |
} |
protected void resetOrigin() |
{ |
origin = null; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getLogin() |
{ |
return login; |
} |
protected void setLogin(String login) |
{ |
this.login = login; |
} |
public void setLogin(User editor, String login) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.login = login; |
} |
protected void addPasswordStore(PasswordStore ps) |
{ |
if(passwords == null) passwords = new HashSet(); |
passwords.add(ps); |
} |
protected PasswordStore getDefaultPasswordStore() |
throws ModelException |
{ |
if(passwords == null) |
throw new ModelException("No password store"); |
for(Iterator i = passwords.iterator(); i.hasNext(); ) { |
Object o = i.next(); |
if(!(o instanceof PasswordStore)) |
throw new ModelException("It's not a password store"); |
PasswordStore ps = (PasswordStore)o; |
if(DEFAULT_PASSWORD_STORE.equals(ps.getDigest())) |
return ps; |
} |
throw new ModelException("No password store for digest " + DEFAULT_PASSWORD_STORE); |
} |
public String getPassword(User editor) |
throws ModelException |
{ |
if(!partEditableBy(editor)) |
throw new ModelSecurityException(); |
return getDefaultPasswordStore().getPassword(); |
} |
public String getPassword(User editor, String digest) |
throws ModelException |
{ |
if(!partEditableBy(editor)) |
throw new ModelSecurityException(); |
for(Iterator i = passwords.iterator(); i.hasNext(); ) { |
Object o = i.next(); |
if(!(o instanceof PasswordStore)) |
throw new ModelException("It's not a password store"); |
PasswordStore ps = (PasswordStore)o; |
if(ps.getDigest().equals(digest)) { |
return ps.getPassword(); |
} |
} |
throw new ModelException("Digest " + digest + " not found"); |
} |
public void setPassword(User editor, String password) |
throws ModelException |
{ |
if(!partEditableBy(editor)) |
throw new ModelSecurityException(); |
if(password == null) |
throw new NullPointerException("Null password"); |
backupMe(); |
for(Iterator i = passwords.iterator(); i.hasNext(); ) { |
Object o = i.next(); |
if(!(o instanceof PasswordStore)) |
throw new ModelException("It's not a password store"); |
((PasswordStore)o).setNewPassword(password); |
} |
} |
public boolean checkPassword(String password) |
throws ModelException |
{ |
if(password == null) |
throw new NullPointerException("Null password"); |
return getDefaultPasswordStore().checkPassword(password); |
} |
/** |
* |
* @hibernate.set cascade="all" |
* @hibernate.collection-key column="obj" |
* @hibernate.collection-one-to-many class="ak.hostadmiral.core.model.PasswordStoreAbstract" |
*/ |
protected Collection getPasswords() |
{ |
return passwords; |
} |
protected void setPasswords(Collection passwords) |
{ |
this.passwords = passwords; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getBoss() |
{ |
return boss; |
} |
protected void setBoss(User boss) |
{ |
this.boss = boss; |
} |
public void setBoss(User editor, User boss) |
throws ModelException |
{ |
if(!mayChangeBoss(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.boss = boss; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Boolean getSuperuser() |
{ |
return superuser; |
} |
public boolean isSuperuser() |
{ |
return (superuser != null) && superuser.booleanValue(); |
} |
protected void setSuperuser(Boolean superuser) |
{ |
this.superuser = superuser; |
} |
public void setSuperuser(User editor, Boolean superuser) |
throws ModelException |
{ |
if(!mayChangeSuperuser(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.superuser = superuser; |
} |
/** |
* |
* @hibernate.property column="locale" |
*/ |
protected String getLocaleName() |
{ |
return locale.toString(); |
} |
protected void setLocaleName(String localeName) |
{ |
String language = null; |
String country = null; |
if(localeName != null) { |
StringTokenizer t = new StringTokenizer(localeName, "_"); |
if(t.hasMoreTokens()) language = t.nextToken(); |
if(t.hasMoreTokens()) country = t.nextToken(); |
} |
if(language == null) |
this.locale = Locale.getDefault(); |
else if(country == null) |
this.locale = new Locale(language); |
else |
this.locale = new Locale(language, country); |
} |
public void setLocaleName(User editor, String localeName) |
throws ModelException |
{ |
if(!partEditableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
setLocaleName(localeName); |
} |
public Locale getLocale() |
{ |
return locale; |
} |
public void setLocale(Locale locale) |
{ |
this.locale = locale; |
} |
public void setLocale(User editor, Locale locale) |
throws ModelException |
{ |
if(!partEditableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.locale = locale; |
} |
/** |
* |
* @hibernate.set |
* @hibernate.collection-key column="usr" |
* @hibernate.collection-one-to-many class="ak.hostadmiral.core.model.UserLogin" |
*/ |
protected Collection getLoginHistory() |
{ |
return loginHistory; |
} |
public Collection getLogins() |
{ |
return Collections.unmodifiableCollection(loginHistory); |
} |
protected void setLoginHistory(Collection loginHistory) |
{ |
this.loginHistory = loginHistory; |
} |
protected void update(User origin) |
{ |
this.login = origin.login; |
this.boss = origin.boss; |
this.superuser = origin.superuser; |
this.locale = origin.locale; |
} |
public String getTypeKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.TYPE_USER; |
} |
public String getIdentKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.IDENT_USER; |
} |
public Object[] getIdentParams() |
{ |
return new Object[] { getLogin() }; |
} |
public boolean viewableBy(User user) |
{ |
return user.isSuperuser() || user.equals(boss) || user.equals(this); |
} |
public boolean editableBy(User user) |
{ |
return user.isSuperuser() || user.equals(boss); |
} |
public boolean deleteableBy(User user) |
{ |
return !user.equals(this) && (user.isSuperuser() || user.equals(boss)); |
} |
// editor is allowed to change some additional properties |
public boolean partEditableBy(User user) |
{ |
return user.isSuperuser() || user.equals(boss) || user.equals(this); |
} |
public boolean mayChangeBoss(User user) |
{ |
return user.isSuperuser(); |
} |
public boolean mayChangeSuperuser(User user) |
{ |
return user.isSuperuser() && !user.equals(this); |
} |
public boolean mayViewAllLogins() |
{ |
return isSuperuser(); |
} |
protected static boolean allowedToCreate(UserManager manager, User editor) |
throws ModelException |
{ |
return editor.isSuperuser() |
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor); |
// FIXME: or allow any user to create "subusers"? |
} |
protected static User createLimitedCopy(User origin) |
{ |
User u = new User(); |
u.setLogin(origin.getLogin()); |
return u; |
} |
public String toString() |
{ |
return "User id=[" + getId() + "] login=[" + login + "]"; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailboxManager.java |
---|
0,0 → 1,445 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.Map; |
import java.util.Comparator; |
import ak.hostadmiral.util.ConfigInit; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
import ak.hostadmiral.core.model.store.MailboxStore; |
public class MailboxManager |
implements |
ConfigInit, |
UserBeforeDeleteListener, |
UserDeletingListener, |
SystemUserBeforeDeleteListener, |
SystemUserDeletingListener, |
InetDomainBeforeDeleteListener, |
InetDomainDeletingListener |
{ |
private MailboxStore store; |
private Class[] passwordStores; |
private Collection validateListeners = new ArrayList(); |
private Collection createdListeners = new ArrayList(); |
private Collection modifiedListeners = new ArrayList(); |
private Collection beforeDeleteListeners = new ArrayList(); |
private Collection deletingListeners = new ArrayList(); |
private Collection deletedListeners = new ArrayList(); |
public MailboxManager() |
throws ModelException |
{ |
UserManager.getInstance().addBeforeDeleteListener(this); |
UserManager.getInstance().addDeletingListener(this); |
SystemUserManager.getInstance().addBeforeDeleteListener(this); |
SystemUserManager.getInstance().addDeletingListener(this); |
InetDomainManager.getInstance().addBeforeDeleteListener(this); |
InetDomainManager.getInstance().addDeletingListener(this); |
} |
public Mailbox create(User editor) |
throws ModelException |
{ |
if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
Mailbox mailbox = new Mailbox(); |
setMailboxPasswordStores(mailbox); |
return mailbox; |
} |
public boolean allowedToCreate(User editor) |
throws ModelException |
{ |
return Mailbox.allowedToCreate(this, editor); |
} |
public Mailbox get(User editor, Long id) |
throws ModelException |
{ |
Mailbox mailbox = store.get(id); |
if(!mailbox.viewableBy(editor)) |
throw new ModelSecurityException(); |
return mailbox; |
} |
public boolean loginExists(User editor, Mailbox mailbox, String login) |
throws ModelException |
{ |
if(mailbox.getDomain() == null) |
throw new ModelException("Cannot check unique login for mailbox without domain"); |
return store.loginExists(mailbox, login); |
} |
public Mailbox findForLogin(User editor, String login) |
throws ModelException |
{ |
Mailbox mailbox = store.findForLogin(login); |
if(!mailbox.viewableBy(editor)) |
throw new ModelSecurityException(); |
return mailbox; |
} |
public void save(User editor, Mailbox mailbox) |
throws ModelException |
{ |
// security check |
if(!mailbox.editableBy(editor)) |
throw new ModelSecurityException(); |
//mailbox.setModUser(editor); // FIXME |
boolean isNew = mailbox.isNew(); |
Mailbox oldMailbox = mailbox.getOrigin(); |
if(oldMailbox == null) oldMailbox = mailbox; |
// validate |
for(Iterator i = validateListeners.iterator(); i.hasNext(); ) { |
MailboxValidateListener listener = (MailboxValidateListener)i.next(); |
listener.mailboxValidate(editor, mailbox, oldMailbox); |
} |
store.save(mailbox); |
// inform listeners |
if(isNew) { |
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) { |
MailboxCreatedListener listener = (MailboxCreatedListener)i.next(); |
listener.mailboxCreated(editor, mailbox); |
} |
} |
else { |
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) { |
MailboxModifiedListener listener = (MailboxModifiedListener)i.next(); |
listener.mailboxModified(editor, mailbox, oldMailbox); |
} |
} |
// reset backup |
mailbox.resetOrigin(); |
} |
public void addValidateListener(MailboxValidateListener listener) |
{ |
validateListeners.add(listener); |
} |
public void removeValidateListener(MailboxValidateListener listener) |
{ |
validateListeners.remove(listener); |
} |
public void addCreatedListener(MailboxCreatedListener listener) |
{ |
createdListeners.add(listener); |
} |
public void removeCreatedListener(MailboxCreatedListener listener) |
{ |
createdListeners.remove(listener); |
} |
public void addModifiedListener(MailboxModifiedListener listener) |
{ |
modifiedListeners.add(listener); |
} |
public void removeModifiedListener(MailboxModifiedListener listener) |
{ |
modifiedListeners.remove(listener); |
} |
public void addBeforeDeleteListener(MailboxBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.add(listener); |
} |
public void removeBeforeDeleteListener(MailboxBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.remove(listener); |
} |
public void addDeletingListener(MailboxDeletingListener listener) |
{ |
deletingListeners.add(listener); |
} |
public void removeDeletingListener(MailboxDeletingListener listener) |
{ |
deletingListeners.remove(listener); |
} |
public void addDeletedListener(MailboxDeletedListener listener) |
{ |
deletedListeners.add(listener); |
} |
public void removeDeletedListener(MailboxDeletedListener listener) |
{ |
deletedListeners.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 |
{ |
// check rights |
if(!mailbox.deleteableBy(editor)) |
throw new ModelSecurityException(); |
// inform deleting listeners |
for(Iterator i = deletingListeners.iterator(); i.hasNext(); ) { |
MailboxDeletingListener listener = (MailboxDeletingListener)i.next(); |
listener.mailboxDeleting(editor, mailbox); |
} |
// backup copy |
Mailbox oldMailbox = new Mailbox(mailbox); |
// delete it |
store.delete(mailbox); |
// inform deleted listeners |
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) { |
MailboxDeletedListener listener = (MailboxDeletedListener)i.next(); |
listener.mailboxDeleted(editor, oldMailbox); |
} |
} |
public Collection listMailboxes(User editor) |
throws ModelException |
{ |
return listMailboxes(null, 0, 0, null, editor); |
} |
public Collection listMailboxes(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User editor) |
throws ModelException |
{ |
if(editor.isSuperuser()) |
return store.listAllMailboxes(info, rowsPerPage, pageNumber, sortingKeys); |
else |
return store.listMailboxes(info, rowsPerPage, pageNumber, sortingKeys, editor); |
} |
public boolean areMailboxesAvailable(User editor) |
throws ModelException |
{ |
if(editor.isSuperuser() || InetDomainManager.getInstance().areInetDomainsAvailable(editor)) |
return true; |
else |
return store.countMailboxesAvailable(editor) > 0; |
} |
public Collection userBeforeDelete(User editor, User user, Collection known) |
throws ModelException |
{ |
Collection mailboxes = store.listOwnMailboxes(user); |
return iterateBeforeDelete(editor, mailboxes, known, CascadeDeleteElement.DELETE); |
} |
public void userDeleting(User editor, User user) |
throws ModelException |
{ |
Collection mailboxes = store.listOwnMailboxes(user); |
for(Iterator i = mailboxes.iterator(); i.hasNext(); ) { |
delete(editor, (Mailbox)i.next()); |
} |
} |
public Collection inetDomainBeforeDelete(User editor, InetDomain domain, Collection known) |
throws ModelException |
{ |
Collection mailboxes = store.listMailboxesForDomain(domain); |
return iterateBeforeDelete(editor, mailboxes, known, CascadeDeleteElement.DELETE); |
} |
public void inetDomainDeleting(User editor, InetDomain domain) |
throws ModelException |
{ |
Collection mailboxes = store.listMailboxesForDomain(domain); |
for(Iterator i = mailboxes.iterator(); i.hasNext(); ) { |
delete(editor, (Mailbox)i.next()); |
} |
} |
public Collection systemUserBeforeDelete(User editor, SystemUser user, Collection known) |
throws ModelException |
{ |
Collection mailboxes = store.listMailboxesForSystemUser(user); |
return iterateBeforeDelete(editor, mailboxes, known, CascadeDeleteElement.CHANGE); |
} |
public void systemUserDeleting(User editor, SystemUser user) |
throws ModelException |
{ |
Collection mailboxes = store.listMailboxesForSystemUser(user); |
for(Iterator i = mailboxes.iterator(); i.hasNext(); ) { |
Mailbox mailbox = (Mailbox)i.next(); |
mailbox.setSystemUser(null); |
save(editor, mailbox); |
} |
} |
private Collection iterateBeforeDelete(User editor, Collection mailboxes, Collection known, int action) |
throws ModelException |
{ |
Collection cascade = new ArrayList(); |
for(Iterator i = mailboxes.iterator(); i.hasNext(); ) { |
Mailbox mailbox = (Mailbox)i.next(); |
if(known.contains(mailbox)) continue; |
known.add(mailbox); |
if(mailbox.viewableBy(editor)) { |
if(action == CascadeDeleteElement.CHANGE && mailbox.editableBy(editor)) |
cascade.add(new CascadeDeleteElement(mailbox, CascadeDeleteElement.CHANGE, null)); |
else if(action == CascadeDeleteElement.DELETE && 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; |
} |
protected void setMailboxPasswordStores(Mailbox mailbox) |
throws ModelException |
{ |
if(passwordStores == null) return; |
try { |
for(int i = 0; i < passwordStores.length; i++) |
mailbox.addPasswordStore((PasswordStore)passwordStores[i].newInstance()); |
} |
catch(Exception ex) { |
throw new ModelException(ex); |
} |
} |
public static final Integer SORT_LOGIN = new Integer(1); |
public static final Integer SORT_DOMAIN = new Integer(2); |
public static final Comparator LOGIN_COMPARATOR = new LoginComparator(); |
public static final Comparator DOMAIN_COMPARATOR = new DomainComparator(); |
private static class LoginComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Mailbox) || !(o2 instanceof Mailbox)) |
throw new ClassCastException("not a Mailbox"); |
Mailbox a1 = (Mailbox)o1; |
Mailbox a2 = (Mailbox)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getLogin().compareToIgnoreCase(a2.getLogin()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof LoginComparator); |
} |
} |
private static class DomainComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Mailbox) || !(o2 instanceof Mailbox)) |
throw new ClassCastException("not a Mailbox"); |
Mailbox a1 = (Mailbox)o1; |
Mailbox a2 = (Mailbox)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getDomain().getName().compareToIgnoreCase(a2.getDomain().getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof DomainComparator); |
} |
} |
public void init(Map params) |
throws ModelException |
{ |
try { |
mailboxManager = this; |
Class c = Class.forName(((String[])params.get("store"))[0]); |
store = (MailboxStore)c.newInstance(); |
String[] passwordStoreNames = (String[])params.get("passwordStore"); |
if(passwordStoreNames != null) { |
passwordStores = new Class[passwordStoreNames.length]; |
for(int i = 0; i < passwordStoreNames.length; i++) { |
passwordStores[i] = Class.forName(passwordStoreNames[i]); |
} |
} |
} |
catch(Exception ex) { |
throw new ModelException(ex); |
} |
} |
private static MailboxManager mailboxManager = null; |
public static MailboxManager getInstance() |
{ |
return mailboxManager; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/hibernate/MailAliasDestinationHibernate.java |
---|
0,0 → 1,97 |
package ak.hostadmiral.core.model.store.hibernate; |
import java.util.Collection; |
import java.util.List; |
import java.util.Map; |
import java.util.HashMap; |
import org.hibernate.Hibernate; |
import org.hibernate.HibernateException; |
import org.hibernate.type.Type; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.util.hibernate.HibernateUtil; |
import ak.hostadmiral.core.model.MailAlias; |
import ak.hostadmiral.core.model.MailAliasDestination; |
import ak.hostadmiral.core.model.MailAliasDestinationManager; |
import ak.hostadmiral.core.model.store.MailAliasDestinationStore; |
public class MailAliasDestinationHibernate |
implements MailAliasDestinationStore |
{ |
public MailAliasDestinationHibernate() |
throws ModelStoreException |
{ |
register(); |
} |
public MailAliasDestination get(Long id) |
throws ModelStoreException |
{ |
try { |
return (MailAliasDestination)HibernateUtil.currentSession() |
.load(MailAliasDestination.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public void save(MailAliasDestination mailAliasDestination) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailAliasDestination); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public void delete(MailAliasDestination mailAliasDestination) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().delete(mailAliasDestination); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listMailAliasesDestination(MailAlias alias) |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select d from MailAliasDestination d left join fetch d.mailbox where d.alias=?", |
alias, Hibernate.entity(MailAlias.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
private static boolean registered = false; |
protected static void register() |
throws ModelStoreException |
{ |
synchronized(MailAliasDestinationHibernate.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/hostadmiral/core/model/MailAliasDestination.hbm.xml"); |
} |
catch(Exception ex) { |
throw new ModelStoreException(ex); |
} |
} |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/hibernate/UserHibernate.java |
---|
0,0 → 1,245 |
package ak.hostadmiral.core.model.store.hibernate; |
import java.util.Collection; |
import java.util.List; |
import java.util.Map; |
import java.util.HashMap; |
import org.hibernate.Hibernate; |
import org.hibernate.HibernateException; |
import org.hibernate.type.Type; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.util.hibernate.HibernateUtil; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserLogin; |
import ak.hostadmiral.core.model.UserManager; |
import ak.hostadmiral.core.model.store.UserStore; |
public class UserHibernate |
implements UserStore |
{ |
public UserHibernate() |
throws ModelStoreException |
{ |
initSortKeys(); |
register(); |
} |
public User get(Long id) |
throws ModelStoreException |
{ |
try { |
return (User)HibernateUtil.currentSession().load(User.class, id); |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
public boolean loginExists(User user, String login) |
throws ModelStoreException |
{ |
try { |
if(user.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from User u where login = ?", |
login, Hibernate.STRING) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from User u where login = ? and u != ?", |
new Object[] { login, user }, |
new Type[] { Hibernate.STRING, Hibernate.entity(User.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
public User findForLogin(String login) |
throws ModelStoreException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"select u from User u left join fetch u.boss where u.login = ? and u.enabled = ?", |
new Object[] { login, Boolean.TRUE }, |
new Type[] { Hibernate.STRING, Hibernate.BOOLEAN } ); |
if(list.size() == 0) |
return null; |
else |
return (User)list.get(0); |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
public void save(User user) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(user); |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
public void delete(User user) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().delete(user); |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
public Collection listAllUsers(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from User").next()).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableList(rowsPerPage, pageNumber, |
"select u from User u left join fetch u.boss" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), null, null); |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
public Collection listUsers(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from User u where u = ? or u.boss = ?", |
new Object[] { user, user}, |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } |
).next()).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableList(rowsPerPage, pageNumber, |
"select u from User u left join fetch u.boss where u = ? or u.boss = ?" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), |
new Object[] { user, user}, |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } ); |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
public void saveUserLogin(UserLogin userLogin) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(userLogin); |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
public Collection listFailedLogins() |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select l from UserLogin l left join fetch l.user where l.success = ?", |
Boolean.FALSE, Hibernate.BOOLEAN); |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
public Collection listSubusers(User user) |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select u from User u where u.boss = ?", |
user, Hibernate.entity(User.class) ); |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
public Collection listUserLogins(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from UserLogin where usr = ?", |
new Object[] { user }, |
new Type[] { Hibernate.entity(User.class) } |
).next()).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableList(rowsPerPage, pageNumber, |
"select l from UserLogin l where usr = ?" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeysLogins), |
new Object[] { user }, |
new Type[] { Hibernate.entity(User.class) } ); |
} |
catch(HibernateException ex) { |
throw new ModelStoreException(ex); |
} |
} |
protected static Map sortKeys = new HashMap(); |
protected static Map sortKeysLogins = new HashMap(); |
private static boolean sortKeysInitialized = false; |
private static void initSortKeys() |
{ |
if(!sortKeysInitialized) { |
sortKeys.put(UserManager.SORT_LOGIN, "u.login"); |
sortKeysLogins.put(UserManager.SORT_LOGINS_TIME, "l.loginTime"); |
sortKeysLogins.put(UserManager.SORT_LOGINS_TIME_REVERSE, "l.loginTime desc"); |
sortKeysInitialized = true; |
} |
} |
private static boolean registered = false; |
protected static void register() |
throws ModelStoreException |
{ |
synchronized(UserHibernate.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/hostadmiral/core/model/User.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"ak/hostadmiral/core/model/UserLogin.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"ak/hostadmiral/core/model/PasswordStoreAbstract.hbm.xml"); |
} |
catch(Exception ex) { |
throw new ModelStoreException(ex); |
} |
} |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/hibernate/SystemUserHibernate.java |
---|
0,0 → 1,251 |
package ak.hostadmiral.core.model.store.hibernate; |
import java.util.Collection; |
import java.util.List; |
import java.util.Map; |
import java.util.HashMap; |
import org.hibernate.Hibernate; |
import org.hibernate.HibernateException; |
import org.hibernate.type.Type; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.util.hibernate.HibernateUtil; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.SystemUser; |
import ak.hostadmiral.core.model.SystemUserManager; |
import ak.hostadmiral.core.model.store.SystemUserStore; |
public class SystemUserHibernate |
implements SystemUserStore |
{ |
public SystemUserHibernate() |
throws ModelStoreException |
{ |
initSortKeys(); |
register(); |
} |
public SystemUser get(Long id) |
throws ModelStoreException |
{ |
try { |
return (SystemUser)HibernateUtil.currentSession().load(SystemUser.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public boolean nameExists(SystemUser user, String name) |
throws ModelStoreException |
{ |
try { |
if(user.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from SystemUser u where name = ?", |
name, Hibernate.STRING) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from SystemUser u where name = ? and u != ?", |
new Object[] { name, user }, |
new Type[] { Hibernate.STRING, Hibernate.entity(SystemUser.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public boolean uidExists(SystemUser user, Integer uid) |
throws ModelStoreException |
{ |
try { |
if(user.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from SystemUser u where uid = ?", |
uid, Hibernate.INTEGER) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from SystemUser u where uid = ? and u != ?", |
new Object[] { uid, user }, |
new Type[] { Hibernate.INTEGER, Hibernate.entity(SystemUser.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public SystemUser findForName(String name) |
throws ModelStoreException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"select u from SystemUser u left join fetch u.owner where u.name=?", |
name, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (SystemUser)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public SystemUser findForUid(Integer uid) |
throws ModelStoreException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"select u from SystemUser u left join fetch u.owner where u.uid=?", |
uid, Hibernate.INTEGER); |
if(list.size() == 0) |
return null; |
else |
return (SystemUser)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public void save(SystemUser systemUser) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(systemUser); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public void delete(SystemUser systemUser) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().delete(systemUser); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listAllSystemUsers(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from SystemUser").next()).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableList(rowsPerPage, pageNumber, |
"select u from SystemUser u left join fetch u.owner" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), null, null); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listSystemUsers(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from SystemUser where owner is null or owner = ?", |
user, Hibernate.entity(User.class)) |
.next()).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableList(rowsPerPage, pageNumber, |
"select u from SystemUser u left join u.owner o" |
+ " where u.owner is null or u.owner = ?" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), |
new Object[] { user }, new Type[] { Hibernate.entity(User.class) } ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public int countSystemUsersAvailable(User user) |
throws ModelStoreException |
{ |
try { |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from SystemUser u left join u.owner o where o is null or o=?", |
user, Hibernate.entity(User.class)).next()).intValue(); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listOwnSystemUsers(User user) |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select u from SystemUser u where u.owner = ?", |
user, Hibernate.entity(User.class) ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
protected static Map sortKeys = new HashMap(); |
private static boolean sortKeysInitialized = false; |
private static void initSortKeys() |
{ |
if(!sortKeysInitialized) { |
sortKeys.put(SystemUserManager.SORT_UID, "u.uid"); |
sortKeys.put(SystemUserManager.SORT_NAME, "u.name"); |
sortKeysInitialized = true; |
} |
} |
private static boolean registered = false; |
protected static void register() |
throws ModelStoreException |
{ |
synchronized(SystemUserManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/hostadmiral/core/model/SystemUser.hbm.xml"); |
} |
catch(Exception ex) { |
throw new ModelStoreException(ex); |
} |
} |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/hibernate/InetDomainHibernate.java |
---|
0,0 → 1,208 |
package ak.hostadmiral.core.model.store.hibernate; |
import java.util.Collection; |
import java.util.List; |
import java.util.Map; |
import java.util.HashMap; |
import org.hibernate.Hibernate; |
import org.hibernate.HibernateException; |
import org.hibernate.type.Type; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.util.hibernate.HibernateUtil; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.InetDomain; |
import ak.hostadmiral.core.model.InetDomainManager; |
import ak.hostadmiral.core.model.store.InetDomainStore; |
public class InetDomainHibernate |
implements InetDomainStore |
{ |
public InetDomainHibernate() |
throws ModelStoreException |
{ |
initSortKeys(); |
register(); |
} |
public InetDomain get(Long id) |
throws ModelStoreException |
{ |
try { |
return (InetDomain)HibernateUtil.currentSession().load( |
InetDomain.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public boolean nameExists(InetDomain domain, String name) |
throws ModelStoreException |
{ |
try { |
if(domain.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from InetDomain d where name = ?", |
name, Hibernate.STRING) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from InetDomain d where name = ? and d != ?", |
new Object[] { name, domain }, |
new Type[] { Hibernate.STRING, Hibernate.entity(InetDomain.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public InetDomain findForName(String name) |
throws ModelStoreException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"select d from InetDomain d left join fetch d.owner where d.name=?", |
name, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (InetDomain)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public void save(InetDomain domain) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(domain); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public void delete(InetDomain domain) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().delete(domain); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listAllInetDomains(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from InetDomain").next()).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableList(rowsPerPage, pageNumber, |
"select d from InetDomain d left join fetch d.owner" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), null, null); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listInetDomains(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from InetDomain d where d.owner=?", |
user, Hibernate.entity(User.class)).next()).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableList(rowsPerPage, pageNumber, |
"select d from InetDomain d where d.owner=?" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), |
new Object[] { user }, new Type[] { Hibernate.entity(User.class) } ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public int countInetDomainsAvailable(User user) |
throws ModelStoreException |
{ |
try { |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from InetDomain where owner=?", |
user, Hibernate.entity(User.class)).next()).intValue(); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listOwnInetDomains(User user) |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select d from InetDomain d where d.owner = ?", |
user, Hibernate.entity(User.class) ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
protected static Map sortKeys = new HashMap(); |
private static boolean sortKeysInitialized = false; |
private static void initSortKeys() |
{ |
if(!sortKeysInitialized) { |
sortKeys.put(InetDomainManager.SORT_NAME, "d.name"); |
sortKeysInitialized = true; |
} |
} |
private static boolean registered = false; |
protected static void register() |
throws ModelStoreException |
{ |
synchronized(InetDomainHibernate.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/hostadmiral/core/model/InetDomain.hbm.xml"); |
} |
catch(Exception ex) { |
throw new ModelStoreException(ex); |
} |
} |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/hibernate/MailboxHibernate.java |
---|
0,0 → 1,289 |
package ak.hostadmiral.core.model.store.hibernate; |
import java.util.Collection; |
import java.util.List; |
import java.util.Map; |
import java.util.HashMap; |
import org.hibernate.Hibernate; |
import org.hibernate.HibernateException; |
import org.hibernate.type.Type; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.util.hibernate.HibernateUtil; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.SystemUser; |
import ak.hostadmiral.core.model.InetDomain; |
import ak.hostadmiral.core.model.Mailbox; |
import ak.hostadmiral.core.model.MailboxManager; |
import ak.hostadmiral.core.model.store.MailboxStore; |
public class MailboxHibernate |
implements MailboxStore |
{ |
public MailboxHibernate() |
throws ModelStoreException |
{ |
initSortKeys(); |
register(); |
} |
public Mailbox get(Long id) |
throws ModelStoreException |
{ |
try { |
return (Mailbox)HibernateUtil.currentSession().load(Mailbox.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public boolean loginExists(Mailbox mailbox, String login) |
throws ModelStoreException |
{ |
try { |
if(mailbox.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Mailbox where login = ? and domain = ?", |
new Object[] { login, mailbox.getDomain() }, |
new Type[] { Hibernate.STRING, Hibernate.entity(InetDomain.class) } ) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Mailbox b where login = ? and domain = ? and b != ?", |
new Object[] { login, mailbox.getDomain(), mailbox }, |
new Type[] { Hibernate.STRING, Hibernate.entity(InetDomain.class), |
Hibernate.entity(Mailbox.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Mailbox findForLogin(String login) |
throws ModelStoreException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"select mb from Mailbox mb left join fetch mb.domain as d" |
+ " left join fetch mb.owner left join fetch mb.systemUser where mb.login=?", |
login, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (Mailbox)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public void save(Mailbox mailbox) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailbox); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public void delete(Mailbox mailbox) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().delete(mailbox); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listAllMailboxes(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Mailbox").next()).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableListSql(rowsPerPage, pageNumber, |
"select {mb.*}, {d.*}, {o.*}, {su.*}" |
+ " from mailboxes as mb" |
+ " left join domains as d on mb.domain = d.id" |
+ " left join users as o on mb.owner = o.id" |
+ " left join systemusers as su on mb.systemUser = su.id" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeysSql), |
new String[] { "mb", "d", "o", "su" }, |
new Class[] { Mailbox.class, InetDomain.class, User.class, SystemUser.class }, |
null, |
null); |
} |
catch(HibernateException ex) |
{ |
ex.printStackTrace(); |
throw new ModelStoreException(ex); |
} |
} |
public Collection listMailboxes(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
List countlist = HibernateUtil.sqlQuery( |
"select count(*) from (" |
+ " select mb.id from mailboxes mb" |
+ " where mb.owner=?" |
+ " union" |
+ " select mb.id from mailboxes mb" |
+ " left join domains as d on mb.domain = d.id" |
+ " where d.owner=?" |
+ ") as count_table", |
new Object[] { user.getId(), user.getId() }); |
info.init(((Long)countlist.get(0)).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableListSql(rowsPerPage, pageNumber, |
"(select {mb.*}, {d.*}, {o.*}, {su.*}" |
+ " from mailboxes as mb" |
+ " left join domains as d on mb.domain = d.id" |
+ " left join users as o on mb.owner = o.id" |
+ " left join systemusers as su on mb.systemUser = su.id" |
+ " where mb.owner=?)" |
+ " union " |
+ "(select {mb.*}, {d.*}, {o.*}, {su.*}" |
+ " from mailboxes as mb" |
+ " left join domains as d on mb.domain = d.id" |
+ " left join users as o on mb.owner = o.id" |
+ " left join systemusers as su on mb.systemUser = su.id" |
+ " where d.owner=?)" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeysSql), |
new String[] { "mb", "d", "o", "su" }, |
new Class[] { Mailbox.class, InetDomain.class, User.class, SystemUser.class }, |
new Object[] { user, user }, |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) }); |
} |
catch(HibernateException ex) |
{ |
ex.printStackTrace(); |
throw new ModelStoreException(ex); |
} |
} |
public int countMailboxesAvailable(User user) |
throws ModelStoreException |
{ |
try { |
List countlist = HibernateUtil.sqlQuery( |
"select count(*) from (" |
+ " select mb.id from mailboxes mb" |
+ " where mb.owner=?" |
+ " union" |
+ " select mb.id from mailboxes mb" |
+ " left join domains as d on mb.domain = d.id" |
+ " where d.owner=?" |
+ ") as count_table", |
new Object[] { user.getId(), user.getId() }); |
return ((Long)countlist.get(0)).intValue(); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listOwnMailboxes(User user) |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select mb from Mailbox mb left join fetch mb.domain" |
+ " left join fetch mb.systemUser where mb.owner = ?", |
user, Hibernate.entity(User.class) ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listMailboxesForDomain(InetDomain domain) |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select mb from Mailbox mb left join fetch mb.owner" |
+ " left join fetch mb.systemUser where mb.domain = ?", |
domain, Hibernate.entity(InetDomain.class) ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listMailboxesForSystemUser(SystemUser user) |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select mb from Mailbox mb left join fetch mb.domain" |
+ " left join fetch mb.owner where mb.systemUser = ?", |
user, Hibernate.entity(SystemUser.class) ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
protected static Map sortKeysSql = new HashMap(); |
private static boolean sortKeysInitialized = false; |
private static void initSortKeys() |
{ |
if(!sortKeysInitialized) { |
sortKeysSql.put(MailboxManager.SORT_LOGIN, "login0_"); |
sortKeysSql.put(MailboxManager.SORT_DOMAIN, "name1_"); |
sortKeysInitialized = true; |
} |
} |
private static boolean registered = false; |
protected static void register() |
throws ModelStoreException |
{ |
synchronized(MailboxHibernate.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/hostadmiral/core/model/Mailbox.hbm.xml"); |
} |
catch(Exception ex) { |
throw new ModelStoreException(ex); |
} |
} |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/hibernate/MailAliasHibernate.java |
---|
0,0 → 1,276 |
package ak.hostadmiral.core.model.store.hibernate; |
import java.util.Collection; |
import java.util.List; |
import java.util.Map; |
import java.util.HashMap; |
import org.hibernate.Hibernate; |
import org.hibernate.HibernateException; |
import org.hibernate.type.Type; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.util.hibernate.HibernateUtil; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.InetDomain; |
import ak.hostadmiral.core.model.Mailbox; |
import ak.hostadmiral.core.model.MailAlias; |
import ak.hostadmiral.core.model.MailAliasManager; |
import ak.hostadmiral.core.model.store.MailAliasStore; |
public class MailAliasHibernate |
implements MailAliasStore |
{ |
public MailAliasHibernate() |
throws ModelStoreException |
{ |
initSortKeys(); |
register(); |
} |
public MailAlias get(Long id) |
throws ModelStoreException |
{ |
try { |
return (MailAlias)HibernateUtil.currentSession().load(MailAlias.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public boolean addressExists(MailAlias alias, String address) |
throws ModelStoreException |
{ |
try { |
if(alias.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from MailAlias where address = ? and domain = ?", |
new Object[] { address, alias.getDomain() }, |
new Type[] { Hibernate.STRING, Hibernate.entity(InetDomain.class) } ) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from MailAlias a where address = ? and domain = ? and a != ?", |
new Object[] { address, alias.getDomain(), alias }, |
new Type[] { Hibernate.STRING, Hibernate.entity(InetDomain.class), |
Hibernate.entity(MailAlias.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public MailAlias findForName(String name) |
throws ModelStoreException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"select a from MailAlias a left join fetch a.domain" |
+ " left join fetch a.owner where a.name=?", name, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (MailAlias)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public void save(MailAlias mailAlias) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailAlias); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public void delete(MailAlias mailAlias) |
throws ModelStoreException |
{ |
try { |
HibernateUtil.currentSession().delete(mailAlias); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listAllMailAliases(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
info.init(((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from MailAlias").next()).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableList(rowsPerPage, pageNumber, |
"select a from MailAlias a left join fetch a.domain as d" |
+ " left join fetch a.owner" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeys), null, null); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listMailAliases(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException |
{ |
try { |
if(info != null) { |
List countlist = HibernateUtil.sqlQuery( |
"select count(*) from (" |
+ " select a.id from mailaliases a" |
+ " where a.owner=?" |
+ " union" |
+ " select a.id from mailaliases a" |
+ " left join domains as d on a.domain = d.id" |
+ " where d.owner=?" |
+ ") as count_table", |
new Object[] { user.getId(), user.getId() }); |
info.init(((Long)countlist.get(0)).intValue(), |
pageNumber, rowsPerPage); |
} |
return HibernateUtil.pageableListSql(rowsPerPage, pageNumber, |
"(select {a.*}, {d.*}, {o.*}" |
+ " from mailaliases as a" |
+ " left join domains as d on a.domain = d.id" |
+ " left join users as o on a.owner = o.id" |
+ " where a.owner=?)" |
+ " union " |
+ "(select {a.*}, {d.*}, {o.*}" |
+ " from mailaliases as a" |
+ " left join domains as d on a.domain = d.id" |
+ " left join users as o on a.owner = o.id" |
+ " where d.owner=?)" |
+ HibernateUtil.formOrderClause(sortingKeys, sortKeysSql), |
new String[] { "a", "d", "o" }, |
new Class[] { MailAlias.class, InetDomain.class, User.class }, |
new Object[] { user, user }, |
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) }); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public int countMailAliasesAvailable(User user) |
throws ModelStoreException |
{ |
try { |
List countlist = HibernateUtil.sqlQuery( |
"select count(*) from (" |
+ " select a.id from mailaliases a" |
+ " where a.owner=?" |
+ " union" |
+ " select a.id from mailaliases a" |
+ " left join domains as d on a.domain = d.id" |
+ " where d.owner=?" |
+ ") as count_table", |
new Object[] { user.getId(), user.getId() }); |
return ((Long)countlist.get(0)).intValue(); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listOwnMailAliases(User user) |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select a from MailAlias a left join fetch a.domain where a.owner = ?", |
user, Hibernate.entity(User.class) ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listMailAliasesForDomain(InetDomain domain) |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select a from MailAlias a left join fetch a.owner where a.domain = ?", |
domain, Hibernate.entity(InetDomain.class) ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
public Collection listMailAliasesForMailbox(Mailbox mailbox) |
throws ModelStoreException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"select a from MailAlias a left join fetch a.owner" |
+ " left join fetch a.destinations as dest where dest.mailbox = ?", |
mailbox, Hibernate.entity(Mailbox.class) ); |
} |
catch(HibernateException ex) |
{ |
throw new ModelStoreException(ex); |
} |
} |
protected static Map sortKeys = new HashMap(); |
protected static Map sortKeysSql = new HashMap(); |
private static boolean sortKeysInitialized = false; |
private static void initSortKeys() |
{ |
if(!sortKeysInitialized) { |
sortKeys.put(MailAliasManager.SORT_ADDRESS, "a.address"); |
sortKeys.put(MailAliasManager.SORT_DOMAIN, "d.name"); |
sortKeysSql.put(MailAliasManager.SORT_ADDRESS, "address0_"); |
sortKeysSql.put(MailAliasManager.SORT_DOMAIN, "name1_"); |
sortKeysInitialized = true; |
} |
} |
private static boolean registered = false; |
protected static void register() |
throws ModelStoreException |
{ |
synchronized(MailAliasHibernate.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/hostadmiral/core/model/MailAlias.hbm.xml"); |
} |
catch(Exception ex) { |
throw new ModelStoreException(ex); |
} |
} |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/MailAliasStore.java |
---|
0,0 → 1,47 |
package ak.hostadmiral.core.model.store; |
import java.util.Collection; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.InetDomain; |
import ak.hostadmiral.core.model.Mailbox; |
import ak.hostadmiral.core.model.MailAlias; |
public interface MailAliasStore |
{ |
public MailAlias get(Long id) |
throws ModelStoreException; |
public boolean addressExists(MailAlias alias, String address) |
throws ModelStoreException; |
public MailAlias findForName(String name) |
throws ModelStoreException; |
public void save(MailAlias mailAlias) |
throws ModelStoreException; |
public void delete(MailAlias mailAlias) |
throws ModelStoreException; |
public Collection listAllMailAliases(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys) |
throws ModelStoreException; |
public Collection listMailAliases(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException; |
public int countMailAliasesAvailable(User user) |
throws ModelStoreException; |
public Collection listOwnMailAliases(User user) |
throws ModelStoreException; |
public Collection listMailAliasesForDomain(InetDomain domain) |
throws ModelStoreException; |
public Collection listMailAliasesForMailbox(Mailbox mailbox) |
throws ModelStoreException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/UserStore.java |
---|
0,0 → 1,46 |
package ak.hostadmiral.core.model.store; |
import java.util.Collection; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.UserLogin; |
public interface UserStore |
{ |
public User get(Long id) |
throws ModelStoreException; |
public boolean loginExists(User user, String login) |
throws ModelStoreException; |
public User findForLogin(String login) |
throws ModelStoreException; |
public void save(User user) |
throws ModelStoreException; |
public void delete(User user) |
throws ModelStoreException; |
public Collection listAllUsers(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys) |
throws ModelStoreException; |
public Collection listUsers(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException; |
public void saveUserLogin(UserLogin userLogin) |
throws ModelStoreException; |
public Collection listFailedLogins() |
throws ModelStoreException; |
public Collection listSubusers(User user) |
throws ModelStoreException; |
public Collection listUserLogins(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/SystemUserStore.java |
---|
0,0 → 1,45 |
package ak.hostadmiral.core.model.store; |
import java.util.Collection; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.SystemUser; |
public interface SystemUserStore |
{ |
public SystemUser get(Long id) |
throws ModelStoreException; |
public boolean nameExists(SystemUser user, String name) |
throws ModelStoreException; |
public boolean uidExists(SystemUser user, Integer uid) |
throws ModelStoreException; |
public SystemUser findForName(String name) |
throws ModelStoreException; |
public SystemUser findForUid(Integer uid) |
throws ModelStoreException; |
public void save(SystemUser systemUser) |
throws ModelStoreException; |
public void delete(SystemUser systemUser) |
throws ModelStoreException; |
public Collection listAllSystemUsers(CollectionInfo info, int rowsPerPage, |
int pageNumber, Integer[] sortingKeys) |
throws ModelStoreException; |
public Collection listSystemUsers(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException; |
public int countSystemUsersAvailable(User user) |
throws ModelStoreException; |
public Collection listOwnSystemUsers(User user) |
throws ModelStoreException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/InetDomainStore.java |
---|
0,0 → 1,39 |
package ak.hostadmiral.core.model.store; |
import java.util.Collection; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.InetDomain; |
public interface InetDomainStore |
{ |
public InetDomain get(Long id) |
throws ModelStoreException; |
public boolean nameExists(InetDomain domain, String name) |
throws ModelStoreException; |
public InetDomain findForName(String name) |
throws ModelStoreException; |
public void save(InetDomain domain) |
throws ModelStoreException; |
public void delete(InetDomain domain) |
throws ModelStoreException; |
public Collection listAllInetDomains(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys) |
throws ModelStoreException; |
public Collection listInetDomains(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException; |
public int countInetDomainsAvailable(User user) |
throws ModelStoreException; |
public Collection listOwnInetDomains(User user) |
throws ModelStoreException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/MailboxStore.java |
---|
0,0 → 1,47 |
package ak.hostadmiral.core.model.store; |
import java.util.Collection; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.model.SystemUser; |
import ak.hostadmiral.core.model.InetDomain; |
import ak.hostadmiral.core.model.Mailbox; |
public interface MailboxStore |
{ |
public Mailbox get(Long id) |
throws ModelStoreException; |
public boolean loginExists(Mailbox mailbox, String login) |
throws ModelStoreException; |
public Mailbox findForLogin(String login) |
throws ModelStoreException; |
public void save(Mailbox mailbox) |
throws ModelStoreException; |
public void delete(Mailbox mailbox) |
throws ModelStoreException; |
public Collection listAllMailboxes(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys) |
throws ModelStoreException; |
public Collection listMailboxes(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User user) |
throws ModelStoreException; |
public int countMailboxesAvailable(User user) |
throws ModelStoreException; |
public Collection listOwnMailboxes(User user) |
throws ModelStoreException; |
public Collection listMailboxesForDomain(InetDomain domain) |
throws ModelStoreException; |
public Collection listMailboxesForSystemUser(SystemUser user) |
throws ModelStoreException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/store/MailAliasDestinationStore.java |
---|
0,0 → 1,23 |
package ak.hostadmiral.core.model.store; |
import java.util.Collection; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelStoreException; |
import ak.hostadmiral.core.model.InetDomain; |
import ak.hostadmiral.core.model.MailAlias; |
import ak.hostadmiral.core.model.MailAliasDestination; |
public interface MailAliasDestinationStore |
{ |
public MailAliasDestination get(Long id) |
throws ModelStoreException; |
public void save(MailAliasDestination mailAliasDestination) |
throws ModelStoreException; |
public void delete(MailAliasDestination mailAliasDestination) |
throws ModelStoreException; |
public Collection listMailAliasesDestination(MailAlias alias) |
throws ModelStoreException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/SystemUserManager.java |
---|
0,0 → 1,378 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.Map; |
import java.util.Comparator; |
import ak.hostadmiral.util.ConfigInit; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
import ak.hostadmiral.core.model.store.SystemUserStore; |
public class SystemUserManager |
implements |
ConfigInit, |
UserBeforeDeleteListener, |
UserDeletingListener |
{ |
private SystemUserStore store; |
private Collection validateListeners = new ArrayList(); |
private Collection createdListeners = new ArrayList(); |
private Collection modifiedListeners = new ArrayList(); |
private Collection beforeDeleteListeners = new ArrayList(); |
private Collection deletingListeners = new ArrayList(); |
private Collection deletedListeners = new ArrayList(); |
public SystemUserManager() |
throws ModelException |
{ |
UserManager.getInstance().addBeforeDeleteListener(this); |
UserManager.getInstance().addDeletingListener(this); |
} |
public SystemUser create(User editor) |
throws ModelException |
{ |
if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
return new SystemUser(); |
} |
public boolean allowedToCreate(User editor) |
throws ModelException |
{ |
return SystemUser.allowedToCreate(this, editor); |
} |
public SystemUser get(User editor, Long id) |
throws ModelException |
{ |
SystemUser user = store.get(id); |
if(!user.viewableBy(editor)) |
throw new ModelSecurityException(); |
return user; |
} |
public boolean nameExists(User editor, SystemUser user, String name) |
throws ModelException |
{ |
return store.nameExists(user, name); |
} |
public boolean uidExists(User editor, SystemUser user, Integer uid) |
throws ModelException |
{ |
return store.uidExists(user, uid); |
} |
public SystemUser findForName(User editor, String name) |
throws ModelException |
{ |
SystemUser user = store.findForName(name); |
if(user != null && !user.viewableBy(editor)) |
throw new ModelSecurityException(); |
return user; |
} |
public SystemUser findForUid(User editor, Integer uid) |
throws ModelException |
{ |
SystemUser user = store.findForUid(uid); |
if(user != null && !user.viewableBy(editor)) |
throw new ModelSecurityException(); |
return user; |
} |
public void save(User editor, SystemUser systemUser) |
throws ModelException |
{ |
// security check |
if(!systemUser.editableBy(editor)) |
throw new ModelSecurityException(); |
//systemUser.setModUser(editor); // FIXME |
boolean isNew = systemUser.isNew(); |
SystemUser oldSystemUser = systemUser.getOrigin(); |
if(oldSystemUser == null) oldSystemUser = systemUser; |
// validate |
for(Iterator i = validateListeners.iterator(); i.hasNext(); ) { |
SystemUserValidateListener listener = (SystemUserValidateListener)i.next(); |
listener.systemUserValidate(editor, systemUser, oldSystemUser); |
} |
store.save(systemUser); |
// inform listeners |
if(isNew) { |
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) { |
SystemUserCreatedListener listener = (SystemUserCreatedListener)i.next(); |
listener.systemUserCreated(editor, systemUser); |
} |
} |
else { |
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) { |
SystemUserModifiedListener listener = (SystemUserModifiedListener)i.next(); |
listener.systemUserModified(editor, systemUser, oldSystemUser); |
} |
} |
// reset backup |
systemUser.resetOrigin(); |
} |
public void addValidateListener(SystemUserValidateListener listener) |
{ |
validateListeners.add(listener); |
} |
public void removeValidateListener(SystemUserValidateListener listener) |
{ |
validateListeners.remove(listener); |
} |
public void addCreatedListener(SystemUserCreatedListener listener) |
{ |
createdListeners.add(listener); |
} |
public void removeCreatedListener(SystemUserCreatedListener listener) |
{ |
createdListeners.remove(listener); |
} |
public void addModifiedListener(SystemUserModifiedListener listener) |
{ |
modifiedListeners.add(listener); |
} |
public void removeModifiedListener(SystemUserModifiedListener listener) |
{ |
modifiedListeners.remove(listener); |
} |
public void addBeforeDeleteListener(SystemUserBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.add(listener); |
} |
public void removeBeforeDeleteListener(SystemUserBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.remove(listener); |
} |
public void addDeletingListener(SystemUserDeletingListener listener) |
{ |
deletingListeners.add(listener); |
} |
public void removeDeletingListener(SystemUserDeletingListener listener) |
{ |
deletingListeners.remove(listener); |
} |
public void addDeletedListener(SystemUserDeletedListener listener) |
{ |
deletedListeners.add(listener); |
} |
public void removeDeletedListener(SystemUserDeletedListener listener) |
{ |
deletedListeners.remove(listener); |
} |
public Collection beforeDelete(User editor, SystemUser user, Collection known) |
throws ModelException |
{ |
Collection cascade = new ArrayList(); |
for(Iterator i = beforeDeleteListeners.iterator(); i.hasNext(); ) { |
SystemUserBeforeDeleteListener listener = (SystemUserBeforeDeleteListener)i.next(); |
Collection subcascade = listener.systemUserBeforeDelete(editor, user, known); |
if(subcascade != null) |
cascade.addAll(subcascade); |
} |
return cascade; |
} |
public void delete(User editor, SystemUser systemUser) |
throws ModelException |
{ |
// check rights |
if(!systemUser.deleteableBy(editor)) |
throw new ModelSecurityException(); |
// inform deleting listeners |
for(Iterator i = deletingListeners.iterator(); i.hasNext(); ) { |
SystemUserDeletingListener listener = (SystemUserDeletingListener)i.next(); |
listener.systemUserDeleting(editor, systemUser); |
} |
// backup copy |
SystemUser oldSystemUser = new SystemUser(systemUser); |
// delete it |
store.delete(systemUser); |
// inform deleted listeners |
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) { |
SystemUserDeletedListener listener = (SystemUserDeletedListener)i.next(); |
listener.systemUserDeleted(editor, oldSystemUser); |
} |
} |
public Collection listSystemUsers(User editor) |
throws ModelException |
{ |
return listSystemUsers(null, 0, 0, null, editor); |
} |
public Collection listSystemUsers(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User editor) |
throws ModelException |
{ |
if(editor.isSuperuser()) |
return store.listAllSystemUsers(info, rowsPerPage, pageNumber, sortingKeys); |
else |
return store.listSystemUsers(info, rowsPerPage, pageNumber, sortingKeys, editor); |
} |
public boolean areSystemUsersAvailable(User editor) |
throws ModelException |
{ |
if(editor.isSuperuser()) |
return true; |
else |
return store.countSystemUsersAvailable(editor) > 0; |
} |
public Collection userBeforeDelete(User editor, User user, Collection known) |
throws ModelException |
{ |
Collection systemUsers = store.listOwnSystemUsers(user); |
Collection cascade = new ArrayList(); |
for(Iterator i = systemUsers.iterator(); i.hasNext(); ) { |
SystemUser u = (SystemUser)i.next(); |
if(known.contains(u)) continue; |
known.add(u); |
if(u.viewableBy(editor)) { |
if(u.deleteableBy(editor)) |
cascade.add(new CascadeDeleteElement(u, CascadeDeleteElement.DELETE, |
this.beforeDelete(editor, u, known))); |
else |
cascade.add(new CascadeDeleteElement(u, CascadeDeleteElement.FORBIDDEN, null)); |
} |
else { |
cascade.add(new CascadeDeleteElement(SystemUser.createLimitedCopy(u), |
CascadeDeleteElement.FORBIDDEN, null)); |
} |
} |
return cascade; |
} |
public void userDeleting(User editor, User user) |
throws ModelException |
{ |
Collection systemUsers = store.listOwnSystemUsers(user); |
for(Iterator i = systemUsers.iterator(); i.hasNext(); ) { |
delete(editor, (SystemUser)i.next()); |
} |
} |
public static final Integer SORT_UID = new Integer(1); |
public static final Integer SORT_NAME = new Integer(2); |
public static final Comparator UID_COMPARATOR = new UidComparator(); |
public static final Comparator NAME_COMPARATOR = new NameComparator(); |
private static class UidComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof SystemUser) || !(o2 instanceof SystemUser)) |
throw new ClassCastException("not a SystemUser"); |
SystemUser a1 = (SystemUser)o1; |
SystemUser a2 = (SystemUser)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getUid().compareTo(a2.getUid()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof UidComparator); |
} |
} |
private static class NameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof SystemUser) || !(o2 instanceof SystemUser)) |
throw new ClassCastException("not a SystemUser"); |
SystemUser a1 = (SystemUser)o1; |
SystemUser a2 = (SystemUser)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getName().compareToIgnoreCase(a2.getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NameComparator); |
} |
} |
public void init(Map params) |
throws ModelException |
{ |
try { |
systemUserManager = this; |
Class c = Class.forName(((String[])params.get("store"))[0]); |
store = (SystemUserStore)c.newInstance(); |
} |
catch(Exception ex) { |
throw new ModelException(ex); |
} |
} |
private static SystemUserManager systemUserManager = null; |
public static SystemUserManager getInstance() |
{ |
return systemUserManager; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailAliasManager.java |
---|
0,0 → 1,394 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.Map; |
import java.util.Comparator; |
import ak.hostadmiral.util.ConfigInit; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
import ak.hostadmiral.core.model.store.MailAliasStore; |
public class MailAliasManager |
implements |
ConfigInit, |
UserBeforeDeleteListener, |
UserDeletingListener, |
InetDomainBeforeDeleteListener, |
InetDomainDeletingListener, |
MailboxDeletingListener |
{ |
private MailAliasStore store; |
private Collection validateListeners = new ArrayList(); |
private Collection createdListeners = new ArrayList(); |
private Collection modifiedListeners = new ArrayList(); |
private Collection beforeDeleteListeners = new ArrayList(); |
private Collection deletingListeners = new ArrayList(); |
private Collection deletedListeners = new ArrayList(); |
public MailAliasManager() |
throws ModelException |
{ |
UserManager.getInstance().addBeforeDeleteListener(this); |
UserManager.getInstance().addDeletingListener(this); |
InetDomainManager.getInstance().addBeforeDeleteListener(this); |
InetDomainManager.getInstance().addDeletingListener(this); |
// FIXME register for mailbox before delete event? or silently delete destinations? |
MailboxManager.getInstance().addDeletingListener(this); |
} |
public MailAlias create(User editor) |
throws ModelException |
{ |
if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
MailAlias alias = new MailAlias(); |
alias.setDestinations(new ArrayList()); |
return alias; |
} |
public boolean allowedToCreate(User editor) |
throws ModelException |
{ |
return MailAlias.allowedToCreate(this, editor); |
} |
public MailAlias get(User editor, Long id) |
throws ModelException |
{ |
MailAlias alias = store.get(id); |
if(!alias.viewableBy(editor)) |
throw new ModelSecurityException(); |
return alias; |
} |
public boolean addressExists(User editor, MailAlias alias, String address) |
throws ModelException |
{ |
if(alias.getDomain() == null) |
throw new ModelException("Cannot check unique address for mail alias without domain"); |
return store.addressExists(alias, address); |
} |
public MailAlias findForName(User editor, String name) |
throws ModelException |
{ |
MailAlias alias = store.findForName(name); |
if(!alias.viewableBy(editor)) |
throw new ModelSecurityException(); |
return alias; |
} |
public void save(User editor, MailAlias mailAlias) |
throws ModelException |
{ |
// FIXME: how the onwer can save new destinations if he has no right to save the alias? |
// security check |
if(!mailAlias.editableBy(editor)) |
throw new ModelSecurityException(); |
//mailAlias.setModUser(editor); // FIXME |
boolean isNew = mailAlias.isNew(); |
MailAlias oldMailAlias = mailAlias.getOrigin(); |
if(oldMailAlias == null) oldMailAlias = mailAlias; |
// validate |
for(Iterator i = validateListeners.iterator(); i.hasNext(); ) { |
MailAliasValidateListener listener = (MailAliasValidateListener)i.next(); |
listener.mailAliasValidate(editor, mailAlias, oldMailAlias); |
} |
store.save(mailAlias); |
// inform listeners |
if(isNew) { |
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) { |
MailAliasCreatedListener listener = (MailAliasCreatedListener)i.next(); |
listener.mailAliasCreated(editor, mailAlias); |
} |
} |
else { |
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) { |
MailAliasModifiedListener listener = (MailAliasModifiedListener)i.next(); |
listener.mailAliasModified(editor, mailAlias, oldMailAlias); |
} |
} |
// reset backup |
mailAlias.resetOrigin(); |
} |
public void addValidateListener(MailAliasValidateListener listener) |
{ |
validateListeners.add(listener); |
} |
public void removeValidateListener(MailAliasValidateListener listener) |
{ |
validateListeners.remove(listener); |
} |
public void addCreatedListener(MailAliasCreatedListener listener) |
{ |
createdListeners.add(listener); |
} |
public void removeCreatedListener(MailAliasCreatedListener listener) |
{ |
createdListeners.remove(listener); |
} |
public void addModifiedListener(MailAliasModifiedListener listener) |
{ |
modifiedListeners.add(listener); |
} |
public void removeModifiedListener(MailAliasModifiedListener listener) |
{ |
modifiedListeners.remove(listener); |
} |
public void addBeforeDeleteListener(MailAliasBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.add(listener); |
} |
public void removeBeforeDeleteListener(MailAliasBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.remove(listener); |
} |
public void addDeletingListener(MailAliasDeletingListener listener) |
{ |
deletingListeners.add(listener); |
} |
public void removeDeletingListener(MailAliasDeletingListener listener) |
{ |
deletingListeners.remove(listener); |
} |
public void addDeletedListener(MailAliasDeletedListener listener) |
{ |
deletedListeners.add(listener); |
} |
public void removeDeletedListener(MailAliasDeletedListener listener) |
{ |
deletedListeners.remove(listener); |
} |
public Collection beforeDelete(User editor, MailAlias mailAlias, Collection known) |
throws ModelException |
{ |
Collection cascade = new ArrayList(); |
for(Iterator i = beforeDeleteListeners.iterator(); i.hasNext(); ) { |
MailAliasBeforeDeleteListener listener = (MailAliasBeforeDeleteListener)i.next(); |
Collection subcascade = listener.mailAliasBeforeDelete(editor, mailAlias, known); |
if(subcascade != null) |
cascade.addAll(subcascade); |
} |
return cascade; |
} |
public void delete(User editor, MailAlias mailAlias) |
throws ModelException |
{ |
// check rights |
if(!mailAlias.deleteableBy(editor)) |
throw new ModelSecurityException(); |
// inform deleting listeners |
for(Iterator i = deletingListeners.iterator(); i.hasNext(); ) { |
MailAliasDeletingListener listener = (MailAliasDeletingListener)i.next(); |
listener.mailAliasDeleting(editor, mailAlias); |
} |
// backup copy |
MailAlias oldMailAlias = new MailAlias(mailAlias); |
// delete it |
store.delete(mailAlias); |
// inform deleted listeners |
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) { |
MailAliasDeletedListener listener = (MailAliasDeletedListener)i.next(); |
listener.mailAliasDeleted(editor, oldMailAlias); |
} |
} |
public Collection listMailAliases(User editor) |
throws ModelException |
{ |
return listMailAliases(null, 0, 0, null, editor); |
} |
public Collection listMailAliases(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User editor) |
throws ModelException |
{ |
if(editor.isSuperuser()) |
return store.listAllMailAliases(info, rowsPerPage, pageNumber, sortingKeys); |
else |
return store.listMailAliases(info, rowsPerPage, pageNumber, sortingKeys, editor); |
} |
public boolean areMailAliasesAvailable(User editor) |
throws ModelException |
{ |
if(editor.isSuperuser() || InetDomainManager.getInstance().areInetDomainsAvailable(editor)) |
return true; |
else |
return store.countMailAliasesAvailable(editor) > 0; |
} |
public Collection userBeforeDelete(User editor, User user, Collection known) |
throws ModelException |
{ |
Collection mailAliases = store.listOwnMailAliases(user); |
return iterateBeforeDelete(editor, mailAliases, known); |
} |
public void userDeleting(User editor, User user) |
throws ModelException |
{ |
Collection mailAliases = store.listOwnMailAliases(user); |
for(Iterator i = mailAliases.iterator(); i.hasNext(); ) { |
delete(editor, (MailAlias)i.next()); |
} |
} |
public Collection inetDomainBeforeDelete(User editor, InetDomain domain, Collection known) |
throws ModelException |
{ |
Collection mailAliases = store.listMailAliasesForDomain(domain); |
return iterateBeforeDelete(editor, mailAliases, known); |
} |
public void inetDomainDeleting(User editor, InetDomain domain) |
throws ModelException |
{ |
Collection mailAliases = store.listMailAliasesForDomain(domain); |
for(Iterator i = mailAliases.iterator(); i.hasNext(); ) { |
delete(editor, (MailAlias)i.next()); |
} |
} |
private Collection iterateBeforeDelete(User editor, Collection mailAliases, Collection known) |
throws ModelException |
{ |
Collection cascade = new ArrayList(); |
for(Iterator i = mailAliases.iterator(); i.hasNext(); ) { |
MailAlias mailAlias = (MailAlias)i.next(); |
if(known.contains(mailAlias)) continue; |
known.add(mailAlias); |
if(mailAlias.viewableBy(editor)) { |
if(mailAlias.deleteableBy(editor)) |
cascade.add(new CascadeDeleteElement(mailAlias, CascadeDeleteElement.DELETE, |
this.beforeDelete(editor, mailAlias, known))); |
else |
cascade.add(new CascadeDeleteElement(mailAlias, CascadeDeleteElement.FORBIDDEN, |
null)); |
} |
else { |
cascade.add(new CascadeDeleteElement(MailAlias.createLimitedCopy(mailAlias), |
CascadeDeleteElement.FORBIDDEN, null)); |
} |
} |
return cascade; |
} |
public void mailboxDeleting(User editor, Mailbox mailbox) |
throws ModelException |
{ |
Collection mailAliases = store.listMailAliasesForMailbox(mailbox); |
for(Iterator i = mailAliases.iterator(); i.hasNext(); ) { |
MailAlias mailAlias = (MailAlias)i.next(); |
System.out.println("mailboxDeleting: " + mailAlias); |
// FIXME is it possible that editor has right to delete mailbox |
// but has no right to change alias? |
if(mailAlias.mayChangeDestinations(editor)) { |
for(Iterator j = mailAlias.getDestinations(editor).iterator(); j.hasNext(); ) { |
MailAliasDestination dest = (MailAliasDestination)j.next(); |
if(mailbox == dest.getMailbox()) j.remove(); |
} |
save(editor, mailAlias); |
} |
} |
} |
public static final Integer SORT_ADDRESS = new Integer(1); |
public static final Integer SORT_DOMAIN = new Integer(2); |
public static final Comparator ADDRESS_COMPARATOR = new AddressComparator(); |
private static class AddressComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof MailAlias) || !(o2 instanceof MailAlias)) |
throw new ClassCastException("not a MailAlias"); |
MailAlias a1 = (MailAlias)o1; |
MailAlias a2 = (MailAlias)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getAddress().compareToIgnoreCase(a2.getAddress()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof AddressComparator); |
} |
} |
public void init(Map params) |
throws ModelException |
{ |
try { |
mailAliasManager = this; |
Class c = Class.forName(((String[])params.get("store"))[0]); |
store = (MailAliasStore)c.newInstance(); |
} |
catch(Exception ex) { |
throw new ModelException(ex); |
} |
} |
private static MailAliasManager mailAliasManager = null; |
public static MailAliasManager getInstance() |
{ |
return mailAliasManager; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailAliasDestination.java |
---|
0,0 → 1,141 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="mailaliasdests" |
*/ |
public class MailAliasDestination |
extends GeneralModelObject |
{ |
private MailAlias alias; |
private Mailbox mailbox; |
private String email; |
protected MailAliasDestination() |
{ |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public MailAlias getAlias() |
{ |
return alias; |
} |
protected void setAlias(MailAlias alias) |
{ |
this.alias = alias; |
} |
public void setAlias(User editor, MailAlias alias) |
throws ModelException |
{ |
if(this.alias != null && !editableBy(editor)) |
throw new ModelSecurityException(); |
this.alias = alias; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Mailbox getMailbox() |
{ |
return mailbox; |
} |
protected void setMailbox(Mailbox mailbox) |
{ |
this.mailbox = mailbox; |
} |
public void setMailbox(User editor, Mailbox mailbox) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
this.mailbox = mailbox; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getEmail() |
{ |
return email; |
} |
protected void setEmail(String email) |
{ |
this.email = email; |
} |
public void setEmail(User editor, String email) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
this.email = email; |
} |
public String getTypeKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.TYPE_MAIL_ALIAS_DESTINATION; |
} |
public String getIdentKey() |
{ |
if(getMailbox() == null) |
return ak.hostadmiral.core.resources.CoreResources.IDENT_MAIL_ALIAS_DESTINATION_EXTERNAL; |
else |
return ak.hostadmiral.core.resources.CoreResources.IDENT_MAIL_ALIAS_DESTINATION_INTERNAL; |
} |
public Object[] getIdentParams() |
{ |
if(getMailbox() == null) |
return new Object[] { getEmail() }; |
else |
return new Object[] { getMailbox().getLogin(), getMailbox().getDomain().getName() }; |
} |
public boolean viewableBy(User user) |
{ |
return alias.viewableBy(user); |
} |
public boolean editableBy(User user) |
{ |
return alias.mayChangeDestinations(user); |
} |
public boolean deleteableBy(User user) |
{ |
return alias.mayChangeDestinations(user); |
} |
protected static boolean allowedToCreate(MailAliasDestinationManager manager, User editor) |
throws ModelException |
{ |
return true; |
} |
public String toString() |
{ |
return "MailAliasDestination id=[" + getId() + "] alias=[" |
+ (alias == null ? "_none_" : alias.getAddress() + "@" |
+ (alias.getDomain() == null ? "_none_" : alias.getDomain().getName())) |
+ "] mailbox=[" + (mailbox == null ? "_none_" : mailbox.getLogin() + "@" |
+ (mailbox.getDomain() == null ? "_none_" : mailbox.getDomain().getName())) |
+ "] email=[" + (email == null ? "_none_" : email) + "]"; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/PasswordStore.java |
---|
0,0 → 1,44 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
/** |
* A password store must implement java.lang.Cloneable interface. |
*/ |
public interface PasswordStore |
{ |
/** |
* returns digest name, e.g. "MD5" |
*/ |
public String getDigest(); |
/** |
* returns true if the store is able to return the original password |
*/ |
public boolean getReversable(); |
/** |
* to store to persistent store |
*/ |
public String getPassword(); |
/** |
* to store from persistent store |
*/ |
public void setPassword(String password); |
/** |
* to set by user |
*/ |
public void setNewPassword(String password) |
throws ModelException; |
public boolean checkPassword(String password) |
throws ModelException; |
/** |
* return the password in plain text if possible |
*/ |
public String getOriginalPassword() |
throws UnsupportedOperationException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/PasswordStoreAbstract.java |
---|
0,0 → 1,126 |
package ak.hostadmiral.core.model; |
import java.util.Date; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.DigestMd5; |
/** |
* |
* @hibernate.class table="passwords" |
* @hibernate.discriminator column="digest" type="string" |
*/ |
public abstract class PasswordStoreAbstract |
implements PasswordStore, Cloneable |
{ |
private Long id; |
private Date modStamp; |
private User modUser; |
protected String digest; |
protected String password; |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
protected void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
protected void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
/** |
* |
* @hibernate.many-to-one column="mod_user" |
*/ |
public User getModUser() |
{ |
return modUser; |
} |
protected void setModUser(User modUser) |
{ |
this.modUser = modUser; |
} |
/** |
* returns digest name, e.g. "MD5" |
*/ |
public String getDigest() |
{ |
return digest; |
} |
/** |
* to store to persistent store |
* |
* @hibernate.property |
*/ |
public String getPassword() |
{ |
return password; |
} |
/** |
* to store from persistent store |
*/ |
public void setPassword(String password) |
{ |
this.password = password; |
} |
/** |
* to set by user |
*/ |
public void setNewPassword(String password) |
throws ModelException |
{ |
this.password = encode(password); |
} |
public boolean checkPassword(String password) |
throws ModelException |
{ |
return this.password.equals(encode(password)); |
} |
protected abstract String encode(String password) |
throws ModelException; |
public Object clone() |
throws CloneNotSupportedException |
{ |
PasswordStoreAbstract theClone = (PasswordStoreAbstract)super.clone(); |
theClone.password = password; |
return theClone; |
} |
public boolean getReversable() |
{ |
return false; |
} |
public String getOriginalPassword() |
throws UnsupportedOperationException |
{ |
throw new UnsupportedOperationException("Not able to restore original password"); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/PasswordStorePlain.java |
---|
0,0 → 1,34 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.DigestMd5; |
/** |
* |
* @hibernate.subclass discriminator-value="Plain" |
*/ |
public class PasswordStorePlain |
extends PasswordStoreAbstract |
{ |
public PasswordStorePlain() |
{ |
digest = "Plain"; |
} |
protected String encode(String password) |
throws ModelException |
{ |
return password; |
} |
public boolean getReversable() |
{ |
return true; |
} |
public String getOriginalPassword() |
throws UnsupportedOperationException |
{ |
return password; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/UserManager.java |
---|
0,0 → 1,449 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.Map; |
import java.util.WeakHashMap; |
import java.util.Comparator; |
import java.util.Date; |
import ak.hostadmiral.util.ConfigInit; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
import ak.hostadmiral.core.model.store.UserStore; |
public class UserManager |
implements |
ConfigInit, |
UserBeforeDeleteListener, |
UserDeletingListener |
{ |
private UserStore store; |
private Class[] passwordStores; |
private Collection validateListeners = new ArrayList(); |
private Collection createdListeners = new ArrayList(); |
private Collection modifiedListeners = new ArrayList(); |
private Collection beforeDeleteListeners = new ArrayList(); |
private Collection deletingListeners = new ArrayList(); |
private Collection deletedListeners = new ArrayList(); |
// FIMXE: check that it works |
private Map loggedinUsers = new WeakHashMap(); |
public UserManager() |
throws ModelException |
{ |
addBeforeDeleteListener(this); |
addDeletingListener(this); |
} |
public User create(User editor) |
throws ModelException |
{ |
if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
User user = new User(); |
if(!user.mayChangeBoss(editor)) // ordinal user can create only own "subusers" |
user.setBoss(editor); |
setUserPasswordStores(user); |
return user; |
} |
public boolean allowedToCreate(User editor) |
throws ModelException |
{ |
return User.allowedToCreate(this, editor); |
} |
public User get(User editor, Long id) |
throws ModelException |
{ |
User user = store.get(id); |
if(!user.viewableBy(editor)) |
throw new ModelSecurityException(); |
return user; |
} |
public User get(Long id) |
throws ModelException |
{ |
return store.get(id); |
} |
public boolean loginExists(User editor, User user, String login) |
throws ModelException |
{ |
return store.loginExists(user, login); |
} |
public User findForLogin(User editor, String login) |
throws ModelException |
{ |
User user = store.findForLogin(login); |
if(user != null && !user.viewableBy(editor)) |
throw new ModelSecurityException(); |
return user; |
} |
public void save(User editor, User user) |
throws ModelException |
{ |
// security check |
if(!user.editableBy(editor) && !user.partEditableBy(editor) |
&& !user.mayChangeSuperuser(editor)) |
{ |
throw new ModelSecurityException(); |
} |
//user.setModUser(editor); // FIXME: disabled because hb throws exception |
// if user edits itself |
boolean isNew = user.isNew(); |
User oldUser = user.getOrigin(); |
if(oldUser == null) oldUser = user; |
// validate |
for(Iterator i = validateListeners.iterator(); i.hasNext(); ) { |
UserValidateListener listener = (UserValidateListener)i.next(); |
listener.userValidate(editor, user, oldUser); |
} |
store.save(user); |
// update user if he is logged in |
for(Iterator i = loggedinUsers.keySet().iterator(); i.hasNext(); ) { |
User u = (User)i.next(); |
if(u.equals(user)) |
u.update(user); |
} |
// inform listeners |
if(isNew) { |
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) { |
UserCreatedListener listener = (UserCreatedListener)i.next(); |
listener.userCreated(editor, user); |
} |
} |
else { |
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) { |
UserModifiedListener listener = (UserModifiedListener)i.next(); |
listener.userModified(editor, user, oldUser); |
} |
} |
// reset backup |
user.resetOrigin(); |
} |
public void addValidateListener(UserValidateListener listener) |
{ |
validateListeners.add(listener); |
} |
public void removeValidateListener(UserValidateListener listener) |
{ |
validateListeners.remove(listener); |
} |
public void addCreatedListener(UserCreatedListener listener) |
{ |
createdListeners.add(listener); |
} |
public void removeCreatedListener(UserCreatedListener listener) |
{ |
createdListeners.remove(listener); |
} |
public void addModifiedListener(UserModifiedListener listener) |
{ |
modifiedListeners.add(listener); |
} |
public void removeModifiedListener(UserModifiedListener listener) |
{ |
modifiedListeners.remove(listener); |
} |
public void addBeforeDeleteListener(UserBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.add(listener); |
} |
public void removeBeforeDeleteListener(UserBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.remove(listener); |
} |
public void addDeletedListener(UserDeletedListener listener) |
{ |
deletedListeners.add(listener); |
} |
public void removeDeletedListener(UserDeletedListener listener) |
{ |
deletedListeners.remove(listener); |
} |
public void addDeletingListener(UserDeletingListener listener) |
{ |
deletingListeners.add(listener); |
} |
public void removeDeletingListener(UserDeletingListener listener) |
{ |
deletingListeners.remove(listener); |
} |
public Collection beforeDelete(User editor, User user, Collection known) |
throws ModelException |
{ |
Collection cascade = new ArrayList(); |
for(Iterator i = beforeDeleteListeners.iterator(); i.hasNext(); ) { |
UserBeforeDeleteListener listener = (UserBeforeDeleteListener)i.next(); |
Collection subcascade = listener.userBeforeDelete(editor, user, known); |
if(subcascade != null) |
cascade.addAll(subcascade); |
} |
return cascade; |
} |
public void delete(User editor, User user) |
throws ModelException |
{ |
// check rights |
if(!user.deleteableBy(editor)) |
throw new ModelSecurityException(); |
// inform deleting listeners |
for(Iterator i = deletingListeners.iterator(); i.hasNext(); ) { |
UserDeletingListener listener = (UserDeletingListener)i.next(); |
listener.userDeleting(editor, user); |
} |
// backup copy |
User oldUser = new User(user); |
// delete it |
store.delete(user); |
// inform delete listeners |
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) { |
UserDeletedListener listener = (UserDeletedListener)i.next(); |
listener.userDeleted(editor, oldUser); |
} |
} |
public Collection listUsers(User editor) |
throws ModelException |
{ |
return listUsers(null, 0, 0, null, editor); |
} |
public Collection listUsers(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User editor) |
throws ModelException |
{ |
if(editor.isSuperuser()) |
return store.listAllUsers(info, rowsPerPage, pageNumber, sortingKeys); |
else |
return store.listUsers(info, rowsPerPage, pageNumber, sortingKeys, editor); |
} |
public boolean areUsersAvailable(User editor) |
throws ModelException |
{ |
return true; |
} |
public User loginUser(String login, String password, String ip) |
throws ModelException |
{ |
User user = (login == null || password == null) |
? null : store.findForLogin(login); |
boolean success = (user == null) ? false : user.checkPassword(password); |
UserLogin userLogin = new UserLogin(user, login, new Date(), Boolean.valueOf(success), ip); |
// save login information |
store.saveUserLogin(userLogin); |
if(success) { |
user = new User(user); // unbind the user from store |
loggedinUsers.put(user, Boolean.TRUE); |
return user; |
} |
else { |
return null; // wrong login or password |
} |
} |
public Collection listFailedLogins(User editor) |
throws ModelException |
{ |
if(!editor.mayViewAllLogins()) |
throw new ModelSecurityException(); |
return store.listFailedLogins(); |
} |
public Collection userBeforeDelete(User editor, User user, Collection known) |
throws ModelException |
{ |
Collection subusers = store.listSubusers(user); |
Collection cascade = new ArrayList(); |
for(Iterator i = subusers.iterator(); i.hasNext(); ) { |
User u = (User)i.next(); |
if(known.contains(u)) continue; |
known.add(u); |
if(u.viewableBy(editor)) { |
if(u.deleteableBy(editor)) |
cascade.add(new CascadeDeleteElement(u, CascadeDeleteElement.DELETE, |
this.beforeDelete(editor, u, known))); |
else |
cascade.add(new CascadeDeleteElement(u, CascadeDeleteElement.FORBIDDEN, null)); |
} |
else { |
cascade.add(new CascadeDeleteElement(User.createLimitedCopy(u), |
CascadeDeleteElement.FORBIDDEN, null)); |
} |
} |
return cascade; |
} |
public void userDeleting(User editor, User user) |
throws ModelException |
{ |
Collection subusers = store.listSubusers(user); |
for(Iterator i = subusers.iterator(); i.hasNext(); ) { |
delete(editor, (User)i.next()); |
} |
} |
protected void setUserPasswordStores(User user) |
throws ModelException |
{ |
if(passwordStores == null) return; |
try { |
for(int i = 0; i < passwordStores.length; i++) |
user.addPasswordStore((PasswordStore)passwordStores[i].newInstance()); |
} |
catch(Exception ex) { |
throw new ModelException(ex); |
} |
} |
public Collection listUserLogins(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User editor, User user) |
throws ModelException |
{ |
return store.listUserLogins(info, rowsPerPage, pageNumber, sortingKeys, user); |
} |
public static final Integer SORT_LOGIN = new Integer(1); |
public static final Integer SORT_LOGINS_TIME = new Integer(2); |
public static final Integer SORT_LOGINS_TIME_REVERSE = new Integer(3); |
public static final Comparator LOGIN_COMPARATOR = new LoginComparator(); |
public static final Comparator LOGINS_TIME_COMPARATOR = new LoginsTimeComparator(); |
private static class LoginComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof User) || !(o2 instanceof User)) |
throw new ClassCastException("not a User"); |
User a1 = (User)o1; |
User a2 = (User)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getLogin().compareToIgnoreCase(a2.getLogin()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof LoginComparator); |
} |
} |
private static class LoginsTimeComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof UserLogin) || !(o2 instanceof UserLogin)) |
throw new ClassCastException("not a UserLogin"); |
UserLogin a1 = (UserLogin)o1; |
UserLogin a2 = (UserLogin)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getLoginTime().compareTo(a2.getLoginTime()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof LoginComparator); |
} |
} |
public void init(Map params) |
throws ModelException |
{ |
try { |
userManager = this; |
Class c = Class.forName(((String[])params.get("store"))[0]); |
store = (UserStore)c.newInstance(); |
String[] passwordStoreNames = (String[])params.get("passwordStore"); |
if(passwordStoreNames != null) { |
passwordStores = new Class[passwordStoreNames.length]; |
for(int i = 0; i < passwordStoreNames.length; i++) { |
passwordStores[i] = Class.forName(passwordStoreNames[i]); |
} |
} |
} |
catch(Exception ex) { |
throw new ModelException(ex); |
} |
} |
private static UserManager userManager = null; |
public static UserManager getInstance() |
{ |
return userManager; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/UserDeletedListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface UserDeletedListener |
{ |
/** |
* called if some user is just deleted. |
* |
* @param editor who is doing the operation |
* @param user the user deleted |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other UserDeletedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void userDeleted(User editor, User user) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/UserCreatedListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface UserCreatedListener |
{ |
/** |
* called if new user is just created. |
* |
* @param editor who is doing the operation |
* @param user the new user |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other UserCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void userCreated(User editor, User user) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/InetDomainDeletedListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface InetDomainDeletedListener |
{ |
/** |
* called if some domain is just deleted. |
* |
* @param editor who is doing the operation |
* @param domain the domain deleted |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other InetDomainDeletedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void inetDomainDeleted(User editor, InetDomain domain) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/InetDomainCreatedListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface InetDomainCreatedListener |
{ |
/** |
* called if new domain is just created. |
* |
* @param editor who is doing the operation |
* @param domain the new domain |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other InetDomainCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void inetDomainCreated(User editor, InetDomain domain) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/UserModifiedListener.java |
---|
0,0 → 1,20 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface UserModifiedListener |
{ |
/** |
* called if some user is just changed. |
* |
* @param editor who is doing the operation |
* @param user the user in its new state |
* @param oldUser copy of user as it was before the operation |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other UserCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void userModified(User editor, User user, User oldUser) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailboxDeletedListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface MailboxDeletedListener |
{ |
/** |
* called if some mailbox is just deleted. |
* |
* @param editor who is doing the operation |
* @param mailbox the mailbox deleted |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other MailboxDeletedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void mailboxDeleted(User editor, Mailbox mailbox) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailboxCreatedListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface MailboxCreatedListener |
{ |
/** |
* called if new mailbox is just created. |
* |
* @param editor who is doing the operation |
* @param mailbox the new mailbox |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other MailboxCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void mailboxCreated(User editor, Mailbox mailbox) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/SystemUserModifiedListener.java |
---|
0,0 → 1,20 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface SystemUserModifiedListener |
{ |
/** |
* called if some system user is just changed. |
* |
* @param editor who is doing the operation |
* @param systemUser the system user in its new state |
* @param oldSystemUser copy of system user as it was before the operation |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other SystemUserCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void systemUserModified(User editor, SystemUser systemUser, SystemUser oldSystemUser) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/InetDomainValidateListener.java |
---|
0,0 → 1,18 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface InetDomainValidateListener |
{ |
/** |
* called if domain information is about to be changed - by new or existing entry |
* |
* @param editor who is doing the operation |
* @param inetDomain the domain in its new state |
* @param oldInetDomain copy of domain as it was before the operation |
* @throws ModelException in case of any validation errors, validation will be stopped |
* by first exception |
*/ |
public void inetDomainValidate(User editor, InetDomain inetDomain, InetDomain oldInetDomain) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/InetDomainDeletingListener.java |
---|
0,0 → 1,17 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface InetDomainDeletingListener |
{ |
/** |
* called just before some domain is deleted. |
* |
* @param editor who is doing the operation |
* @param domain the domain is being deleting |
* @throws ModelException in case of any errors, no action should be done |
* until this moment in other classes |
*/ |
public void inetDomainDeleting(User editor, InetDomain domain) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailboxValidateListener.java |
---|
0,0 → 1,18 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface MailboxValidateListener |
{ |
/** |
* called if mailbox information is about to be changed - by new or existing entry |
* |
* @param editor who is doing the operation |
* @param mailbox the mailbox in its new state |
* @param oldMailbox copy of mailbox as it was before the operation |
* @throws ModelException in case of any validation errors, validation will be stopped |
* by first exception |
*/ |
public void mailboxValidate(User editor, Mailbox mailbox, Mailbox oldMailbox) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailAliasValidateListener.java |
---|
0,0 → 1,18 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface MailAliasValidateListener |
{ |
/** |
* called if mail alias information is about to be changed - by new or existing entry |
* |
* @param editor who is doing the operation |
* @param mailAlias the mail alias in its new state |
* @param oldMailAlias copy of mail alias as it was before the operation |
* @throws ModelException in case of any validation errors, validation will be stopped |
* by first exception |
*/ |
public void mailAliasValidate(User editor, MailAlias mailAlias, MailAlias oldMailAlias) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailboxDeletingListener.java |
---|
0,0 → 1,17 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface MailboxDeletingListener |
{ |
/** |
* called just before some mailbox is deleted. |
* |
* @param editor who is doing the operation |
* @param mailbox the mailbox is being deleting |
* @throws ModelException in case of any errors, no action should be done |
* until this moment in other classes |
*/ |
public void mailboxDeleting(User editor, Mailbox mailbox) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailAliasDeletingListener.java |
---|
0,0 → 1,17 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface MailAliasDeletingListener |
{ |
/** |
* called just before some mail alias is deleted. |
* |
* @param editor who is doing the operation |
* @param mailAlias the mail alias is being deleting |
* @throws ModelException in case of any errors, no action should be done |
* until this moment in other classes |
*/ |
public void mailAliasDeleting(User editor, MailAlias mailAlias) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/SystemUserDeletedListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface SystemUserDeletedListener |
{ |
/** |
* called if some system user is just deleted. |
* |
* @param editor who is doing the operation |
* @param systemUser the system user deleted |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other SystemUserDeletedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void systemUserDeleted(User editor, SystemUser systemUser) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/SystemUserCreatedListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface SystemUserCreatedListener |
{ |
/** |
* called if new system user is just created. |
* |
* @param editor who is doing the operation |
* @param systemUser the new system user |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other SystemUserCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void systemUserCreated(User editor, SystemUser systemUser) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/InetDomainManager.java |
---|
0,0 → 1,332 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.Map; |
import java.util.Comparator; |
import ak.hostadmiral.util.ConfigInit; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
import ak.hostadmiral.core.model.store.InetDomainStore; |
public class InetDomainManager |
implements |
ConfigInit, |
UserBeforeDeleteListener, |
UserDeletingListener |
{ |
private InetDomainStore store; |
private Collection validateListeners = new ArrayList(); |
private Collection createdListeners = new ArrayList(); |
private Collection modifiedListeners = new ArrayList(); |
private Collection beforeDeleteListeners = new ArrayList(); |
private Collection deletingListeners = new ArrayList(); |
private Collection deletedListeners = new ArrayList(); |
public InetDomainManager() |
throws ModelException |
{ |
UserManager.getInstance().addBeforeDeleteListener(this); |
UserManager.getInstance().addDeletingListener(this); |
} |
public InetDomain create(User editor) |
throws ModelException |
{ |
if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
return new InetDomain(); |
} |
public boolean allowedToCreate(User editor) |
throws ModelException |
{ |
return InetDomain.allowedToCreate(this, editor); |
} |
public InetDomain get(User editor, Long id) |
throws ModelException |
{ |
InetDomain domain = store.get(id); |
if(!domain.viewableBy(editor)) |
throw new ModelSecurityException(); |
return domain; |
} |
public boolean nameExists(User editor, InetDomain domain, String name) |
throws ModelException |
{ |
return store.nameExists(domain, name); |
} |
public InetDomain findForName(User editor, String name) |
throws ModelException |
{ |
InetDomain domain = store.findForName(name); |
if(domain != null && !domain.viewableBy(editor)) |
throw new ModelSecurityException(); |
return domain; |
} |
public void save(User editor, InetDomain domain) |
throws ModelException |
{ |
// security check |
if(!domain.editableBy(editor)) |
throw new ModelSecurityException(); |
//domain.setModUser(editor); // FIXME |
boolean isNew = domain.isNew(); |
InetDomain oldDomain = domain.getOrigin(); |
if(oldDomain == null) oldDomain = domain; |
// validate |
for(Iterator i = validateListeners.iterator(); i.hasNext(); ) { |
InetDomainValidateListener listener = (InetDomainValidateListener)i.next(); |
listener.inetDomainValidate(editor, domain, oldDomain); |
} |
store.save(domain); |
// inform listeners |
if(isNew) { |
for(Iterator i = createdListeners.iterator(); i.hasNext(); ) { |
InetDomainCreatedListener listener = (InetDomainCreatedListener)i.next(); |
listener.inetDomainCreated(editor, domain); |
} |
} |
else { |
for(Iterator i = modifiedListeners.iterator(); i.hasNext(); ) { |
InetDomainModifiedListener listener = (InetDomainModifiedListener)i.next(); |
listener.inetDomainModified(editor, domain, oldDomain); |
} |
} |
// reset backup |
domain.resetOrigin(); |
} |
public void addValidateListener(InetDomainValidateListener listener) |
{ |
validateListeners.add(listener); |
} |
public void removeValidateListener(InetDomainValidateListener listener) |
{ |
validateListeners.remove(listener); |
} |
public void addCreatedListener(InetDomainCreatedListener listener) |
{ |
createdListeners.add(listener); |
} |
public void removeCreatedListener(InetDomainCreatedListener listener) |
{ |
createdListeners.remove(listener); |
} |
public void addModifiedListener(InetDomainModifiedListener listener) |
{ |
modifiedListeners.add(listener); |
} |
public void removeModifiedListener(InetDomainModifiedListener listener) |
{ |
modifiedListeners.remove(listener); |
} |
public void addBeforeDeleteListener(InetDomainBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.add(listener); |
} |
public void removeBeforeDeleteListener(InetDomainBeforeDeleteListener listener) |
{ |
beforeDeleteListeners.remove(listener); |
} |
public void addDeletingListener(InetDomainDeletingListener listener) |
{ |
deletingListeners.add(listener); |
} |
public void removeDeletingListener(InetDomainDeletingListener listener) |
{ |
deletingListeners.remove(listener); |
} |
public void addDeletedListener(InetDomainDeletedListener listener) |
{ |
deletedListeners.add(listener); |
} |
public void removeDeletedListener(InetDomainDeletedListener listener) |
{ |
deletedListeners.remove(listener); |
} |
public Collection beforeDelete(User editor, InetDomain domain, Collection known) |
throws ModelException |
{ |
Collection cascade = new ArrayList(); |
for(Iterator i = beforeDeleteListeners.iterator(); i.hasNext(); ) { |
InetDomainBeforeDeleteListener listener = (InetDomainBeforeDeleteListener)i.next(); |
Collection subcascade = listener.inetDomainBeforeDelete(editor, domain, known); |
if(subcascade != null) |
cascade.addAll(subcascade); |
} |
return cascade; |
} |
public void delete(User editor, InetDomain domain) |
throws ModelException |
{ |
// check rights |
if(!domain.deleteableBy(editor)) |
throw new ModelSecurityException(); |
// inform deleting listeners |
for(Iterator i = deletingListeners.iterator(); i.hasNext(); ) { |
InetDomainDeletingListener listener = (InetDomainDeletingListener)i.next(); |
listener.inetDomainDeleting(editor, domain); |
} |
// backup copy |
InetDomain oldDomain = new InetDomain(domain); |
// delete it |
store.delete(domain); |
// inform deleted listeners |
for(Iterator i = deletedListeners.iterator(); i.hasNext(); ) { |
InetDomainDeletedListener listener = (InetDomainDeletedListener)i.next(); |
listener.inetDomainDeleted(editor, oldDomain); |
} |
} |
public Collection listInetDomains(User editor) |
throws ModelException |
{ |
return listInetDomains(null, 0, 0, null, editor); |
} |
public Collection listInetDomains(CollectionInfo info, int rowsPerPage, int pageNumber, |
Integer[] sortingKeys, User editor) |
throws ModelException |
{ |
if(editor.isSuperuser()) |
return store.listAllInetDomains(info, rowsPerPage, pageNumber, sortingKeys); |
else |
return store.listInetDomains(info, rowsPerPage, pageNumber, sortingKeys, editor); |
} |
public boolean areInetDomainsAvailable(User editor) |
throws ModelException |
{ |
if(editor.isSuperuser()) |
return true; |
else |
return store.countInetDomainsAvailable(editor) > 0; |
} |
public Collection userBeforeDelete(User editor, User user, Collection known) |
throws ModelException |
{ |
Collection domains = store.listOwnInetDomains(user); |
Collection cascade = new ArrayList(); |
for(Iterator i = domains.iterator(); i.hasNext(); ) { |
InetDomain d = (InetDomain)i.next(); |
if(known.contains(d)) continue; |
known.add(d); |
if(d.viewableBy(editor)) { |
if(d.deleteableBy(editor)) |
cascade.add(new CascadeDeleteElement(d, CascadeDeleteElement.DELETE, |
this.beforeDelete(editor, d, known))); |
else |
cascade.add(new CascadeDeleteElement(d, CascadeDeleteElement.FORBIDDEN, null)); |
} |
else { |
cascade.add(new CascadeDeleteElement(InetDomain.createLimitedCopy(d), |
CascadeDeleteElement.FORBIDDEN, null)); |
} |
} |
return cascade; |
} |
public void userDeleting(User editor, User user) |
throws ModelException |
{ |
Collection domains = store.listOwnInetDomains(user); |
for(Iterator i = domains.iterator(); i.hasNext(); ) { |
delete(editor, (InetDomain)i.next()); |
} |
} |
public static final Integer SORT_NAME = new Integer(1); |
public static final Comparator NAME_COMPARATOR = new NameComparator(); |
private static class NameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof InetDomain) || !(o2 instanceof InetDomain)) |
throw new ClassCastException("not a InetDomain"); |
InetDomain a1 = (InetDomain)o1; |
InetDomain a2 = (InetDomain)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getName().compareToIgnoreCase(a2.getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NameComparator); |
} |
} |
public void init(Map params) |
throws ModelException |
{ |
try { |
inetDomainManager = this; |
Class c = Class.forName(((String[])params.get("store"))[0]); |
store = (InetDomainStore)c.newInstance(); |
} |
catch(Exception ex) { |
throw new ModelException(ex); |
} |
} |
private static InetDomainManager inetDomainManager = null; |
public static InetDomainManager getInstance() |
{ |
return inetDomainManager; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailAliasDeletedListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface MailAliasDeletedListener |
{ |
/** |
* called if some mail alias is just deleted. |
* |
* @param editor who is doing the operation |
* @param mailAlias the mail alias deleted |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other MailAliasDeletedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void mailAliasDeleted(User editor, MailAlias mailAlias) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailAliasCreatedListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface MailAliasCreatedListener |
{ |
/** |
* called if new mail alias is just created. |
* |
* @param editor who is doing the operation |
* @param mailAlias the new mail alias |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other MailAliasCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void mailAliasCreated(User editor, MailAlias mailAlias) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/InetDomainModifiedListener.java |
---|
0,0 → 1,20 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface InetDomainModifiedListener |
{ |
/** |
* called if some domain is just changed. |
* |
* @param editor who is doing the operation |
* @param domain the domain in its new state |
* @param oldDomain copy of domain as it was before the operation |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other InetDomainCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void inetDomainModified(User editor, InetDomain domain, InetDomain oldDomain) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/UserValidateListener.java |
---|
0,0 → 1,18 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface UserValidateListener |
{ |
/** |
* called if user information is about to be changed - by new or existing entry |
* |
* @param editor who is doing the operation |
* @param user the user in its new state |
* @param oldUser copy of user as it was before the operation |
* @throws ModelException in case of any validation errors, validation will be stopped |
* by first exception |
*/ |
public void userValidate(User editor, User user, User oldUser) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/UserDeletingListener.java |
---|
0,0 → 1,17 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface UserDeletingListener |
{ |
/** |
* called just before some user is deleted. |
* |
* @param editor who is doing the operation |
* @param user the user is being deleting |
* @throws ModelException in case of any errors, no action should be done |
* until this moment in other classes |
*/ |
public void userDeleting(User editor, User user) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailboxModifiedListener.java |
---|
0,0 → 1,20 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface MailboxModifiedListener |
{ |
/** |
* called if some mailbox is just changed. |
* |
* @param editor who is doing the operation |
* @param mailbox the mailbox in its new state |
* @param oldMailbox copy of mailbox as it was before the operation |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other MailboxCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void mailboxModified(User editor, Mailbox mailbox, Mailbox oldMailbox) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailAliasModifiedListener.java |
---|
0,0 → 1,20 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface MailAliasModifiedListener |
{ |
/** |
* called if some mail alias is just changed. |
* |
* @param editor who is doing the operation |
* @param mailAlias the mail alias in its new state |
* @param oldMailAlias copy of mail alias as it was before the operation |
* @throws ModelException in case of any *fatal* errors, |
* Note: throw it on fatal errors only, because database transaction |
* will be rolled back but any other MailAliasCreatedListeners might be already called |
* and (possible) they will not restore their original state. |
*/ |
public void mailAliasModified(User editor, MailAlias mailAlias, MailAlias oldMailAlias) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/SystemUserValidateListener.java |
---|
0,0 → 1,18 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface SystemUserValidateListener |
{ |
/** |
* called if system user information is about to be changed - by new or existing entry |
* |
* @param editor who is doing the operation |
* @param systemUser the user in its new state |
* @param oldSystemUser copy of user as it was before the operation |
* @throws ModelException in case of any validation errors, validation will be stopped |
* by first exception |
*/ |
public void systemUserValidate(User editor, SystemUser systemUser, SystemUser oldSystemUser) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/SystemUserDeletingListener.java |
---|
0,0 → 1,17 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
public interface SystemUserDeletingListener |
{ |
/** |
* called just before some system user is deleted. |
* |
* @param editor who is doing the operation |
* @param systemUser the system user is being deleting |
* @throws ModelException in case of any errors, no action should be done |
* until this moment in other classes |
*/ |
public void systemUserDeleting(User editor, SystemUser systemUser) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailboxBeforeDeleteListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
public interface MailboxBeforeDeleteListener |
{ |
/** |
* called if some mailbox is about to be deleted. |
* |
* @param editor who is doing the operation |
* @param mailbox the mailbox to delete |
* @param known Collection(Object) - already known objects which are touched by current operation, |
* to avoid loops |
* @return Collection(CascadeDeleteElement) - object which are touched by deleting the mailbox |
*/ |
public Collection mailboxBeforeDelete(User editor, Mailbox mailbox, Collection known) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailAliasBeforeDeleteListener.java |
---|
0,0 → 1,20 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
public interface MailAliasBeforeDeleteListener |
{ |
/** |
* called if some mail alias is about to be deleted. |
* |
* @param editor who is doing the operation |
* @param alias the mail alias to delete |
* @param known Collection(Object) - already known objects which are touched by current operation, |
* to avoid loops |
* @return Collection(CascadeDeleteElement) |
* - object which are touched by deleting the mail alias |
*/ |
public Collection mailAliasBeforeDelete(User editor, MailAlias mailAlias, Collection known) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/InetDomainBeforeDeleteListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
public interface InetDomainBeforeDeleteListener |
{ |
/** |
* called if some domain is about to be deleted. |
* |
* @param editor who is doing the operation |
* @param domain the domain to delete |
* @param known Collection(Object) - already known objects which are touched by current operation, |
* to avoid loops |
* @return Collection(CascadeDeleteElement) - object which are touched by deleting the domain |
*/ |
public Collection inetDomainBeforeDelete(User editor, InetDomain domain, Collection known) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/UserBeforeDeleteListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
public interface UserBeforeDeleteListener |
{ |
/** |
* called if some user is about to be deleted. |
* |
* @param editor who is doing the operation |
* @param user the user to delete |
* @param known Collection(Object) - already known objects which are touched by current operation, |
* to avoid loops |
* @return Collection(CascadeDeleteElement) - object which are touched by deleting the user |
*/ |
public Collection userBeforeDelete(User editor, User user, Collection known) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/SystemUserBeforeDeleteListener.java |
---|
0,0 → 1,19 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
public interface SystemUserBeforeDeleteListener |
{ |
/** |
* called if some system user is about to be deleted. |
* |
* @param editor who is doing the operation |
* @param user the user to delete |
* @param known Collection(Object) - already known objects which are touched by current operation, |
* to avoid loops |
* @return Collection(CascadeDeleteElement) - object which are touched by deleting the user |
*/ |
public Collection systemUserBeforeDelete(User editor, SystemUser user, Collection known) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/GeneralModelObject.java |
---|
0,0 → 1,146 |
package ak.hostadmiral.core.model; |
import java.util.Date; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
public abstract class GeneralModelObject |
implements ModelObject |
{ |
private Long id; |
private Boolean enabled; |
private String comment; |
private Date modStamp; |
private User modUser; |
protected GeneralModelObject() |
{ |
} |
protected GeneralModelObject(GeneralModelObject origin) |
{ |
this.id = origin.id; |
this.enabled = origin.enabled; |
this.comment = origin.comment; |
this.modStamp = origin.modStamp; |
this.modUser = origin.modUser; |
} |
/** |
* @return true if the object is not yet saved in DB |
*/ |
public boolean isNew() |
{ |
return (id == null); |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
protected void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Boolean getEnabled() |
{ |
return enabled; |
} |
protected void setEnabled(Boolean enabled) |
{ |
this.enabled = enabled; |
} |
public void setEnabled(User editor, Boolean enabled) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
this.enabled = enabled; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
} |
protected void setComment(String comment) |
{ |
this.comment = comment; |
} |
public void setComment(User editor, String comment) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
this.comment = comment; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
protected void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
/** |
* |
* @hibernate.many-to-one column="mod_user" |
*/ |
public User getModUser() |
{ |
return modUser; |
} |
protected void setModUser(User modUser) |
{ |
this.modUser = modUser; |
} |
public String toString() |
{ |
return getClass().getName() + " [" + getId() + "]"; |
} |
public boolean equals(Object o) |
{ |
if(o == null) return false; |
if(!getClass().isInstance(o)) return false; |
ModelObject u = (ModelObject)o; |
return (getId() != null) && (u.getId() != null) && (getId().equals(u.getId())); |
} |
public int hashCode() |
{ |
if(getId() == null) |
return 0; |
else |
return getId().hashCode(); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/InetDomain.java |
---|
0,0 → 1,139 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="domains" |
*/ |
public class InetDomain |
extends GeneralModelObject |
{ |
private String name; |
private User owner; |
private InetDomain origin; // save original object state before any changes |
protected InetDomain() |
{ |
} |
protected InetDomain(InetDomain origin) |
{ |
super(origin); |
this.name = origin.name; |
this.owner = origin.owner; |
} |
protected InetDomain getOrigin() |
{ |
return origin; |
} |
protected void backupMe() |
{ |
if(origin == null) |
origin = new InetDomain(this); |
} |
protected void resetOrigin() |
{ |
origin = null; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
protected void setName(String name) |
{ |
this.name = name; |
} |
public void setName(User editor, String name) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.name = name; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getOwner() |
{ |
return owner; |
} |
protected void setOwner(User owner) |
{ |
this.owner = owner; |
} |
public void setOwner(User editor, User owner) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
backupMe(); |
this.owner = owner; |
} |
public String getTypeKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.TYPE_DOMAIN; |
} |
public String getIdentKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.IDENT_DOMAIN; |
} |
public Object[] getIdentParams() |
{ |
return new Object[] { getName() }; |
} |
public boolean viewableBy(User user) |
{ |
return user.isSuperuser() || user.equals(owner); |
} |
public boolean editableBy(User user) |
{ |
return user.isSuperuser(); |
} |
public boolean deleteableBy(User user) |
{ |
return user.isSuperuser(); |
} |
protected static boolean allowedToCreate(InetDomainManager manager, User editor) |
throws ModelException |
{ |
return editor.isSuperuser(); |
} |
protected static InetDomain createLimitedCopy(InetDomain origin) |
{ |
InetDomain d = new InetDomain(); |
d.setName(origin.getName()); |
return d; |
} |
public String toString() |
{ |
return "InetDomain id=[" + getId() + "] name=[" + name + "]"; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/SystemUser.java |
---|
0,0 → 1,164 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="systemusers" |
*/ |
public class SystemUser |
extends GeneralModelObject |
{ |
/** user id in the OS */ |
private Integer uid; |
private String name; |
private User owner; |
private SystemUser origin; // save original object state before any changes |
protected SystemUser() |
{ |
} |
protected SystemUser(SystemUser origin) |
{ |
super(origin); |
this.uid = origin.uid; |
this.name = origin.name; |
this.owner = origin.owner; |
} |
protected SystemUser getOrigin() |
{ |
return origin; |
} |
protected void backupMe() |
{ |
if(origin == null) |
origin = new SystemUser(this); |
} |
protected void resetOrigin() |
{ |
origin = null; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Integer getUid() |
{ |
return uid; |
} |
protected void setUid(Integer uid) |
{ |
this.uid = uid; |
} |
public void setUid(User editor, Integer uid) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
this.uid = uid; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
protected void setName(String name) |
{ |
this.name = name; |
} |
public void setName(User editor, String name) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
this.name = name; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getOwner() |
{ |
return owner; |
} |
protected void setOwner(User owner) |
{ |
this.owner = owner; |
} |
public void setOwner(User editor, User owner) |
throws ModelException |
{ |
if(!editableBy(editor)) |
throw new ModelSecurityException(); |
this.owner = owner; |
} |
public String getTypeKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.TYPE_SYSTEM_USER; |
} |
public String getIdentKey() |
{ |
return ak.hostadmiral.core.resources.CoreResources.IDENT_SYSTEM_USER; |
} |
public Object[] getIdentParams() |
{ |
return new Object[] { getName(), getUid() }; |
} |
public boolean viewableBy(User user) |
{ |
return user.isSuperuser() || (owner == null) || user.equals(owner); |
} |
public boolean editableBy(User user) |
{ |
return user.isSuperuser(); |
} |
public boolean deleteableBy(User user) |
{ |
return user.isSuperuser(); |
} |
protected static boolean allowedToCreate(SystemUserManager manager, User editor) |
throws ModelException |
{ |
return editor.isSuperuser(); |
} |
protected static SystemUser createLimitedCopy(SystemUser origin) |
{ |
SystemUser u = new SystemUser(); |
u.setUid(origin.getUid()); |
u.setName(origin.getName()); |
return u; |
} |
public String toString() |
{ |
return "SystemUser id=[" + getId() + "] uid=[" + uid + "] name=[" + name + "]"; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/MailAliasDestinationManager.java |
---|
0,0 → 1,136 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.Map; |
import java.util.Comparator; |
import ak.hostadmiral.util.ConfigInit; |
import ak.hostadmiral.util.CollectionInfo; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
import ak.hostadmiral.core.model.store.MailAliasDestinationStore; |
public class MailAliasDestinationManager |
implements |
ConfigInit |
{ |
// FIXME create, delete and modify listeners are not implemented, bacause |
// all operations are done via MailAliasManager. Do we need them? |
private MailAliasDestinationStore store; |
public MailAliasDestinationManager() |
throws ModelException |
{ |
} |
public MailAliasDestination create(User editor) |
throws ModelException |
{ |
if(!allowedToCreate(editor)) throw new ModelSecurityException(); |
return new MailAliasDestination(); |
} |
public boolean allowedToCreate(User editor) |
throws ModelException |
{ |
return MailAliasDestination.allowedToCreate(this, editor); |
} |
public MailAliasDestination get(User editor, Long id) |
throws ModelException |
{ |
MailAliasDestination dest = store.get(id); |
if(!dest.viewableBy(editor)) |
throw new ModelSecurityException(); |
return dest; |
} |
public void save(User editor, MailAliasDestination mailAliasDestination) |
throws ModelException |
{ |
if(!mailAliasDestination.editableBy(editor)) |
throw new ModelSecurityException(); |
//mailAliasDestination.setModUser(editor); // FIXME |
// FIXME: the mod_user is not set when changing a destination as element of collection |
store.save(mailAliasDestination); |
} |
public void delete(User editor, MailAliasDestination mailAliasDestination) |
throws ModelException |
{ |
if(!mailAliasDestination.deleteableBy(editor)) |
throw new ModelSecurityException(); |
store.delete(mailAliasDestination); |
} |
public Collection listMailAliasesDestination(MailAlias alias) |
throws ModelException |
{ |
return store.listMailAliasesDestination(alias); |
} |
public boolean areMailAliasesDestinationsAvailable(User editor) |
throws ModelException |
{ |
return true; |
} |
public static final Comparator EMAIL_COMPARATOR = new EmailComparator(); |
private static class EmailComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof MailAliasDestination) || !(o2 instanceof MailAliasDestination)) |
throw new ClassCastException("not a MailAliasDestination"); |
MailAliasDestination a1 = (MailAliasDestination)o1; |
MailAliasDestination a2 = (MailAliasDestination)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getEmail().compareToIgnoreCase(a2.getEmail()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof EmailComparator); |
} |
} |
public void init(Map params) |
throws ModelException |
{ |
try { |
mailAliasDestinationManager = this; |
Class c = Class.forName(((String[])params.get("store"))[0]); |
store = (MailAliasDestinationStore)c.newInstance(); |
} |
catch(Exception ex) { |
throw new ModelException(ex); |
} |
} |
private static MailAliasDestinationManager mailAliasDestinationManager = null; |
public static MailAliasDestinationManager getInstance() |
{ |
return mailAliasDestinationManager; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/UserLogin.java |
---|
0,0 → 1,114 |
package ak.hostadmiral.core.model; |
import java.util.Date; |
/** |
* |
* @hibernate.class table="userlogins" |
*/ |
public class UserLogin |
{ |
private Long id; |
private User user; |
private String login; |
private Date loginTime; |
private Boolean success; |
private String ip; |
protected UserLogin() |
{ |
} |
protected UserLogin(User user, String login, Date loginTime, Boolean success, String ip) |
{ |
this.user = user; |
this.login = login; |
this.loginTime = loginTime; |
this.success = success; |
this.ip = ip; |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
protected void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.many-to-one column="usr" |
*/ |
public User getUser() |
{ |
return user; |
} |
protected void setUser(User user) |
{ |
this.user = user; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getLogin() |
{ |
return login; |
} |
protected void setLogin(String login) |
{ |
this.login = login; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Date getLoginTime() |
{ |
return loginTime; |
} |
protected void setLoginTime(Date loginTime) |
{ |
this.loginTime = loginTime; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Boolean getSuccess() |
{ |
return success; |
} |
protected void setSuccess(Boolean success) |
{ |
this.success = success; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getIp() |
{ |
return ip; |
} |
protected void setIp(String ip) |
{ |
this.ip = ip; |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/PasswordStoreCrypt.java |
---|
0,0 → 1,33 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.DigestCrypt; |
/** |
* |
* @hibernate.subclass discriminator-value="crypt" |
*/ |
public class PasswordStoreCrypt |
extends PasswordStoreAbstract |
{ |
public PasswordStoreCrypt() |
{ |
digest = "crypt"; |
} |
protected String encode(String password) |
throws ModelException |
{ |
return DigestCrypt.crypt(password); |
} |
public boolean checkPassword(String password) |
throws ModelException |
{ |
if(this.password == null || this.password.length() < 3) return false; |
String salt = this.password.substring(0, 2); |
String crypted = DigestCrypt.crypt(salt, password); |
return crypted.equals(this.password); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/PasswordStoreMd5.java |
---|
0,0 → 1,23 |
package ak.hostadmiral.core.model; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.DigestMd5; |
/** |
* |
* @hibernate.subclass discriminator-value="MD5" |
*/ |
public class PasswordStoreMd5 |
extends PasswordStoreAbstract |
{ |
public PasswordStoreMd5() |
{ |
digest = "MD5"; |
} |
protected String encode(String password) |
throws ModelException |
{ |
return DigestMd5.encode(password); |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/TransactionController.java |
---|
0,0 → 1,34 |
package ak.hostadmiral.core.model; |
import java.util.Map; |
import java.util.HashMap; |
import ak.hostadmiral.util.ModelException; |
// FIXME: implement it |
public class TransactionController |
{ |
private static TransactionController transactionController = null; |
public static TransactionController getInstance() |
{ |
return transactionController; |
} |
private Map listeners = new HashMap(); |
public void beginTransaction(Object transaction) |
{ |
} |
public void commitTransaction(Object transaction) |
{ |
} |
public void rollbackTransaction(Object transaction) |
{ |
} |
public void addObject(Object transaction, Object object) |
{ |
} |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/TransactionListener.java |
---|
0,0 → 1,43 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
import ak.hostadmiral.util.ModelException; |
/** |
* One could implement this interface to receive transaction start, commit and |
* rollback events. |
* An object will be informed about this events if it actualy interacts with the |
* transaction, e.g. if it is registered as listener for object modifications. |
*/ |
public interface TransactionListener |
{ |
/** |
* called when this object first time interacts with given transaction, |
* before any other callbacks of this object in the transaction |
* |
* @param id some transaction identifier, the same for all transaction* methods |
* @throws ModelException if transaction must be aborted immediately |
*/ |
public void transactionBegin(Object id) |
throws ModelException; |
/** |
* called when transaction is commited |
* |
* @param id some transaction identifier, the same as in corresponding transactionBegin |
* method call |
* @throws ModelException logged, but ignored |
*/ |
public void transactionCommited(Object id) |
throws ModelException; |
/** |
* called when transaction is rolled back |
* |
* @param id some transaction identifier, the same as in corresponding transactionBegin |
* method call |
* @throws ModelException logged, but ignored |
*/ |
public void transactionRolledBack(Object id) |
throws ModelException; |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/ModelObject.java |
---|
0,0 → 1,18 |
package ak.hostadmiral.core.model; |
public interface ModelObject |
{ |
public Long getId(); |
public String getTypeKey(); |
public String getIdentKey(); |
public Object[] getIdentParams(); |
public boolean viewableBy(User user); |
public boolean editableBy(User user); |
public boolean deleteableBy(User user); |
} |
/hostadmiral/branches/hibernate3/src/ak/hostadmiral/core/model/CascadeDeleteElement.java |
---|
0,0 → 1,55 |
package ak.hostadmiral.core.model; |
import java.util.Collection; |
public class CascadeDeleteElement |
{ |
public static final int FORBIDDEN = 1; |
public static final int DELETE = 2; |
public static final int CHANGE = 3; |
private ModelObject object; |
private int effect; |
private Collection cascade; // Collection(CascadeDeleteElement) |
public CascadeDeleteElement() |
{ |
} |
public CascadeDeleteElement(ModelObject object, int effect, Collection cascade) |
{ |
this.object = object; |
this.effect = effect; |
this.cascade = cascade; |
} |
public ModelObject getObject() |
{ |
return object; |
} |
public void setObject(ModelObject object) |
{ |
this.object = object; |
} |
public int getEffect() |
{ |
return effect; |
} |
public void setEffect(int effect) |
{ |
this.effect = effect; |
} |
public Collection getCascade() |
{ |
return cascade; |
} |
public void setCascade(Collection cascade) |
{ |
this.cascade = cascade; |
} |
} |