FileDocCategorySizeDatePackage
UsedCarListingService.javaAPI DocExample2114Tue Jan 15 11:46:26 GMT 2002javasoap.book.ch8

UsedCarListingService

public class UsedCarListingService extends Object

Fields Summary
Hashtable
_listings
int
_nextId
Constructors Summary
Methods Summary
public intaddListing(Listing listing, javax.activation.DataHandler handler)


         
                  
      _listings.put(new Integer(_nextId), listing);
      int listno = _nextId;
      _nextId++;

      if (handler != null) {
         String fname = String.valueOf(listno) + ".bin";
         DataSource ds = handler.getDataSource();
         ByteArrayDataSource bsource = 
               new ByteArrayDataSource(ds.getInputStream(), 
                                       handler.getContentType());
         bsource.writeTo(new FileOutputStream(fname));
      }      

      return listno;
   
protected java.util.VectorfindListingIds(java.lang.String make, java.lang.String model)

      
      Vector result = new Vector();
      for (Enumeration e = _listings.keys() ; 
                             e.hasMoreElements() ;) {
         Integer i = (Integer)e.nextElement();
         Listing listing = (Listing)_listings.get(i);
         if (make.equals(listing.getMake()) &&
             model.equals(listing.getModel())) {
            result.add(i);
         }
      }
      
      return result; 
   
public javax.activation.DataHandlergetImage(int id)

      String fname = String.valueOf(id) + ".bin";
      DataSource ds = 
           new ByteArrayDataSource(new File(fname), null);
      DataHandler dh = new DataHandler(ds);
      return dh;
   
public ListinggetListing(int id)

      Listing listing = (Listing)_listings.get(new Integer(id));
      return listing;
   
public java.lang.Integer[]search(java.lang.String make, java.lang.String model)

      Vector v = findListingIds(make, model);
      int cnt = v.size();
      if (cnt == 0)
         return null;

      Integer ids[] = new Integer[cnt];
      for (int i = 0; i < cnt; i++) {
         ids[i] = (Integer)v.elementAt(i);
      }

      return ids;