Home > Products > SophiaFramework UNIVERSE > Tutorial > Amazon E-Commerce > - 8 / 9 -

Some Classes of Amazon application

Data Structure of an Amazon Product

AWSProduct class describes a common AWS (Amazon Web Services) product.

AWSProduct is defined as an abstract class. Classes for specific products such as Book or DVD are derived from this class.

Each Amazon product data comprises of descriptive information (or attributes) such as ASIN, Title, Offers, CustomerReviews etc..

An offer, for example, is the data associated with a vendor offering a product for sale in a specific condition (new, used, refurbished or collectible). In the application, offer data is organized in the struct as following:

// Number of offer listings and the lowest price for each of the offer listing condition classes, 
// including New, Used, Collectible, and Refurbished
SFMTYPEDEFSTRUCT(OfferSummaryRec)
struct OfferSummaryRec {
	SInt32          lowestNewPrice;
	SFXAnsiString   currencyCode;
	SFXAnsiString   formattedPrice;
	SInt32          totalNew;
	SInt32          totalUsed;
	SInt32          totalCollectible;
	SInt32          totalRefurbished;
};

// Contents of the OfferSummary response group
SFMTYPEDEFSTRUCT(OfferRec)
struct OfferRec {
	SFXAnsiString   merchantId;
	SFXAnsiString   condition;
	SFXAnsiString   offerListingId;
	SInt32          amount;
	SFXAnsiString   CurrencyCode;
	SFXAnsiString   formattedPrice;
};

// List of offers
SFMTYPEDEFSTRUCT(OffersRec)
struct OffersRec {
	SInt32 totalOffers;
	SInt32 totalOfferspages;
	SFXArray<OfferRecPtr> offers;
};

There are some differences between the AWSProduct class of Amazon-DOM application and the AWSProduct class of Amazon-SAX application.

First, Amazon-DOM needs the bool data members such as _isParseCustomerReviews, _isParseSimilarProducts etc. for determining what kind of information to be parsed. These bool data members are not needed in Amazon-SAX application since what kind of information to be collected is determined by the the map of tracers.

Second, all the member functions such as ParseCustomerReviews, ParseSimilarProducts etc. for parsing different kind of information of Amazon-DOM are also not needed in Amazon-SAX application since information is collected through the set–data member functions.

The abstract AWSProduct class of Amazon-DOM application is shown below. Repeatitive information is obmitted.

SFMTYPEDEFCLASS(AWSProduct)
class AWSProduct {
SFMSEALCOPY(AWSProduct)

private:
	//
	// member variables for parsing the XML document
	//
	Bool _isParseItemAttributes;
	Bool _isParseImageUrl;	
	Bool _isParseOfferSummary;
	Bool _isParseOffers;
	Bool _isParseCustomerReviews;
	Bool _isParseSimilarProducts;s
	Bool _isParseBrowserNodes;
	Bool _isParseListmaniaLists;

	// common attributes for all products
protected:
	SFXAnsiString   _asin;          // Amazon product ASIN
	SFXAnsiString   _detailPageURL; // detail page URL
	SInt32          _salesRank;     // Amazon sale rank
	SFXAnsiString   _title;         // product title

	ImageUrlRecPtr         _imageUrl;		
	OfferSummaryRecPtr     _offerSummary;
	OffersRecPtr           _offers;
	CustomerReviewsRecPtr  _customerReviews;
	SimilarProductsRecPtr  _similarProducts;
	BrowserNodesRecPtr     _browserNodes;
	ListmaniaListsRecPtr   _listmaniaLists;

public:
	AWSProduct();
	virtual ~AWSProduct(Void);
	static AWSProductPtr Factory(SFXAnsiString producttype);

	// set values
	Void SetAsin(SFXAnsiString param) {_asin = param;}
	Void SetDetailPageURL(SFXAnsiString param) 
	                         {_detailPageURL = param;}

    ...
    

	// get value
	Bool IsParseItemAttributes(Void) 
	                  {return _isParseItemAttributes;}
	Bool IsParseImageUrl(Void) 
	                        {return _isParseImageUrl;}

    ...
    

	SFXAnsiStringConstRef GetAsin(Void) 
	                                  {return _asin;}
	SFXAnsiStringConstRef GetDetailPageURL(Void) 
	                         {return _detailPageURL;}
	
    ...
    

	Void ClearData(); // release resource
    
	// parse the received XML data
	virtual	SFCError ParseItemAttributes(SFXXMLNodePtr node)=0;

	SFCError ParseTitle(SFXXMLNodePtr node);
	SFCError ParseSmallImage(SFXXMLNodePtr node);

    ...

	// display product information
	//
	// to be implemented by derived classes
	virtual	SFCError MakeGeneralPane(SFRTabControlPtr tab)=0; 
	// to be implemented by derived classes
	virtual	SFCError MakeDetailPane(SFRTabControlPtr tab)=0;	
	// same with all products
	virtual	SFCError MakeReviewPane(SFRTabControlPtr tab); 
	
    ...
	
  virtual  SFCError DisplayMe(SFXAnsiStringConstRef producttype, 
                              bool addedFavorite);
};

A class for a specific product (Book) is shown below.

SFMTYPEDEFCLASS(AWSBook)
class AWSBook : public AWSProduct {
	SFMSEALCOPY(AWSBook)

private:
	BookItemAttributesRecPtr _itemAttributes; 

public:
	AWSBook(Void);
	virtual ~AWSBook(Void);

	virtual SFCError ParseItemAttributes(SFXXMLNodePtr node);

	// display book information
	virtual SFCError MakeGeneralPane(SFRTabControlPtr tab);
	virtual SFCError MakeDetailPane(SFRTabControlPtr tab);
};

BookItemAttributesRec is a struct that holds specific information about Book.

In a derived class of the AWSProduct abstract class, only 3 methods need to be implemented; these are ParseItemAttributes, MakeGeneralPane, and MakeDetailPane.

Please refer to the source code for information of AWSProduct class of Amazon-SAX application.

Classes for Displaying Product Information

The application displays product information in various panes, each pane for a kind of information such as customer review or image.

Below are classes that are used to create information tab panes.

// to display a text as a link
SFMRESPONDERBEHAVIOR(LINKLABEL, BEHAVIOR_SFRCONTROL, PROPERTY_DIRECT,  APPEARANCE_TRANSPARENT)
SFMTYPEDEFCLASS(LinkLabel)
class LinkLabel : public SFRButtonBase {
private:
	SFXWideString _title;
public:
	LinkLabel(SFRResponderPtr, 
	          SFXRectangleConstRef, 
	          SFXWideStringConstRef, 
	          BehaviorType = BEHAVIOR_LINKLABEL);
	~LinkLabel(Void);
	Void SetTitle(SFXWideStringConstRef);
	SFXWideStringConstRef GetTitle(Void) const;
private:
	virtual Void HandleRelease(Void);
	virtual Void HandleContent(SFXGraphicsPtr);	

};

//ScrollTabPane class to display long information
SFMTYPEDEFCLASS(ScrollTabPane)
class ScrollTabPane : public SFRTabPane {
	SFMSEALCOPY(ScrollTabPane)
public:
	ScrollTabPane(SFRTabControlPtr tab, 
	              SFXWideStringConstRef title);
	Void SetHeight(SInt16 height);
private:
	HANDLER_DECLARE_BOOLEVENT(OnKey)
	HANDLER_DECLARE_VOIDRENDER(OnRender)
};

// to display product information, inherits from ScrollTabPane
SFMTYPEDEFCLASS(AWSTabPane)
class AWSTabPane : public ScrollTabPane {
	SFMSEALCOPY(AWSTabPane)
private:
	SFXAnsiString _string;
	SFXProperty   _value;
	UInt16        _maxWidth;
public:
	AWSTabPane(SFRTabControlPtr tab, SFXWideStringConstRef title);
	virtual ~AWSTabPane(Void);
	SFCError MakeLabels(Void);
	SFCError MakeLabelsLineFeed(Void);
	SFCError Append(SFXAnsiStringConstRef name, SFXAnsiStringConstRef value);
	SFCError Append(SFXAnsiStringConstRef name, SInt32 value);
	Void Clear(Void);
private:
	HANDLER_DECLARE_VOIDCONTROL(OnLink)
};

// to display product image, inherits from ScrollTabPane
SFMTYPEDEFCLASS(AWSImageTabPane)
class AWSImageTabPane : public ScrollTabPane {
	SFMSEALCOPY(AWSImageTabPane)
private:
	SFXHTTPConnection     _http;
	SFXBinaryStreamReader _reader;
	SFXAnsiString         _url;
	SFXAnsiString         _asin;
	SFXBuffer             _imageBuffer;
	SFBImageSmp           _image;
public:
	AWSImageTabPane(SFRTabControlPtr tab, 
	                SFXWideStringConstRef title, 
	                SFXAnsiStringConstRef url, 
	                SFXAnsiStringConstRef asin);
	virtual ~AWSImageTabPane(Void);
private:
	Void ProceedNetworkError(Void);
	HANDLER_DECLARE_VOIDRENDER(OnRenderContent)
	HANDLER_DECLARE_VOIDCONTROL(OnButtonControl)

	// Callback function: begin HTTP connection
	CALLBACK_DECLARE_SFXHTTPCONNECTION(ConnectCallback)
	// Callback function: HTTP information receiving
	CALLBACK_DECLARE_SFXBINARYSTREAMREADER(FetchCallback)
};

// to display product information
SFMRESPONDERATTRIBUTE(AWSDISPLAYWINDOW, four_char_code('D', 'i', 's', 'p'))

SFMTYPEDEFCLASS(AWSDisplayWindow)
class AWSDisplayWindow : public SFRPlainWindow {
	SFMSEALCOPY(AWSDisplayWindow)
private:
	enum {
		OPERATION_ADD,
		OPERATION_BACK,
		OPERATION_LIMIT
    };
	
	SFXAnsiString  _searchindex;      
	SFXAnsiString  _asin;             
	SFXAnsiString  _title;            
	Bool           _addedToFavorites; 
	SFXAnsiString  _favoriteFileName; 
	
public:
	explicit AWSDisplayWindow(SFXAnsiStringConstRef searchindex, 
	                          SFXAnsiStringConstRef asin, 
	                          SFXAnsiStringConstRef	title, 
	                          Bool addedToFavorites) static_throws;
	virtual ~AWSDisplayWindow(Void);

private:
	HANDLER_DECLARE_BOOLEVENT(OnKey)
	HANDLER_DECLARE_VOIDEVENT(OnSoftkey)
	HANDLER_DECLARE_VOIDMENU(FromSoftkey)

	SFCError AddToFavorites(Void);
};

Classes for Search Input Window

The SearchWindow class has a tab control which has various panes for various product searches.

The SearchPane class has members such as combo box, text control for input search parameters.

For REST request, an instance of SGRNetworkDialogSet class is needed.

For SOAP request, an instance of SGRSOAPSet class is needed.

// Search Pane for a specific product search
SFMRESPONDERATTRIBUTE(SEARCHPANE, four_char_code('S', 'e', 'a', 'r'))

SFMTYPEDEFCLASS(SearchPane)
class SearchPane : public SFRTabPane {
    SFMSEALCOPY(SearchPane)
private:
	// product type such as Books or DVD
	SFXAnsiString _searchindex;	

	// product sub-categories labels used by combobox
	SFXWideString	*BrowseNodesTitle;
	// product sub-categories values
	SFXAnsiString	*BrowseNodesValue;
	// number of sub-categories
	SInt32	_size;		

	// select product sub-categories
	SFRComboboxControlPtr _combobox;
	// input keyword
	SFREditboxControlPtr _textcontrol;	
	// search button
	SFRButtonControlPtr _button;	

	// display network error
	SGRErrorDialogSet _errorDialog;		
	// dialog for REST request
	SGRNetworkDialogSet _networkDialog;	
	

public:
	SearchPane(SFRTabControlPtr tab, 
	           SFXWideStringConstRef title, 
	           SFXWideStringConstRef searchindex);
	virtual ~SearchPane(Void);

	HANDLER_DECLARE_BOOLEVENT(OnKey)
	HANDLER_DECLARE_VOIDEVENT(OnSoftkey)
	HANDLER_DECLARE_VOIDCONTROL(OnTextControl)
	HANDLER_DECLARE_VOIDCONTROL(OnButtonControl)

  static Void OnNetworkEntry(SGRNetworkDialogSet::NotifyEnum notify, 
                             SFCError error, 
                             VoidPtr reference);
	Void OnNetwork(SGRNetworkDialogSet::NotifyEnum notify, 
	               SFCError error);
	
	SFCError GetBrowseNodes(Void);
	SFCError ParseXML(Void);

private:
	SFCError AddComponents(Void);

};

// Search Window
SFMTYPEDEFCLASS(SearchWindow)
class SearchWindow : public SFRPlainWindow {
	SFMSEALCOPY(SearchWindow)
private:
       
	SFRTabControlPtr _tab;

public:
	SearchWindow(Void) static_throws;
	virtual ~SearchWindow(Void);
	
	HANDLER_DECLARE_VOIDVOID(TabSelect)
};

Other Classes

Above are some main classes used by the application. There are a number of other classes such as class for softkey window, class for product list, class for displaying list of products etc.. For detailed information of these classes, please refer to the source code that is free to download.

Go back  1   2   3   4   5   6   7   8   9  Next page