Source code: com/xpn/xwiki/objects/BaseElement.java
1 /**
2 * ===================================================================
3 *
4 * Copyright (c) 2003 Ludovic Dubost, All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details, published at
15 * http://www.gnu.org/copyleft/gpl.html or in gpl.txt in the
16 * root folder of this distribution.
17
18 * Created by
19 * User: Ludovic Dubost
20 * Date: 25 déc. 2003
21 * Time: 13:32:37
22 */
23 package com.xpn.xwiki.objects;
24
25
26
27 public abstract class BaseElement extends Object {
28 private String name;
29 private String prettyName;
30
31 public String getName() {
32 return name;
33 }
34
35 public void setName(String name) {
36 this.name = name;
37 }
38
39 public String getPrettyName() {
40 return prettyName;
41 }
42
43 public void setPrettyName(String name) {
44 this.prettyName = name;
45 }
46
47 public boolean equals(Object el) {
48 if (el==null)
49 return false;
50
51 BaseElement element = (BaseElement ) el;
52
53 if (element.getName()==null) {
54 if (getName()!=null)
55 return false;
56 } else if (!element.getName().equals(getName()))
57 return false;
58
59 if (element.getPrettyName()==null) {
60 if (getPrettyName()!=null)
61 return false;
62 } else if (!element.getPrettyName().equals(getPrettyName()))
63 return false;
64
65 if (element.getClass()==null) {
66 if (getClass()!=null)
67 return false;
68 } else if (!(element.getClass().equals(this.getClass())))
69 return false;
70
71 return true;
72 }
73
74 public Object clone()
75 {
76 BaseElement element = null;
77 try {
78 element = (BaseElement) getClass().newInstance();
79 } catch (Exception e) {
80 // This should not happen
81 }
82 element.setName(getName());
83 element.setPrettyName(getPrettyName());
84 return element;
85 }
86
87 }