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: DirectCOSDefinition.java,v 1.3 2008/06/25 05:41:47 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * Portions Copyrighted 2011-2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.iplanet.ums.cos;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.ArrayList;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Collection;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.ldap.Attr;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.ldap.AttrSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.util.I18n;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.ums.CreationTemplate;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.ums.Guid;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.ums.IUMSConstants;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.ums.PersistentObject;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.ums.SearchResults;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.ums.TemplateManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.ums.UMSException;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.ModificationType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class represents a Direct (or Classic) COS definition.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class DirectCOSDefinition extends PersistentObject implements
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ICOSDefinition {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * NoArg Constructor
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public DirectCOSDefinition() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructor with attribute set argument. The attribute set needs to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * contain all the required attributes for this definition: name,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * cosspecifier, cosattribute (with qualifier).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrSet
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the attribute set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The exception thrown from the DirectCOSDefinition constructor
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * accepting a creation template and attribute set.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.ums.cos.DirectCOSDefinition#DirectCOSDefinition
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (CreationTemplate, AttrSet)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public DirectCOSDefinition(AttrSet attrSet) throws UMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this(TemplateManager.getTemplateManager().getCreationTemplate(_class,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster null), attrSet);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructor with creation template and attribute set arguments.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param template
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the Creation template.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrSet
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the attribute set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The exception thrown from the parent class constructor.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.ums.PersistentObject#PersistentObject (CreationTemplate,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * AttrSet)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public DirectCOSDefinition(CreationTemplate template, AttrSet attrSet)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws UMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster super(template, attrSet);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the name of this COS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the name of this COS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setName(String name) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster setAttribute(new Attr(ICOSDefinition.DEFAULT_NAMING_ATTR, name));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the name of this COS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the name of this COS
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getName() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String attributeValue = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Attr attribute = getAttribute(getNamingAttribute());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (attribute != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attributeValue = attribute.getValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return attributeValue;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Adds the COS attribute to the definition. The COS attribute is the name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the attribute for which you want to generate a value.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The name of the attribute (for example, mailQuota)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param qualifier
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * An integer representing the following values: "default" - The
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * server only returns a generated value if there is no
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * corresponding attribute value stored with the entry.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "override" - This value will always be generated by the server
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (it will override entry values). "operational" - the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * will only be returned if it is requested in the search.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "operational" can be combined with "default" or "override".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * These values are represented as integers in the ICOSDefinition
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * interface.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The exception thrown from the data layer.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void addCOSAttribute(String attrName, int qualifier)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws UMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder attrStr = new StringBuilder();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (qualifier < ICOSDefinition.minQualifier
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster || qualifier > ICOSDefinition.maxQualifier) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = i18n.getString(IUMSConstants.BAD_COS_ATTR_QUALIFIER);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new UMSException(msg);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attrStr.append(attrName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attrStr.append(" ");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attrStr.append(ICOSDefinition.qualifiers[qualifier]);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington modify(ICOSDefinition.COSATTRIBUTE, attrStr.toString(), ModificationType.ADD);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Removes the COS attribute from the definition.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The name of the attribute to be removed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void removeCOSAttribute(String attrName) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington modify(new Attr(ICOSDefinition.COSATTRIBUTE, attrName), ModificationType.DELETE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Retrieves the COS attributes for this definition.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return String[] A string array of COS attributes (for example,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * mailquota).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String[] getCOSAttributes() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Attr attr = getAttribute(ICOSDefinition.COSATTRIBUTE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return attr.getStringValues();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the COS specifier. The COS specifier is the attribute value used in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * conjunction with the template entry's DN, to identify the template entry.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param cosSpecifier
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The COS specifier.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setCOSSpecifier(String cosSpecifier) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster setAttribute(new Attr(COSSPECIFIER, cosSpecifier));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the COS specifier.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the COS specifier
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see DirectCOSDefinition#setCOSSpecifier(String cosSpecifier)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getCOSSpecifier() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String attributeValue = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Attr attribute = getAttribute(COSSPECIFIER);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (attribute != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attributeValue = attribute.getValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return attributeValue;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Adds a COS Template to this COS definition. This COS definition must be
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * persistent before adding the template.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param cosTemplate
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The COS Template to be added.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The exception thrown from the data layer.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void addCOSTemplate(COSTemplate cosTemplate) throws UMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (getGuid() == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = i18n
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .getString(IUMSConstants.DEFINITION_NOT_PERSISTENT);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new UMSException(msg);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (getAttribute(ICOSDefinition.COSTEMPLATEDN) == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.modify(new Attr(ICOSDefinition.COSTEMPLATEDN, getGuid()
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington .getDn()), ModificationType.ADD);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.save();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.addChild(cosTemplate);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Removes a COS Template from this COS definition.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The name of the template to be removed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The exception thrown from the data layer.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void removeCOSTemplate(String name) throws UMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Guid tGuid = new Guid(COSTemplate.DEFAULT_NAMING_ATTR + "=" + name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "," + this.getGuid());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.removeChild(tGuid);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Removes all COS Templates from this COS definition.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The exception thrown from the data layer.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void removeCOSTemplates() throws UMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ArrayList aList = (ArrayList) getCOSTemplates();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (int i = 0; i < aList.size(); i++) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster COSTemplate cosTemplate = (COSTemplate) aList.get(i);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cosTemplate.remove();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a template from this definition given the name of the template.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The name of the template to be returned.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The COS template.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws COSNotFoundException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The exception thrown if the COS template is not found.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The exception thrown from the data layer.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public COSTemplate getCOSTemplate(String name) throws COSNotFoundException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster UMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster COSTemplate cosTemplate = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] resultAttributes = { "*" };
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SearchResults sr = this.search("(" + COSTemplate.DEFAULT_NAMING_ATTR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "=" + name + ")", resultAttributes, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (sr.hasMoreElements()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cosTemplate = (COSTemplate) sr.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sr.abandon();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (cosTemplate == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = i18n.getString(IUMSConstants.COS_TEMPLATE_NOT_FOUND);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new COSNotFoundException(msg);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return cosTemplate;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns all templates for this definition.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a collection of COS templates
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The exception thrown from the data layer.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Collection getCOSTemplates() throws UMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster COSTemplate cosTemplate = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Collection cosTemplates = new ArrayList();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] resultAttributes = { "*" };
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SearchResults sr = this.search("(objectclass=costemplate)",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster resultAttributes, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (sr.hasMoreElements()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cosTemplate = (COSTemplate) sr.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cosTemplates.add(cosTemplate);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return cosTemplates;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final Class _class =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster com.iplanet.ums.cos.DirectCOSDefinition.class;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static I18n i18n = I18n.getInstance(IUMSConstants.UMS_PKG);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}