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: OrganizationalUnit.java,v 1.3 2008/06/25 05:41:45 qcheng Exp $
026 *
027 */
028
029package com.iplanet.ums;
030
031import java.security.Principal;
032
033import com.iplanet.services.ldap.AttrSet;
034
035/**
036 * Representation of organizational unit. Such as
037 * 
038 * <pre>
039 *   ou=people,o=vortex.com 
040 *   ou=groups,o=vortex.com
041 * </pre>
042 * 
043 * They are persistent objects and can be used as a container. For example,
044 * 
045 * <PRE>
046 * 
047 * orgUnit = (OrganizationalUnit)UMSSession.getObject( ctx, id ); orgUnit.add(
048 * User1 );
049 * 
050 * </PRE>
051 *
052 * @supported.api
053 */
054public class OrganizationalUnit extends PersistentObject {
055
056    /**
057     * No args constructor; used to construct the right object as entries are
058     * are read from persistent storage
059     */
060    protected OrganizationalUnit() throws UMSException {
061    }
062
063    /**
064     * Constructor of OrganizationalUnit from supplied session and guid
065     * identifying the organization to be constructed
066     * 
067     * @param session
068     *            authenticated session object maintained by the Session Manager
069     * @param guid
070     *            globally unique identifier for the organizational unit
071     */
072    OrganizationalUnit(Principal principal, Guid guid) throws UMSException {
073        super(principal, guid);
074        verifyClass();
075    }
076
077    /**
078     * Constructs an OrganizationalUnit object without a session. Unlike the
079     * constructor with a session parameter , this one simply creates an object
080     * in memory, using the default template. Call save() to save the object to
081     * the persistent store.
082     * 
083     * @param attrSet
084     *            attribute/value set
085     */
086    OrganizationalUnit(AttrSet attrSet) throws UMSException {
087        this(TemplateManager.getTemplateManager().getCreationTemplate(_class,
088                null), attrSet);
089    }
090
091    /**
092     * Constructs a Organizational unit object without a session. Unlike
093     * constructor with session, this one simply creates OrganizationalUnit
094     * object in memory. Call save() to save the object to persistent storage.
095     * 
096     * @param template
097     *            template for the OrganizationalUnit, containing required and
098     *            optional attributes, and possibly default values
099     * @param attrSet
100     *            attribute/value set
101     * @supported.api
102     */
103    public OrganizationalUnit(CreationTemplate template, AttrSet attrSet)
104            throws UMSException {
105        super(template, attrSet);
106    }
107
108    /**
109     * Return name of the organizational unit
110     * 
111     * @return name of the organizational unit
112     * @supported.api
113     */
114    public String getName() throws UMSException {
115        return (getAttribute(getNamingAttribute()).getValue());
116    }
117
118    private static final Class _class = 
119            com.iplanet.ums.OrganizationalUnit.class;
120}