001: package nl.knowlogy.validation.test;
002:
003: import nl.knowlogy.validation.ClassValidator;
004: import nl.knowlogy.validation.ClassValidatorImpl;
005: import nl.knowlogy.validation.Messages;
006: import nl.knowlogy.validation.Validatable;
007: import nl.knowlogy.validation.validators.AllowedValuesValidator;
008: import nl.knowlogy.validation.validators.IsNotBlankValidator;
009: import nl.knowlogy.validation.validators.IsRequiredValidator;
010: import nl.knowlogy.validation.validators.MaxLengthValidator;
011: import nl.knowlogy.validation.validators.PatternValidator;
012:
013: public class AddressWithProgrammaticValidations implements Validatable {
014:
015: public static ClassValidator validator = new AddressWithProgrammaticValidationsValidator();
016:
017: // optional register it with the validationengine with a static method here
018: // static{
019: // nl.knowlogy.validation.ValidationEngine.registerValidator(validator);
020: // }
021:
022: public static class AddressWithProgrammaticValidationsValidator
023: extends ClassValidatorImpl {
024:
025: public AddressWithProgrammaticValidationsValidator() {
026: super (AddressWithProgrammaticValidations.class);
027: add(new IsRequiredValidator("city"));
028: add(new MaxLengthValidator("city", new Long(10)));
029: add(new IsNotBlankValidator("city"));
030: add(new IsRequiredValidator("countryCode"));
031: add(new IsRequiredValidator("houseNumber"));
032: add(new MaxLengthValidator("houseNumber", new Long(5)));
033: add(new IsNotBlankValidator("houseNumber"));
034: add(new IsNotBlankValidator("houseNumberExtension"));
035: add(new IsRequiredValidator("street"));
036: add(new MaxLengthValidator("street", new Long(30)));
037: add(new IsNotBlankValidator("street"));
038: add(new IsRequiredValidator("zipCode", "zipcode.isrequired"));
039: add(new PatternValidator("zipCode",
040: "^[1-9]\\d{3}[- ]?[a-zA-Z]{2}$",
041: "zipcode.invalidformat"));
042: add(new MaxLengthValidator("zipCode", new Long(6),
043: "zipcode.tolong"));
044: add(new IsRequiredValidator("typeAdres"));
045: add(new AllowedValuesValidator("typeAdres", "C,V",
046: "typeadress.notallowedvalue"));
047: }
048: }
049:
050: private String street;
051:
052: private Integer houseNumber;
053:
054: private String houseNumberExtension;
055:
056: private String zipCode;
057:
058: private String city;
059:
060: private String countryCode;
061:
062: private String typeAdres;
063:
064: /**
065: * @return Returns the city.
066: */
067: public String getCity() {
068: return city;
069: }
070:
071: /**
072: *
073: * @param city
074: * The city to set.
075: */
076: public void setCity(String city) {
077: this .city = city;
078: }
079:
080: /**
081: * @return Returns the countryCode.
082: */
083: public String getCountryCode() {
084: return countryCode;
085: }
086:
087: /**
088: * @param countryCode
089: * The countryCode to set.
090: */
091: public void setCountryCode(String countryCode) {
092: this .countryCode = countryCode;
093: }
094:
095: /**
096: *
097: *
098: * @return Returns the houseNumber.
099: */
100: public Integer getHouseNumber() {
101: return houseNumber;
102: }
103:
104: /**
105: *
106: * @param houseNumber
107: * The houseNumber to set.
108: */
109: public void setHouseNumber(Integer houseNumber) {
110: this .houseNumber = houseNumber;
111: }
112:
113: /**
114: * @return Returns the houseNumberExtension.
115: */
116: public String getHouseNumberExtension() {
117: return houseNumberExtension;
118: }
119:
120: /**
121: * @param houseNumberExtension
122: * The houseNumberExtension to set.
123: */
124: public void setHouseNumberExtension(String houseNumberExtension) {
125: this .houseNumberExtension = houseNumberExtension;
126: }
127:
128: /**
129: * @return Returns the street.
130: */
131: public String getStreet() {
132: return street;
133: }
134:
135: /**
136: *
137: * @param street
138: * The street to set.
139: */
140: public void setStreet(String street) {
141: this .street = street;
142: }
143:
144: /**
145: * @return Returns the zipCode.
146: */
147: public String getZipCode() {
148: return zipCode;
149: }
150:
151: /**
152: *
153: * @param zipCode
154: * The zipCode to set.
155: */
156: public void setZipCode(String zipCode) {
157: this .zipCode = zipCode;
158: }
159:
160: /**
161: * @return Returns the typeAdres.
162: */
163: public String getTypeAdres() {
164: return typeAdres;
165: }
166:
167: /**
168: *
169: * @param typeAdres
170: * The typeAdres to set.
171: */
172: public void setTypeAdres(String typeAdres) {
173: this .typeAdres = typeAdres;
174: }
175:
176: public void validate(Messages messages) {
177: validator.validate(this, messages);
178: }
179:
180: }
|