1 package ejava.projects.esales.xml; 2 3 import ejava.projects.esales.dto.Account; 4 5 import ejava.projects.esales.dto.Address; 6 import ejava.projects.esales.dto.Auction; 7 import ejava.projects.esales.dto.Bid; 8 import ejava.projects.esales.dto.ESales; 9 10 import java.util.Date; 11 12 public class SampleGen { 13 static int addressId = 0; 14 static int auctionId = 0; 15 static int bidId = 0; 16 static int accountId = 0; 17 public ESales createSales() throws Exception { 18 ESales sales = new ESales(); 19 20 Account seller = createAccount("Joe", "Charles", "Seller"); 21 Account bidder1 = createAccount("Jill", "Bean", "Bidwell"); 22 Account bidder2 = createAccount("Dan", "Didly", "Doneright"); 23 sales.getAccount().add(seller); 24 sales.getAccount().add(bidder1); 25 sales.getAccount().add(bidder2); 26 27 Auction auction = createAuction(seller, bidder1, bidder2); 28 sales.getAuction().add(auction); 29 30 for (Account account : sales.getAccount()) { 31 for (Object object : account.getAddress()) { 32 sales.getAddress().add((Address)object); 33 } 34 } 35 for (Auction a : sales.getAuction()) { 36 for (Bid bid : a.getBid()) { 37 sales.getBid().add(bid); 38 } 39 } 40 return sales; 41 } 42 43 public Auction createAuction(Account seller, Account...bidder) { 44 Auction auction = new Auction(); 45 auction.setId(auctionId); 46 auction.setRefid("auction:"+auctionId++); 47 auction.setAskingPrice(1.00F); 48 auction.setBuyer(bidder[0]); 49 auction.setCategory("exampleCategory"); 50 auction.setEndTime(new Date()); 51 auction.setStartTime( 52 new Date(auction.getEndTime().getTime()-3*3600*1000)); 53 auction.setPurchasePrice(auction.getAskingPrice()); 54 auction.setSeller(seller); 55 auction.setShipTo(seller.getAddress().get(0)); 56 auction.setTitle("example item"); 57 for (Account account : bidder) { 58 Bid bid = new Bid(); 59 bid.setAmount(1.00F); 60 bid.setBidder(account); 61 bid.setId(bidId++); 62 bid.setItem(auction); 63 auction.getBid().add(bid); 64 } 65 return auction; 66 } 67 68 public Address createAddress1(String addressee) { 69 Address address = new Address(); 70 address.setId(addressId); 71 address.setRefid("address:" + addressId++); 72 address.setAddressee(addressee); 73 address.setCity("Acity"); 74 address.setName("primary"); 75 address.setState("EX"); 76 address.setStreet("Example"); 77 address.setZip("12345"); 78 return address; 79 } 80 81 public Account createAccount( 82 String firstName, String middleName, String lastName) { 83 Account account = new Account(); 84 account.setRefid("account:" + accountId++); 85 account.setEmail(firstName + "." + lastName + "@example.com"); 86 account.setEndDate(null); 87 account.setFirstName(firstName); 88 account.setMiddleName(middleName); 89 account.setLastName(lastName); 90 account.setLogin( 91 firstName.substring(0, 1).toLowerCase() + 92 middleName.substring(0, 1).toLowerCase() + 93 lastName.toLowerCase()); 94 account.setStartDate(new Date()); 95 96 account.getAddress().add( 97 createAddress1(firstName + " " + lastName)); 98 return account; 99 } 100 101 }