Tutorial: Creating a WebSphere Commerce service module > < Previous | Next >
Implementing the client library
This step adds the client-specific code to the TutorialStore-Client project that is not generated by the ComponentProjects pattern.
- Open the TutorialStore-Client/src/com.mycompany.commerce.tutorialstore.facade.TutorialStoreFacadeConstants class.
- Add the following constants to represent the actions supported by the store, XPath search expressions, and URL parameter names.
- Process actions
/** * The Open Store process action. */ public static String PROCESS_ACTION_OPEN = "Open"; /** * The Close Store process action. */ public static String PROCESS_ACTION_CLOSE = "Close";- XPath search expression
/** * The XPath key for the TutorialStore. */ public static String XPATH_STORE = "/Store"; /** * The XPath key for finding a store by ID. */ public static String IDEXPRESSION = "/Store[StoreIdentifier[(UniqueID={0})]]"; /** * The XPath key for finding a store by name. */ public static String NAMEEXPRESSION = "/Store[StoreIdentifier[ExternalIdentifier[(NameIdentifier=\"{0}\")]]]";- URL parameter names
/** * The store ID. */ public static String STORE_ID = "storeId";
- Open the com.mycompany.commerce.tutorialstore.facade.client.TutorialStoreFacadeClient class.
- 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. */public ShowTutorialStoreDataAreaType findStoreById(String[]storeId, String accessProfile) { final String METHODNAME="findStoreById"; // Build the expression. String expression = java.text.MessageFormat.format(TutorialStoreFacadeConstants.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 = null; try { showTutorialStoreDataArea = getTutorialStore(verb); } catch (TutorialStoreException se) {} return showTutorialStoreDataArea; }/** * This method composes a Get BOD with an expression to find a store by name and sends the BOD to the TutorialStore-Server. */ public ShowTutorialStoreDataAreaType findStoreByIdentifier(String[] storeIdentifier, String accessProfile) { final String METHODNAME="findStoreByIdentifier"; // Build the expression. String expression = java.text.MessageFormat.format(TutorialStoreFacadeConstants.NAMEEXPRESSION, storeIdentifier); 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 = null; try { showTutorialStoreDataArea = getTutorialStore(verb); } catch (TutorialStoreException se) {} 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() { final String METHODNAME="findAllStores"; // Build the expression. SelectionCriteriaHelper selectionCriteriaHelper = new SelectionCriteriaHelper(TutorialStoreFacadeConstants.XPATH_STORE); selectionCriteriaHelper.addAccessProfile(TutorialStoreFacadeConstants.ACCESS_PROFILE_SUMMARY_INFOMATION); ExpressionType queryExpression = selectionCriteriaHelper.getSelectionCriteriaExpression(); // Create the request message. GetType verb = createGetVerb(queryExpression); // Send the request. ShowTutorialStoreDataAreaType showTutorialStoreDataArea = null; try { showTutorialStoreDataArea = getTutorialStore(verb); } catch (TutorialStoreException se) {} return showTutorialStoreDataArea; } /** * This method composes a Process BOD with an Action of 'Close' and sends the BOD to the TutorialStore-Server. */ public AcknowledgeTutorialStoreDataAreaType closeStore(String storeId) { final String METHODNAME = "closeStore(String storeId)"; StoreIdentifierType storeIdentifier = CommerceFoundationFactory.eINSTANCE.createStoreIdentifierType(); storeIdentifier.setUniqueID(storeId); ProcessTutorialStoreType processTutorialStore = TutorialStoreFactory.eINSTANCE.createProcessTutorialStoreType(); ProcessTutorialStoreDataAreaType dataArea = TutorialStoreFactory.eINSTANCE.createProcessTutorialStoreDataAreaType(); processTutorialStore.setDataArea(dataArea); java.util.List expressions = new ArrayList(); expressions.add(createActionExpression(TutorialStoreFacadeConstants.PROCESS_ACTION_CLOSE, SelectionCriteriaHelper.STR_XPATH_LANG, TutorialStoreFacadeConstants.XPATH_STORE)); dataArea.setProcess(createProcessVerb(expressions)); TutorialStoreType tutorialStore = TutorialStoreFactory.eINSTANCE.createTutorialStoreType(); tutorialStore.setStoreIdentifier(storeIdentifier); dataArea.getTutorialStore().add(tutorialStore); AcknowledgeTutorialStoreDataAreaType acknowledgeTutorialStoreDataArea = processTutorialStore(processTutorialStore).getDataArea(); return acknowledgeTutorialStoreDataArea; } /** * This method composes a Process BOD with an Action of 'Open' and sends the BOD to the TutorialStore-Server. */ public AcknowledgeTutorialStoreDataAreaType openStore(String storeId) { final String METHODNAME = "openStore(String storeId)"; StoreIdentifierType storeIdentifier = CommerceFoundationFactory.eINSTANCE.createStoreIdentifierType(); storeIdentifier.setUniqueID(storeId); ProcessTutorialStoreType processStore = TutorialStoreFactory.eINSTANCE.createProcessTutorialStoreType(); ProcessTutorialStoreDataAreaType dataArea = TutorialStoreFactory.eINSTANCE.createProcessTutorialStoreDataAreaType(); processStore.setDataArea(dataArea); java.util.List expressions = new ArrayList(); expressions.add(createActionExpression(TutorialStoreFacadeConstants.PROCESS_ACTION_OPEN, SelectionCriteriaHelper.STR_XPATH_LANG, TutorialStoreFacadeConstants.XPATH_STORE)); dataArea.setProcess(createProcessVerb(expressions)); TutorialStoreType store = TutorialStoreFactory.eINSTANCE.createTutorialStoreType(); store.setStoreIdentifier(storeIdentifier); dataArea.getTutorialStore().add(store); AcknowledgeTutorialStoreDataAreaType acknowledgeStoreDataArea = processTutorialStore(processStore).getDataArea(); return acknowledgeStoreDataArea; }- Organize the imports for the TutorialStore-Client project:
- Open the Java perspective in WebSphere Commerce Developer.
- Right-click the TutorialStore-Client\src folder and select Source.
- Select Organize Imports.