/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
*/
/**
* Integer property definition.
* <p>
* constraints. Support is provided for "unlimited" values. These are
* represented using a negative value or using the string "unlimited".
*/
public final class IntegerPropertyDefinition extends
// String used to represent unlimited.
// The lower limit of the property value.
private final int lowerLimit;
// The optional upper limit of the property value.
// Indicates whether this property allows the use of the "unlimited" value
// (represented using a -1 or the string "unlimited").
private final boolean allowUnlimited;
/**
* An interface for incrementally constructing integer property definitions.
*/
public static class Builder extends
// The lower limit of the property value.
// The optional upper limit of the property value.
// Indicates whether this property allows the use of the "unlimited" value
// (represented using a -1 or the string "unlimited").
private boolean allowUnlimited = false;
// Private constructor
private Builder(
super(d, propertyName);
}
/**
* Set the lower limit.
*
* @param lowerLimit
* The new lower limit (must be >= 0).
* @throws IllegalArgumentException
* If a negative lower limit was specified or the lower limit is
* greater than the upper limit.
*/
throws IllegalArgumentException {
if (lowerLimit < 0) {
throw new IllegalArgumentException("Negative lower limit");
}
throw new IllegalArgumentException(
"Lower limit greater than upper limit");
}
this.lowerLimit = lowerLimit;
}
/**
* Set the upper limit.
*
* @param upperLimit
* The new upper limit or <code>null</code> if there is no upper
* limit.
*/
if (upperLimit != null) {
if (upperLimit < 0) {
throw new IllegalArgumentException("Negative lower limit");
}
if (lowerLimit > upperLimit) {
throw new IllegalArgumentException(
"Lower limit greater than upper limit");
}
}
this.upperLimit = upperLimit;
}
/**
* Specify whether or not this property definition will allow unlimited
* values (default is false).
*
* @param allowUnlimited
* <code>true</code> if the property will allow unlimited values,
* or <code>false</code> otherwise.
*/
this.allowUnlimited = allowUnlimited;
}
/**
* {@inheritDoc}
*/
}
}
/**
* Create an integer property definition builder.
*
* @param d
* The managed object definition associated with this
* property definition.
* @param propertyName
* The property name.
* @return Returns the new integer property definition builder.
*/
return new Builder(d, propertyName);
}
// Private constructor.
private IntegerPropertyDefinition(
this.lowerLimit = lowerLimit;
this.upperLimit = upperLimit;
this.allowUnlimited = allowUnlimited;
}
/**
* Get the lower limit.
*
* @return Returns the lower limit.
*/
public int getLowerLimit() {
return lowerLimit;
}
/**
* Get the upper limit.
*
* @return Returns the upper limit or <code>null</code> if there is no upper
* limit.
*/
return upperLimit;
}
/**
* Gets the optional unit synopsis of this integer property
* definition in the default locale.
*
* @return Returns the unit synopsis of this integer property
* definition in the default locale, or <code>null</code>
* if there is no unit synopsis.
*/
}
/**
* Gets the optional unit synopsis of this integer property
* definition in the specified locale.
*
* @param locale
* The locale.
* @return Returns the unit synopsis of this integer property
* definition in the specified locale, or <code>null</code>
* if there is no unit synopsis.
*/
try {
} catch (MissingResourceException e) {
return null;
}
}
/**
* Determine whether this property allows unlimited values.
*
* @return Returns <code>true</code> if this this property allows unlimited
* values.
*/
public boolean isAllowUnlimited() {
return allowUnlimited;
}
/**
* {@inheritDoc}
*/
throws IllegalPropertyValueException {
throw new IllegalPropertyValueException(this, value);
// unlimited allowed
throw new IllegalPropertyValueException(this, value);
}
throw new IllegalPropertyValueException(this, value);
}
}
/**
* {@inheritDoc}
*/
throws IllegalPropertyValueException {
// Make sure that we correctly encode negative values as "unlimited".
if (allowUnlimited) {
if (value < 0) {
return UNLIMITED;
}
}
}
/**
* {@inheritDoc}
*/
throws IllegalPropertyValueStringException {
if (allowUnlimited) {
return -1;
}
}
Integer i;
try {
} catch (NumberFormatException e) {
throw new IllegalPropertyValueStringException(this, value);
}
try {
validateValue(i);
} catch (IllegalPropertyValueException e) {
throw new IllegalPropertyValueStringException(this, value);
}
return i;
}
/**
* {@inheritDoc}
*/
return v.visitInteger(this, p);
}
/**
* {@inheritDoc}
*/
return v.visitInteger(this, value, p);
}
/**
* {@inheritDoc}
*/
if (upperLimit != null) {
}
}
/**
* {@inheritDoc}
*/
}
}