Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package it.polito.dp2.FDS.sol3;
- import static org.junit.Assert.assertNotNull;
- import java.math.BigInteger;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- import java.util.TimeZone;
- import javax.xml.ws.Holder;
- import javax.xml.ws.WebServiceException;
- import it.polito.dp2.FDS.lab3.FDSBookingClient;
- import it.polito.dp2.FDS.lab3.FDSUnbookingClient;
- import it.polito.dp2.FDS.lab3.MissingDataException;
- import it.polito.dp2.FDS.lab3.OperationFailException;
- import it.polito.dp2.FDS.lab3.UnbookClientImpl;
- import it.polito.dp2.FDS.lab3.gen.FDSBooking;
- import it.polito.dp2.FDS.lab3.gen.FDSBookingService;
- import it.polito.dp2.FDS.lab3.gen.FlightDateType;
- import it.polito.dp2.FDS.lab3.gen.InvalidFlightInstanceFault_Exception;
- import it.polito.dp2.FDS.lab3.server.FlightDate;
- import it.polito.dp2.FDS.lab3.server.FlightInstance;
- public class FDSBookingClientImpl implements FDSBookingClient {
- public URL service_url = null;
- WebServiceException e = null;
- FDSBooking proxy;
- String flightNumber = null;
- FlightDateType departureDate = null;
- boolean partialBookingAllowed = false;
- Holder<List<String>> passenger;
- Holder<Boolean> success;
- public FDSBookingClientImpl(){
- try{
- success = new Holder<Boolean>(false);
- setServiceURL(new URL(System.getProperty("it.polito.dp2.FDS.sol3.URL")));
- FDSBookingService service = new FDSBookingService(service_url);
- proxy = service.getFDSBookingServiceSOAPPort();
- } catch (MalformedURLException ex) {
- e = new WebServiceException(ex);
- }catch(Exception e){
- System.out.println ("Fatal error: " + e);
- }
- }
- public static void main(String[] args)
- {
- FDSBookingClientImpl f = new FDSBookingClientImpl();
- System.out.println("URL :"+f.service_url);
- String stringdate = "05/03/2010 GMT";
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy z");
- GregorianCalendar gdate = new GregorianCalendar();
- try {
- gdate.setTime(dateFormat.parse(stringdate));
- gdate.setTimeZone(TimeZone.getTimeZone(stringdate.substring(11)));
- } catch (ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- f.setDepartureDate(gdate);
- f.setFlightNumber("FI097");
- Set<String> p = new HashSet<String>();
- p.add("Lorella Ferlito");
- try
- {
- System.out.println("size before = "+f.getPassengers().size());
- p = f.book(p, true);
- System.out.println("Result of BOOK: ");
- for(String name : p)
- System.out.println("passenger :"+name);
- p = f.getPassengers();
- System.out.println("size after = "+p.size());
- System.out.println("Result of GETPASSENGERS: ");
- for(String name : p)
- System.out.println("passenger :"+name);
- }
- catch (MissingDataException | OperationFailException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- @Override
- public void setFlightNumber(String number) {
- // TODO Auto-generated method stub
- flightNumber = number;
- }
- @Override
- public void setDepartureDate(GregorianCalendar gdate) {
- departureDate = new FlightDateType();
- departureDate.setDay(gdate.get(Calendar.DAY_OF_MONTH));
- departureDate.setMonth(gdate.get(Calendar.MONTH));
- departureDate.setYear(BigInteger.valueOf(gdate.get(Calendar.YEAR)));
- }
- @Override
- public void setServiceURL(URL url) {
- // TODO Auto-generated method stub
- service_url = url;
- }
- @Override
- public Set<String> book(Set<String> passengerNames,
- boolean partialBookingAllowed) throws MissingDataException,
- OperationFailException {
- if(flightNumber==null || departureDate==null || passengerNames==null || passengerNames.size()==0)
- throw new MissingDataException();
- List<String> l = new ArrayList<String>();
- l.addAll(passengerNames);
- passenger = new Holder<List<String>>( l );
- try {
- proxy.book(flightNumber, departureDate, partialBookingAllowed, passenger, success);
- } catch (InvalidFlightInstanceFault_Exception e) {
- throw new OperationFailException(e);
- }
- /*
- if(success.value==true)
- {
- System.out.println("Book operation successfully completed.");
- return new HashSet<String>(passenger.value);
- }
- else {
- System.out.println("Book operation failed.");
- return null;
- }*/
- if(success.value!=null)
- return new HashSet<String>(passenger.value);
- else return null;
- }
- @Override
- public Set<String> getPassengers() throws MissingDataException,
- OperationFailException {
- if(flightNumber==null || departureDate==null)
- throw new MissingDataException();
- List<String> l = new ArrayList<String>();
- try {
- l = proxy.getPassengerList(flightNumber, departureDate);
- } catch (InvalidFlightInstanceFault_Exception e) {
- throw new OperationFailException();
- }
- return new HashSet<String>(l);
- }
- static private GregorianCalendar flightDateToGregorianCalendar(FlightDate date)
- {
- GregorianCalendar cal = new GregorianCalendar(date.getYear().intValue(), date.getMonth(), date.getDay());
- return cal;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement