jdk/src/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java
author prappo
Fri, 01 Aug 2014 22:32:51 +0100
changeset 25808 e113d0a0fde0
parent 24969 afa6934dd8e8
permissions -rw-r--r--
8054158: Fix typos in JNDI-related packages Reviewed-by: rriggs, vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.jndi.ldap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.naming.directory.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Netscape's 3.1 servers have some schema bugs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * - It puts quotes around OIDs (such as those for SUP, SYNTAX).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * - When you try to write out the MUST/MAY list (such as "MUST cn"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *   it wants ("MUST (cn)") instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
final class LdapSchemaParser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    // do debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    // names of attribute IDs in the LDAP schema entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final String OBJECTCLASSDESC_ATTR_ID = "objectClasses";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static final String ATTRIBUTEDESC_ATTR_ID = "attributeTypes";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static final String SYNTAXDESC_ATTR_ID = "ldapSyntaxes";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static final String MATCHRULEDESC_ATTR_ID = "matchingRules";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    // information for creating internal nodes in JNDI schema tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static final String OBJECTCLASS_DEFINITION_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                        "ClassDefinition";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final String[] CLASS_DEF_ATTRS = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                         "objectclass", "ClassDefinition"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            static final String ATTRIBUTE_DEFINITION_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                        "AttributeDefinition";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static final String[] ATTR_DEF_ATTRS = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                        "objectclass", "AttributeDefinition" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            static final String SYNTAX_DEFINITION_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                        "SyntaxDefinition";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final String[] SYNTAX_DEF_ATTRS = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                        "objectclass", "SyntaxDefinition" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            static final String MATCHRULE_DEFINITION_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                        "MatchingRule";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final String[] MATCHRULE_DEF_ATTRS = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                        "objectclass", "MatchingRule" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // special tokens used in LDAP schema descriptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final char   SINGLE_QUOTE = '\'';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final char   WHSP = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final char   OID_LIST_BEGIN = '(';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final char   OID_LIST_END = ')';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final char   OID_SEPARATOR = '$';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // common IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final String  NUMERICOID_ID = "NUMERICOID";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static final String        NAME_ID = "NAME";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final String        DESC_ID = "DESC";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static final String    OBSOLETE_ID = "OBSOLETE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final String         SUP_ID = "SUP";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final String     PRIVATE_ID = "X-";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // Object Class specific IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final String    ABSTRACT_ID = "ABSTRACT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static final String  STRUCTURAL_ID = "STRUCTURAL";
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 24969
diff changeset
    87
    private static final String   AUXILIARY_ID = "AUXILIARY";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static final String        MUST_ID = "MUST";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final String         MAY_ID = "MAY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // Attribute Type specific IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static final String    EQUALITY_ID = "EQUALITY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static final String    ORDERING_ID = "ORDERING";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static final String      SUBSTR_ID = "SUBSTR";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static final String      SYNTAX_ID = "SYNTAX";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private static final String  SINGLE_VAL_ID = "SINGLE-VALUE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final String  COLLECTIVE_ID = "COLLECTIVE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static final String NO_USER_MOD_ID = "NO-USER-MODIFICATION";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final String       USAGE_ID = "USAGE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    // The string value we give to boolean variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static final String SCHEMA_TRUE_VALUE = "true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // To get around writing schemas that crash Netscape server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private boolean netscapeBug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    LdapSchemaParser(boolean netscapeBug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        this.netscapeBug = netscapeBug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    final static void LDAP2JNDISchema(Attributes schemaAttrs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        LdapSchemaCtx schemaRoot) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        Attribute               objectClassesAttr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        Attribute               attributeDefAttr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        Attribute               syntaxDefAttr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        Attribute               matchRuleDefAttr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        objectClassesAttr = schemaAttrs.get(OBJECTCLASSDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if(objectClassesAttr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            objectDescs2ClassDefs(objectClassesAttr,schemaRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        attributeDefAttr = schemaAttrs.get(ATTRIBUTEDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if(attributeDefAttr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            attrDescs2AttrDefs(attributeDefAttr, schemaRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        syntaxDefAttr = schemaAttrs.get(SYNTAXDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if(syntaxDefAttr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            syntaxDescs2SyntaxDefs(syntaxDefAttr, schemaRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        matchRuleDefAttr = schemaAttrs.get(MATCHRULEDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if(matchRuleDefAttr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            matchRuleDescs2MatchRuleDefs(matchRuleDefAttr, schemaRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    final private static DirContext objectDescs2ClassDefs(Attribute objDescsAttr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                                   LdapSchemaCtx schemaRoot)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   143
        NamingEnumeration<?> objDescs;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   144
        Attributes                objDef;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   145
        LdapSchemaCtx             classDefTree;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // create the class def subtree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        attrs.put(CLASS_DEF_ATTRS[0], CLASS_DEF_ATTRS[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        classDefTree = schemaRoot.setup(LdapSchemaCtx.OBJECTCLASS_ROOT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            OBJECTCLASS_DEFINITION_NAME, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        objDescs = objDescsAttr.getAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        String currentName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        while(objDescs.hasMore()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            String objDesc = (String)objDescs.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                Object[] def = desc2Def(objDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                currentName = (String) def[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                objDef = (Attributes) def[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                classDefTree.setup(LdapSchemaCtx.OBJECTCLASS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    currentName, objDef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            } catch (NamingException ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                // error occurred while parsing, ignore current entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return classDefTree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    final private static DirContext attrDescs2AttrDefs(Attribute attributeDescAttr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                                LdapSchemaCtx schemaRoot)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   175
        NamingEnumeration<?> attrDescs;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   176
        Attributes           attrDef;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   177
        LdapSchemaCtx        attrDefTree;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // create the AttributeDef subtree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        attrs.put(ATTR_DEF_ATTRS[0], ATTR_DEF_ATTRS[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        attrDefTree = schemaRoot.setup(LdapSchemaCtx.ATTRIBUTE_ROOT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            ATTRIBUTE_DEFINITION_NAME, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        attrDescs = attributeDescAttr.getAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        String currentName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        while(attrDescs.hasMore()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            String attrDesc = (String)attrDescs.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                Object[] def = desc2Def(attrDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                currentName = (String) def[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                attrDef = (Attributes) def[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                attrDefTree.setup(LdapSchemaCtx.ATTRIBUTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    currentName, attrDef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            } catch (NamingException ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                // error occurred while parsing, ignore current entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return attrDefTree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    final private static DirContext syntaxDescs2SyntaxDefs(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                                Attribute syntaxDescAttr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                                                LdapSchemaCtx schemaRoot)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   208
        NamingEnumeration<?> syntaxDescs;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   209
        Attributes           syntaxDef;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   210
        LdapSchemaCtx        syntaxDefTree;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // create the SyntaxDef subtree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        attrs.put(SYNTAX_DEF_ATTRS[0], SYNTAX_DEF_ATTRS[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        syntaxDefTree = schemaRoot.setup(LdapSchemaCtx.SYNTAX_ROOT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            SYNTAX_DEFINITION_NAME, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        syntaxDescs = syntaxDescAttr.getAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        String currentName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        while(syntaxDescs.hasMore()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            String syntaxDesc = (String)syntaxDescs.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                Object[] def = desc2Def(syntaxDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                currentName = (String) def[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                syntaxDef = (Attributes) def[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                syntaxDefTree.setup(LdapSchemaCtx.SYNTAX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    currentName, syntaxDef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            } catch (NamingException ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                // error occurred while parsing, ignore current entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return syntaxDefTree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    final private static DirContext matchRuleDescs2MatchRuleDefs(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                                Attribute matchRuleDescAttr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                                LdapSchemaCtx schemaRoot)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   241
        NamingEnumeration<?> matchRuleDescs;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   242
        Attributes           matchRuleDef;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   243
        LdapSchemaCtx        matchRuleDefTree;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        // create the MatchRuleDef subtree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        attrs.put(MATCHRULE_DEF_ATTRS[0], MATCHRULE_DEF_ATTRS[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        matchRuleDefTree = schemaRoot.setup(LdapSchemaCtx.MATCHRULE_ROOT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            MATCHRULE_DEFINITION_NAME, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        matchRuleDescs = matchRuleDescAttr.getAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        String currentName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        while(matchRuleDescs.hasMore()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            String matchRuleDesc = (String)matchRuleDescs.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                Object[] def = desc2Def(matchRuleDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                currentName = (String) def[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                matchRuleDef = (Attributes) def[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                matchRuleDefTree.setup(LdapSchemaCtx.MATCHRULE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    currentName, matchRuleDef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            } catch (NamingException ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                // error occurred while parsing, ignore current entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return matchRuleDefTree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    final private static Object[] desc2Def(String desc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            //System.err.println(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        Attributes      attrs = new BasicAttributes(LdapClient.caseIgnore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        Attribute       attr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        int[]           pos = new int[]{1}; // tolerate missing leading space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        boolean         moreTags = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        // Always begins with <whsp numericoid whsp>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        attr = readNumericOID(desc, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        String currentName = (String) attr.get(0);  // name is OID by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        attrs.put(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        skipWhitespace(desc, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        while (moreTags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            attr = readNextTag(desc, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            attrs.put(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            if (attr.getID().equals(NAME_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                currentName = (String) attr.get(0);  // use NAME attribute as name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            skipWhitespace(desc, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if( pos[0] >= desc.length() -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                moreTags = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return new Object[] {currentName, attrs};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 24969
diff changeset
   303
    // returns the index of the first whitespace char of a linear whitespace
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 24969
diff changeset
   304
    // sequence ending at the given position.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    final private static int findTrailingWhitespace(String string, int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        for(int i = pos; i > 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if(string.charAt(i) != WHSP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                return i + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    final private static void skipWhitespace(String string, int[] pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        for(int i=pos[0]; i < string.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            if(string.charAt(i) != WHSP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                pos[0] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    System.err.println("skipWhitespace: skipping to "+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    final private static Attribute readNumericOID(String string, int[] pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            System.err.println("readNumericoid: pos="+pos[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        int begin, end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        String value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        skipWhitespace(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        begin = pos[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        end = string.indexOf(WHSP, begin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (end == -1 || end - begin < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            throw new InvalidAttributeValueException("no numericoid found: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                                     + string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        value = string.substring(begin, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        pos[0] += value.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return new BasicAttribute(NUMERICOID_ID, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    final private static Attribute readNextTag(String string, int[] pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        Attribute       attr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        String          tagName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        String[]        values = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        skipWhitespace(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            System.err.println("readNextTag: pos="+pos[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        // get the name and values of the attribute to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        int trailingSpace = string.indexOf( WHSP, pos[0] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        // tolerate a schema that omits the trailing space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (trailingSpace < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            tagName = string.substring( pos[0], string.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            tagName = string.substring( pos[0], trailingSpace );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        values = readTag(tagName, string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // make sure at least one value was returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if(values.length < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            throw new InvalidAttributeValueException("no values for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                                                     "attribute \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                                                     tagName + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        // create the attribute, using the first value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        attr = new BasicAttribute(tagName, values[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        // add other values if there are any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        for(int i = 1; i < values.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            attr.add(values[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    final private static String[] readTag(String tag, String string, int[] pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            System.err.println("ReadTag: " + tag + " pos="+pos[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        // move parser past tag name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        pos[0] += tag.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        skipWhitespace(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if (tag.equals(NAME_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            return readQDescrs(string, pos);  // names[0] is NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if(tag.equals(DESC_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
           return readQDString(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
           tag.equals(EQUALITY_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
           tag.equals(ORDERING_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
           tag.equals(SUBSTR_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
           tag.equals(SYNTAX_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            return readWOID(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if (tag.equals(OBSOLETE_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            tag.equals(ABSTRACT_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            tag.equals(STRUCTURAL_ID) ||
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 24969
diff changeset
   426
            tag.equals(AUXILIARY_ID) ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            tag.equals(SINGLE_VAL_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            tag.equals(COLLECTIVE_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            tag.equals(NO_USER_MOD_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            return new String[] {SCHEMA_TRUE_VALUE};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        if (tag.equals(SUP_ID) ||   // oid list for object class; WOID for attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            tag.equals(MUST_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            tag.equals(MAY_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            tag.equals(USAGE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return readOIDs(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        // otherwise it's a schema element with a quoted string value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return readQDStrings(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    final private static String[] readQDString(String string, int[] pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        int begin, end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        begin = string.indexOf(SINGLE_QUOTE, pos[0]) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        end = string.indexOf(SINGLE_QUOTE, begin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            System.err.println("ReadQDString: pos=" + pos[0] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                               " begin=" + begin + " end=" + end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if(begin == -1 || end == -1 || begin == end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            throw new InvalidAttributeIdentifierException("malformed " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                                          "QDString: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                                                          string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        // make sure the qdstring end symbol is there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (string.charAt(begin - 1) != SINGLE_QUOTE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            throw new InvalidAttributeIdentifierException("qdstring has " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                                          "no end mark: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                                          string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        pos[0] = end+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        return new String[] {string.substring(begin, end)};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    * dstring         = 1*utf8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    * qdstring        = whsp "'" dstring "'" whsp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    * qdstringlist    = [ qdstring *( qdstring ) ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    * qdstrings       = qdstring / ( whsp "(" qdstringlist ")" whsp )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    private final static String[] readQDStrings(String string, int[] pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return readQDescrs(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * ; object descriptors used as schema element names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * qdescrs         = qdescr / ( whsp "(" qdescrlist ")" whsp )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * qdescrlist      = [ qdescr *( qdescr ) ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * qdescr          = whsp "'" descr "'" whsp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * descr           = keystring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    final private static String[] readQDescrs(String string, int[] pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            System.err.println("readQDescrs: pos="+pos[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        skipWhitespace(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        switch( string.charAt(pos[0]) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        case OID_LIST_BEGIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            return readQDescrList(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        case SINGLE_QUOTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            return readQDString(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            throw new InvalidAttributeValueException("unexpected oids " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                                     "string: " + string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * qdescrlist      = [ qdescr *( qdescr ) ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * qdescr          = whsp "'" descr "'" whsp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * descr           = keystring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    final private static String[] readQDescrList(String string, int[] pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   521
        int begin, end;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   522
        Vector<String> values = new Vector<>(5);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            System.err.println("ReadQDescrList: pos="+pos[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        pos[0]++; // skip '('
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        skipWhitespace(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        begin = pos[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        end = string.indexOf(OID_LIST_END, begin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        if(end == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            throw new InvalidAttributeValueException ("oidlist has no end "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                                      "mark: " + string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        while(begin < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            String[] one = readQDString(string,  pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                System.err.println("ReadQDescrList: found '" + one[0] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                                   "' at begin=" + begin + " end =" + end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            values.addElement(one[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            skipWhitespace(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            begin = pos[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        pos[0] = end+1; // skip ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        String[] answer = new String[values.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        for (int i = 0; i < answer.length; i++) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   555
            answer[i] = values.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    final private static String[] readWOID(String string, int[] pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            System.err.println("readWOIDs: pos="+pos[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        skipWhitespace(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        if (string.charAt(pos[0]) == SINGLE_QUOTE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            // %%% workaround for Netscape schema bug
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            return readQDString(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        int begin, end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        begin = pos[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        end = string.indexOf(WHSP, begin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            System.err.println("ReadWOID: pos=" + pos[0] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                               " begin=" + begin + " end=" + end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if(end == -1 || begin == end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            throw new InvalidAttributeIdentifierException("malformed " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                                                          "OID: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                                                          string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        pos[0] = end+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        return new String[] {string.substring(begin, end)};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * oids            = woid / ( "(" oidlist ")" )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * oidlist         = woid *( "$" woid )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    final private static String[] readOIDs(String string, int[] pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            System.err.println("readOIDs: pos="+pos[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        skipWhitespace(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        // Single OID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        if (string.charAt(pos[0]) != OID_LIST_BEGIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            return readWOID(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        // Multiple OIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        int     begin, cur, end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        String  oidName = null;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   616
        Vector<String> values = new Vector<>(5);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            System.err.println("ReadOIDList: pos="+pos[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        pos[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        skipWhitespace(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        begin = pos[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        end = string.indexOf(OID_LIST_END, begin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        cur = string.indexOf(OID_SEPARATOR, begin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        if(end == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            throw new InvalidAttributeValueException ("oidlist has no end "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                                                      "mark: " + string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        if(cur == -1 || end < cur) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            cur = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        while(cur < end && cur > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            int wsBegin = findTrailingWhitespace(string, cur - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            oidName = string.substring(begin, wsBegin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                System.err.println("ReadOIDList: found '" + oidName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                                   "' at begin=" + begin + " end =" + end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            values.addElement(oidName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            pos[0] = cur + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            skipWhitespace(string, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            begin = pos[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            cur = string.indexOf(OID_SEPARATOR, begin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            if(debug) {System.err.println("ReadOIDList: begin = " + begin);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            System.err.println("ReadOIDList: found '" + oidName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                               "' at begin=" + begin + " end =" + end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        int wsBegin = findTrailingWhitespace(string, end - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        oidName = string.substring(begin, wsBegin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        values.addElement(oidName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        pos[0] = end+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        String[] answer = new String[values.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        for (int i = 0; i < answer.length; i++) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   665
            answer[i] = values.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
// ----------------- "unparser" methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
// Methods that are used for translating a node in the schema tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
// into RFC2252 format for storage back into the LDAP directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     static Attributes JNDI2LDAPSchema(DirContext schemaRoot)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        Attribute objDescAttr = new BasicAttribute(OBJECTCLASSDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        Attribute attrDescAttr = new BasicAttribute(ATTRIBUTEDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        Attribute syntaxDescAttr = new BasicAttribute(SYNTAXDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        DirContext classDefs, attributeDefs, syntaxDefs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        Attributes classDefsAttrs, attributeDefsAttrs, syntaxDefsAttrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        NamingEnumeration defs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        Object obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            obj = schemaRoot.lookup(OBJECTCLASS_DEFINITION_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            if(obj != null && obj instanceof DirContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                classDefs = (DirContext)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                defs = classDefs.listBindings("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                while(defs.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    DirContext classDef = (DirContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                        ((Binding)(defs.next())).getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    classDefAttrs = classDef.getAttributes("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    objDescAttr.add(classDef2ObjectDesc(classDefAttrs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    System.err.println(i + " total object classes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                attrs.put(objDescAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                throw new NamingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                    "Problem with Schema tree: the object named " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                    OBJECTCLASS_DEFINITION_NAME + " is not a " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                    "DirContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        } catch (NameNotFoundException e) {} // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            obj = schemaRoot.lookup(ATTRIBUTE_DEFINITION_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            if(obj instanceof DirContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                attributeDefs = (DirContext)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                defs = attributeDefs.listBindings("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                while(defs.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                    DirContext attrDef = (DirContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                        ((Binding)defs.next()).getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                    attrDefAttrs = attrDef.getAttributes("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                    attrDescAttr.add(attrDef2AttrDesc(attrDefAttrs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                    System.err.println(i + " attribute definitions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                attrs.put(attrDescAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                throw new NamingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                    "Problem with schema tree: the object named " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    ATTRIBUTE_DEFINITION_NAME + " is not a " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                    "DirContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        } catch (NameNotFoundException e) {} // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            obj = schemaRoot.lookup(SYNTAX_DEFINITION_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            if(obj instanceof DirContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                syntaxDefs = (DirContext)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                defs =syntaxDefs.listBindings("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                while(defs.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                    DirContext syntaxDef = (DirContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                        ((Binding)defs.next()).getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    syntaxDefAttrs = syntaxDef.getAttributes("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    syntaxDescAttr.add(syntaxDef2SyntaxDesc(syntaxDefAttrs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                    System.err.println(i + " total syntax definitions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                attrs.put(syntaxDescAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                throw new NamingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    "Problem with schema tree: the object named " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                    SYNTAX_DEFINITION_NAME + " is not a " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                    "DirContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        } catch (NameNotFoundException e) {} // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        return attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
      * Translate attributes that describe an object class into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
      * string description as defined in RFC 2252.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    final private String classDef2ObjectDesc(Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 10324
diff changeset
   770
        StringBuilder objectDesc = new StringBuilder("( ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        Attribute attr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        // extract attributes by ID to guarantee ordering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        attr = attrs.get(NUMERICOID_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            objectDesc.append(writeNumericOID(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            throw new ConfigurationException("Class definition doesn't" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                                             "have a numeric OID");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        attr = attrs.get(NAME_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            objectDesc.append(writeQDescrs(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        attr = attrs.get(DESC_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            objectDesc.append(writeQDString(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        attr = attrs.get(OBSOLETE_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            objectDesc.append(writeBoolean(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        attr = attrs.get(SUP_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            objectDesc.append(writeOIDs(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        attr = attrs.get(ABSTRACT_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            objectDesc.append(writeBoolean(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        attr = attrs.get(STRUCTURAL_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            objectDesc.append(writeBoolean(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 24969
diff changeset
   822
        attr = attrs.get(AUXILIARY_ID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            objectDesc.append(writeBoolean(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        attr = attrs.get(MUST_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            objectDesc.append(writeOIDs(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        attr = attrs.get(MAY_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            objectDesc.append(writeOIDs(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        // process any remaining attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        if (count < attrs.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            String attrId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            // use enumeration because attribute ID is not known
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   845
            for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                ae.hasMoreElements(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   848
                attr = ae.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                attrId = attr.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                // skip those already processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                if (attrId.equals(NUMERICOID_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                    attrId.equals(NAME_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                    attrId.equals(SUP_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                    attrId.equals(MAY_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                    attrId.equals(MUST_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                    attrId.equals(STRUCTURAL_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                    attrId.equals(DESC_ID) ||
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 24969
diff changeset
   859
                    attrId.equals(AUXILIARY_ID) ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                    attrId.equals(ABSTRACT_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                    attrId.equals(OBSOLETE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    objectDesc.append(writeQDStrings(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        objectDesc.append(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        return objectDesc.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
      * Translate attributes that describe an attribute definition into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
      * string description as defined in RFC 2252.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    final private String attrDef2AttrDesc(Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 10324
diff changeset
   882
        StringBuilder attrDesc = new StringBuilder("( "); // opening parens
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        Attribute attr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        // extract attributes by ID to guarantee ordering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        attr = attrs.get(NUMERICOID_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            attrDesc.append(writeNumericOID(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            throw new ConfigurationException("Attribute type doesn't" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                                             "have a numeric OID");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        attr = attrs.get(NAME_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            attrDesc.append(writeQDescrs(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        attr = attrs.get(DESC_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            attrDesc.append(writeQDString(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        attr = attrs.get(OBSOLETE_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            attrDesc.append(writeBoolean(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        attr = attrs.get(SUP_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            attrDesc.append(writeWOID(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        attr = attrs.get(EQUALITY_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            attrDesc.append(writeWOID(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        attr = attrs.get(ORDERING_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            attrDesc.append(writeWOID(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        attr = attrs.get(SUBSTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            attrDesc.append(writeWOID(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        attr = attrs.get(SYNTAX_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            attrDesc.append(writeWOID(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        attr = attrs.get(SINGLE_VAL_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            attrDesc.append(writeBoolean(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        attr = attrs.get(COLLECTIVE_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            attrDesc.append(writeBoolean(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        attr = attrs.get(NO_USER_MOD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            attrDesc.append(writeBoolean(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        attr = attrs.get(USAGE_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            attrDesc.append(writeQDString(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        // process any remaining attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        if (count < attrs.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            String attrId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            // use enumeration because attribute ID is not known
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   975
            for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                ae.hasMoreElements(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   978
                attr = ae.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                attrId = attr.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                // skip those already processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                if (attrId.equals(NUMERICOID_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                    attrId.equals(NAME_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                    attrId.equals(SYNTAX_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                    attrId.equals(DESC_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                    attrId.equals(SINGLE_VAL_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    attrId.equals(EQUALITY_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                    attrId.equals(ORDERING_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                    attrId.equals(SUBSTR_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                    attrId.equals(NO_USER_MOD_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                    attrId.equals(USAGE_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                    attrId.equals(SUP_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                    attrId.equals(COLLECTIVE_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                    attrId.equals(OBSOLETE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                    attrDesc.append(writeQDStrings(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        attrDesc.append(")");  // add closing parens
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        return attrDesc.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
      * Translate attributes that describe an attribute syntax definition into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
      * string description as defined in RFC 2252.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    final private String syntaxDef2SyntaxDesc(Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 10324
diff changeset
  1015
        StringBuilder syntaxDesc = new StringBuilder("( "); // opening parens
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        Attribute attr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        // extract attributes by ID to guarantee ordering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        attr = attrs.get(NUMERICOID_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            syntaxDesc.append(writeNumericOID(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            throw new ConfigurationException("Attribute type doesn't" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                                             "have a numeric OID");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        attr = attrs.get(DESC_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            syntaxDesc.append(writeQDString(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        // process any remaining attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        if (count < attrs.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            String attrId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            // use enumeration because attribute ID is not known
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1042
            for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                ae.hasMoreElements(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1045
                attr = ae.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                attrId = attr.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                // skip those already processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                if (attrId.equals(NUMERICOID_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                    attrId.equals(DESC_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                    syntaxDesc.append(writeQDStrings(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        syntaxDesc.append(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        return syntaxDesc.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
      * Translate attributes that describe an attribute matching rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
      * definition into the string description as defined in RFC 2252.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    final private String matchRuleDef2MatchRuleDesc(Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 10324
diff changeset
  1071
        StringBuilder matchRuleDesc = new StringBuilder("( "); // opening parens
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        Attribute attr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        // extract attributes by ID to guarantee ordering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        attr = attrs.get(NUMERICOID_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            matchRuleDesc.append(writeNumericOID(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            throw new ConfigurationException("Attribute type doesn't" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                                             "have a numeric OID");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        attr = attrs.get(NAME_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            matchRuleDesc.append(writeQDescrs(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        attr = attrs.get(DESC_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            matchRuleDesc.append(writeQDString(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        attr = attrs.get(OBSOLETE_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            matchRuleDesc.append(writeBoolean(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        attr = attrs.get(SYNTAX_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            matchRuleDesc.append(writeWOID(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            throw new ConfigurationException("Attribute type doesn't" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                                             "have a syntax OID");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        // process any remaining attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        if (count < attrs.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            String attrId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            // use enumeration because attribute ID is not known
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1119
            for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                ae.hasMoreElements(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1122
                attr = ae.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                attrId = attr.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                // skip those already processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                if (attrId.equals(NUMERICOID_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                    attrId.equals(NAME_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                    attrId.equals(SYNTAX_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                    attrId.equals(DESC_ID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                    attrId.equals(OBSOLETE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                    matchRuleDesc.append(writeQDStrings(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        matchRuleDesc.append(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        return matchRuleDesc.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
    final private String writeNumericOID(Attribute nOIDAttr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        if(nOIDAttr.size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            throw new InvalidAttributeValueException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                "A class definition must have exactly one numeric OID");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        return (String)(nOIDAttr.get()) + WHSP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    final private String writeWOID(Attribute attr) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        if (netscapeBug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            return writeQDString(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            return attr.getID() + WHSP + attr.get() + WHSP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    /*  qdescr          = whsp "'" descr "'" whsp */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    final private String writeQDString(Attribute qdStringAttr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        if(qdStringAttr.size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            throw new InvalidAttributeValueException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                qdStringAttr.getID() + " must have exactly one value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        return qdStringAttr.getID() + WHSP +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            SINGLE_QUOTE + qdStringAttr.get() + SINGLE_QUOTE + WHSP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    * dstring         = 1*utf8
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    * qdstring        = whsp "'" dstring "'" whsp
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    * qdstringlist    = [ qdstring *( qdstring ) ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    * qdstrings       = qdstring / ( whsp "(" qdstringlist ")" whsp )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    private final String writeQDStrings(Attribute attr) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        return writeQDescrs(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * qdescrs         = qdescr / ( whsp "(" qdescrlist ")" whsp )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * qdescrlist      = [ qdescr *( qdescr ) ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * qdescr          = whsp "'" descr "'" whsp
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * descr           = keystring
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    private final String writeQDescrs(Attribute attr) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        switch(attr.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            throw new InvalidAttributeValueException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                attr.getID() + "has no values");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            return writeQDString(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        // write QDList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 10324
diff changeset
  1199
        StringBuilder qdList = new StringBuilder(attr.getID());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        qdList.append(WHSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        qdList.append(OID_LIST_BEGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1203
        NamingEnumeration<?> values = attr.getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        while(values.hasMore()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            qdList.append(WHSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            qdList.append(SINGLE_QUOTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            qdList.append((String)values.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            qdList.append(SINGLE_QUOTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            qdList.append(WHSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        qdList.append(OID_LIST_END);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        qdList.append(WHSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        return qdList.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    final private String writeOIDs(Attribute oidsAttr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        switch(oidsAttr.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            throw new InvalidAttributeValueException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                oidsAttr.getID() + "has no values");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            if (netscapeBug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                break; // %%% write out as list to avoid crashing server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            return writeWOID(oidsAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        // write OID List
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 10324
diff changeset
  1236
        StringBuilder oidList = new StringBuilder(oidsAttr.getID());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        oidList.append(WHSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        oidList.append(OID_LIST_BEGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
  1240
        NamingEnumeration<?> values = oidsAttr.getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        oidList.append(WHSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        oidList.append(values.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        while(values.hasMore()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            oidList.append(WHSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            oidList.append(OID_SEPARATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            oidList.append(WHSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            oidList.append((String)values.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        oidList.append(WHSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        oidList.append(OID_LIST_END);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        oidList.append(WHSP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        return oidList.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
    private final String writeBoolean(Attribute booleanAttr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            return booleanAttr.getID() + WHSP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * Returns an attribute for updating the Object Class Definition schema
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    final Attribute stringifyObjDesc(Attributes classDefAttrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        Attribute objDescAttr = new BasicAttribute(OBJECTCLASSDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        objDescAttr.add(classDef2ObjectDesc(classDefAttrs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        return objDescAttr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * Returns an attribute for updating the Attribute Definition schema attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    final Attribute stringifyAttrDesc(Attributes attrDefAttrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        Attribute attrDescAttr = new BasicAttribute(ATTRIBUTEDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        attrDescAttr.add(attrDef2AttrDesc(attrDefAttrs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        return attrDescAttr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * Returns an attribute for updating the Syntax schema attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    final Attribute stringifySyntaxDesc(Attributes syntaxDefAttrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        Attribute syntaxDescAttr = new BasicAttribute(SYNTAXDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        syntaxDescAttr.add(syntaxDef2SyntaxDesc(syntaxDefAttrs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        return syntaxDescAttr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * Returns an attribute for updating the Matching Rule schema attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    final Attribute stringifyMatchRuleDesc(Attributes matchRuleDefAttrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        Attribute matchRuleDescAttr = new BasicAttribute(MATCHRULEDESC_ATTR_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        matchRuleDescAttr.add(matchRuleDef2MatchRuleDesc(matchRuleDefAttrs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        return matchRuleDescAttr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
}