Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* ====================
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of the Common Development
* and Distribution License("CDDL") (the "License"). You may not use this file
* except in compliance with the License.
*
* You can obtain a copy of the License at
* http://IdentityConnectors.dev.java.net/legal/license.txt
* See the License for the specific language governing permissions and limitations
* under the License.
*
* When distributing the Covered Code, include this CDDL Header Notice in each file
* and include the License file at identityconnectors/legal/license.txt.
* If applicable, add the following below this CDDL Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
* ====================
*/
package org.identityconnectors.framework.common.objects;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.identityconnectors.common.Assertions;
import org.identityconnectors.common.CollectionUtil;
import org.identityconnectors.common.security.GuardedString;
/**
* Utility methods to retrieve values from instances of {@link Attribute}.
*/
public final class AttributeUtil {
/**
* Get the string value from the specified (single-valued) attribute.
*
* @param attr
* Attribute from which to retrieve the string value.
* @return null if the value is null otherwise the string value for the
* attribute.
* @throws ClassCastException
* iff the object in the attribute is not an string.
* @throws IllegalArgumentException
* iff the attribute is a multi-valued (rather than
* single-valued).
*/
public static String getStringValue(Attribute attr) {
Object obj = getSingleValue(attr);
return obj != null ? (String) obj : null;
}
/**
* Get the {@link GuardedString} value from the specified (single-valued)
* attribute.
*
* @param attr
* Attribute from which to retrieve the string value.
* @return null if the value is null otherwise the string value for the
* attribute.
* @throws ClassCastException
* iff the object in the attribute is not an GuardedString.
* @throws IllegalArgumentException
* iff the attribute is a multi-valued (rather than
* single-valued).
*/
public static GuardedString getGuardedStringValue(Attribute attr) {
Object obj = getSingleValue(attr);
return obj != null ? (GuardedString) obj : null;
}
/**
* Get the string value from the specified (single-valued) attribute.
*
* @param attr
* Attribute from which to retrieve the string value.
* @return null if the value is null otherwise the string value for the
* attribute.
* @throws IllegalArgumentException
* iff the attribute is a multi-valued (rather than
* single-valued).
*/
public static String getAsStringValue(Attribute attr) {
Object obj = getSingleValue(attr);
return obj != null ? obj.toString() : null;
}
/**
* Get the integer value from the specified (single-valued) attribute.
*
* @param attr
* Attribute from which to retrieve the integer value.
* @return null if the value is null otherwise the integer value for the
* attribute.
* @throws ClassCastException
* iff the object in the attribute is not an integer.
* @throws IllegalArgumentException
* iff the attribute is a multi-valued (rather than
* single-valued).
*/
public static Integer getIntegerValue(Attribute attr) {
Object obj = getSingleValue(attr);
return obj != null ? (Integer) obj : null;
}
/**
* Get the long value from the specified (single-valued) attribute.
*
* @param attr
* Attribute from which to retrieve the long value.
* @return null if the value is null otherwise the long value for the
* attribute.
* @throws ClassCastException
* iff the object in the attribute is not an long.
* @throws IllegalArgumentException
* iff the attribute is a multi-valued (rather than
* single-valued).
*/
public static Long getLongValue(Attribute attr) {
Object obj = getSingleValue(attr);
return obj != null ? (Long) obj : null;
}
/**
* Get the date value from the specified (single-valued) attribute that contains a long.
*
* @param attr
* Attribute from which to retrieve the date value.
* @return null if the value is null otherwise the date value for the
* attribute.
* @throws ClassCastException
* iff the object in the attribute is not an long.
* @throws IllegalArgumentException
* iff the attribute is a multi-valued (rather than
* single-valued).
*/
public static Date getDateValue(Attribute attr) {
Long value = getLongValue(attr);
return value != null ? new Date(value.longValue()) : null;
}
/**
* Get the integer value from the specified (single-valued) attribute.
*
* @param attr
* Attribute from which to retrieve the integer value.
* @return null if the value is null otherwise the integer value for the
* attribute.
* @throws ClassCastException
* iff the object in the attribute is not an integer.
* @throws IllegalArgumentException
* iff the attribute is a multi-valued (rather than
* single-valued)..
*/
public static Double getDoubleValue(Attribute attr) {
Object obj = getSingleValue(attr);
return obj != null ? (Double) obj : null;
}
/**
* Get the big decimal value from the specified (single-valued) attribute.
*
* @param attr
* Attribute from which to retrieve the big decimal value.
* @return null if the value is null otherwise the big decimal value for the
* attribute.
* @throws ClassCastException
* iff the object in the attribute is not an big decimal.
* @throws IllegalArgumentException
* iff the attribute is a multi-valued (rather than
* single-valued).
*/
public static BigDecimal getBigDecimalValue(Attribute attr) {
Object obj = getSingleValue(attr);
return obj != null ? (BigDecimal) obj : null;
}
/**
* Get the boolean value from the specified (single-valued) attribute.
*
* @param attr
* Attribute from which to retrieve the boolean value.
* @return null if the value is null otherwise the boolean value for the
* attribute.
* @throws ClassCastException
* iff the object in the attribute is not an {@link Boolean}.
* @throws IllegalArgumentException
* iff the attribute is a multi-valued (rather than
* single-valued).
*/
public static Boolean getBooleanValue(Attribute attr) {
Object obj = getSingleValue(attr);
return obj != null ? (Boolean) obj : null;
}
/**
* Get the Object value from the specified (single-valued)
* attribute. Return null if the attribute's list of values
* is null or empty.
*/
public static Object getSingleValue(Attribute attr) {
Object ret = null;
List