8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: Attr.java,v 1.4 2009/01/28 05:34:49 ww203982 Exp $
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * Portions Copyrighted 2011-2015 ForgeRock AS.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.Attributes;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Represents an attribute value pair in UMS. The value of an attribute can be
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of multiple values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class Attr implements java.io.Serializable, java.lang.Cloneable {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Default constructor
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs an attribute value pair with no value.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * attribute name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Construct an attribute value pair with a single string value.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the name of attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * string value of attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Construct an attribute value pair with a multiple string values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the name of attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * multiple string values of attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs an attribute value pair with byte array.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * attribute name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * byte array as input for value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs an attribute value pair with array of byte array.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * attribute name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * array of byte array as input for value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Construct an attribute based on a LDAP attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attr
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ldap attribute to construct from
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington _name = attr.getAttributeDescriptionAsString().toLowerCase();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Map to a ldap attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return an ldap attribute
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington ldapAttribute = Attributes.emptyAttribute(_name);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington ldapAttribute = Attributes.singletonAttribute(_name, _stringValues.get(0));
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington ldapAttribute = Attributes.emptyAttribute(_name);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington ldapAttribute = Attributes.emptyAttribute(_name);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington ldapAttribute = Attributes.emptyAttribute(_name);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Set value of an attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the attribute value to be set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Add a string value to the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * value to be added to the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Add mulitple string values to the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param values
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * string values to be added to the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Remove a specified string value in the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * specified value to be remvoed from the value array
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Set value of an attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the attribute value to be set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Add a byte array value to the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * byte array value to be added to the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Add a list byte array values to the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param values
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of byte array values to be added to the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Remove a specified string value in the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * specified value to be remvoed from the value array
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // we might have to change the logic here to compare each byte
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get name of an UMS attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return name of an UMS attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get name of attribute in a given Locale
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param locale
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Given locale for the attribute name to return
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return name of an UMS attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get attribute name with locale input.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * name of the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param locale
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * desired locale for the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return attribute name with locale attached for retrieval
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static public String getName(String attrName, Locale locale) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // TODO: ??? check if locale.toString method provides the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // contents in locale.getLanguage, locale.getSubtype, and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // locale.getVariant methods that match the language subtypes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder sb = new StringBuilder(baseName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get base name for the attribute. e.g, the base name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of "cn;lang-en" or "cn;lang-ja" is "cn"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return basename of an attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get base name for an attribute name. e.g, the base
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * name of "cn;lang-en" or "cn;lang-ja" is "cn"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return basename of the given attribute name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static public String getBaseName(String attrName) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington StringTokenizer st = new StringTokenizer(attrName, ";");
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington // First element is base name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get one string value of the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return one value of the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get the string values of the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the values in an string array
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Returning a colletion would be better, but would break existing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // higher level
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // com.iplanet.ums.Pauser.pause("10", "_stringValues : " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // _stringValues);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // com.iplanet.ums.Pauser.pause("10", "_stringValue : " + _stringValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // System.out.println("_stringValue : " + _stringValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // System.out.println("_stringValues : " + _stringValues);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster stringValues[i] = (String) _stringValues.get(i);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Checks whether the given value already exist for
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the value to check for
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>true</code> if the value already exists,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>false</code> otherwise
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean contained = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get one byte[] value of the attribute Returning a
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * colletion would be better, but will not be consistent with the method
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * getStringValues()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return one byte[] value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Not cloning the value before returning. Do we need to clone?
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get the byte[] values of the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the byte[] values in array
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Not cloning the values before returning. Do we need to clone?
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Checks whether the given value already exist for
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the value to check for
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>true</code> if the value already exists,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>false</code> otherwise
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean contained = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // we might have to change the logic here to compare each byte
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get the number of values of the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The number of values of the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Return a copy of the object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return A copy of the object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * TO DO : revisit and do proper deep cloning?
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington theClone._stringValues = new ArrayList<>(_stringValues);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington theClone._byteValues = new ArrayList<>(_byteValues);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster theClone._ldapAttribute = _ldapAttribute; // clone?
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Retrieves the string representation of an attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return string representation of the attribute.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String[] values = _ldapAttribute.toArray(new String[0]);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington byte[][] values = _ldapAttribute.toArray(new byte[0][]);