Better Software - January 2008 - (Page 25) package com.bigcorporation.personnel.ws; import import import import import java.util.Random; javax.xml.xpath.*; com.bigcorporation.ws.AbstractDomServlet; org.joda.time.LocalDate; org.w3c.dom.*; public class VacationServlet extends AbstractDomServlet { private XPathFactory xpathFactory = XPathFactory.newInstance(); private Random rnd = new Random(); protected Element onRequest(Element vacationRequest) throws Exception { XPath xpath = xpathFactory.newXPath(); xpath.setNamespaceContext(new PersonnelNamespaceContext()); String startDateString = xpath.evaluate("/p:vacationRequest/p:vacation/p:startDate", vacationRequest); LocalDate startDate = new LocalDate(startDateString); String endDateString = xpath.evaluate("/p:vacationRequest/p:vacation/p:endDate", vacationRequest); LocalDate endDate = new LocalDate(endDateString); String firstName = xpath.evaluate("/p:vacationRequest/p:employee/p:name/p:firstName", vacationRequest); String lastName = xpath.evaluate("/p:vacationRequest/p:employee/p:name/p:lastName", vacationRequest); String department = xpath.evaluate("/p:vacationRequest/p:employee/p:department", vacationRequest); boolean accepted = handleVacationRequest(startDate, endDate, firstName, lastName, department); if (accepted) { vacationRequest.setAttribute("state", "accepted"); } else { vacationRequest.setAttribute("state", "rejected"); } return vacationRequest; } private boolean handleVacationRequest(LocalDate startDate, LocalDate endDate, String firstName, String lastName, String department) { return rnd.nextBoolean(); } } Listing 10 www.StickyMinds.com JANUARY/FEBRUARY 2008 BETTER SOFTWARE 25 http://www.StickyMinds.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.