1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.web.jcr.rest.client.domain;
25
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.List;
29 import java.util.Properties;
30
31 import net.jcip.annotations.Immutable;
32
33 import org.modeshape.common.util.HashCode;
34 import org.modeshape.web.jcr.rest.client.RestClientI18n;
35
36
37
38
39 @Immutable
40 public class NodeType implements IModeShapeObject {
41
42
43
44
45
46
47
48
49 private final String name;
50
51
52
53
54 private final Workspace workspace;
55
56 private Properties properties = null;
57
58 private NodeType parentNodeType = null;
59
60 private List<NodeType> childrenNodeType = null;
61
62 private List<NodeType> propertyDefinitons = null;
63
64 private List<NodeType> childNodeDefinitons = null;
65
66
67
68
69
70
71
72
73
74
75
76
77
78 public NodeType( String name,
79 Workspace workspace,
80 Properties properties) {
81 assert name != null;
82 assert workspace != null;
83 this.name = name;
84 this.workspace = workspace;
85 this.properties = (properties == null ? new Properties() : properties);
86
87 }
88
89
90
91
92
93
94
95
96
97
98 @Override
99 public boolean equals( Object obj ) {
100 if (this == obj) return true;
101 if ((obj == null) || (getClass() != obj.getClass())) return false;
102
103 NodeType otherNodeType = (NodeType)obj;
104 return (this.name.equals(otherNodeType.name) && this.workspace.equals(otherNodeType.workspace));
105 }
106
107
108
109
110
111
112 public String getName() {
113 return this.name;
114 }
115
116
117
118
119 public Workspace getWorkspace() {
120 return this.workspace;
121 }
122
123
124
125
126 public Properties getProperties() {
127 return this.properties;
128 }
129
130 public void setProperties(Properties properties ){
131 this.properties = properties;
132 }
133
134 public String getProperty(String key) {
135 return this.properties.getProperty(key);
136 }
137
138 @SuppressWarnings("unchecked")
139 public List<NodeType> getChildren() {
140 return (List<NodeType>) (this.childrenNodeType != null ? this.childrenNodeType : Collections.emptyList());
141 }
142
143 public void addChildNodeType(NodeType childNodeType) {
144 if (this.childrenNodeType == null) this.childrenNodeType = new ArrayList<NodeType>();
145 this.childrenNodeType.add(childNodeType);
146
147 childNodeType.setParentNodeType(this);
148 }
149
150 public void addPropertyDefinitionNodeType(NodeType propertyDefinitionNodeType) {
151 if (this.propertyDefinitons == null) this.propertyDefinitons = new ArrayList<NodeType>();
152 propertyDefinitons.add(propertyDefinitionNodeType);
153
154 propertyDefinitionNodeType.setParentNodeType(this);
155 }
156
157 public void addChildNodeDefinitionNodeType(NodeType childNodeDefinitionNodeType) {
158 if (this.childNodeDefinitons == null) this.childNodeDefinitons = new ArrayList<NodeType>();
159 childNodeDefinitons.add(childNodeDefinitionNodeType);
160
161 childNodeDefinitionNodeType.setParentNodeType(this);
162 }
163
164 @SuppressWarnings("unchecked")
165 public List<NodeType> getPropertyDefinitions() {
166 return (List<NodeType>) (this.propertyDefinitons != null ? this.propertyDefinitons : Collections.emptyList());
167 }
168
169 @SuppressWarnings("unchecked")
170 public List<NodeType> getChildNodeDefinitions() {
171 return (List<NodeType>) (this.childNodeDefinitons != null ? this.childNodeDefinitons : Collections.emptyList());
172 }
173
174 public NodeType getParentNodeType() {
175 return this.parentNodeType;
176 }
177
178 public void setParentNodeType(NodeType parent) {
179 this.parentNodeType = parent;
180 }
181
182
183
184
185
186
187
188 public String getShortDescription() {
189 return RestClientI18n.nodeTypeShortDescription.text(this.name, this.workspace.getServer());
190 }
191
192
193
194
195
196
197 @Override
198 public int hashCode() {
199 return HashCode.compute(this.name, this.workspace);
200 }
201
202
203
204
205
206
207 @Override
208 public String toString() {
209 return getShortDescription();
210 }
211
212 }