< prev index next >

src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java

Print this page
rev 52881 : 8214971: Replace use of string.equals("") with isEmpty()
Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad


 898             throw cont.fillInException(e2);
 899         } catch (NamingException e) {
 900             throw cont.fillInException(e);
 901         }
 902     }
 903 
 904     /**
 905      * Adds attributes from RDN to attrs if not already present.
 906      * Note that if attrs already contains an attribute by the same name,
 907      * or if the distinguished name is empty, then leave attrs unchanged.
 908      *
 909      * @param dn The non-null DN of the entry to add
 910      * @param attrs The non-null attributes of entry to add
 911      * @param directUpdate Whether attrs can be updated directly
 912      * @return Non-null attributes with attributes from the RDN added
 913      */
 914     private static Attributes addRdnAttributes(String dn, Attributes attrs,
 915         boolean directUpdate) throws NamingException {
 916 
 917             // Handle the empty name
 918             if (dn.equals("")) {
 919                 return attrs;
 920             }
 921 
 922             // Parse string name into list of RDNs
 923             List<Rdn> rdnList = (new LdapName(dn)).getRdns();
 924 
 925             // Get leaf RDN
 926             Rdn rdn = rdnList.get(rdnList.size() - 1);
 927             Attributes nameAttrs = rdn.toAttributes();
 928 
 929             // Add attributes of RDN to attrs if not already there
 930             NamingEnumeration<? extends Attribute> enum_ = nameAttrs.getAll();
 931             Attribute nameAttr;
 932             while (enum_.hasMore()) {
 933                 nameAttr = enum_.next();
 934 
 935                 // If attrs already has the attribute, don't change or add to it
 936                 if (attrs.get(nameAttr.getID()) ==  null) {
 937 
 938                     /**


1254         throws NamingException
1255     {
1256         Name result;
1257 
1258         // Handle compound names.  A pair of LdapNames is an easy case.
1259         if ((name instanceof LdapName) && (prefix instanceof LdapName)) {
1260             result = (Name)(prefix.clone());
1261             result.addAll(name);
1262             return new CompositeName().add(result.toString());
1263         }
1264         if (!(name instanceof CompositeName)) {
1265             name = new CompositeName().add(name.toString());
1266         }
1267         if (!(prefix instanceof CompositeName)) {
1268             prefix = new CompositeName().add(prefix.toString());
1269         }
1270 
1271         int prefixLast = prefix.size() - 1;
1272 
1273         if (name.isEmpty() || prefix.isEmpty() ||
1274                 name.get(0).equals("") || prefix.get(prefixLast).equals("")) {
1275             return super.composeName(name, prefix);
1276         }
1277 
1278         result = (Name)(prefix.clone());
1279         result.addAll(name);
1280 
1281         if (parentIsLdapCtx) {
1282             String ldapComp = concatNames(result.get(prefixLast + 1),
1283                                           result.get(prefixLast));
1284             result.remove(prefixLast + 1);
1285             result.remove(prefixLast);
1286             result.add(prefixLast, ldapComp);
1287         }
1288         return result;
1289     }
1290 
1291     private String fullyQualifiedName(Name rel) {
1292         return rel.isEmpty()
1293                 ? currentDN
1294                 : fullyQualifiedName(rel.get(0));
1295     }
1296 
1297     private String fullyQualifiedName(String rel) {
1298         return (concatNames(rel, currentDN));
1299     }
1300 
1301     // used by LdapSearchEnumeration
1302     private static String concatNames(String lesser, String greater) {
1303         if (lesser == null || lesser.equals("")) {
1304             return greater;
1305         } else if (greater == null || greater.equals("")) {
1306             return lesser;
1307         } else {
1308             return (lesser + "," + greater);
1309         }
1310     }
1311 
1312    // --------------- Reading and Updating Attributes
1313    // getAttributes/modifyAttributes
1314 
1315     protected Attributes c_getAttributes(Name name, String[] attrIds,
1316                                       Continuation cont)
1317             throws NamingException {
1318         cont.setError(this, name);
1319 
1320         SearchControls cons = new SearchControls();
1321         cons.setSearchScope(SearchControls.OBJECT_SCOPE);
1322         cons.setReturningAttributes(attrIds);
1323 
1324         try {
1325             LdapResult answer =


3019         /*
3020          * Handle SLAPD-style referrals.
3021          *
3022          * Referrals received during name resolution should be followed
3023          * until one succeeds - the target entry is located. An exception
3024          * is thrown now to handle these.
3025          *
3026          * Referrals received during a search operation point to unexplored
3027          * parts of the directory and each should be followed. An exception
3028          * is thrown later (during results enumeration) to handle these.
3029          */
3030 
3031         case LdapClient.LDAP_PARTIAL_RESULTS:
3032 
3033             if (handleReferrals == LdapClient.LDAP_REF_IGNORE) {
3034                 e = new PartialResultException(msg);
3035                 break;
3036             }
3037 
3038             // extract SLAPD-style referrals from errorMessage
3039             if ((res.errorMessage != null) && (!res.errorMessage.equals(""))) {
3040                 res.referrals = extractURLs(res.errorMessage);
3041             } else {
3042                 e = new PartialResultException(msg);
3043                 break;
3044             }
3045 
3046             // build exception
3047             r = new LdapReferralException(resolvedName,
3048                 resolvedObj,
3049                 remainName,
3050                 msg,
3051                 envprops,
3052                 fullDN,
3053                 handleReferrals,
3054                 reqCtls);
3055 
3056             if (hopCount > 1) {
3057                 r.setHopCount(hopCount);
3058             }
3059             /*




 898             throw cont.fillInException(e2);
 899         } catch (NamingException e) {
 900             throw cont.fillInException(e);
 901         }
 902     }
 903 
 904     /**
 905      * Adds attributes from RDN to attrs if not already present.
 906      * Note that if attrs already contains an attribute by the same name,
 907      * or if the distinguished name is empty, then leave attrs unchanged.
 908      *
 909      * @param dn The non-null DN of the entry to add
 910      * @param attrs The non-null attributes of entry to add
 911      * @param directUpdate Whether attrs can be updated directly
 912      * @return Non-null attributes with attributes from the RDN added
 913      */
 914     private static Attributes addRdnAttributes(String dn, Attributes attrs,
 915         boolean directUpdate) throws NamingException {
 916 
 917             // Handle the empty name
 918             if (dn.isEmpty()) {
 919                 return attrs;
 920             }
 921 
 922             // Parse string name into list of RDNs
 923             List<Rdn> rdnList = (new LdapName(dn)).getRdns();
 924 
 925             // Get leaf RDN
 926             Rdn rdn = rdnList.get(rdnList.size() - 1);
 927             Attributes nameAttrs = rdn.toAttributes();
 928 
 929             // Add attributes of RDN to attrs if not already there
 930             NamingEnumeration<? extends Attribute> enum_ = nameAttrs.getAll();
 931             Attribute nameAttr;
 932             while (enum_.hasMore()) {
 933                 nameAttr = enum_.next();
 934 
 935                 // If attrs already has the attribute, don't change or add to it
 936                 if (attrs.get(nameAttr.getID()) ==  null) {
 937 
 938                     /**


1254         throws NamingException
1255     {
1256         Name result;
1257 
1258         // Handle compound names.  A pair of LdapNames is an easy case.
1259         if ((name instanceof LdapName) && (prefix instanceof LdapName)) {
1260             result = (Name)(prefix.clone());
1261             result.addAll(name);
1262             return new CompositeName().add(result.toString());
1263         }
1264         if (!(name instanceof CompositeName)) {
1265             name = new CompositeName().add(name.toString());
1266         }
1267         if (!(prefix instanceof CompositeName)) {
1268             prefix = new CompositeName().add(prefix.toString());
1269         }
1270 
1271         int prefixLast = prefix.size() - 1;
1272 
1273         if (name.isEmpty() || prefix.isEmpty() ||
1274                 name.get(0).isEmpty() || prefix.get(prefixLast).isEmpty()) {
1275             return super.composeName(name, prefix);
1276         }
1277 
1278         result = (Name)(prefix.clone());
1279         result.addAll(name);
1280 
1281         if (parentIsLdapCtx) {
1282             String ldapComp = concatNames(result.get(prefixLast + 1),
1283                                           result.get(prefixLast));
1284             result.remove(prefixLast + 1);
1285             result.remove(prefixLast);
1286             result.add(prefixLast, ldapComp);
1287         }
1288         return result;
1289     }
1290 
1291     private String fullyQualifiedName(Name rel) {
1292         return rel.isEmpty()
1293                 ? currentDN
1294                 : fullyQualifiedName(rel.get(0));
1295     }
1296 
1297     private String fullyQualifiedName(String rel) {
1298         return (concatNames(rel, currentDN));
1299     }
1300 
1301     // used by LdapSearchEnumeration
1302     private static String concatNames(String lesser, String greater) {
1303         if (lesser == null || lesser.isEmpty()) {
1304             return greater;
1305         } else if (greater == null || greater.isEmpty()) {
1306             return lesser;
1307         } else {
1308             return (lesser + "," + greater);
1309         }
1310     }
1311 
1312    // --------------- Reading and Updating Attributes
1313    // getAttributes/modifyAttributes
1314 
1315     protected Attributes c_getAttributes(Name name, String[] attrIds,
1316                                       Continuation cont)
1317             throws NamingException {
1318         cont.setError(this, name);
1319 
1320         SearchControls cons = new SearchControls();
1321         cons.setSearchScope(SearchControls.OBJECT_SCOPE);
1322         cons.setReturningAttributes(attrIds);
1323 
1324         try {
1325             LdapResult answer =


3019         /*
3020          * Handle SLAPD-style referrals.
3021          *
3022          * Referrals received during name resolution should be followed
3023          * until one succeeds - the target entry is located. An exception
3024          * is thrown now to handle these.
3025          *
3026          * Referrals received during a search operation point to unexplored
3027          * parts of the directory and each should be followed. An exception
3028          * is thrown later (during results enumeration) to handle these.
3029          */
3030 
3031         case LdapClient.LDAP_PARTIAL_RESULTS:
3032 
3033             if (handleReferrals == LdapClient.LDAP_REF_IGNORE) {
3034                 e = new PartialResultException(msg);
3035                 break;
3036             }
3037 
3038             // extract SLAPD-style referrals from errorMessage
3039             if ((res.errorMessage != null) && (!res.errorMessage.isEmpty())) {
3040                 res.referrals = extractURLs(res.errorMessage);
3041             } else {
3042                 e = new PartialResultException(msg);
3043                 break;
3044             }
3045 
3046             // build exception
3047             r = new LdapReferralException(resolvedName,
3048                 resolvedObj,
3049                 remainName,
3050                 msg,
3051                 envprops,
3052                 fullDN,
3053                 handleReferrals,
3054                 reqCtls);
3055 
3056             if (hopCount > 1) {
3057                 r.setHopCount(hopCount);
3058             }
3059             /*


< prev index next >