From e91a87afe532a9a3aa42189ca43cf5cd63ecf759 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Sat, 07 Oct 2006 19:57:47 +0000
Subject: [PATCH] Add a new ByteStringFactory class that can be used to create ByteString objects without needing to reference any classes outside of the public API. Also, update several classes that should use the public API to use the ByteStringFactory rather than creating ASN1OctetString objects.
---
opends/src/server/org/opends/server/extensions/SaltedSHA512PasswordStorageScheme.java | 8 +-
opends/src/server/org/opends/server/extensions/SaltedSHA384PasswordStorageScheme.java | 8 +-
opends/src/server/org/opends/server/types/ByteStringFactory.java | 102 +++++++++++++++++++++++++
opends/src/server/org/opends/server/extensions/SaltedSHA256PasswordStorageScheme.java | 8 +-
opends/src/server/org/opends/server/types/ByteString.java | 4
opends/src/server/org/opends/server/extensions/ClearPasswordStorageScheme.java | 4
opends/src/server/org/opends/server/extensions/RandomPasswordGenerator.java | 7 +
opends/src/server/org/opends/server/extensions/Base64PasswordStorageScheme.java | 9 +-
opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java | 8 +-
opends/src/server/org/opends/server/plugins/LastModPlugin.java | 20 ++--
opends/src/server/org/opends/server/extensions/SHA1PasswordStorageScheme.java | 6
opends/src/server/org/opends/server/plugins/EntryUUIDPlugin.java | 6
opends/src/server/org/opends/server/protocols/asn1/ASN1OctetString.java | 8 ++
opends/src/server/org/opends/server/extensions/LengthBasedPasswordValidator.java | 2
opends/src/server/org/opends/server/extensions/SaltedMD5PasswordStorageScheme.java | 8 +-
opends/src/server/org/opends/server/extensions/MD5PasswordStorageScheme.java | 6
16 files changed, 164 insertions(+), 50 deletions(-)
diff --git a/opends/src/server/org/opends/server/extensions/Base64PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/Base64PasswordStorageScheme.java
index 49230ba..47b7a40 100644
--- a/opends/src/server/org/opends/server/extensions/Base64PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/Base64PasswordStorageScheme.java
@@ -31,8 +31,8 @@
import org.opends.server.api.PasswordStorageScheme;
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.types.ResultCode;
@@ -114,7 +114,7 @@
{
assert debugEnter(CLASS_NAME, "encodePassword", "ByteString");
- return new ASN1OctetString(Base64.encode(plaintext.value()));
+ return ByteStringFactory.create(Base64.encode(plaintext.value()));
}
@@ -135,7 +135,7 @@
buffer.append('}');
buffer.append(Base64.encode(plaintext.value()));
- return new ASN1OctetString(buffer.toString());
+ return ByteStringFactory.create(buffer.toString());
}
@@ -184,7 +184,8 @@
try
{
- return new ASN1OctetString(Base64.decode(storedPassword.stringValue()));
+ return ByteStringFactory.create(Base64.decode(
+ storedPassword.stringValue()));
}
catch (Exception e)
{
diff --git a/opends/src/server/org/opends/server/extensions/ClearPasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/ClearPasswordStorageScheme.java
index 69e5f28..6a71496 100644
--- a/opends/src/server/org/opends/server/extensions/ClearPasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/ClearPasswordStorageScheme.java
@@ -31,8 +31,8 @@
import org.opends.server.api.PasswordStorageScheme;
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.types.ResultCode;
@@ -134,7 +134,7 @@
buffer.append('}');
buffer.append(plaintext.stringValue());
- return new ASN1OctetString(buffer.toString());
+ return ByteStringFactory.create(buffer.toString());
}
diff --git a/opends/src/server/org/opends/server/extensions/LengthBasedPasswordValidator.java b/opends/src/server/org/opends/server/extensions/LengthBasedPasswordValidator.java
index 8bad509..0a03f5f 100644
--- a/opends/src/server/org/opends/server/extensions/LengthBasedPasswordValidator.java
+++ b/opends/src/server/org/opends/server/extensions/LengthBasedPasswordValidator.java
@@ -203,7 +203,7 @@
StringBuilder invalidReason)
{
assert debugEnter(CLASS_NAME, "passwordIsAcceptable",
- "org.opends.server.protocols.asn1.ASN1OctetString",
+ "ByteString", "Set<ByteString>",
String.valueOf(operation), String.valueOf(userEntry),
"java.lang.StringBuilder");
diff --git a/opends/src/server/org/opends/server/extensions/MD5PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/MD5PasswordStorageScheme.java
index d84285e..6a5e8e5 100644
--- a/opends/src/server/org/opends/server/extensions/MD5PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/MD5PasswordStorageScheme.java
@@ -36,8 +36,8 @@
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ErrorLogCategory;
import org.opends.server.types.ErrorLogSeverity;
@@ -171,7 +171,7 @@
digestLock.unlock();
}
- return new ASN1OctetString(Base64.encode(digestBytes));
+ return ByteStringFactory.create(Base64.encode(digestBytes));
}
@@ -218,7 +218,7 @@
buffer.append(Base64.encode(digestBytes));
- return new ASN1OctetString(buffer.toString());
+ return ByteStringFactory.create(buffer.toString());
}
diff --git a/opends/src/server/org/opends/server/extensions/RandomPasswordGenerator.java b/opends/src/server/org/opends/server/extensions/RandomPasswordGenerator.java
index 4cb0242..b9379ca 100644
--- a/opends/src/server/org/opends/server/extensions/RandomPasswordGenerator.java
+++ b/opends/src/server/org/opends/server/extensions/RandomPasswordGenerator.java
@@ -42,7 +42,8 @@
import org.opends.server.config.ConfigException;
import org.opends.server.config.StringConfigAttribute;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.asn1.ASN1OctetString;
+import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.ConfigChangeResult;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.DN;
@@ -297,7 +298,7 @@
* @throws DirectoryException If a problem occurs while attempting to
* generate the password.
*/
- public ASN1OctetString generatePassword(Entry userEntry)
+ public ByteString generatePassword(Entry userEntry)
throws DirectoryException
{
assert debugEnter(CLASS_NAME, "generatePassword",
@@ -320,7 +321,7 @@
generatorLock.unlock();
}
- return new ASN1OctetString(buffer.toString());
+ return ByteStringFactory.create(buffer.toString());
}
diff --git a/opends/src/server/org/opends/server/extensions/SHA1PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/SHA1PasswordStorageScheme.java
index f37b4a7..9e005e3 100644
--- a/opends/src/server/org/opends/server/extensions/SHA1PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/SHA1PasswordStorageScheme.java
@@ -36,8 +36,8 @@
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ErrorLogCategory;
import org.opends.server.types.ErrorLogSeverity;
@@ -171,7 +171,7 @@
digestLock.unlock();
}
- return new ASN1OctetString(Base64.encode(digestBytes));
+ return ByteStringFactory.create(Base64.encode(digestBytes));
}
@@ -217,7 +217,7 @@
buffer.append(Base64.encode(digestBytes));
- return new ASN1OctetString(buffer.toString());
+ return ByteStringFactory.create(buffer.toString());
}
diff --git a/opends/src/server/org/opends/server/extensions/SaltedMD5PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/SaltedMD5PasswordStorageScheme.java
index 873b592..9683992 100644
--- a/opends/src/server/org/opends/server/extensions/SaltedMD5PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/SaltedMD5PasswordStorageScheme.java
@@ -37,8 +37,8 @@
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ErrorLogCategory;
import org.opends.server.types.ErrorLogSeverity;
@@ -206,7 +206,7 @@
System.arraycopy(saltBytes, 0, hashPlusSalt, digestBytes.length,
NUM_SALT_BYTES);
- return new ASN1OctetString(Base64.encode(hashPlusSalt));
+ return ByteStringFactory.create(Base64.encode(hashPlusSalt));
}
@@ -270,7 +270,7 @@
NUM_SALT_BYTES);
buffer.append(Base64.encode(hashPlusSalt));
- return new ASN1OctetString(buffer.toString());
+ return ByteStringFactory.create(buffer.toString());
}
@@ -427,7 +427,7 @@
authPWValue.append('$');
authPWValue.append(Base64.encode(digestBytes));
- return new ASN1OctetString(authPWValue.toString());
+ return ByteStringFactory.create(authPWValue.toString());
}
diff --git a/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java
index bec66eb..1149430 100644
--- a/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java
@@ -37,8 +37,8 @@
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ErrorLogCategory;
import org.opends.server.types.ErrorLogSeverity;
@@ -205,7 +205,7 @@
System.arraycopy(saltBytes, 0, hashPlusSalt, digestBytes.length,
NUM_SALT_BYTES);
- return new ASN1OctetString(Base64.encode(hashPlusSalt));
+ return ByteStringFactory.create(Base64.encode(hashPlusSalt));
}
@@ -269,7 +269,7 @@
NUM_SALT_BYTES);
buffer.append(Base64.encode(hashPlusSalt));
- return new ASN1OctetString(buffer.toString());
+ return ByteStringFactory.create(buffer.toString());
}
@@ -426,7 +426,7 @@
authPWValue.append('$');
authPWValue.append(Base64.encode(digestBytes));
- return new ASN1OctetString(authPWValue.toString());
+ return ByteStringFactory.create(authPWValue.toString());
}
diff --git a/opends/src/server/org/opends/server/extensions/SaltedSHA256PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/SaltedSHA256PasswordStorageScheme.java
index 492da2c..c6d4ce4 100644
--- a/opends/src/server/org/opends/server/extensions/SaltedSHA256PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/SaltedSHA256PasswordStorageScheme.java
@@ -37,8 +37,8 @@
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ErrorLogCategory;
import org.opends.server.types.ErrorLogSeverity;
@@ -208,7 +208,7 @@
System.arraycopy(saltBytes, 0, hashPlusSalt, digestBytes.length,
NUM_SALT_BYTES);
- return new ASN1OctetString(Base64.encode(hashPlusSalt));
+ return ByteStringFactory.create(Base64.encode(hashPlusSalt));
}
@@ -272,7 +272,7 @@
NUM_SALT_BYTES);
buffer.append(Base64.encode(hashPlusSalt));
- return new ASN1OctetString(buffer.toString());
+ return ByteStringFactory.create(buffer.toString());
}
@@ -429,7 +429,7 @@
authPWValue.append('$');
authPWValue.append(Base64.encode(digestBytes));
- return new ASN1OctetString(authPWValue.toString());
+ return ByteStringFactory.create(authPWValue.toString());
}
diff --git a/opends/src/server/org/opends/server/extensions/SaltedSHA384PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/SaltedSHA384PasswordStorageScheme.java
index dfd5fb5..dd207dd 100644
--- a/opends/src/server/org/opends/server/extensions/SaltedSHA384PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/SaltedSHA384PasswordStorageScheme.java
@@ -37,8 +37,8 @@
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ErrorLogCategory;
import org.opends.server.types.ErrorLogSeverity;
@@ -208,7 +208,7 @@
System.arraycopy(saltBytes, 0, hashPlusSalt, digestBytes.length,
NUM_SALT_BYTES);
- return new ASN1OctetString(Base64.encode(hashPlusSalt));
+ return ByteStringFactory.create(Base64.encode(hashPlusSalt));
}
@@ -272,7 +272,7 @@
NUM_SALT_BYTES);
buffer.append(Base64.encode(hashPlusSalt));
- return new ASN1OctetString(buffer.toString());
+ return ByteStringFactory.create(buffer.toString());
}
@@ -429,7 +429,7 @@
authPWValue.append('$');
authPWValue.append(Base64.encode(digestBytes));
- return new ASN1OctetString(authPWValue.toString());
+ return ByteStringFactory.create(authPWValue.toString());
}
diff --git a/opends/src/server/org/opends/server/extensions/SaltedSHA512PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/SaltedSHA512PasswordStorageScheme.java
index 9412ea5..f2ba389 100644
--- a/opends/src/server/org/opends/server/extensions/SaltedSHA512PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/SaltedSHA512PasswordStorageScheme.java
@@ -37,8 +37,8 @@
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ErrorLogCategory;
import org.opends.server.types.ErrorLogSeverity;
@@ -207,7 +207,7 @@
System.arraycopy(saltBytes, 0, hashPlusSalt, digestBytes.length,
NUM_SALT_BYTES);
- return new ASN1OctetString(Base64.encode(hashPlusSalt));
+ return ByteStringFactory.create(Base64.encode(hashPlusSalt));
}
@@ -271,7 +271,7 @@
NUM_SALT_BYTES);
buffer.append(Base64.encode(hashPlusSalt));
- return new ASN1OctetString(buffer.toString());
+ return ByteStringFactory.create(buffer.toString());
}
@@ -428,7 +428,7 @@
authPWValue.append('$');
authPWValue.append(Base64.encode(digestBytes));
- return new ASN1OctetString(authPWValue.toString());
+ return ByteStringFactory.create(authPWValue.toString());
}
diff --git a/opends/src/server/org/opends/server/plugins/EntryUUIDPlugin.java b/opends/src/server/org/opends/server/plugins/EntryUUIDPlugin.java
index 95c944c..254c026 100644
--- a/opends/src/server/org/opends/server/plugins/EntryUUIDPlugin.java
+++ b/opends/src/server/org/opends/server/plugins/EntryUUIDPlugin.java
@@ -42,11 +42,11 @@
import org.opends.server.api.plugin.PreOperationPluginResult;
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeUsage;
import org.opends.server.types.AttributeValue;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryConfig;
import org.opends.server.types.Entry;
import org.opends.server.types.LDIFImportConfig;
@@ -184,7 +184,7 @@
LinkedHashSet<AttributeValue> values = new LinkedHashSet<AttributeValue>(1);
values.add(new AttributeValue(entryUUIDType,
- new ASN1OctetString(uuid.toString())));
+ ByteStringFactory.create(uuid.toString())));
uuidList = new ArrayList<Attribute>(1);
Attribute uuidAttr = new Attribute(entryUUIDType, "entryUUID", values);
@@ -226,7 +226,7 @@
LinkedHashSet<AttributeValue> values = new LinkedHashSet<AttributeValue>(1);
values.add(new AttributeValue(entryUUIDType,
- new ASN1OctetString(uuid.toString())));
+ ByteStringFactory.create(uuid.toString())));
uuidList = new ArrayList<Attribute>(1);
Attribute uuidAttr = new Attribute(entryUUIDType, "entryUUID", values);
diff --git a/opends/src/server/org/opends/server/plugins/LastModPlugin.java b/opends/src/server/org/opends/server/plugins/LastModPlugin.java
index ebe73e6..a886a41 100644
--- a/opends/src/server/org/opends/server/plugins/LastModPlugin.java
+++ b/opends/src/server/org/opends/server/plugins/LastModPlugin.java
@@ -37,10 +37,10 @@
import org.opends.server.api.plugin.PreOperationPluginResult;
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
-import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeValue;
+import org.opends.server.types.ByteStringFactory;
import org.opends.server.types.DirectoryConfig;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.DN;
@@ -172,12 +172,12 @@
// This must mean that the operation was performed anonymously. Even so,
// we still need to update the creatorsName attribute.
nameValues.add(new AttributeValue(creatorsNameType,
- new ASN1OctetString()));
+ ByteStringFactory.create()));
}
else
{
nameValues.add(new AttributeValue(creatorsNameType,
- new ASN1OctetString(creatorDN.toString())));
+ ByteStringFactory.create(creatorDN.toString())));
}
Attribute nameAttr = new Attribute(creatorsNameType, OP_ATTR_CREATORS_NAME,
nameValues);
@@ -190,7 +190,7 @@
LinkedHashSet<AttributeValue> timeValues =
new LinkedHashSet<AttributeValue>(1);
timeValues.add(new AttributeValue(createTimestampType,
- new ASN1OctetString(getUTCTime())));
+ ByteStringFactory.create(getUTCTime())));
Attribute timeAttr = new Attribute(createTimestampType,
OP_ATTR_CREATE_TIMESTAMP, timeValues);
@@ -225,12 +225,12 @@
// This must mean that the operation was performed anonymously. Even so,
// we still need to update the modifiersName attribute.
nameValues.add(new AttributeValue(modifiersNameType,
- new ASN1OctetString()));
+ ByteStringFactory.create()));
}
else
{
nameValues.add(new AttributeValue(modifiersNameType,
- new ASN1OctetString(modifierDN.toString())));
+ ByteStringFactory.create(modifierDN.toString())));
}
Attribute nameAttr = new Attribute(modifiersNameType,
OP_ATTR_MODIFIERS_NAME, nameValues);
@@ -254,7 +254,7 @@
LinkedHashSet<AttributeValue> timeValues =
new LinkedHashSet<AttributeValue>(1);
timeValues.add(new AttributeValue(modifyTimestampType,
- new ASN1OctetString(getUTCTime())));
+ ByteStringFactory.create(getUTCTime())));
Attribute timeAttr = new Attribute(modifyTimestampType,
OP_ATTR_MODIFY_TIMESTAMP, timeValues);
@@ -300,12 +300,12 @@
// This must mean that the operation was performed anonymously. Even so,
// we still need to update the modifiersName attribute.
nameValues.add(new AttributeValue(modifiersNameType,
- new ASN1OctetString()));
+ ByteStringFactory.create()));
}
else
{
nameValues.add(new AttributeValue(modifiersNameType,
- new ASN1OctetString(modifierDN.toString())));
+ ByteStringFactory.create(modifierDN.toString())));
}
Attribute nameAttr = new Attribute(modifiersNameType,
OP_ATTR_MODIFIERS_NAME, nameValues);
@@ -317,7 +317,7 @@
LinkedHashSet<AttributeValue> timeValues =
new LinkedHashSet<AttributeValue>(1);
timeValues.add(new AttributeValue(modifyTimestampType,
- new ASN1OctetString(getUTCTime())));
+ ByteStringFactory.create(getUTCTime())));
Attribute timeAttr = new Attribute(modifyTimestampType,
OP_ATTR_MODIFY_TIMESTAMP, timeValues);
diff --git a/opends/src/server/org/opends/server/protocols/asn1/ASN1OctetString.java b/opends/src/server/org/opends/server/protocols/asn1/ASN1OctetString.java
index d524cad..c977a77 100644
--- a/opends/src/server/org/opends/server/protocols/asn1/ASN1OctetString.java
+++ b/opends/src/server/org/opends/server/protocols/asn1/ASN1OctetString.java
@@ -42,6 +42,14 @@
/**
* This class defines the data structures and methods to use when interacting
* with ASN.1 octet string elements.
+ * <BR><BR>
+ * Note that this class also implements the <CODE>ByteString</CODE> interface,
+ * but in most cases whenever it is necessary to create an instance of a
+ * <CODE>ByteString</CODE> object, the caller should use one of the
+ * <CODE>ByteStringFactory.create</CODE> methods rather than creating an
+ * <CODE>ASN1OctetString</CODE> object directly. In general, direct references
+ * to ASN.1 elements should be limited to cases in which ASN.1 is actually
+ * involved.
*/
public class ASN1OctetString
extends ASN1Element
diff --git a/opends/src/server/org/opends/server/types/ByteString.java b/opends/src/server/org/opends/server/types/ByteString.java
index 4da86c9..ccc830c 100644
--- a/opends/src/server/org/opends/server/types/ByteString.java
+++ b/opends/src/server/org/opends/server/types/ByteString.java
@@ -34,7 +34,9 @@
/**
* This interface defines data type that is backed by a byte array but
- * may also have a string representation.
+ * may also have a string representation. The preferred way to create
+ * a <CODE>ByteString</CODE> object is to use one of the
+ * <CODE>ByteStringFactory.create</CODE> methods.
*/
public interface ByteString
{
diff --git a/opends/src/server/org/opends/server/types/ByteStringFactory.java b/opends/src/server/org/opends/server/types/ByteStringFactory.java
new file mode 100644
index 0000000..82078a5
--- /dev/null
+++ b/opends/src/server/org/opends/server/types/ByteStringFactory.java
@@ -0,0 +1,102 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ * Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+package org.opends.server.types;
+
+
+
+import org.opends.server.protocols.asn1.ASN1OctetString;
+
+import static org.opends.server.loggers.Debug.*;
+
+
+
+/**
+ * This class provides static factory methods for creating ByteString
+ * objects.
+ */
+public final class ByteStringFactory
+{
+ /**
+ * The fully-qualified name of this class for debugging purposes.
+ */
+ private static final String CLASS_NAME =
+ "org.opends.server.types.ByteStringFactory";
+
+
+
+ /**
+ * Creates a new <CODE>ByteString</CODE> object with no value.
+ *
+ * @return A new <CODE>ByteString</CODE> object with no value.
+ */
+ public static ByteString create()
+ {
+ assert debugEnter(CLASS_NAME, "create");
+
+ return new ASN1OctetString();
+ }
+
+
+
+ /**
+ * Creates a new <CODE>ByteString</CODE> object for the provided
+ * byte array value.
+ *
+ * @param value The value to use to create the
+ * <CODE>ByteString</CODE> object.
+ *
+ * @return A new <CODE>ByteString</CODE> object with the specified
+ * value.
+ */
+ public static ByteString create(byte[] value)
+ {
+ assert debugEnter(CLASS_NAME, "create",
+ "byte[" + value.length + "]");
+
+ return new ASN1OctetString(value);
+ }
+
+
+
+ /**
+ * Creates a new <CODE>ByteString</CODE> object for the provided
+ * string value.
+ *
+ * @param value The value to use to create the
+ * <CODE>ByteString</CODE> object.
+ *
+ * @return A new <CODE>ByteString</CODE> object with the specified
+ * value.
+ */
+ public static ByteString create(String value)
+ {
+ assert debugEnter(CLASS_NAME, "create", value);
+
+ return new ASN1OctetString(value);
+ }
+}
+
--
Gitblit v1.10.0