/** * @author Hyacinthe MENIET * Created on 21 juil. 07 */ package net.dotmyself.ws; import java.util.Random; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; /** * Randomly generates useful data about the given Department. */ @WebService(name="DepartmentService") public class DepartmentInformation { /** * Used to retrieve random data. */ private Random random; /** * Default constructor. */ public DepartmentInformation() { this.random = new Random(); } /** * Retrieves random data from the given department's code. * @param departmentCode the department's code. * @return a {@link Department} */ @WebMethod public @WebResult(name="department") Department getDepartment( @WebParam(name="departmentcode") int departmentCode) { // we set the seed so that the sequence can be // reproduced for the same department random.setSeed(departmentCode); // fills the department String urbanization = "campagnard"; Department department = new Department(); department.setCode(departmentCode); department.setPopulation(random.nextInt(10000000)); department.setSurface(random.nextFloat()*10); if (random.nextBoolean()) { urbanization = "citadin"; } department.setUrbanization(urbanization); return department; } }