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.model.schema.registries;
21
22
23 import java.util.Arrays;
24 import java.util.HashSet;
25 import java.util.Set;
26
27 import org.apache.directory.api.i18n.I18n;
28 import org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper;
29 import org.apache.directory.api.util.StringConstants;
30
31
32
33
34
35
36
37 public class DefaultSchema implements Schema
38 {
39
40 protected static final String DEFAULT_OWNER = "uid=admin,ou=system";
41
42
43 protected boolean disabled;
44
45
46 protected String[] dependencies;
47
48
49 protected String owner;
50
51
52 protected String name;
53
54
55 protected Set<SchemaObjectWrapper> content;
56
57
58
59
60
61
62
63 public DefaultSchema( String name )
64 {
65 this( name, null, null, false );
66 }
67
68
69
70
71
72
73
74
75 public DefaultSchema( String name, String owner )
76 {
77 this( name, owner, null, false );
78 }
79
80
81
82
83
84
85
86
87
88 public DefaultSchema( String name, String owner, String[] dependencies )
89 {
90 this( name, owner, dependencies, false );
91 }
92
93
94
95
96
97
98
99
100
101
102 public DefaultSchema( String name, String owner, String[] dependencies, boolean disabled )
103 {
104 if ( name == null )
105 {
106 throw new IllegalArgumentException( I18n.err( I18n.ERR_04266 ) );
107 }
108
109 this.name = name;
110
111 if ( owner != null )
112 {
113 this.owner = owner;
114 }
115 else
116 {
117 this.owner = DEFAULT_OWNER;
118 }
119
120 if ( dependencies != null )
121 {
122 this.dependencies = new String[dependencies.length];
123 System.arraycopy( dependencies, 0, this.dependencies, 0, dependencies.length );
124 }
125 else
126 {
127 this.dependencies = StringConstants.EMPTY_STRINGS;
128 }
129
130 this.disabled = disabled;
131
132 content = new HashSet<SchemaObjectWrapper>();
133 }
134
135
136
137
138
139 public String[] getDependencies()
140 {
141 String[] copy = new String[dependencies.length];
142 System.arraycopy( dependencies, 0, copy, 0, dependencies.length );
143 return copy;
144 }
145
146
147
148
149
150 public void addDependencies( String... dependenciesToAdd )
151 {
152 if ( dependenciesToAdd != null )
153 {
154 int start = 0;
155
156 if ( dependencies == null )
157 {
158 dependencies = new String[dependenciesToAdd.length];
159 }
160 else
161 {
162 String[] tempDependencies = new String[dependencies.length + dependenciesToAdd.length];
163 System.arraycopy( dependencies, 0, tempDependencies, 0, dependencies.length );
164 start = dependencies.length;
165 dependencies = tempDependencies;
166 }
167
168 System.arraycopy( dependenciesToAdd, 0, dependencies, start, dependenciesToAdd.length );
169 }
170 }
171
172
173
174
175
176 public String getOwner()
177 {
178 return owner;
179 }
180
181
182
183
184
185 public String getSchemaName()
186 {
187 return name;
188 }
189
190
191
192
193
194 public boolean isDisabled()
195 {
196 return disabled;
197 }
198
199
200
201
202
203 public boolean isEnabled()
204 {
205 return !disabled;
206 }
207
208
209
210
211
212 public void disable()
213 {
214 this.disabled = true;
215 }
216
217
218
219
220
221 public void enable()
222 {
223 this.disabled = false;
224 }
225
226
227
228
229
230 public Set<SchemaObjectWrapper> getContent()
231 {
232 return content;
233 }
234
235
236
237
238
239 @Override
240 public String toString()
241 {
242 StringBuilder sb = new StringBuilder( "\tSchema Name: " );
243 sb.append( name );
244 sb.append( "\n\t\tDisabled: " );
245 sb.append( disabled );
246 sb.append( "\n\t\tOwner: " );
247 sb.append( owner );
248 sb.append( "\n\t\tDependencies: " );
249 sb.append( Arrays.toString( dependencies ) );
250
251
252 return sb.toString();
253 }
254 }