Warning: Attempt to read property "date" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "msg" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/www/websvn.26th.net/html/blame.php on line 247
WebSVN – general – Blame – /hostadmiral/trunk/src/ak/hostadmiral/core/model/MailAliasDestinationManager.java/ – Rev 919

Subversion Repositories general

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
919 dev 1
package ak.hostcaptain.core.model;
2
 
3
import java.util.*;
4
import net.sf.hibernate.*;
5
import ak.hostcaptain.util.HibernateUtil;
6
import ak.hostcaptain.util.ModelException;
7
import ak.hostcaptain.util.ModelSecurityException;
8
 
9
public class MailAliasDestinationManager
10
{
11
	private static boolean registered = false;
12
	protected static void register()
13
	{
14
		synchronized(MailAliasDestinationManager.class) {
15
			if(registered) return;
16
 
17
			registered = true;
18
			try {
19
				HibernateUtil.getConfiguration().addResource(
20
					"/ak/hostcaptain/core/model/MailAliasDestination.hbm.xml");
21
			}
22
			catch(Exception ex) {
23
				ex.printStackTrace();
24
				throw new RuntimeException(ex.getMessage());
25
			}
26
		}
27
	}
28
 
29
	static {
30
		register();
31
	}
32
 
33
	private MailAliasDestinationManager()
34
	{
35
	}
36
 
37
	public MailAliasDestination create(User editor)
38
		throws ModelException
39
	{
40
		if(!allowedToCreate(editor)) throw new ModelSecurityException();
41
 
42
		return new MailAliasDestination();
43
	}
44
 
45
	public boolean allowedToCreate(User editor)
46
		throws ModelException
47
	{
48
		return true;
49
	}
50
 
51
	public MailAliasDestination get(User editor, Long id)
52
		throws ModelException
53
	{
54
		MailAliasDestination dest;
55
 
56
		try {
57
			dest = (MailAliasDestination)HibernateUtil.currentSession()
58
				.load(MailAliasDestination.class, id);
59
		}
60
		catch(HibernateException ex)
61
		{
62
			throw new ModelException(ex);
63
		}
64
 
65
		if(!dest.viewableBy(editor))
66
			throw new ModelSecurityException();
67
 
68
		return dest;
69
	}
70
 
71
	public void save(User editor, MailAliasDestination mailAliasDestination)
72
		throws ModelException
73
	{
74
		if(!mailAliasDestination.editableBy(editor))
75
			throw new ModelSecurityException();
76
 
77
		mailAliasDestination.setModUser(editor);
78
 
79
		try {
80
			HibernateUtil.currentSession().saveOrUpdate(mailAliasDestination);
81
		}
82
		catch(HibernateException ex)
83
		{
84
			throw new ModelException(ex);
85
		}
86
	}
87
 
88
	public void delete(User editor, MailAliasDestination mailAliasDestination)
89
		throws ModelException
90
	{
91
		if(!mailAliasDestination.deleteableBy(editor))
92
			throw new ModelSecurityException();
93
 
94
		try {
95
			HibernateUtil.currentSession().delete(mailAliasDestination);
96
		}
97
		catch(HibernateException ex)
98
		{
99
			throw new ModelException(ex);
100
		}
101
	}
102
 
103
	public Collection listMailAliasesDestination(MailAlias alias)
104
		throws ModelException
105
	{
106
		try {
107
			return HibernateUtil.currentSession().find(
108
				"from MailAliasDestination where alias=?",
109
				alias, Hibernate.entity(MailAlias.class));
110
		}
111
		catch(HibernateException ex)
112
		{
113
			throw new ModelException(ex);
114
		}
115
	}
116
 
117
	public boolean areMailAliasesDestinationsAvailable(User editor)
118
		throws ModelException
119
	{
120
		return true;
121
	}
122
 
123
	private static MailAliasDestinationManager mailAliasDestinationManager = null;
124
 
125
	public static MailAliasDestinationManager getInstance()
126
	{
127
		if(mailAliasDestinationManager == null)
128
			mailAliasDestinationManager = new MailAliasDestinationManager();
129
 
130
		return mailAliasDestinationManager;
131
	}
132
 
133
	public static final Comparator EMAIL_COMPARATOR = new EmailComparator();
134
 
135
	private static class EmailComparator
136
		implements Comparator
137
	{
138
		public int compare(Object o1, Object o2)
139
		{
140
			if(!(o1 instanceof MailAliasDestination) || !(o2 instanceof MailAliasDestination))
141
				throw new ClassCastException("not a MailAliasDestination");
142
 
143
		    MailAliasDestination a1 = (MailAliasDestination)o1;
144
		    MailAliasDestination a2 = (MailAliasDestination)o2;
145
 
146
		    if(a1 == null && a2 == null)
147
		    	return 0;
148
		    else if(a1 == null && a2 != null)
149
		    	return -1;
150
		    else if(a1 != null && a2 == null)
151
		    	return 1;
152
		    else
153
		    	return a1.getEmail().compareToIgnoreCase(a2.getEmail());
154
		}
155
 
156
		public boolean equals(Object obj)
157
		{
158
			return (obj instanceof EmailComparator);
159
		}
160
	}
161
}