01: package org.databene.domain.person;
02:
03: import org.databene.benerator.LightweightGenerator;
04: import org.databene.benerator.IllegalGeneratorStateException;
05: import org.databene.region.Region;
06: import org.databene.region.Country;
07:
08: import java.util.Locale;
09:
10: /**
11: * (c) Copyright 2006 by Volker Bergmann
12: * Created: 09.06.2006 21:45:13
13: */
14: public class PersonGenerator extends LightweightGenerator<Person> {
15:
16: private GenderGenerator genderGen;
17: private GivenNameGenerator maleGivenNameGen;
18: private GivenNameGenerator femaleGivenNameGen;
19: private FamilyNameGenerator familyNameGen;
20: private TitleGenerator titleGen;
21: private SalutationProvider salutationProvider;
22:
23: private BirthDateGenerator birthDateGenerator;
24:
25: // constructors ----------------------------------------------------------------------------------------------------
26:
27: public PersonGenerator() {
28: this (Country.getDefault(), Locale.getDefault());
29: }
30:
31: public PersonGenerator(Country country, Locale locale) {
32: genderGen = new GenderGenerator();
33: Region region = country.getRegion();
34: maleGivenNameGen = new GivenNameGenerator(region, Gender.MALE);
35: femaleGivenNameGen = new GivenNameGenerator(region,
36: Gender.FEMALE);
37: familyNameGen = new FamilyNameGenerator(region);
38: titleGen = new TitleGenerator(locale);
39: salutationProvider = new SalutationProvider(locale);
40: //addressGenerator = new AddressGenerator(country, locale);
41: birthDateGenerator = new BirthDateGenerator(15, 105);
42: }
43:
44: // properties ------------------------------------------------------------------------------------------------------
45:
46: public void setLocale(Locale locale) {
47: titleGen.setLocale(locale);
48: salutationProvider.setLocale(locale);
49: }
50:
51: public void setRegion(Region region) {
52: maleGivenNameGen.setRegion(region);
53: femaleGivenNameGen.setRegion(region);
54: familyNameGen.setRegion(region);
55: }
56:
57: // Generator interface ---------------------------------------------------------------------------------------------
58:
59: public Class<Person> getGeneratedType() {
60: return Person.class;
61: }
62:
63: public Person generate() throws IllegalGeneratorStateException {
64: Person person = new Person();
65: person.setGender(genderGen.generate());
66: if (Gender.MALE.equals(person.getGender()))
67: person.setGivenName(maleGivenNameGen.generate());
68: else
69: person.setGivenName(femaleGivenNameGen.generate());
70: person.setFamilyName(familyNameGen.generate());
71: person.setSalutation(salutationProvider.salutation(person
72: .getGender()));
73: person.setTitle(titleGen.generate());
74: person.setBirthDate(birthDateGenerator.generate());
75: return person;
76: }
77:
78: // java.lang.Object overrides --------------------------------------------------------------------------------------
79:
80: public String toString() {
81: return getClass().getSimpleName() + '['
82: + familyNameGen.getRegion() + ']';
83: }
84: }
|