KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > notification > CmsExtendedNotificationCause


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/notification/CmsExtendedNotificationCause.java,v $
3  * Date : $Date: 2006/03/27 14:52:46 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2002 - 2004 Alkacon Software (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.notification;
33
34 import org.opencms.file.CmsResource;
35
36 import java.util.Date JavaDoc;
37
38 /**
39  * Class to encapsulate a resource and the cause of its notification.<p>
40  *
41  * @author Jan Baudisch
42  *
43  */

44 public class CmsExtendedNotificationCause implements Comparable JavaDoc {
45
46     /** The notification is sent because the resource will expire soon. */
47     public static final int RESOURCE_EXPIRES = 0;
48
49     /** The notification is sent because the resource will get outdated. */
50     public static final int RESOURCE_OUTDATED = 1;
51
52     /** constant indicating the cause of the notification for a resource. */
53     public static final int RESOURCE_UPDATE_REQUIRED = 2;
54
55     /** The notification is sent because the resource will be released soon. */
56     public static final int RESOURCE_RELEASE = 3;
57
58     /** The reason that the resource occures in the notification. */
59     private int m_cause;
60
61     /** The date when the event (e.g. release or expiration) will happen. */
62     private Date JavaDoc m_date;
63
64     /** The resource. */
65     private CmsResource m_resource;
66
67     /**
68      * Creates a new CmsNotificationResourceInfo.<p>
69      *
70      * @param resource the specific resource
71      * @param cause that the resource occures in the notification
72      * @param date when the event will happen
73      */

74     public CmsExtendedNotificationCause(CmsResource resource, int cause, Date JavaDoc date) {
75
76         m_resource = resource;
77         m_cause = cause;
78         m_date = date;
79     }
80
81     /**
82      *
83      * @see java.lang.Comparable#compareTo(java.lang.Object)
84      */

85     public int compareTo(Object JavaDoc o) {
86
87         if (o instanceof CmsExtendedNotificationCause) {
88             return getDate().compareTo(((CmsExtendedNotificationCause)o).getDate());
89         } else {
90             return -1;
91         }
92     }
93
94     /**
95      * Returns true if the Object equals to the corresponding CmsResourceInfo, that means a resource info
96      * with the same resource and cause.
97      *
98      * @return true if the resource info is equal to a notification cause or resource info with the same resource and cause
99      *
100      * @param o the object to check for equality
101      *
102      * @see org.opencms.notification.CmsNotificationCause#equals(java.lang.Object)
103      */

104     public boolean equals(Object JavaDoc o) {
105
106         if (!(o instanceof CmsExtendedNotificationCause) && !(o instanceof CmsNotificationCause)) {
107             return false;
108         }
109         return hashCode() == o.hashCode();
110     }
111
112     /**
113      *
114      * @see java.lang.Object#hashCode()
115      */

116     public int hashCode() {
117
118         return m_cause + m_resource.getStructureId().hashCode();
119     }
120
121     /**
122      * Returns the cause.<p>
123      *
124      * @return the cause
125      */

126     public int getCause() {
127
128         return m_cause;
129     }
130
131     /**
132      * Returns the date.<p>
133      *
134      * @return the date
135      */

136     public Date JavaDoc getDate() {
137
138         return m_date;
139     }
140
141     /**
142      * Returns the resource.<p>
143      *
144      * @return the resource
145      */

146     public CmsResource getResource() {
147
148         return m_resource;
149     }
150
151     /**
152      * Sets the cause.<p>
153      *
154      * @param cause the cause to set
155      */

156     public void setCause(int cause) {
157
158         m_cause = cause;
159     }
160
161     /**
162      * Sets the date.<p>
163      *
164      * @param date the date to set
165      */

166     public void setDate(Date JavaDoc date) {
167
168         m_date = date;
169     }
170
171     /**
172      * Sets the resource.<p>
173      *
174      * @param resource the resource to set
175      */

176     public void setResource(CmsResource resource) {
177
178         m_resource = resource;
179     }
180 }
181
Popular Tags