001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: Guid.java,v 1.4 2009/01/28 05:34:50 ww203982 Exp $
026 *
027 */
028
029package com.iplanet.ums;
030
031import com.sun.identity.shared.ldap.LDAPDN;
032
033/**
034 * This class represents an LDAP entry and it provides
035 * access to the ID (dn) and GUID of the given name. Every persistent object
036 * (that is, entry in the Directory server) has a GUID (Globally Unique
037 * Identifier) associated with it. Upon doing a getGuid() (getGuid() is a method
038 * in the PersistentObject class) on an LDAP entry, this GUID object would be
039 * returned (not a DN string or a guid in the LDAP sense). Methods of the Guid
040 * object could then be used to get the actual DN, etc.
041 *
042 * @supported.all.api
043 */
044public class Guid {
045
046    // holds the LDAP dn for the LDAP entry associated with this Guid object
047    private String _dn;
048
049    // holds the unique ID for the LDAP entry associated with this Guid object
050    private long _uniqueId;
051
052    /**
053     * Constructs a Guid object from the specified distinguished name.
054     * 
055     * @param dn
056     *            string representation of the distinguished name
057     */
058    public Guid(String dn) {
059        _dn = dn;
060        _uniqueId = -1;
061    }
062
063    /**
064     * Constructs a Guid object from the specified unique ID.
065     * 
066     * @param id
067     *            unique ID
068     */
069    public Guid(long id) {
070        _dn = "";
071        _uniqueId = id;
072    }
073
074    /**
075     * Constructs a Guid object from the specified distinguished name and unique
076     * ID.
077     * 
078     * @param dn
079     *            string representation of the distinguished name
080     * @param id
081     *            unique ID
082     */
083    public Guid(String dn, long id) {
084        _dn = dn;
085        _uniqueId = id;
086    }
087
088    /**
089     * Returns the string representation of the distinguished name.
090     * 
091     * @return the string representation of the distinguished name
092     */
093    public String getDn() {
094        return _dn;
095    }
096
097    /**
098     * Sets the dn for this object. Note that the value is not persisted in
099     * LDAP.
100     * 
101     * @param dn
102     *            string representation of the distinguished name
103     */
104    protected void setDn(String dn) {
105        _dn = dn;
106    }
107
108    /**
109     * Returns the nsuniqueID name in the Guid object associated with an LDAP
110     * entry.
111     * 
112     * @return the nsuniqueID name in the Guid object associated with an LDAP
113     *         entry
114     */
115    public long getId() {
116        return _uniqueId;
117    }
118
119    /**
120     * Sets the nsuniqueID name in the Guid object associated with an LDAP entry
121     * Note that the value is not persisted in LDAP.
122     * 
123     * @param id
124     *            the nsuniqueID name
125     */
126    protected void setId(long id) {
127        _uniqueId = id;
128    }
129
130    /**
131     * Determines if the current Guid is equal to the specified Guid.
132     * 
133     * @param guid
134     *            Guid to compare against the current Guid
135     * @return true if the two Guids are the same
136     */
137    public boolean equals(Guid guid) {
138        return LDAPDN.equals(_dn, guid.getDn());
139    }
140
141    /**
142     * Compares two dn's for equality.
143     * 
144     * @param dn1
145     *            the first dn to compare
146     * @param dn2
147     *            the second dn to compare
148     * @return true if the two dn's are equal
149     */
150    static boolean equals(String dn1, String dn2) {
151        return LDAPDN.equals(dn1, dn2);
152    }
153
154    /**
155     * Returns the String form of this Guid object.
156     * 
157     * @return the string representation of the Guid
158     */
159    public String toString() {
160        return _dn;
161        // For future use
162        // StringBuffer buff = new StringBuffer();
163        // buff.append("DN : " + _dn + "\n");
164        // buff.append("ID : " + _uniqueId + "\n");
165        // return buff.toString();
166    }
167}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.