Implementing the client library

In this step, you add convenience methods that hide the complexity of creating the different GetTutorialStore requests.

Procedure

  1. In the Enterprise Explorer view, go to SOITutorialStore-Client/src/com.mycompany.commerce.soitutorialstore.facade.
  2. Open the SOITutorialStoreFacadeConstants class for editing.
  3. Add the following constants to represent the actions supported by the store, XPath search expressions, and URL parameter names.
    
    /**
    * The XPath key for the TutorialStore.
    */
     public static final String XPATH_STORE = "/TutorialStore";
    
    /**
    * The XPath key for finding a store by ID.
    */
     public static final String IDEXPRESSION = "/TutorialStore/TutorialStoreIdentifier[(UniqueID={0})]";
    
    /**
    * The store ID.
    */
     public static final String STORE_ID = "storeId"; 
    
  4. Save your changes and close the file.
  5. Go to com.mycompany.commerce.soitutorialstore.facade.client.
  6. Open the SOITutorialStoreFacadeClient class for editing.
  7. Add the following Import:
    import com.ibm.commerce.foundation.common.util.logging.LoggingHelper;
  8. Add the following client methods that build the appropriate BOD:
    /**
     * This method composes a Get BOD with an expression to find a store by ID
     * and sends the BOD to the TutorialStore-Server.
     * @throws TutorialStoreException 
     */
    public ShowTutorialStoreDataAreaType findStoreById(String[] storeId,
        String accessProfile) throws TutorialStoreException {
      final String METHODNAME = "findStoreById";
      if(LoggingHelper.isEntryExitTraceEnabled(LOGGER)){
        LOGGER.entering(CLASSNAME, METHODNAME);
      }
    
      // Build the expression.
      String expression = java.text.MessageFormat.format(
        SOITutorialStoreFacadeConstants.IDEXPRESSION, storeId);
      SelectionCriteriaHelper selectionCriteriaHelper = new SelectionCriteriaHelper(
        expression);
      selectionCriteriaHelper.addAccessProfile(accessProfile);
      ExpressionType queryExpression = selectionCriteriaHelper
        .getSelectionCriteriaExpression();
    
      // Create the request message.
      GetType verb = createGetVerb(queryExpression);
    
      // Perform the request.
      ShowTutorialStoreDataAreaType showTutorialStoreDataArea = getTutorialStore(verb);
      
      if(LoggingHelper.isEntryExitTraceEnabled(LOGGER)){
        LOGGER.exiting(CLASSNAME, METHODNAME);
      }
    		return showTutorialStoreDataArea;
    }
    
    /**
     * This method composes a Get BOD with an expression to find all the stores
     * and sends the BOD to the TutorialStore-Server.
     */
    public ShowTutorialStoreDataAreaType findAllStores() throws Exception {
      final String METHODNAME = "findAllStores";
      if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)){
        LOGGER.entering(CLASSNAME, METHODNAME);
      }
    
      // Build the expression.
      SelectionCriteriaHelper selectionCriteriaHelper = new SelectionCriteriaHelper(
        SOITutorialStoreFacadeConstants.XPATH_STORE);
      selectionCriteriaHelper
        .addAccessProfile(SOITutorialStoreFacadeConstants.ACCESS_PROFILE_SUMMARY_INFORMATION);
      ExpressionType queryExpression = selectionCriteriaHelper
        .getSelectionCriteriaExpression();
    
      // Create the request message.
      GetType verb = createGetVerb(queryExpression);
    
      // Send the request.
      ShowTutorialStoreDataAreaType showTutorialStoreDataArea = getTutorialStore(verb);
    
      if(LoggingHelper.isEntryExitTraceEnabled(LOGGER)){
        LOGGER.exiting(CLASSNAME, METHODNAME);
      }
      return showTutorialStoreDataArea;
    
    	}
    
  9. Save your changes and close the file.
  10. Organize the imports for the SOITutorialStore-Client project:
    1. Open the Java perspective in WebSphere Commerce Developer.
    2. Right-click the SOITutorialStore-Client\src folder.
    3. Select Source > Organize Imports.