From 0cc40b0c847f78964d74a675b829a29c6d3f3a87 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Fri, 04 Dec 2009 17:33:52 +0000
Subject: [PATCH] Add some missing constructors.
---
sdk/src/org/opends/sdk/RDN.java | 107 +++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 91 insertions(+), 16 deletions(-)
diff --git a/sdk/src/org/opends/sdk/RDN.java b/sdk/src/org/opends/sdk/RDN.java
index 8c61bff..2f3cabb 100644
--- a/sdk/src/org/opends/sdk/RDN.java
+++ b/sdk/src/org/opends/sdk/RDN.java
@@ -53,18 +53,16 @@
* siblings).
* <p>
* The following are examples of string representations of RDNs:
- *
+ *
* <pre>
* uid=12345
* ou=Engineering
* cn=Kurt Zeilenga+L=Redwood Shores
* </pre>
- *
+ *
* The last is an example of a multi-valued RDN; that is, an RDN
* composed of multiple AVAs.
- * <p>
- * TODO: need more constructors.
- *
+ *
* @see <a href="http://tools.ietf.org/html/rfc4512#section-2.3">RFC
* 4512 - Lightweight Directory Access Protocol (LDAP): Directory
* Information Models </a>
@@ -87,7 +85,7 @@
/**
* Creates a new attribute value assertion (AVA) using the provided
* attribute type and value.
- *
+ *
* @param attributeType
* The attribute type.
* @param attributeValue
@@ -108,6 +106,37 @@
/**
+ * Creates a new attribute value assertion (AVA) using the provided
+ * attribute type and value decoded using the default schema.
+ * <p>
+ * If {@code attributeValue} is not an instance of {@code
+ * ByteString} then it will be converted using the
+ * {@link ByteString#valueOf(Object)} method.
+ *
+ * @param attributeType
+ * The attribute type.
+ * @param attributeValue
+ * The attribute value.
+ * @throws UnknownSchemaElementException
+ * If {@code attributeType} was not found in the default
+ * schema.
+ * @throws NullPointerException
+ * If {@code attributeType} or {@code attributeValue} was
+ * {@code null}.
+ */
+ public AVA(String attributeType, Object attributeValue)
+ throws UnknownSchemaElementException, NullPointerException
+ {
+ Validator.ensureNotNull(attributeType, attributeValue);
+
+ this.attributeType = Schema.getDefaultSchema().getAttributeType(
+ attributeType);
+ this.attributeValue = ByteString.valueOf(attributeValue);
+ }
+
+
+
+ /**
* {@inheritDoc}
*/
public int compareTo(AVA ava)
@@ -149,7 +178,7 @@
/**
* Returns the attribute type associated with this AVA.
- *
+ *
* @return The attribute type associated with this AVA.
*/
public AttributeType getAttributeType()
@@ -161,7 +190,7 @@
/**
* Returns the attribute value associated with this AVA.
- *
+ *
* @return The attribute value associated with this AVA.
*/
public ByteString getAttributeValue()
@@ -304,7 +333,7 @@
/**
* Parses the provided LDAP string representation of an RDN using the
* default schema.
- *
+ *
* @param rdn
* The LDAP string representation of a RDN.
* @return The parsed RDN.
@@ -325,7 +354,7 @@
/**
* Parses the provided LDAP string representation of a RDN using the
* provided schema.
- *
+ *
* @param rdn
* The LDAP string representation of a RDN.
* @param schema
@@ -675,6 +704,52 @@
+ /**
+ * Creates a new RDN using the provided attribute type and value.
+ *
+ * @param attributeType
+ * The attribute type.
+ * @param attributeValue
+ * The attribute value.
+ * @throws NullPointerException
+ * If {@code attributeType} or {@code attributeValue} was
+ * {@code null}.
+ */
+ public RDN(AttributeType attributeType, ByteString attributeValue)
+ throws NullPointerException
+ {
+ this.avas = new AVA[] { new AVA(attributeType, attributeValue) };
+ }
+
+
+
+ /**
+ * Creates a new RDN using the provided attribute type and value
+ * decoded using the default schema.
+ * <p>
+ * If {@code attributeValue} is not an instance of {@code ByteString}
+ * then it will be converted using the
+ * {@link ByteString#valueOf(Object)} method.
+ *
+ * @param attributeType
+ * The attribute type.
+ * @param attributeValue
+ * The attribute value.
+ * @throws UnknownSchemaElementException
+ * If {@code attributeType} was not found in the default
+ * schema.
+ * @throws NullPointerException
+ * If {@code attributeType} or {@code attributeValue} was
+ * {@code null}.
+ */
+ public RDN(String attributeType, Object attributeValue)
+ throws UnknownSchemaElementException, NullPointerException
+ {
+ this.avas = new AVA[] { new AVA(attributeType, attributeValue) };
+ }
+
+
+
private RDN(AVA[] avas, String stringValue)
{
this.avas = avas;
@@ -749,7 +824,7 @@
* Returns the attribute value contained in this RDN which is
* associated with the provided attribute type, or {@code null} if
* this RDN does not include such an attribute value.
- *
+ *
* @param attributeType
* The attribute type.
* @return The attribute value.
@@ -770,7 +845,7 @@
/**
* Returns the first AVA contained in this RDN.
- *
+ *
* @return The first AVA contained in this RDN.
*/
public AVA getFirstAVA()
@@ -798,7 +873,7 @@
/**
* Returns {@code true} if this RDN contains more than one AVA.
- *
+ *
* @return {@code true} if this RDN contains more than one AVA,
* otherwise {@code false}.
*/
@@ -816,7 +891,7 @@
* Attempts to remove AVAs using an iterator's {@code remove()} method
* are not permitted and will result in an {@code
* UnsupportedOperationException} being thrown.
- *
+ *
* @return An iterator of the AVAs contained in this RDN.
*/
public Iterator<AVA> iterator()
@@ -828,7 +903,7 @@
/**
* Returns the number of AVAs in this RDN.
- *
+ *
* @return The number of AVAs in this RDN.
*/
public int size()
@@ -840,7 +915,7 @@
/**
* Returns the RFC 4514 string representation of this RDN.
- *
+ *
* @return The RFC 4514 string representation of this RDN.
* @see <a href="http://tools.ietf.org/html/rfc4514">RFC 4514 -
* Lightweight Directory Access Protocol (LDAP): String
--
Gitblit v1.10.0