/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: CreationTemplate.java,v 1.4 2008/06/25 05:41:44 qcheng Exp $
*
*/
/**
* Portions Copyrighted [2011] [ForgeRock AS]
*/
/**
* Represents templates for creating objects in UMS. CreationTemplate is used to
* aid in creating objects in which it serves as reusable guidelines to
* instantiate UMS objects properly at runtime. The guidelines are used to
* instantiate objects in memory correctly so that subsequent storage in
* persistent storage can be done successfully. It is the intention that
* CreationTemplate allows applications to determine what is correct so that
* some control is given in the application for early detection of problems of
* UMS object creations. Reusability and flexibility are two desired goals of
* CreationTemplate.
*
* @see Template
* @see SearchTemplate
*
* @supported.api
*/
/**
* Default constructor for deserialization
*
*/
public CreationTemplate() {
super();
}
/**
* Creates a template with required and optional attributes.
*
* @param name
* Template name
* @param required
* Set of required attributes
* @param optional
* Set of optional attributes
* @param classes
* Array of classes that this CreationTemplate is associated with
* for object creation
*/
super(name);
}
/**
* Creates a template with required and optional attributes.
*
* @param name
* Template name
* @param required
* Set of required attributes
* @param optional
* Set of optional attributes
* @param cls
* Class that this CreationTemplate is associated with for object
* creation
*/
}
/**
* Creates a template with required and optional attributes.
*
* @param name
* Template name
* @param required
* Set of required attributes
* @param optional
* Set of optional attributes
*/
// No definition for the class
//
// this( name, required, optional, null );
super(name);
}
/**
* Gets the value of a given attribute in the template.
*
* @param attributeName
* Name of attribute for which to return values
* @return The attribute with the specified name, or <CODE>null</CODE> if
* attributeName is <CODE>null</CODE>, or the attribute is not
* found.
*
* @supported.api
*/
if (attributeName == null) {
return null;
}
if (m_required != null) {
}
}
return attr;
}
/**
* Gets a list of required attribute names defined in the object.
*
* @return Names of all required attributes defined
*
* @supported.api
*/
}
/**
* Gets a list of optional attribute names defined in the object.
*
* @return Names of all optional attributes defined
*
* @supported.api
*/
}
/**
* Gets the required attributes for object creation.
*
* @return set of required attributes
*
* @supported.api
*/
return m_required;
}
/**
* Gets the optional attributes for object creation.
*
* @return set of optional attributes
*
* @supported.api
*/
return m_optional;
}
/**
* Get the classes that the CreationTemplate is associated with.
*
* @return classes associated with this template
*
* @supported.api
*/
return m_classes;
}
/**
* Gets enumeration of ValidationElement for the attribute name
*
* @param attrName
* Attribute name
* @return Enumeration of ValidationElement
*
* @supported.api
*/
}
}
}
return v.elements();
}
return m_validated;
}
/**
* Gets a list of attribute names registered for validation.
*
* @return a list of attribute names registered for validation
*
* @supported.api
*/
}
/**
* Gets enumeration of attributes for object creation.
*
* @return enumeration of required and optional attributes
*/
if (m_required != null) {
}
}
if (m_optional != null) {
}
}
return v.elements();
}
/**
* Sets the required attributes.
*
* @param attrSet
* set of required attributes
*/
// ??? Should we clone attrSet instead of keeping a reference?
}
/**
* Sets the optional attributes.
*
* @param attrSet
* set of optional attributes
*/
// ??? Should we clone attrSet instead of keeping a reference?
}
/**
* Set the class that the CreationTemplate is associated with.
*
* @param classes
* Classes associated with this template
*/
}
/**
* Adds the attribute to the required attributes.
*
* @param attr
* The attribute to be added
*/
if (m_required == null) {
m_required = new AttrSet();
}
}
/**
* Adds the attribute to the optional attributes.
*
* @param attr
* The attribute to be added
*/
if (m_optional == null) {
m_optional = new AttrSet();
}
}
/**
* Sets the validation table
*
* @param attrSet
* validation table in attribute set format
*/
// ??? Should we clone attrSet instead of keeping a reference?
}
/**
* Adds the validator and the rule for the attribute name.
*
* @param attrName Attribute name to validate.
* @param validatorClass Validator class name used for validation.
* @param rule The optional rule used by the validator.
*/
public void addValidation(
) {
rule);
if (validationString != null) {
if (m_validated == null) {
m_validated = new AttrSet();
}
}
}
}
}
/**
* Removes all validations from the attribute.
*
* @param attrName
* attribute name of the validations to be removed
*/
if (m_validated != null) {
}
}
/**
* Sets the naming attribute.
*
* @param namingAttribute
* naming attribute
*/
}
/**
* Gets the naming attribute.
*
* @return the naming attribute
*
* @supported.api
*/
return m_namingAttribute;
}
/**
* Returns a copy of the template.
*
* @return a copy of the template
*
* @supported.api
*/
if (m_required != null) {
}
if (m_optional != null) {
}
if (m_validated != null) {
}
return t;
}
/**
* Encode an attrSet in a single attribute with multiple values using the
* given attribute name and the values (tag,value) found in the given
* attribute set. For example:
*
* <pre>
* required: objectclass=top
* required: objectclass=groupofuniquenames
* required: cn
* required: sn
* </pre>
*
* @param attrName
* Name of the encoded attribute
* @param attrSet
* Attribute Set to be encoded in a single attribute
* @param delimiter
* String token used as delimiter for the encoding
* @return Encoded attribute or null object if attrSet is empty
*/
{
return null;
}
while (attrEnum.hasMoreElements()) {
} else {
}
}
}
return encodedAttr;
}
{
return className;
}
}
if (index < 0) {
}
}
/**
* Render the object.
*
* @return The object in printable form
*
* @supported.api
*/
}
/**
* Validate attrSet according to the definition of required and optional
* attributes defined in the template.
*
* @param attrSet
* Attribute set to be validated
* @return true if the given attrSet conforms to the template
* @throws UMSException
* if attrSet doesn't conform to the template
*/
throw new UMSException(i18n
}
// Loop on attributes in the template comparing with the argument
// attSet and ensure all required attributtes are supplied
// or have a default
while (attrEnum.hasMoreElements()) {
// if ( !attrSet.contains(anAttr.getName().toLowerCase())) {
// A required attribute which was not supplied
// There is a default value
} else {
// No default value. This is an error! A value
// should have been supplied in attrSet.
args);
throw new UMSException(msg);
}
}
}
}
// If the optional attributes set is set to "*", which means allowing
// all attributes, then no need to ensure the given attributes are in
// either the required attributes set or the optional attributes set
return true;
}
// Loop on attributes in the argument attrSet comparing with the
// template and ensure all the attributes are allowed
//
boolean attrAllowed = false;
for (int i = 0; i < attrSetSize; i++) {
attrAllowed = false;
attrAllowed = true;
} else if (optionalAttrs != null
attrAllowed = true;
}
if (!attrAllowed) {
args);
// TODO: need to define new and meaningful exception for
// unknown attribute not conforming to the
// given creation template
//
throw new UMSException(msg);
}
}
return true;
}
/**
* Validate attrSet according to the definition of validated attributes
* defined in the template.
*
* @param attrSet
* Attribute set to be validated
* @return true if the given attrSet conforms to the template
* @throws DataConstraintException
* if attrSet doesn't conform to the template
* @throws UMSException
* failure
*/
while (en1.hasMoreElements()) {
while (en2.hasMoreElements()) {
.nextElement();
// calls method in Validation to validate each values
// of the attribute
}
}
return true;
}
}