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: COSTemplate.java,v 1.4 2008/06/25 05:41:47 qcheng Exp $
026 *
027 * Portions Copyright 2015 ForgeRock AS.
028 */
029
030package com.iplanet.ums.cos;
031
032import com.iplanet.services.ldap.Attr;
033import com.iplanet.services.ldap.AttrSet;
034import com.iplanet.ums.CreationTemplate;
035import com.iplanet.ums.PersistentObject;
036import com.iplanet.ums.UMSException;
037import org.forgerock.opendj.ldap.ModificationType;
038
039/**
040 * This class represents a COS Template. A COS Template has attributes and
041 * attribute values which will be dynamically added to entries affected by COS
042 * definitions.
043 * @supported.api
044 */
045public class COSTemplate extends PersistentObject {
046
047    /**
048     * NoArg constructor
049     */
050    public COSTemplate() {
051    }
052
053    /**
054     * Constructor with creation template and name parameter.
055     * 
056     * @param temp
057     *            the creation tenplate
058     * @param name
059     *            the name of this template
060     * 
061     * @throws UMSException
062     *             The exception thrown from the parent class constructor.
063     * @see com.iplanet.ums.PersistentObject#PersistentObject (CreationTemplate,
064     *      AttrSet)
065     * @supported.api
066     */
067    public COSTemplate(CreationTemplate temp, String name) throws UMSException {
068        super(temp,
069                new AttrSet(new Attr(COSTemplate.DEFAULT_NAMING_ATTR, name)));
070    }
071
072    /**
073     * Returns the name of this COS template.
074     * 
075     * @return The name of this COS template.
076     * @supported.api
077     */
078    public String getName() {
079        String attributeValue = null;
080        Attr attribute = getAttribute(getNamingAttribute());
081        if (attribute != null) {
082            attributeValue = attribute.getValue();
083        }
084        return attributeValue;
085    }
086
087    /**
088     * Sets the priority for this template. The priority determines which COS
089     * template will provide the attribute value if there are competing
090     * templates. A priority of "0" is the highest priority.
091     * 
092     * @param priority Priority for this template.
093     * @supported.api
094     */
095    public void setPriority(int priority) {
096        setAttribute(new Attr("cosPriority", new Integer(priority).toString()));
097    }
098
099    /**
100     * Adds a name/value attribute pair for this template; for example,
101     * "postalcode" and "95020".
102     * 
103     * @param name
104     *            the name of the attribute
105     * 
106     * @param value
107     *            the value of the attribute
108     * @supported.api
109     */
110    public void addTemplateAttribute(String name, String value) {
111        modify(name, value, ModificationType.ADD);
112    }
113
114    /**
115     * Removes a name/value attribute pair from this template.
116     * 
117     * @param name
118     *            the name of the attribute
119     * @supported.api
120     */
121    public void removeTemplateAttribute(String name) {
122        removeAttribute(new Attr(name));
123    }
124
125    /**
126     * LDAP attribute names that apply to COS LDAP entries; used internally by
127     * UMS and COS Manager.
128     */
129    static final String DEFAULT_NAMING_ATTR = "cn";
130
131    static final String[] ATTRIBUTE_NAMES = { "objectclass",
132            DEFAULT_NAMING_ATTR };
133
134}