Rules

These are the rules for a published business service method calling a business service method:

  • The signature for the business service static method must contain an IContext object, an IConnection object, and an internal value object.

  • The published business service method passes the IContext and IConnection objects to the business service, enabling the published business service to keep track of transaction information throughout the entire processing of the published business service.

  • The published business service method creates a new internal value object that is based on the external value object.

  • The business service static method returns an E1MessageList object, which contains an array of all error, warning, and information messages that occurred during processing and were set by the business function.

  • If the array contains an error message, the published business service must throw an exception using the text from the E1MessageList

  • If no error messages exist in the array, the business service returns a confirm value object to the published business service method caller.

    The confirm object is created when the business service passes the internal value object to the constructor for the published confirm value. All warnings and information messages that are returned from calling the business service are mapped to the confirm object.

This code sample shows implementation of these rules:

public ConfirmAddAddressBook addAddressBook(AddAddressBook vo) throws 
BusinessServiceException {
       return (addAddressBook(null, null, vo));
   }
   protected ConfirmAddAddressBook addAddressBook(IContext context, 
                                 IConnection connection, 
                                 AddAddressBook vo) throws 
BusinessServiceException {
        //perform all work within try block, finally will clean up any 
connections
       try {
           //Call start published method, passing context of null 
           //will return context object so BSFN or DB operation can 
           //be called later.
           //Context will be used to indicate default transaction 
           //boundary, as well as access to formatting and logging 
           //operations.
           context = startPublishedMethod(context, "addAddressBook", 
vo);
           //Create new published business service messages object for 
           //holding errors and warnings that occur during processing.
           E1MessageList messages = new E1MessageList();
           // Create a new internal value object.
           InternalAddAddressBook internalVO = 
               new InternalAddAddressBook();
           vo.mapFromPublished(context, internalVO);
           //Call business service passing context, connection and 
           //internal VO
           E1MessageList bssvMessages = AddressBookProcessor.addAddressBook
(context, connection, internalVO);
          //Add messages returned from business service to message list
          //for published business service.
           messages.addMessages(bssvMessages);
         //Published Business Service will send either warnings in the
         //Confirm Value Object or throw a published business service 
         //Exception.
           //If messages contains errors, throw the exception
           if (messages.hasErrors()) {
               //Get the string representation of all the messages.
               String error = messages.getMessagesAsString();
               //Throw new BusinessServiceException
               throw new BusinessServiceException(error, context);
           }
           //Exception was not thrown, so create the confirm VO from 
           //internal VO
           ConfirmAddAddressBook confirmVO = 
               new ConfirmAddAddressBook(internalVO);
           confirmVO.setE1MessageList(messages);
           finishPublishedMethod(context, "addAddressBook");
           //return outVO, filled with return values and messages
           return confirmVO;
       } finally {
           //Call close to clean up all remaining connections and 
           //resources.
           close(context, "addAddressBook");
       }
   }