KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > pojos > PingTargetData


1 /*
2  * Copyright (c) 2005
3  * Anil R. Gangolli. All rights reserved.
4  *
5  * Distributed as part of the Roller Weblogger under the terms of the Roller Software License.
6  */

7
8 package org.roller.pojos;
9
10 import org.roller.RollerException;
11 import org.roller.model.Roller;
12 import org.roller.model.RollerFactory;
13 import org.roller.model.AutoPingManager;
14 import org.roller.model.PingQueueManager;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.List JavaDoc;
18 import java.sql.Timestamp JavaDoc;
19
20 /**
21  * Ping target. Each instance represents a possible target of a weblog update ping that we send. Ping targets are
22  * either common (defined centrally by an administrator and used by any website), or custom (defined by the user of a
23  * specific website) for update pings issued for that website.
24  *
25  * @author Anil Gangolli anil@busybuddha.org
26  * @ejb:bean name="PingTargetData"
27  * @struts.form include-all="true"
28  * @hibernate.class table="pingtarget"
29  */

30 public class PingTargetData extends PersistentObject implements Serializable JavaDoc
31 {
32     protected String JavaDoc id;
33     protected String JavaDoc name;
34     protected String JavaDoc pingUrl;
35     protected WebsiteData website;
36     protected int conditionCode;
37     protected Timestamp JavaDoc lastSuccess;
38
39     public static final int CONDITION_OK = 0; // last use (after possible retrials) was successful
40
public static final int CONDITION_FAILING = 1; // last use failed after retrials
41
public static final int CONDITION_DISABLED = 2; // disabled by failure policy after failures - editing resets
42

43     static final long serialVersionUID = -6354583200913127874L;
44
45     /**
46      * Default empty constructor.
47      */

48     public PingTargetData()
49     {
50     }
51
52     /**
53      * Constructor.
54      *
55      * @param id the id (primary key) of this target
56      * @param name the descriptive name of this target
57      * @param pingUrl the URL to which to send the ping
58      * @param website the website (on this server) for which this is a custom ping target (may be null)
59      */

60     public PingTargetData(String JavaDoc id, String JavaDoc name, String JavaDoc pingUrl, WebsiteData website)
61     {
62         this.id = id;
63         this.name = name;
64         this.pingUrl = pingUrl;
65         this.website = website;
66         this.conditionCode = CONDITION_OK;
67         this.lastSuccess = null;
68     }
69
70     /**
71      * Setter needed by RollerImpl.storePersistentObject()
72      */

73     public void setData(PersistentObject vo)
74     {
75         PingTargetData other = (PingTargetData) vo;
76         id = other.id;
77         name = other.name;
78         pingUrl = other.pingUrl;
79         website = other.website;
80         conditionCode = other.conditionCode;
81         lastSuccess = other.lastSuccess;
82     }
83
84
85     /**
86      * Get the unique id of this ping target.
87      *
88      * @return the unique id of this ping target.
89      * @struts.validator type="required" msgkey="errors.required"
90      * @ejb:persistent-field
91      * @hibernate.id column="id" type="string" generator-class="uuid.hex" unsaved-value="null"
92      */

93     public java.lang.String JavaDoc getId()
94     {
95         return this.id;
96     }
97
98     /**
99      * Set the unique id of this ping target
100      *
101      * @param id
102      * @ejb:persistent-field
103      */

104     public void setId(java.lang.String JavaDoc id)
105     {
106         this.id = id;
107     }
108
109     /**
110      * get the name of this ping target. This is a name assigned by the administrator or a user (for custom) targets.
111      * It is deescriptive and is not necessarily unique.
112      *
113      * @return the name of this ping target
114      * @ejb:persistent-field
115      * @hibernate.property column="name" non-null="true"
116      */

117     public java.lang.String JavaDoc getName()
118     {
119         return this.name;
120     }
121
122     /**
123      * Set the name of this ping target.
124      *
125      * @param name the name of this ping target
126      * @ejb:persistent-field
127      */

128     public void setName(java.lang.String JavaDoc name)
129     {
130         this.name = name;
131     }
132
133     /**
134      * Get the URL to ping.
135      *
136      * @return the URL to ping.
137      * @ejb:persistent-field
138      * @hibernate.property column="pingurl" non-null="true"
139      */

140     public String JavaDoc getPingUrl()
141     {
142         return pingUrl;
143     }
144
145     /**
146      * Set the URL to ping.
147      *
148      * @param pingUrl
149      * @ejb:persistent-field
150      */

151     public void setPingUrl(String JavaDoc pingUrl)
152     {
153         this.pingUrl = pingUrl;
154     }
155
156     /**
157      * Get the website (on this server) for which this ping target is a custom target. This may be null, indicating
158      * that it is a common ping target, not a custom one.
159      *
160      * @return the website for which this ping target is a custom target, or null if this ping target is not a custom
161      * target.
162      * @ejb:persistent-field
163      * @hibernate.many-to-one column="websiteid" cascade="none" not-null="false"
164      */

165     public WebsiteData getWebsite()
166     {
167         return website;
168     }
169
170     /**
171      * Set the website (on this server) for which this ping target is a custom target.
172      *
173      * @param website the website for which this ping target is a custom target, or null if this ping target is not a
174      * custom target
175      * @ejb:persistent-field
176      */

177     public void setWebsite(WebsiteData website)
178     {
179         this.website = website;
180     }
181
182     /**
183      * Get the condition code value. This code, in combination with the last success timestamp, provides a status
184      * indicator on the ping target based on its usage by the ping queue processor. It can be used to implement a
185      * failure-based disabling policy.
186      *
187      * @return one of the condition codes {@link #CONDITION_OK}, {@link #CONDITION_FAILING}, {@link
188      * #CONDITION_DISABLED}.
189      * @ejb:persistent-field
190      * @hibernate.property column="condition" not-null="true"
191      */

192     public int getConditionCode()
193     {
194         return conditionCode;
195     }
196
197     /**
198      * Set the condition code value.
199      *
200      * @param conditionCode the condition code value to set
201      * @ejb:persistent-field
202      */

203     public void setConditionCode(int conditionCode)
204     {
205         this.conditionCode = conditionCode;
206     }
207
208     /**
209      * Get the timestamp of the last successful ping (UTC/GMT).
210      *
211      * @return the timestamp of the last successful ping; <code>null</code> if the target has not yet been used.
212      * @ejb:persistent-field
213      * @hibernate.property column="lastsuccess" not-null="false"
214      */

215     public Timestamp JavaDoc getLastSuccess()
216     {
217         return lastSuccess;
218     }
219
220     /**
221      * Set the timestamp of the last successful ping.
222      *
223      * @param lastSuccess the timestamp of the last successful ping.
224      * @ejb:persistent-field
225      */

226     public void setLastSuccess(Timestamp JavaDoc lastSuccess)
227     {
228         this.lastSuccess = lastSuccess;
229     }
230
231     /**
232      * @see java.lang.Object#hashCode()
233      */

234     public int hashCode()
235     {
236         return id.hashCode();
237     }
238
239     /**
240      * @see java.lang.Object#equals(Object o)
241      */

242     public boolean equals(Object JavaDoc o)
243     {
244         if (this == o) return true;
245         if (!(o instanceof PingTargetData)) return false;
246
247         final PingTargetData pingTargetData = (PingTargetData) o;
248
249         if (conditionCode != pingTargetData.conditionCode) return false;
250         if (id != null ? !id.equals(pingTargetData.id) : pingTargetData.id != null) return false;
251         if (lastSuccess != null ? !lastSuccess.equals(pingTargetData.lastSuccess) : pingTargetData.lastSuccess != null) return false;
252         if (name != null ? !name.equals(pingTargetData.name) : pingTargetData.name != null) return false;
253         if (pingUrl != null ? !pingUrl.equals(pingTargetData.pingUrl) : pingTargetData.pingUrl != null) return false;
254         if (website != null ? !website.equals(pingTargetData.website) : pingTargetData.website != null) return false;
255
256         return true;
257     }
258
259     /**
260      * Determine if the current user has rights to save the current instance.
261      *
262      * @return true if the user has rights to save the current instance, false otherwise.
263      * @throws RollerException
264      */

265     public boolean canSave() throws RollerException
266     {
267         Roller roller = RollerFactory.getRoller();
268         UserData user = roller.getUser();
269         // This is more verbose but easier to debug than returning the value of the boolean expression
270
if (user.equals(UserData.SYSTEM_USER))
271         {
272             return true;
273         }
274         if (website == null && user.hasRole("admin"))
275         {
276             return true;
277         }
278         if (website != null && website.getUser().equals(user))
279         {
280             return true;
281         }
282         return false;
283     }
284
285     /**
286      * Remove the object.
287      *
288      * @throws RollerException
289      * @see org.roller.pojos.PersistentObject#remove()
290      */

291     public void remove() throws RollerException
292     {
293         // First remove ping queue entries and auto ping configurations that use this target.
294
PingQueueManager pingQueueMgr = RollerFactory.getRoller().getPingQueueManager();
295         pingQueueMgr.removeQueueEntriesByPingTarget(this);
296         AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
297         List JavaDoc autopings = autoPingMgr.getAutoPingsByTarget(this);
298         autoPingMgr.removeAutoPings(autopings);
299         super.remove();
300     }
301
302     /**
303      * Generate a string form of the object appropriate for logging or debugging.
304      *
305      * @return a string form of the object appropriate for logging or debugging.
306      * @see java.lang.Object#toString()
307      */

308     public String JavaDoc toString()
309     {
310         return "PingTargetData{" +
311             "id='" + id + "'" +
312             ", name='" + name + "'" +
313             ", pingUrl='" + pingUrl + "'" +
314             ", website= " + (website == null ? "null" : "{id='" + website.getId() + "', user='" + website.getUser().getUserName() + "'} ") +
315             ", conditionCode=" + conditionCode +
316             ", lastSuccess=" + lastSuccess +
317             "}";
318     }
319 }
320
Popular Tags