예제 #1
0
  /*
   * Adds the given attribute type and value to this Rdn.
   * The string attribute values are not interpreted as
   * <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a>
   * formatted RDN strings. That is the values are used
   * literally (not parsed) and assumed to be unescaped.
   *
   * @param type The non-null and non-empty string attribute type.
   * @param value The non-null and non-empty attribute value.
   * @return The updated Rdn, not a new one. Cannot be null.
   * @see #toString()
   */
  Rdn put(String type, Object value) {

    // create new Entry
    RdnEntry newEntry = new RdnEntry();
    newEntry.type = type;
    if (value instanceof byte[]) { // clone the byte array
      newEntry.value = ((byte[]) value).clone();
    } else {
      newEntry.value = value;
    }
    entries.add(newEntry);
    return this;
  }
예제 #2
0
 /**
  * Constructs an Rdn from the given attribute set. See {@link javax.naming.directory.Attributes
  * Attributes}.
  *
  * <p>The string attribute values are not interpreted as <a
  * href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a> formatted RDN strings. That is, the
  * values are used literally (not parsed) and assumed to be unescaped.
  *
  * @param attrSet The non-null and non-empty attributes containing type/value mappings.
  * @throws InvalidNameException If contents of <tt>attrSet</tt> cannot be used to construct a
  *     valid RDN.
  */
 public Rdn(Attributes attrSet) throws InvalidNameException {
   if (attrSet.size() == 0) {
     throw new InvalidNameException("Attributes cannot be empty");
   }
   entries = new ArrayList<>(attrSet.size());
   NamingEnumeration<? extends Attribute> attrs = attrSet.getAll();
   try {
     for (int nEntries = 0; attrs.hasMore(); nEntries++) {
       RdnEntry entry = new RdnEntry();
       Attribute attr = attrs.next();
       entry.type = attr.getID();
       entry.value = attr.get();
       entries.add(nEntries, entry);
     }
   } catch (NamingException e) {
     InvalidNameException e2 = new InvalidNameException(e.getMessage());
     e2.initCause(e);
     throw e2;
   }
   sort(); // arrange entries for comparison
 }