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.jcr;
25
26 import javax.jcr.nodetype.ConstraintViolationException;
27 import javax.jcr.nodetype.NodeType;
28 import net.jcip.annotations.NotThreadSafe;
29 import org.modeshape.graph.ExecutionContext;
30 import org.modeshape.graph.property.Name;
31 import org.modeshape.graph.property.NameFactory;
32 import org.modeshape.graph.property.NamespaceRegistry;
33 import org.modeshape.graph.property.ValueFormatException;
34 import org.modeshape.jcr.nodetype.NodeDefinitionTemplate;
35
36
37
38
39 @NotThreadSafe
40 class JcrNodeDefinitionTemplate extends JcrItemDefinitionTemplate implements NodeDefinitionTemplate {
41
42 private Name defaultPrimaryType;
43 private Name[] requiredPrimaryTypes;
44 private boolean allowSameNameSiblings;
45
46 JcrNodeDefinitionTemplate( ExecutionContext context ) {
47 super(context);
48 }
49
50 JcrNodeDefinitionTemplate( JcrNodeDefinitionTemplate original,
51 ExecutionContext context ) {
52 super(original, context);
53 this.defaultPrimaryType = original.defaultPrimaryType;
54 this.requiredPrimaryTypes = original.requiredPrimaryTypes;
55 this.allowSameNameSiblings = original.allowSameNameSiblings;
56 JcrItemDefinitionTemplate.registerMissingNamespaces(original.getContext(), context, this.defaultPrimaryType);
57 JcrItemDefinitionTemplate.registerMissingNamespaces(original.getContext(), context, this.requiredPrimaryTypes);
58 }
59
60 JcrNodeDefinitionTemplate with( ExecutionContext context ) {
61 return context == super.getContext() ? this : new JcrNodeDefinitionTemplate(this, context);
62 }
63
64
65
66
67
68
69
70
71
72 public void setDefaultPrimaryType( String defaultPrimaryType ) throws ConstraintViolationException {
73 setDefaultPrimaryTypeName(defaultPrimaryType);
74 }
75
76
77
78
79
80
81
82 public void setDefaultPrimaryTypeName( String defaultPrimaryType ) throws ConstraintViolationException {
83 if (defaultPrimaryType == null || defaultPrimaryType.trim().length() == 0) {
84 this.defaultPrimaryType = null;
85 } else {
86 try {
87 this.defaultPrimaryType = getContext().getValueFactories().getNameFactory().create(defaultPrimaryType);
88 } catch (ValueFormatException vfe) {
89 throw new ConstraintViolationException(vfe);
90 }
91 }
92 }
93
94
95
96
97
98
99
100 @SuppressWarnings( "dep-ann" )
101 public void setRequiredPrimaryTypes( String[] requiredPrimaryTypes ) throws ConstraintViolationException {
102 setRequiredPrimaryTypeNames(requiredPrimaryTypes);
103 }
104
105
106
107
108
109
110 public void setRequiredPrimaryTypeNames( String[] requiredPrimaryTypes ) throws ConstraintViolationException {
111 if (requiredPrimaryTypes == null) {
112 throw new ConstraintViolationException(JcrI18n.badNodeTypeName.text("requiredPrimaryTypes"));
113 }
114
115 NameFactory nameFactory = getContext().getValueFactories().getNameFactory();
116 Name[] rpts = new Name[requiredPrimaryTypes.length];
117 for (int i = 0; i < requiredPrimaryTypes.length; i++) {
118 try {
119 rpts[i] = nameFactory.create(requiredPrimaryTypes[i]);
120 } catch (ValueFormatException vfe) {
121 throw new ConstraintViolationException(vfe);
122 }
123 }
124
125 this.requiredPrimaryTypes = rpts;
126 }
127
128
129
130
131
132
133 public void setSameNameSiblings( boolean allowSameNameSiblings ) {
134 this.allowSameNameSiblings = allowSameNameSiblings;
135 }
136
137
138
139
140
141
142 public boolean allowsSameNameSiblings() {
143 return allowSameNameSiblings;
144 }
145
146
147
148
149
150
151 public NodeType getDefaultPrimaryType() {
152 return null;
153 }
154
155 public String getDefaultPrimaryTypeName() {
156 if (defaultPrimaryType == null) return null;
157 return defaultPrimaryType.getString(getContext().getNamespaceRegistry());
158 }
159
160
161
162
163
164
165 public NodeType[] getRequiredPrimaryTypes() {
166
167 return null;
168 }
169
170
171
172
173
174
175 public String[] getRequiredPrimaryTypeNames() {
176 if (requiredPrimaryTypes == null) return null;
177
178 NamespaceRegistry registry = getContext().getNamespaceRegistry();
179 String[] rpts = new String[requiredPrimaryTypes.length];
180 for (int i = 0; i < requiredPrimaryTypes.length; i++) {
181 rpts[i] = requiredPrimaryTypes[i].getString(registry);
182 }
183 return rpts;
184 }
185
186
187
188
189
190
191 @Override
192 public void setName( String name ) throws ConstraintViolationException {
193 super.setName(name);
194 }
195
196
197
198
199
200
201 @Override
202 public void setAutoCreated( boolean autoCreated ) {
203 super.setAutoCreated(autoCreated);
204 }
205
206
207
208
209
210
211 @Override
212 public void setMandatory( boolean mandatory ) {
213 super.setMandatory(mandatory);
214 }
215
216
217
218
219
220
221 @Override
222 public void setOnParentVersion( int onParentVersion ) {
223 super.setOnParentVersion(onParentVersion);
224 }
225
226
227
228
229
230
231 @Override
232 public void setProtected( boolean isProtected ) {
233 super.setProtected(isProtected);
234 }
235 }