1 /******************************************************************************
3 * Copyright (c) 2003 Novell Inc. www.novell.com
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 *******************************************************************************/
24 // Novell.Directory.Ldap.LdapAttributeSchema.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
33 using LdapObjectClassSchema = Novell.Directory.Ldap.LdapObjectClassSchema;
34 using LdapAttributeSchema = Novell.Directory.Ldap.LdapAttributeSchema;
36 namespace Novell.Directory.Ldap.Utilclass
39 public class SchemaParser
41 private void InitBlock()
43 usage = LdapAttributeSchema.USER_APPLICATIONS;
44 qualifiers = new System.Collections.ArrayList();
46 virtual public System.String RawString
55 this.rawString = value;
59 virtual public System.String[] Names
67 virtual public System.Collections.IEnumerator Qualifiers
71 return new ArrayEnumeration(qualifiers.ToArray());
75 virtual public System.String ID
83 virtual public System.String Description
91 virtual public System.String Syntax
99 virtual public System.String Superior
107 virtual public bool Single
115 virtual public bool Obsolete
123 virtual public System.String Equality
131 virtual public System.String Ordering
139 virtual public System.String Substring
147 virtual public bool Collective
155 virtual public bool UserMod
163 virtual public int Usage
171 virtual public int Type
179 virtual public System.String[] Superiors
187 virtual public System.String[] Required
195 virtual public System.String[] Optional
203 virtual public System.String[] Auxiliary
211 virtual public System.String[] Precluded
219 virtual public System.String[] Applies
227 virtual public System.String NameForm
235 virtual public System.String ObjectClass
244 internal System.String rawString;
245 internal System.String[] names = null;
246 internal System.String id;
247 internal System.String description;
248 internal System.String syntax;
249 internal System.String superior;
250 internal System.String nameForm;
251 internal System.String objectClass;
252 internal System.String[] superiors;
253 internal System.String[] required;
254 internal System.String[] optional;
255 internal System.String[] auxiliary;
256 internal System.String[] precluded;
257 internal System.String[] applies;
258 internal bool single = false;
259 internal bool obsolete = false;
260 internal System.String equality;
261 internal System.String ordering;
262 internal System.String substring;
263 internal bool collective = false;
264 internal bool userMod = true;
266 internal int type = - 1;
268 internal System.Collections.ArrayList qualifiers;
270 public SchemaParser(System.String aString)
276 if ((index = aString.IndexOf((System.Char) '\\')) != - 1)
279 * Unless we escape the slash, StreamTokenizer will interpret the
280 * single slash and convert it assuming octal values.
281 * Two successive back slashes are intrepreted as one backslash.
283 System.Text.StringBuilder newString = new System.Text.StringBuilder(aString.Substring(0, (index) - (0)));
284 for (int i = index; i < aString.Length; i++)
286 newString.Append(aString[i]);
287 if (aString[i] == '\\')
289 newString.Append('\\');
292 rawString = newString.ToString();
299 SchemaTokenCreator st2 = new SchemaTokenCreator(new System.IO.StringReader(rawString));
300 st2.OrdinaryCharacter('.');
301 st2.OrdinaryCharacters('0', '9');
302 st2.OrdinaryCharacter('{');
303 st2.OrdinaryCharacter('}');
304 st2.OrdinaryCharacter('_');
305 st2.OrdinaryCharacter(';');
306 st2.WordCharacters('.', '9');
307 st2.WordCharacters('{', '}');
308 st2.WordCharacters('_', '_');
309 st2.WordCharacters(';', ';');
310 //First parse out the OID
313 System.String currName;
314 if ((int)TokenTypes.EOF != st2.nextToken())
316 if (st2.lastttype == '(')
318 if ((int)TokenTypes.WORD == st2.nextToken())
320 id = st2.StringValue;
322 while ((int)TokenTypes.EOF != st2.nextToken())
324 if (st2.lastttype == (int)TokenTypes.WORD)
326 if (st2.StringValue.ToUpper().Equals("NAME".ToUpper()))
328 if (st2.nextToken() == '\'')
330 names = new System.String[1];
331 names[0] = st2.StringValue;
335 if (st2.lastttype == '(')
337 System.Collections.ArrayList nameList = new System.Collections.ArrayList();
338 while (st2.nextToken() == '\'')
340 if ((System.Object) st2.StringValue != null)
342 nameList.Add(st2.StringValue);
345 if (nameList.Count > 0)
347 names = new System.String[nameList.Count];
348 SupportClass.ArrayListSupport.ToArray(nameList, names);
354 if (st2.StringValue.ToUpper().Equals("DESC".ToUpper()))
356 if (st2.nextToken() == '\'')
358 description = st2.StringValue;
362 if (st2.StringValue.ToUpper().Equals("SYNTAX".ToUpper()))
364 result = st2.nextToken();
365 if ((result == (int)TokenTypes.WORD) || (result == '\''))
366 //Test for non-standard schema
368 syntax = st2.StringValue;
372 if (st2.StringValue.ToUpper().Equals("EQUALITY".ToUpper()))
374 if (st2.nextToken() == (int)TokenTypes.WORD)
376 equality = st2.StringValue;
380 if (st2.StringValue.ToUpper().Equals("ORDERING".ToUpper()))
382 if (st2.nextToken() == (int)TokenTypes.WORD)
384 ordering = st2.StringValue;
388 if (st2.StringValue.ToUpper().Equals("SUBSTR".ToUpper()))
390 if (st2.nextToken() == (int)TokenTypes.WORD)
392 substring = st2.StringValue;
396 if (st2.StringValue.ToUpper().Equals("FORM".ToUpper()))
398 if (st2.nextToken() == (int)TokenTypes.WORD)
400 nameForm = st2.StringValue;
404 if (st2.StringValue.ToUpper().Equals("OC".ToUpper()))
406 if (st2.nextToken() == (int)TokenTypes.WORD)
408 objectClass = st2.StringValue;
412 if (st2.StringValue.ToUpper().Equals("SUP".ToUpper()))
414 System.Collections.ArrayList values = new System.Collections.ArrayList();
416 if (st2.lastttype == '(')
419 while (st2.lastttype != ')')
421 if (st2.lastttype != '$')
423 values.Add(st2.StringValue);
430 values.Add(st2.StringValue);
431 superior = st2.StringValue;
433 if (values.Count > 0)
435 superiors = new System.String[values.Count];
436 SupportClass.ArrayListSupport.ToArray(values, superiors);
440 if (st2.StringValue.ToUpper().Equals("SINGLE-VALUE".ToUpper()))
445 if (st2.StringValue.ToUpper().Equals("OBSOLETE".ToUpper()))
450 if (st2.StringValue.ToUpper().Equals("COLLECTIVE".ToUpper()))
455 if (st2.StringValue.ToUpper().Equals("NO-USER-MODIFICATION".ToUpper()))
460 if (st2.StringValue.ToUpper().Equals("MUST".ToUpper()))
462 System.Collections.ArrayList values = new System.Collections.ArrayList();
464 if (st2.lastttype == '(')
467 while (st2.lastttype != ')')
469 if (st2.lastttype != '$')
471 values.Add(st2.StringValue);
478 values.Add(st2.StringValue);
480 if (values.Count > 0)
482 required = new System.String[values.Count];
483 SupportClass.ArrayListSupport.ToArray(values, required);
487 if (st2.StringValue.ToUpper().Equals("MAY".ToUpper()))
489 System.Collections.ArrayList values = new System.Collections.ArrayList();
491 if (st2.lastttype == '(')
494 while (st2.lastttype != ')')
496 if (st2.lastttype != '$')
498 values.Add(st2.StringValue);
505 values.Add(st2.StringValue);
507 if (values.Count > 0)
509 optional = new System.String[values.Count];
510 SupportClass.ArrayListSupport.ToArray(values, optional);
515 if (st2.StringValue.ToUpper().Equals("NOT".ToUpper()))
517 System.Collections.ArrayList values = new System.Collections.ArrayList();
519 if (st2.lastttype == '(')
522 while (st2.lastttype != ')')
524 if (st2.lastttype != '$')
526 values.Add(st2.StringValue);
533 values.Add(st2.StringValue);
535 if (values.Count > 0)
537 precluded = new System.String[values.Count];
538 SupportClass.ArrayListSupport.ToArray(values, precluded);
542 if (st2.StringValue.ToUpper().Equals("AUX".ToUpper()))
544 System.Collections.ArrayList values = new System.Collections.ArrayList();
546 if (st2.lastttype == '(')
549 while (st2.lastttype != ')')
551 if (st2.lastttype != '$')
553 values.Add(st2.StringValue);
560 values.Add(st2.StringValue);
562 if (values.Count > 0)
564 auxiliary = new System.String[values.Count];
565 SupportClass.ArrayListSupport.ToArray(values, auxiliary);
569 if (st2.StringValue.ToUpper().Equals("ABSTRACT".ToUpper()))
571 type = LdapObjectClassSchema.ABSTRACT;
574 if (st2.StringValue.ToUpper().Equals("STRUCTURAL".ToUpper()))
576 type = LdapObjectClassSchema.STRUCTURAL;
579 if (st2.StringValue.ToUpper().Equals("AUXILIARY".ToUpper()))
581 type = LdapObjectClassSchema.AUXILIARY;
584 if (st2.StringValue.ToUpper().Equals("USAGE".ToUpper()))
586 if (st2.nextToken() == (int)TokenTypes.WORD)
588 currName = st2.StringValue;
589 if (currName.ToUpper().Equals("directoryOperation".ToUpper()))
591 usage = LdapAttributeSchema.DIRECTORY_OPERATION;
593 else if (currName.ToUpper().Equals("distributedOperation".ToUpper()))
595 usage = LdapAttributeSchema.DISTRIBUTED_OPERATION;
597 else if (currName.ToUpper().Equals("dSAOperation".ToUpper()))
599 usage = LdapAttributeSchema.DSA_OPERATION;
601 else if (currName.ToUpper().Equals("userApplications".ToUpper()))
603 usage = LdapAttributeSchema.USER_APPLICATIONS;
608 if (st2.StringValue.ToUpper().Equals("APPLIES".ToUpper()))
610 System.Collections.ArrayList values = new System.Collections.ArrayList();
612 if (st2.lastttype == '(')
615 while (st2.lastttype != ')')
617 if (st2.lastttype != '$')
619 values.Add(st2.StringValue);
626 values.Add(st2.StringValue);
628 if (values.Count > 0)
630 applies = new System.String[values.Count];
631 SupportClass.ArrayListSupport.ToArray(values, applies);
635 currName = st2.StringValue;
636 AttributeQualifier q = parseQualifier(st2, currName);
647 catch (System.IO.IOException e)
653 private AttributeQualifier parseQualifier(SchemaTokenCreator st, System.String name)
655 System.Collections.ArrayList values = new System.Collections.ArrayList(5);
658 if (st.nextToken() == '\'')
660 values.Add(st.StringValue);
664 if (st.lastttype == '(')
666 while (st.nextToken() == '\'')
668 values.Add(st.StringValue);
673 catch (System.IO.IOException e)
677 System.String[] valArray = new System.String[values.Count];
678 valArray = (System.String[]) SupportClass.ArrayListSupport.ToArray(values, valArray);
679 return new AttributeQualifier(name, valArray);