AttributeSchemaImpl.java revision 465cbeb237a572b2165a1f55cfad77a6b6518883
/*
* 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: AttributeSchemaImpl.java,v 1.3 2008/06/25 05:44:03 qcheng Exp $
*
* Portions Copyrighted 2011-2016 ForgeRock AS.
*/
/**
* The class <code>AttributeSchemaImpl</code> provides methods to access the
* schema of a configuration parameter.
*/
public class AttributeSchemaImpl {
// Input variables
private Node attrSchemaNode;
// Variables derived from the Node
private String resourceName;
private Map choiceValues;
private String trueBooleanValue;
private String trueValueKey;
private String falseBooleanValue;
private String falseValueKey;
private String cosQualifier;
private String rangeStart;
private int minValue;
private int maxValue;
private boolean isOptional;
private boolean isServiceIdentifier;
private boolean isResourceNameAllowed;
private boolean isStatusAttribute;
// Attribute display properties
private String attributeViewBeanURL;
boolean isSearchable;
private boolean hasChoiceValues;
/**
* Constructor used by ServiceSchema to instantiate AttributeSchema objects.
*/
}
/**
* Retunrs the name of the attribute.
*/
return (name);
}
/**
* Returns the name of the attribute for CREST representation.
*/
public String getResourceName() {
return (resourceName);
}
/**
* Returns the type of the attribute.
*/
return (type);
}
/**
* Returns the UI type of the attribute; or null if UI type is not defined.
*/
return (uitype);
}
/**
* Returns the list order of the attribute, or {@code null} if the list order is not defined.
*/
return listOrder;
}
/**
* Returns the syntax of the attribute.
*/
return (syntax);
}
/**
* Returns the I18N key to describe the configuration attribute.
*/
public String getI18NKey() {
return (key);
}
/**
* Returns the value of the cosQualifier for this attribute. Either default,
* overrid, operational or merge-cos.
*
* @return the value of the cosQualifier for this attribute.
*/
public String getCosQualifier() {
return (cosQualifier);
}
/**
* Returns the default values of the attribute.
*/
public Set getDefaultValues() {
if (defaultsObject != null) {
}
return getValuesCopy(defaultValues);
}
/**
* Returns the default values of the attribute.
*
* @param envParams
* Map of environment parameter to a set of values
* @return default values for the attribute
*/
if (defaultsObject != null) {
}
return getValuesCopy(defaultValues);
}
/**
* Returns the example values of the attribute.
*/
public Set getExampleValues() {
return getValuesCopy(exampleValues);
}
if (isEmpty(defaultValues)) {
return emptySet();
}
return new LinkedHashSet<>(defaultValues);
} else {
return new HashSet<>(defaultValues);
}
}
/**
* Returns the possible choice values for the attribute if the attribute
* type is either <code>SINGLE_CHOICE</code> or
* <code>MULTIPLE_CHOICE</code>.
*
* @return choice values for the attribute
*/
public String[] getChoiceValues() {
if (choiceObject != null) {
}
if (choiceValues != null) {
}
return (null);
}
/**
* Returns the possible choice values for the attribute if the attribute
* type is either <code>SINGLE_CHOICE</code> or
* <code>MULTIPLE_CHOICE</code>.
*
* @param envParams
* Map of environment parameter to a set of values
* @return choice values for the attribute
*/
if (choiceObject != null) {
}
if (choiceValues != null) {
}
return (null);
}
/**
* Returns the choice values as a Map.
*
* @return choice values for the attribute and its i18n key
*/
protected Map getChoiceValuesMap() {
if (choiceObject != null) {
}
if (choiceValues != null) {
return (choiceValues);
}
return (new HashMap());
}
/**
* Returns the choice values as a set.
*
* @return choice values for the attribute
*/
protected Set getChoiceValuesSet() {
if (choiceObject != null) {
}
if (choiceValues != null) {
return (choiceValues.keySet());
}
return (new HashSet());
}
/**
* Returns the choice values as a Map.
*
* @param envParams
* Map of environment parameter to a set of values
* @return choice values for the attribute
*/
if (choiceObject != null) {
}
if (choiceValues != null) {
return (choiceValues);
}
return (new HashMap());
}
/**
* Returns the choice values as a set.
*
* @param envParams
* Map of environment parameter to a set of values
* @return choice values for the attribute
*/
if (choiceObject != null) {
}
if (choiceValues != null) {
return (choiceValues.keySet());
}
return (new HashSet());
}
/**
* Returns the I18N key for the given choice value.
*
* @return the I18N key for the given choice value
*/
if (choiceObject != null) {
}
}
/**
* Indicates whether this AttributeSchema has choice values configured.
*/
boolean hasChoiceValues() {
return hasChoiceValues;
}
/**
* Returns the start range if the attribute syntax is either
* <code>NUMBER_RANGE</code> or <code>DECIMAL_RANGE</code>.
*/
public String getStartRange() {
return (rangeStart);
}
/**
* Returns the end range if the attribute syntax is either
* <code>NUMBER_RANGE</code> or <code>DECIMAL_RANGE</code>.
*/
public String getEndRange() {
return (rangeEnd);
}
/**
* Method to get the validator name for using to validate this service
* attribute
*
* @return the validator name
*/
public String getValidator() {
return (validator);
}
/**
* Returns the minimum number of values for the attribute if the attribute
* is of type <code>MULTIPLE_CHOICE</code>.
*/
public int getMinValue() {
return (minValue);
}
/**
* Returns the maximum number of values for the attribute if the attribute
* is of type <code>MULTIPLE_CHOICE</code>.
*/
public int getMaxValue() {
return (maxValue);
}
/**
* Returns the string value for BooleanTrueValue.
*/
public String getTrueValue() {
return (trueBooleanValue);
}
/**
* Retruns the I18N Key for BooleanTrueValue.
*/
public String getTrueValueI18NKey() {
return (trueValueKey);
}
/**
* Returns the string value for BooleanFalseValue.
*/
public String getFalseValue() {
return (falseBooleanValue);
}
/**
* Returns the I18N Key for BooleanFalseValue.
*/
public String getFalseValueI18NKey() {
return (falseValueKey);
}
/**
* Checks if the attribute is an optional attribute.
*/
public boolean isOptional() {
return (isOptional);
}
/**
* Chekcs if the attribute is a service identifier (i.e., in the case of
* LDAP it would be the COS Specifier attribute).
*/
public boolean isServiceIdentifier() {
return (isServiceIdentifier);
}
/**
* Checks if the attribute allows to have resource name.
*/
public boolean isResourceNameAllowed() {
return (isResourceNameAllowed);
}
/**
* Checkds if the attribute is a service's status attribute.
*/
public boolean isStatusAttribute() {
return (isStatusAttribute);
}
/**
* Method to get service specific attributes. It return the value of the
* "any" attribute, if set in the XML schema for the service
*/
return (any);
}
/**
* Returns URL of the view bean for the attribute.
*
* @return URL for view bean
*/
public String getPropertiesViewBeanURL() {
return (attributeViewBeanURL);
}
/**
* String represenation of the AttributeSchema
*/
}
public Node getAttributeSchemaNode() {
return attrSchemaNode;
}
/**
* Updates the attribute schema object based on information in the XML node
*/
// Copy the XML node
attrSchemaNode = n;
// Get attribute name
// Get json name
// Get I18N key
// Get Attribute type
try {
} catch (Exception e) {
// do nothing, use the default
}
}
// Get attribute UI type
if (attrUIType != null) {
try {
} catch (Exception e) {
// do nothing, use the default
}
}
// Get attribute list order
if (attrListOrder != null) {
try {
} catch (Exception e) {
// do nothing, use the default
}
}
// Get attribute syntax
if (attrSyntax != null) {
try {
} catch (Exception e) {
// do nothing, use the default setting
}
}
// If syntax is boolean, get the "true" & "false" values
// Get the True value
} else {
trueBooleanValue = "true";
}
// Get the false value
} else {
falseBooleanValue = "false";
}
} else {
trueBooleanValue = "true";
falseBooleanValue = "false";
}
// Get choice values, if applicable
if (choiceValueNode != null) {
hasChoiceValues = true;
// If the sub-element ChoiceValuesClassName, use it
if (cvClassName != null) {
try {
choiceObject.setAttributeSchema(this);
} catch (Exception e) {
+ "Unable to load class: " + className, e);
choiceObject = null;
}
}
// If choice class not present, use ChoiceValues element
if (choiceObject == null) {
// Choice object was not configured or error in obtaining it
choiceValues = new LinkedHashMap();
}
}
}
}
// Get default values
// If the sub-element DefaultValuesClassName, use it
if (dvClassName != null) {
try {
defaultsObject.setAttributeSchema(this);
} catch (Exception e) {
+ "Unable to load class: " + className, e);
// use default approach
}
} else {
}
}
}
// If syntax is password, decrypt the attribute values
&& (defaultValues != null)) {
defaultValues = new HashSet();
try {
} catch (Throwable e) {
"AttributeSchemaImpl: Unable to decode", e);
}
}
}
}
// Set the cosQualifier
cosQualifier = "default";
}
// Get range start
// Get range end
// Get minimum number of values
try {
} catch (NumberFormatException e) {
minValue = -1;
}
// Get maximum number of values
try {
} catch (NumberFormatException e) {
maxValue = -1;
}
// get validator
// Check if the variable is optional
isOptional = true;
}
// COS identifer
isServiceIdentifier = false;
isServiceIdentifier = true;
}
// Resource name allowed
isResourceNameAllowed = false;
isResourceNameAllowed = true;
}
// Service Status attribute
isStatusAttribute = false;
isStatusAttribute = true;
}
// Any attribute
// Get view bean url
isSearchable = false;
isSearchable = true;
}
}
}
}
return (retVal);
}
/**
* Returns <code>true</code> if the attribute is searchable;
* <code>false</code> otherwise
*
* @return <code>true</code> if the attribute is an optional attribute;
* <code>false</code> otherwise
*/
public boolean isSearchable() {
return (isSearchable);
}
}