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 java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
27 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
28 import org.apache.directory.api.ldap.model.entry.Entry;
29 import org.apache.directory.api.ldap.model.exception.LdapException;
30 import org.apache.directory.api.ldap.model.ldif.LdifUtils;
31 import org.apache.directory.api.ldap.model.name.Rdn;
32 import org.apache.directory.api.ldap.model.schema.ObjectClassTypeEnum;
33
34
35
36
37
38
39
40
41 public class ObjectClassHolder extends SchemaElementImpl
42 {
43
44 private List<String> superiors = new ArrayList<>();
45
46
47 private List<String> must = new ArrayList<>();
48
49
50 private List<String> may = new ArrayList<>();
51
52
53 private ObjectClassTypeEnum classType = ObjectClassTypeEnum.STRUCTURAL;
54
55
56
57
58
59
60
61 public ObjectClassHolder( String oid )
62 {
63 this.oid = oid;
64 }
65
66
67
68
69
70
71 public List<String> getSuperiors()
72 {
73 return superiors;
74 }
75
76
77
78
79
80
81 public void setSuperiors( List<String> superiors )
82 {
83 this.superiors = superiors;
84 }
85
86
87
88
89
90 public List<String> getMust()
91 {
92 return must;
93 }
94
95
96
97
98
99
100 public void setMust( List<String> must )
101 {
102 this.must = must;
103 }
104
105
106
107
108
109 public List<String> getMay()
110 {
111 return may;
112 }
113
114
115
116
117
118
119 public void setMay( List<String> may )
120 {
121 this.may = may;
122 }
123
124
125
126
127
128 public ObjectClassTypeEnum getClassType()
129 {
130 return classType;
131 }
132
133
134
135
136
137
138 public void setClassType( ObjectClassTypeEnum classType )
139 {
140 this.classType = classType;
141 }
142
143
144
145
146
147
148
149
150
151 @Override
152 public String toLdif( String schemaName ) throws LdapException
153 {
154 StringBuilder sb = new StringBuilder();
155
156 sb.append( schemaToLdif( schemaName, "metaObjectClass" ) );
157
158
159 if ( !superiors.isEmpty() )
160 {
161 for ( String superior : superiors )
162 {
163 sb.append( "m-supObjectClass: " ).append( superior ).append( '\n' );
164 }
165 }
166
167
168 if ( classType != ObjectClassTypeEnum.STRUCTURAL )
169 {
170 sb.append( "m-typeObjectClass: " ).append( classType ).append( '\n' );
171 }
172
173
174 if ( !must.isEmpty() )
175 {
176 for ( String attr : must )
177 {
178 sb.append( "m-must: " ).append( attr ).append( '\n' );
179 }
180 }
181
182
183 if ( !may.isEmpty() )
184 {
185 for ( String attr : may )
186 {
187 sb.append( "m-may: " ).append( attr ).append( '\n' );
188 }
189 }
190
191
192 if ( !extensions.isEmpty() )
193 {
194 extensionsToLdif( "m-extensionObjectClass" );
195 }
196
197 return sb.toString();
198 }
199
200
201
202
203
204 @Override
205 public String toString()
206 {
207 return getOid();
208 }
209
210
211
212
213
214
215
216
217 @Override
218 public String dnToLdif( String schemaName ) throws LdapException
219 {
220 StringBuilder sb = new StringBuilder();
221
222 String dn = "m-oid=" + oid + ", " + SchemaConstants.OBJECT_CLASSES_PATH + ", cn="
223 + Rdn.escapeValue( schemaName ) + ", ou=schema";
224
225
226 Entry entry = new DefaultEntry( dn );
227 sb.append( LdifUtils.convertToLdif( entry ) );
228
229 return sb.toString();
230 }
231 }