1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.schema.converter;
21
22
23 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
24 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
25 import org.apache.directory.api.ldap.model.entry.Entry;
26 import org.apache.directory.api.ldap.model.exception.LdapException;
27 import org.apache.directory.api.ldap.model.ldif.LdifUtils;
28 import org.apache.directory.api.ldap.model.name.Rdn;
29 import org.apache.directory.api.ldap.model.schema.UsageEnum;
30
31
32
33
34
35
36
37
38 public class AttributeTypeHolder extends SchemaElementImpl
39 {
40
41 private boolean singleValue = false;
42
43
44 private boolean collective = false;
45
46
47 private boolean noUserModification = false;
48
49
50 private String superior;
51
52
53 private String equality;
54
55
56 private String ordering;
57
58
59 private String substr;
60
61
62 private String syntax;
63
64
65 private long oidLen = -1;
66
67
68 private UsageEnum usage = UsageEnum.USER_APPLICATIONS;
69
70
71
72
73
74
75
76 public AttributeTypeHolder( String oid )
77 {
78 this.oid = oid;
79 }
80
81
82
83
84
85
86
87 public boolean isSingleValue()
88 {
89 return singleValue;
90 }
91
92
93
94
95
96
97
98 public void setSingleValue( boolean singleValue )
99 {
100 this.singleValue = singleValue;
101 }
102
103
104
105
106
107
108
109 public boolean isCollective()
110 {
111 return collective;
112 }
113
114
115
116
117
118
119
120 public void setCollective( boolean collective )
121 {
122 this.collective = collective;
123 }
124
125
126
127
128
129
130
131 public boolean isNoUserModification()
132 {
133 return noUserModification;
134 }
135
136
137
138
139
140
141
142 public void setNoUserModification( boolean noUserModification )
143 {
144 this.noUserModification = noUserModification;
145 }
146
147
148
149
150
151
152
153 public String getSuperior()
154 {
155 return superior;
156 }
157
158
159
160
161
162
163
164 public void setSuperior( String superior )
165 {
166 this.superior = superior;
167 }
168
169
170
171
172
173
174
175 public String getEquality()
176 {
177 return equality;
178 }
179
180
181
182
183
184
185
186 public void setEquality( String equality )
187 {
188 this.equality = equality;
189 }
190
191
192
193
194
195
196
197 public String getOrdering()
198 {
199 return ordering;
200 }
201
202
203
204
205
206
207
208 public void setOrdering( String ordering )
209 {
210 this.ordering = ordering;
211 }
212
213
214
215
216
217
218
219 public String getSubstr()
220 {
221 return substr;
222 }
223
224
225
226
227
228
229
230 public void setSubstr( String substr )
231 {
232 this.substr = substr;
233 }
234
235
236
237
238
239
240
241 public String getSyntax()
242 {
243 return syntax;
244 }
245
246
247
248
249
250
251
252 public void setSyntax( String syntax )
253 {
254 this.syntax = syntax;
255 }
256
257
258
259
260
261
262
263 public UsageEnum getUsage()
264 {
265 return usage;
266 }
267
268
269
270
271
272
273
274 public void setUsage( UsageEnum usage )
275 {
276 this.usage = usage;
277 }
278
279
280
281
282
283
284
285 public long getOidLen()
286 {
287 return oidLen;
288 }
289
290
291
292
293
294
295
296 public void setOidLen( long oidLen )
297 {
298 this.oidLen = oidLen;
299 }
300
301
302
303
304
305
306
307
308
309 @Override
310 public String toLdif( String schemaName ) throws LdapException
311 {
312 StringBuilder sb = new StringBuilder();
313
314 sb.append( schemaToLdif( schemaName, "metaAttributeType" ) );
315
316
317 if ( superior != null )
318 {
319 sb.append( "m-supAttributeType: " ).append( superior ).append( '\n' );
320 }
321
322
323 if ( equality != null )
324 {
325 sb.append( "m-equality: " ).append( equality ).append( '\n' );
326 }
327
328
329 if ( ordering != null )
330 {
331 sb.append( "m-ordering: " ).append( ordering ).append( '\n' );
332 }
333
334
335 if ( substr != null )
336 {
337 sb.append( "m-substr: " ).append( substr ).append( '\n' );
338 }
339
340
341 if ( syntax != null )
342 {
343 sb.append( "m-syntax: " ).append( syntax ).append( '\n' );
344
345 if ( oidLen != -1 )
346 {
347 sb.append( "m-length: " ).append( oidLen ).append( '\n' );
348 }
349 }
350
351
352 if ( singleValue )
353 {
354 sb.append( "m-singleValue: TRUE\n" );
355 }
356
357
358 if ( collective )
359 {
360 sb.append( "m-collective: TRUE\n" );
361 }
362
363
364 if ( noUserModification )
365 {
366 sb.append( "m-noUserModification: TRUE\n" );
367 }
368
369
370 if ( usage != UsageEnum.USER_APPLICATIONS )
371 {
372 sb.append( "m-usage: " ).append( usage.toString() ).append( '\n' );
373 }
374
375
376 if ( extensions.size() != 0 )
377 {
378 extensionsToLdif( "m-extensionAttributeType" );
379 }
380
381 return sb.toString();
382
383 }
384
385
386
387
388
389 @Override
390 public String toString()
391 {
392 return getOid();
393 }
394
395
396
397
398
399
400
401
402 @Override
403 public String dnToLdif( String schemaName ) throws LdapException
404 {
405 StringBuilder sb = new StringBuilder();
406
407 String dn = "m-oid=" + oid + ", " + SchemaConstants.ATTRIBUTE_TYPES_PATH + ", cn="
408 + Rdn.escapeValue( schemaName ) + ", ou=schema";
409
410
411 Entry entry = new DefaultEntry( dn );
412 sb.append( LdifUtils.convertToLdif( entry ) );
413
414 return sb.toString();
415 }
416 }