bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
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 *
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 * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
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 *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: Guid.java,v 1.4 2009/01/28 05:34:50 ww203982 Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * Portions Copyright 2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.iplanet.ums;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.DN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class represents an LDAP entry and it provides
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * access to the ID (dn) and GUID of the given name. Every persistent object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (that is, entry in the Directory server) has a GUID (Globally Unique
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Identifier) associated with it. Upon doing a getGuid() (getGuid() is a method
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * in the PersistentObject class) on an LDAP entry, this GUID object would be
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * returned (not a DN string or a guid in the LDAP sense). Methods of the Guid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * object could then be used to get the actual DN, etc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.all.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class Guid {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // holds the LDAP dn for the LDAP entry associated with this Guid object
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington private DN _dn;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // holds the unique ID for the LDAP entry associated with this Guid object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private long _uniqueId;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs a Guid object from the specified distinguished name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param dn
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * string representation of the distinguished name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Guid(String dn) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington _dn = DN.valueOf(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster _uniqueId = -1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs a Guid object from the specified unique ID.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param id
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * unique ID
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Guid(long id) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington _dn = DN.valueOf("");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster _uniqueId = id;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs a Guid object from the specified distinguished name and unique
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ID.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param dn
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * string representation of the distinguished name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param id
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * unique ID
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Guid(String dn, long id) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington _dn = DN.valueOf(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster _uniqueId = id;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the string representation of the distinguished name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the string representation of the distinguished name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getDn() {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington return _dn.toString();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the dn for this object. Note that the value is not persisted in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * LDAP.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param dn
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * string representation of the distinguished name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void setDn(String dn) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington _dn = DN.valueOf(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the nsuniqueID name in the Guid object associated with an LDAP
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * entry.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the nsuniqueID name in the Guid object associated with an LDAP
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * entry
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public long getId() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return _uniqueId;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the nsuniqueID name in the Guid object associated with an LDAP entry
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Note that the value is not persisted in LDAP.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param id
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the nsuniqueID name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void setId(long id) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster _uniqueId = id;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Determines if the current Guid is equal to the specified Guid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param guid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Guid to compare against the current Guid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true if the two Guids are the same
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean equals(Guid guid) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington return _dn.equals(DN.valueOf(guid.getDn()));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Compares two dn's for equality.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param dn1
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the first dn to compare
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param dn2
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the second dn to compare
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true if the two dn's are equal
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static boolean equals(String dn1, String dn2) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington return DN.valueOf(dn1).equals(DN.valueOf(dn2));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the String form of this Guid object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the string representation of the Guid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String toString() {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington return _dn.toString();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // For future use
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // StringBuffer buff = new StringBuffer();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // buff.append("DN : " + _dn + "\n");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // buff.append("ID : " + _uniqueId + "\n");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // return buff.toString();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}