Sample Business Object thresholds programming patterns

The following are a few examples on how to access the configuration files, perform the unbounded condition check, and how to throw an exception in an event of a violation.

Accessing threshold property

String compId = "";
ComponentConfiguration config = ComponentConfigurationRegistry.instance().getComponentConfiguration(compId);
String mapWidth = config.getValueByConfigGroupingNameAndPropertyName("map", "mapWidth");

The above example illustrates a simple comparison against the threshold.

Checking against threshold

 * Returns whether the threshold in the given context has been exceeded.
 * The default behaviour passes if there is no threshold.  Subclasses should
 * override this to provide additional checking using additional
 * information.
 * @return  True if the threshold was exceeded, false otherwise.
public boolean isThresholdAcceptable() {
    final String METHODNAME = "isThresholdAcceptable";

    boolean passed = threshold == null || threshold.compareTo(BigDecimal.ZERO) < 0;

    if (ECTrace.traceEnabled(ECTraceIdentifiers.COMPONENT_ORDER)) {
        ECTrace.exit(ECTraceIdentifiers.COMPONENT_ORDER, CLASSNAME, METHODNAME, Boolean.valueOf(passed));

    return passed;
The following section is another example of how to work with the default page size and maximum page size. The behavior is shown in the following pseudo code:

// enter a point in the code where we need to paginate

maxItems = getObject.getMaxItems()
if (maxItems == null) {
    maxItems = getDefaultPageSize()

maximumPageSize = getMaximumPageSize()
if (maximumPageSize != null && (maxItems == null || maxItems > maximumPageSize)) {
    maxItems = maximumPageSize

if (maxItems == null || maxItems < 0) {
    maxItems = 0

// use the startNumber and maxItems to choose the items in the page to return
In addition, considering the following cases where values are not defined:
  1. defaultPageSize exists and maxPageSize exists
    1. if defaultPageSize == maxPageSize – the page size will be bounded to the maxPageSize whether pagination parameters are set or not.
    2. if defaultPageSize < maxPageSize – if no parameters are set, defaultPageSize will be used, otherwise the parameters will be bounded by maxPageSize.
    3. if defaultPageSize > maxPageSize – the page size will be bounded to the maxPageSize whether pagination parameters are set or not.
  2. defaultPageSize exists but maxPageSize does not exist – the page size will be bounded by defaultPageSize only if there are no pagination parameters set.
  3. defaultPageSize does not exist, but maxPageSize exists – the page size will be bounded to maxPageSize whether pagination parameters are set or not.
  4. defaultPageSize does not exist and maxPageSize does not exist – no bound on the page size will be enforced.

Handling exception

Object[] params = new Object[] {getThreshold(), getNumAdded(), getNumCurrent()};
throw new ECApplicationException(getUserErrorMessage(), CLASSNAME, "throwDefaultException", params);

Logging violation

 * Logs a message to the administrator about the threshold being exceeded.
 * This method should be called when it is known that a threshold has been
 * exceeded.
 * @param logger
 *          The logger to use to notify the administrator.  Cannot be null.
 * @param methodName
 *          The name of the method which is calling this.  Cannot be null
 *          or empty.
public void log(Logger logger, String methodName) {
    if (LoggingHelper.isTraceEnabled(logger)) {
        Object[] params = new Object[] {getThreshold(), getNumAdded(),
                getNumCurrent (), getUserID(), getStoreID(), getOrderID()};

        logger.logp(Level.WARNING, logger.getName(), methodName,
                getAdminErrorMessage().getMessageKey(), params);