1689N/A/*
1689N/A * CDDL HEADER START
1689N/A *
1689N/A * The contents of this file are subject to the terms of the
1689N/A * Common Development and Distribution License, Version 1.0 only
1689N/A * (the "License"). You may not use this file except in compliance
1689N/A * with the License.
1689N/A *
1689N/A * You can obtain a copy of the license at
1689N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
1689N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
1689N/A * See the License for the specific language governing permissions
1689N/A * and limitations under the License.
1689N/A *
1689N/A * When distributing Covered Code, include this CDDL HEADER in each
1689N/A * file and include the License file at
1689N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
1689N/A * add the following below this CDDL HEADER, with the fields enclosed
1689N/A * by brackets "[]" replaced with your own identifying information:
1689N/A * Portions Copyright [yyyy] [name of copyright owner]
1689N/A *
1689N/A * CDDL HEADER END
1689N/A *
1689N/A *
3215N/A * Copyright 2008 Sun Microsystems, Inc.
1689N/A */
1689N/Apackage org.opends.server.core;
2086N/Aimport org.opends.messages.Message;
2086N/Aimport org.opends.messages.MessageBuilder;
1689N/A
1689N/A
1689N/Aimport org.opends.server.types.ResultCode;
1689N/A
1689N/A
1689N/A/**
1689N/A * This class implements the workflow result code. The workflow result code
1689N/A * contains an LDAP result code along with an LDAP error message.
1689N/A */
1689N/Apublic class WorkflowResultCode
1689N/A{
1689N/A // The global result code.
1689N/A private ResultCode resultCode = ResultCode.UNDEFINED;
1689N/A
1689N/A // The global error message.
2086N/A private MessageBuilder errorMessage = new MessageBuilder(Message.EMPTY);
1689N/A
1689N/A
1689N/A /**
1689N/A * Creates a new instance of a workflow result. By default the result code
1689N/A * is set to UNDEFINED and there is no error message.
1689N/A */
1689N/A public WorkflowResultCode()
1689N/A {
1689N/A // Nothing to implement.
1689N/A }
1689N/A
1689N/A
1689N/A /**
1689N/A * Creates a new instance of a workflow result code and initializes it
1689N/A * with a result code and an error message.
1689N/A *
1689N/A * @param resultCode the initial value for the result code
1689N/A * @param errorMessage the initial value for the error message
1689N/A */
1689N/A public WorkflowResultCode(
2086N/A ResultCode resultCode,
2086N/A MessageBuilder errorMessage
1689N/A )
1689N/A {
1689N/A this.resultCode = resultCode;
1689N/A this.errorMessage = errorMessage;
1689N/A }
1689N/A
1689N/A
1689N/A /**
1689N/A * Elaborates a global result code. A workflow may execute an operation
1689N/A * on several subordinate workflows. In such case, the parent workflow
1689N/A * has to take into account all the subordinate result codes to elaborate
1689N/A * a global result code.
1689N/A *
1689N/A * Sometimes, a referral result code has to be turned into a reference
1689N/A * entry. When such case is occurring the elaborateGlobalResultCode method
1689N/A * will return true.
1689N/A *
1689N/A * The global result code is elaborated as follows:
1689N/A *
1689N/A * <PRE>
1689N/A * -----------+------------+------------+-------------------------------
1689N/A * new | current | resulting |
1689N/A * resultCode | resultCode | resultCode | action
1689N/A * -----------+------------+------------+-------------------------------
1689N/A * SUCCESS NO_SUCH_OBJ SUCCESS -
1689N/A * REFERRAL SUCCESS send reference entry to client
1689N/A * other [unchanged] -
1689N/A * ---------------------------------------------------------------------
1689N/A * NO_SUCH_OBJ SUCCESS [unchanged] -
1689N/A * REFERRAL [unchanged] -
1689N/A * other [unchanged] -
1689N/A * ---------------------------------------------------------------------
1689N/A * REFERRAL SUCCESS [unchanged] send reference entry to client
1689N/A * REFERRAL SUCCESS send reference entry to client
1689N/A * NO_SUCH_OBJ REFERRAL -
1689N/A * other [unchanged] send reference entry to client
1689N/A * ---------------------------------------------------------------------
1689N/A * others SUCCESS other -
1689N/A * REFERRAL other send reference entry to client
1689N/A * NO_SUCH_OBJ other -
1689N/A * other2 [unchanged] -
1689N/A * ---------------------------------------------------------------------
1689N/A * </PRE>
1689N/A *
1689N/A * @param newResultCode the new result code to take into account
1689N/A * @param newErrorMessage the new error message associated to the new
1689N/A * error code
1689N/A * @return <code>true</code> if a referral result code must be turned
1689N/A * into a reference entry
1689N/A */
1689N/A public boolean elaborateGlobalResultCode(
2086N/A ResultCode newResultCode,
2086N/A MessageBuilder newErrorMessage
1689N/A )
1689N/A {
1689N/A // Returned value
1689N/A boolean sendReferenceEntry = false;
1689N/A
1689N/A // if global result code has not been set yet then just take the new
1689N/A // result code as is
1689N/A if (resultCode == ResultCode.UNDEFINED)
1689N/A {
1689N/A resultCode = newResultCode;
2086N/A errorMessage = new MessageBuilder (newErrorMessage);
1689N/A }
1689N/A else
1689N/A {
1689N/A // Elaborate the new result code (see table in the description header).
1689N/A
1689N/A switch (newResultCode)
1689N/A {
1689N/A case SUCCESS:
1689N/A //
1689N/A // Received SUCCESS
1689N/A // ----------------
1689N/A //
1689N/A switch (resultCode)
1689N/A {
1689N/A case NO_SUCH_OBJECT:
1689N/A resultCode = ResultCode.SUCCESS;
2086N/A errorMessage = new MessageBuilder(Message.EMPTY);
1689N/A break;
1689N/A case REFERRAL:
1689N/A resultCode = ResultCode.SUCCESS;
2086N/A errorMessage = new MessageBuilder(Message.EMPTY);
1689N/A sendReferenceEntry = true;
1689N/A break;
1689N/A default:
1689N/A // global resultCode remains the same
1689N/A break;
1689N/A }
1689N/A break;
1689N/A case NO_SUCH_OBJECT:
1689N/A //
1689N/A // Received NO SUCH OBJECT
1689N/A // -----------------------
1689N/A //
1689N/A // global resultCode remains the same
1689N/A break;
1689N/A case REFERRAL:
1689N/A //
1689N/A // Received REFERRAL
1689N/A // -----------------
1689N/A //
1689N/A switch (resultCode)
1689N/A {
1689N/A case REFERRAL:
1689N/A resultCode = ResultCode.SUCCESS;
2086N/A errorMessage = new MessageBuilder(Message.EMPTY);
1689N/A sendReferenceEntry = true;
1689N/A break;
1689N/A case NO_SUCH_OBJECT:
1689N/A resultCode = ResultCode.REFERRAL;
2086N/A errorMessage = new MessageBuilder (Message.EMPTY);
1689N/A break;
1689N/A default:
1689N/A // global resultCode remains the same
1689N/A sendReferenceEntry = true;
1689N/A break;
1689N/A }
1689N/A break;
1689N/A default:
1689N/A //
1689N/A // Received other result codes
1689N/A // ---------------------------
1689N/A //
1689N/A switch (resultCode)
1689N/A {
1689N/A case REFERRAL:
1689N/A resultCode = newResultCode;
2086N/A errorMessage = new MessageBuilder (newErrorMessage);
1689N/A sendReferenceEntry = true;
1689N/A break;
1689N/A case SUCCESS:
1689N/A resultCode = newResultCode;
2086N/A errorMessage = new MessageBuilder (newErrorMessage);
1689N/A break;
1689N/A case NO_SUCH_OBJECT:
1689N/A resultCode = newResultCode;
2086N/A errorMessage = new MessageBuilder (newErrorMessage);
1689N/A break;
1689N/A default:
3869N/A // Do nothing (we don't want to override the first error)
1689N/A break;
1689N/A }
1689N/A break;
1689N/A }
1689N/A }
1689N/A
1689N/A return sendReferenceEntry;
1689N/A }
1689N/A
1689N/A
1689N/A /**
1689N/A * Returns the global result code.
1689N/A *
1689N/A * @return the global result code.
1689N/A */
1689N/A public ResultCode resultCode()
1689N/A {
1689N/A return resultCode;
1689N/A }
1689N/A
1689N/A
1689N/A /**
1689N/A * Returns the global error message.
1689N/A *
1689N/A * @return the global error message.
1689N/A */
2086N/A public MessageBuilder errorMessage()
1689N/A {
1689N/A return errorMessage;
1689N/A }
1689N/A
1689N/A}