Skip to main content
summaryrefslogtreecommitdiffstats
blob: c97426bcdb3f509c1d8af797eab55bffee93bc24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*******************************************************************************
 * Copyright (c) 2009, 2011 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.core.context.persistence.customization;

import java.io.Serializable;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;

/**
 *  Entity
 */
public class Entity extends AbstractModel implements Cloneable, Serializable
{
	private String name;
	private Customization parent;

	public static final String DESCRIPTOR_CUSTOMIZER_PROPERTY = Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY;

	// ********** EclipseLink properties **********
	private String descriptorCustomizer;

	private static final long serialVersionUID = 1L;

	// ********** constructors **********
	public Entity(Customization parent, String name) {
		this(parent);
		this.initialize(name);
	}

	private Entity(Customization parent) {
		this.parent = parent;
	}
	
	private void initialize(String name) {
		if(StringTools.stringIsEmpty(name)) {
			throw new IllegalArgumentException();
		}
		this.name = name;
	}

	// ********** behaviors **********
	@Override
	public boolean equals(Object o) {
		if ( ! (o instanceof Entity)) {
			return false;
		}
		Entity customizer = (Entity) o;
		return (
			(this.descriptorCustomizer == null ?
				customizer.descriptorCustomizer == null : 
				this.descriptorCustomizer.equals(customizer.descriptorCustomizer)));
	}
	
	@Override
	public int hashCode() {
		return (this.descriptorCustomizer == null) ? 0 : this.descriptorCustomizer.hashCode();
	}
	
	 @Override
	 public Entity clone() {
		 try {
			 return (Entity)super.clone();
		 }
		 catch (CloneNotSupportedException ex) {
			 throw new InternalError();
		 }
	 }

	public boolean isEmpty() {
		return this.descriptorCustomizer == null;
	}
	
	public boolean entityNameIsValid() {
		return ! StringTools.stringIsEmpty(this.name);
	}

	public Customization getParent() {
		return this.parent;
	}

	// ********** getter/setter **********
	public String getName() {
		return this.name;
	}

	public String getDescriptorCustomizer() {
		return this.descriptorCustomizer;
	}

	public void setDescriptorCustomizer(String descriptorCustomizer) {
		String old = this.descriptorCustomizer;
		this.descriptorCustomizer = descriptorCustomizer;
		this.firePropertyChanged(DESCRIPTOR_CUSTOMIZER_PROPERTY, old, descriptorCustomizer);
	}

	@Override
	public void toString(StringBuilder sb) {
		sb.append("name: "); //$NON-NLS-1$
		sb.append(this.name);
		sb.append(", descriptorCustomizer: "); //$NON-NLS-1$
		sb.append(this.descriptorCustomizer);
	}
}

Back to the top