AmazonClientpublic class AmazonClient extends Object implements PropertyChangeListener
Fields Summary |
---|
private static final String | MODE | private static final String | WEBSERVICE | private static final String | TYPE | private static final String | VERSION | ora.jwsnut.chapter1.amazon.AmazonSearchPort | amazonSearch | private String | devtag | private AmazonClientGUI | gui | private int | lastType | private String | lastKey | private int | page |
Methods Summary |
---|
private void | buildGUI()
gui = new AmazonClientGUI();
// Register to receive notification that a search is required.
gui.addPropertyChangeListener(this);
| public void | doSearch(int type, java.lang.String key)
// If this search is the same as the last, increment
// the page number.
String newKey = key.trim();
if (type == lastType && newKey.equals(lastKey)) {
page++;
} else {
lastType = type;
lastKey = newKey;
}
ProductInfo result = null;
try {
switch (type) {
case AmazonClientGUI.KEYWORD_SEARCH:
KeywordRequest keywordReq = new KeywordRequest(newKey,
String.valueOf(page), MODE,
WEBSERVICE, TYPE,
devtag, VERSION);
result = amazonSearch.keywordSearchRequest(keywordReq);
break;
case AmazonClientGUI.AUTHOR_SEARCH:
AuthorRequest authorReq = new AuthorRequest(newKey,
String.valueOf(page), MODE,
WEBSERVICE, TYPE,
devtag, VERSION);
result = amazonSearch.authorSearchRequest(authorReq);
break;
case AmazonClientGUI.ASIN_SEARCH:
AsinRequest asinReq = new AsinRequest(newKey, WEBSERVICE,
TYPE, devtag, VERSION);
result = amazonSearch.asinSearchRequest(asinReq);
break;
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
} finally {
gui.setResults(result);
}
| public void | execute(java.lang.String devtag, java.lang.String address)
// Save the developer's tag
this.devtag = devtag;
// Build the user interface
buildGUI();
// Get the Service object for Amazon.com
// and configure a stub to get access to it.
AmazonSearchService service = new AmazonSearchService_Impl();
amazonSearch = service.getAmazonSearchPort();
((Stub)amazonSearch)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, address);
| public static void | main(java.lang.String[] args)
if (args.length != 2) {
System.out.println("Must supply your developer tag and service address");
System.exit(1);
}
try {
new AmazonClient().execute(args[0], args[1]);
} catch (Throwable t) {
t.printStackTrace(System.out);
}
| public void | propertyChange(java.beans.PropertyChangeEvent evt)
if (evt.getPropertyName().equals(AmazonClientGUI.SEARCH_PROPERTY)) {
int type = gui.getSearchType();
String key = gui.getSearchKey();
if (type >= 0 && key != null) {
// Need to search....
doSearch(type, key);
}
}
|
|