KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.pojos;
20
21 import java.io.Serializable JavaDoc;
22 import java.sql.Timestamp JavaDoc;
23
24
25 /**
26  * Ping target. Each instance represents a possible target of a weblog update ping that we send. Ping targets are
27  * either common (defined centrally by an administrator and used by any website), or custom (defined by the user of a
28  * specific website) for update pings issued for that website.
29  *
30  * @author <a HREF="mailto:anil@busybuddha.org">Anil Gangolli</a>
31  * @ejb:bean name="PingTargetData"
32  * @struts.form include-all="true"
33  * @hibernate.class lazy="false" table="pingtarget"
34  * @hibernate.cache usage="read-write"
35  */

36 public class PingTargetData extends PersistentObject implements Serializable JavaDoc {
37
38     public static final long serialVersionUID = -6354583200913127874L;
39
40     public static final int CONDITION_OK = 0; // last use (after possible retrials) was successful
41
public static final int CONDITION_FAILING = 1; // last use failed after retrials
42
public static final int CONDITION_DISABLED = 2; // disabled by failure policy after failures - editing resets
43

44     private String JavaDoc id = null;
45     private String JavaDoc name = null;
46     private String JavaDoc pingUrl = null;
47     private WebsiteData website = null;
48     private int conditionCode = -1;
49     private Timestamp JavaDoc lastSuccess = null;
50     private boolean autoEnabled = false;
51
52
53     /**
54      * Default empty constructor.
55      */

56     public PingTargetData() {
57     }
58
59
60     /**
61      * Constructor.
62      *
63      * @param id the id (primary key) of this target
64      * @param name the descriptive name of this target
65      * @param pingUrl the URL to which to send the ping
66      * @param website the website (on this server) for which this is a custom ping target (may be null)
67      */

68     public PingTargetData(String JavaDoc id, String JavaDoc name, String JavaDoc pingUrl, WebsiteData website, boolean autoEnable) {
69         this.id = id;
70         this.name = name;
71         this.pingUrl = pingUrl;
72         this.website = website;
73         this.conditionCode = CONDITION_OK;
74         this.lastSuccess = null;
75         this.autoEnabled = autoEnable;
76     }
77
78
79     /**
80      * Setter needed by RollerImpl.storePersistentObject()
81      */

82     public void setData(PersistentObject vo) {
83         PingTargetData other = (PingTargetData) vo;
84
85         id = other.getId();
86         name = other.getName();
87         pingUrl = other.getPingUrl();
88         website = other.getWebsite();
89         conditionCode = other.getConditionCode();
90         lastSuccess = other.getLastSuccess();
91         autoEnabled = other.isAutoEnabled();
92     }
93
94
95     /**
96      * Get the unique id of this ping target.
97      *
98      * @return the unique id of this ping target.
99      * @struts.validator type="required" msgkey="errors.required"
100      * @ejb:persistent-field
101      * @hibernate.id column="id" generator-class="uuid.hex" unsaved-value="null"
102      */

103     public java.lang.String JavaDoc getId() {
104         return this.id;
105     }
106
107
108     /**
109      * Set the unique id of this ping target
110      *
111      * @param id
112      * @ejb:persistent-field
113      */

114     public void setId(java.lang.String JavaDoc id) {
115         this.id = id;
116     }
117
118
119     /**
120      * get the name of this ping target. This is a name assigned by the administrator or a user (for custom) targets.
121      * It is deescriptive and is not necessarily unique.
122      *
123      * @return the name of this ping target
124      * @ejb:persistent-field
125      * @hibernate.property column="name" non-null="true"
126      */

127     public java.lang.String JavaDoc getName() {
128         return this.name;
129     }
130
131
132     /**
133      * Set the name of this ping target.
134      *
135      * @param name the name of this ping target
136      * @ejb:persistent-field
137      */

138     public void setName(java.lang.String JavaDoc name) {
139         this.name = name;
140     }
141
142
143     /**
144      * Get the URL to ping.
145      *
146      * @return the URL to ping.
147      * @ejb:persistent-field
148      * @hibernate.property column="pingurl" non-null="true"
149      */

150     public String JavaDoc getPingUrl() {
151         return pingUrl;
152     }
153
154
155     /**
156      * Set the URL to ping.
157      *
158      * @param pingUrl
159      * @ejb:persistent-field
160      */

161     public void setPingUrl(String JavaDoc pingUrl) {
162         this.pingUrl = pingUrl;
163     }
164
165
166     /**
167      * Get the website (on this server) for which this ping target is a custom target. This may be null, indicating
168      * that it is a common ping target, not a custom one.
169      *
170      * @return the website for which this ping target is a custom target, or null if this ping target is not a custom
171      * target.
172      * @ejb:persistent-field
173      * @hibernate.many-to-one column="websiteid" cascade="none" not-null="false"
174      */

175     public WebsiteData getWebsite() {
176         return website;
177     }
178
179
180     /**
181      * Set the website (on this server) for which this ping target is a custom target.
182      *
183      * @param website the website for which this ping target is a custom target, or null if this ping target is not a
184      * custom target
185      * @ejb:persistent-field
186      */

187     public void setWebsite(WebsiteData website) {
188         this.website = website;
189     }
190
191
192     /**
193      * Get the condition code value. This code, in combination with the last success timestamp, provides a status
194      * indicator on the ping target based on its usage by the ping queue processor. It can be used to implement a
195      * failure-based disabling policy.
196      *
197      * @return one of the condition codes {@link #CONDITION_OK}, {@link #CONDITION_FAILING}, {@link
198      * #CONDITION_DISABLED}.
199      * @ejb:persistent-field
200      * @hibernate.property column="conditioncode" not-null="true"
201      */

202     public int getConditionCode() {
203         return conditionCode;
204     }
205
206
207     /**
208      * Set the condition code value.
209      *
210      * @param conditionCode the condition code value to set
211      * @ejb:persistent-field
212      */

213     public void setConditionCode(int conditionCode) {
214         this.conditionCode = conditionCode;
215     }
216
217
218     /**
219      * Get the timestamp of the last successful ping (UTC/GMT).
220      *
221      * @return the timestamp of the last successful ping; <code>null</code> if the target has not yet been used.
222      * @ejb:persistent-field
223      * @hibernate.property column="lastsuccess" not-null="false"
224      */

225     public Timestamp JavaDoc getLastSuccess() {
226         return lastSuccess;
227     }
228
229
230     /**
231      * Set the timestamp of the last successful ping.
232      *
233      * @param lastSuccess the timestamp of the last successful ping.
234      * @ejb:persistent-field
235      */

236     public void setLastSuccess(Timestamp JavaDoc lastSuccess) {
237         this.lastSuccess = lastSuccess;
238     }
239
240
241     /**
242      * Is this ping target enabled by default for new weblogs?
243      *
244      * @return true if ping target is auto enabled. false otherwise.
245      * @ejb:persistent-field
246      * @hibernate.property column="autoenabled" not-null="true"
247      */

248     public boolean isAutoEnabled() {
249         return autoEnabled;
250     }
251
252
253     /**
254      * Set the auto enabled status for this ping target. This field only
255      * applies for common ping targets.
256      *
257      * @param autoEnabled true if the ping target should be auto enabled.
258      * @ejb:persistent-field
259      */

260     public void setAutoEnabled(boolean autoEnabled) {
261         this.autoEnabled = autoEnabled;
262     }
263
264
265     /**
266      * @see java.lang.Object#hashCode()
267      */

268     public int hashCode() {
269         return id.hashCode();
270     }
271
272
273     /**
274      * @see java.lang.Object#equals(Object o)
275      */

276     public boolean equals(Object JavaDoc o) {
277         if (this == o) return true;
278         if (!(o instanceof PingTargetData)) return false;
279
280         final PingTargetData pingTargetData = (PingTargetData) o;
281
282         if (conditionCode != pingTargetData.getConditionCode()) return false;
283         if (id != null ? !id.equals(pingTargetData.getId()) : pingTargetData.getId() != null) return false;
284         if (lastSuccess != null ? !lastSuccess.equals(pingTargetData.getLastSuccess()) : pingTargetData.getLastSuccess() != null)
285         {
286             return false;
287         }
288         if (name != null ? !name.equals(pingTargetData.getName()) : pingTargetData.getName() != null) return false;
289         if (pingUrl != null ? !pingUrl.equals(pingTargetData.getPingUrl()) : pingTargetData.getPingUrl() != null) {
290             return false;
291         }
292         if (website != null ? !website.equals(pingTargetData.getWebsite()) : pingTargetData.getWebsite() != null) {
293             return false;
294         }
295
296         return true;
297     }
298
299
300     /**
301      * Generate a string form of the object appropriate for logging or debugging.
302      *
303      * @return a string form of the object appropriate for logging or debugging.
304      * @see java.lang.Object#toString()
305      */

306     public String JavaDoc toString() {
307         return "PingTargetData{" + "id='" + id + "'" + ", name='" + name + "'" + ", pingUrl='" + pingUrl + "'" + ", website= " + (website == null ? "null" : "{id='" + website.getId() + "'} ") + ", conditionCode=" + conditionCode + ", lastSuccess=" + lastSuccess + "}";
308     }
309
310 }
311
Popular Tags