| 1 |
// package samples.bidbuy; |
| 2 |
|
| 3 |
import org.apache.axis.utils.QName; |
| 4 |
import org.apache.axis.encoding.BeanSerializer; |
| 5 |
import org.apache.axis.encoding.TypeMappingRegistry; |
| 6 |
|
| 7 |
/** |
| 8 |
* Big/PurchaseOrder Service |
| 9 |
*/ |
| 10 |
public class BidService { |
| 11 |
|
| 12 |
static int nextReceiptNumber = 9000; |
| 13 |
|
| 14 |
/** |
| 15 |
* Request a quote for a given quantity of a specified product |
| 16 |
* @param productName name of product |
| 17 |
* @param quantity number desired |
| 18 |
* @return Total amount in US$ for complete purchase |
| 19 |
*/ |
| 20 |
public double RequestForQuote(String productName, int quantity) { |
| 21 |
if (quantity < 100) { |
| 22 |
return 1.0 * quantity; |
| 23 |
} if (quantity < 1000) { |
| 24 |
return 0.8 * quantity; |
| 25 |
} else { |
| 26 |
return 0.7 * quantity; |
| 27 |
} |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Purchase a given quantity of a specified product |
| 33 |
* @param productName name of product |
| 34 |
* @param quantity number desired |
| 35 |
* @param price desired price (!!!) |
| 36 |
* @param customerId who you are |
| 37 |
* @param shipTo where you want the goods to go |
| 38 |
* @param date where you want the goods to go |
| 39 |
* @return Receipt |
| 40 |
*/ |
| 41 |
public String SimpleBuy(String productName, String address, int quantity) { |
| 42 |
return Integer.toString(nextReceiptNumber++) + "\n" + |
| 43 |
quantity + " " + productName; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Register the serializers and deserializers required to implement |
| 48 |
* a Buy service |
| 49 |
* @param map the TypeMappingRegistry to update |
| 50 |
*/ |
| 51 |
public void BuyTypeMap(TypeMappingRegistry map) throws Exception { |
| 52 |
|
| 53 |
// register the PurchaseOrder class |
| 54 |
QName poqn = new QName("http://www.soapinterop.org/Bid", |
| 55 |
"PurchaseOrder"); |
| 56 |
Class cls = PurchaseOrder.class; |
| 57 |
map.addSerializer(cls, poqn, new BeanSerializer(cls)); |
| 58 |
map.addDeserializerFactory(poqn, cls, BeanSerializer.getFactory(cls)); |
| 59 |
|
| 60 |
// register the Address class |
| 61 |
QName aqn = new QName("http://www.soapinterop.org/Bid", "Address"); |
| 62 |
cls = Address.class; |
| 63 |
map.addSerializer(cls, aqn, new BeanSerializer(cls)); |
| 64 |
map.addDeserializerFactory(aqn, cls, BeanSerializer.getFactory(cls)); |
| 65 |
|
| 66 |
// register the LineItem class |
| 67 |
QName liqn = new QName("http://www.soapinterop.org/Bid", "LineItem"); |
| 68 |
cls = LineItem.class; |
| 69 |
map.addSerializer(cls, liqn, new BeanSerializer(cls)); |
| 70 |
map.addDeserializerFactory(liqn, cls, BeanSerializer.getFactory(cls)); |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Process a purchase order. |
| 76 |
* @return Receipt |
| 77 |
*/ |
| 78 |
public String Buy(PurchaseOrder PO) { |
| 79 |
String receipt = Integer.toString(nextReceiptNumber++); |
| 80 |
System.out.println("PO: " + PO); |
| 81 |
|
| 82 |
for (int i=0; i<PO.getItems().length; i++) { |
| 83 |
LineItem item = PO.getItems()[i]; |
| 84 |
receipt += "\n " + item.getQuantity() + " " + item.getName(); |
| 85 |
} |
| 86 |
|
| 87 |
return receipt; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Let the world know that we are still alive... |
| 92 |
*/ |
| 93 |
public void Ping() { |
| 94 |
} |
| 95 |
|
| 96 |
} |