< prev index next >

src/java.naming/share/classes/javax/naming/ldap/LdapName.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 741      *
 742      * @return An int representing the hash code of this name.
 743      * @see #equals
 744      */
 745     public int hashCode() {
 746         // Sum up the hash codes of the components.
 747         int hash = 0;
 748 
 749         // For each RDN...
 750         for (int i = 0; i < rdns.size(); i++) {
 751             Rdn rdn = rdns.get(i);
 752             hash += rdn.hashCode();
 753         }
 754         return hash;
 755     }
 756 
 757     /**
 758      * Serializes only the unparsed DN, for compactness and to avoid
 759      * any implementation dependency.
 760      *
 761      * @serialData      The DN string



 762      */

 763     private void writeObject(ObjectOutputStream s)
 764             throws java.io.IOException {
 765         s.defaultWriteObject();
 766         s.writeObject(toString());
 767     }
 768 











 769     private void readObject(ObjectInputStream s)
 770             throws java.io.IOException, ClassNotFoundException {
 771         s.defaultReadObject();
 772         unparsed = (String)s.readObject();
 773         try {
 774             parse();
 775         } catch (InvalidNameException e) {
 776             // shouldn't happen
 777             throw new java.io.StreamCorruptedException(
 778                     "Invalid name: " + unparsed);
 779         }
 780     }
 781 
 782     private void parse() throws InvalidNameException {
 783         // rdns = (ArrayList<Rdn>) (new RFC2253Parser(unparsed)).getDN();
 784 
 785         rdns = new Rfc2253Parser(unparsed).parseDn();
 786     }
 787 }
   1 /*
   2  * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 741      *
 742      * @return An int representing the hash code of this name.
 743      * @see #equals
 744      */
 745     public int hashCode() {
 746         // Sum up the hash codes of the components.
 747         int hash = 0;
 748 
 749         // For each RDN...
 750         for (int i = 0; i < rdns.size(); i++) {
 751             Rdn rdn = rdns.get(i);
 752             hash += rdn.hashCode();
 753         }
 754         return hash;
 755     }
 756 
 757     /**
 758      * Serializes only the unparsed DN, for compactness and to avoid
 759      * any implementation dependency.
 760      *
 761      * @serialData The DN {@code String} representation of this LDAP name.
 762      *
 763      * @param s the {@code ObjectOutputStream} to write to
 764      * @throws java.io.IOException if an I/O error occurs.
 765      */
 766     @java.io.Serial
 767     private void writeObject(ObjectOutputStream s)
 768             throws java.io.IOException {
 769         s.defaultWriteObject();
 770         s.writeObject(toString());
 771     }
 772 
 773     /**
 774      * Initializes the {@code LdapName} from deserialized data.
 775      *
 776      * See {@code writeObject} for a description of the serial form.
 777      *
 778      * @param s the {@code ObjectInputStream} to read from
 779      * @throws java.io.IOException if an I/O error occurs.
 780      * @throws ClassNotFoundException if the class of a serialized object
 781      *         could not be found.
 782      */
 783     @java.io.Serial
 784     private void readObject(ObjectInputStream s)
 785             throws java.io.IOException, ClassNotFoundException {
 786         s.defaultReadObject();
 787         unparsed = (String)s.readObject();
 788         try {
 789             parse();
 790         } catch (InvalidNameException e) {
 791             // shouldn't happen
 792             throw new java.io.StreamCorruptedException(
 793                     "Invalid name: " + unparsed);
 794         }
 795     }
 796 
 797     private void parse() throws InvalidNameException {
 798         // rdns = (ArrayList<Rdn>) (new RFC2253Parser(unparsed)).getDN();
 799 
 800         rdns = new Rfc2253Parser(unparsed).parseDn();
 801     }
 802 }
< prev index next >