KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.commons.lang.builder.EqualsBuilder;
23 import org.apache.commons.lang.builder.ToStringBuilder;
24 import org.apache.commons.lang.builder.ToStringStyle;
25 import org.apache.roller.RollerException;
26
27
28 /**
29  * Base class for all of Roller's persistent objects.
30  */

31 public abstract class PersistentObject implements Serializable JavaDoc {
32     
33     
34     /**
35      * All persistent objects require an identifier.
36      */

37     public abstract String JavaDoc getId();
38     
39     
40     public abstract void setId( String JavaDoc id );
41     
42     
43     /**
44      * Load data based on data from another object.
45      */

46     public abstract void setData(PersistentObject obj);
47     
48     
49     public boolean equals(Object JavaDoc o) {
50         return EqualsBuilder.reflectionEquals(this, o);
51     }
52     
53     
54     // TODO: how efficient is this?
55
public String JavaDoc toString() {
56         try {
57             // this may throw an exception if called by a thread that
58
return ToStringBuilder.reflectionToString(
59                     this, ToStringStyle.MULTI_LINE_STYLE);
60         } catch (Throwable JavaDoc e) {
61             // alternative toString() implementation used in case of exception
62
return getClass().getName() + ":" + getId();
63         }
64     }
65     
66 }
67
68
Popular Tags