View Javadoc
1   /*
2    * #%L
3    * Nuiton Validator
4    * %%
5    * Copyright (C) 2013 - 2014 Code Lutin, Tony Chemit
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  package org.nuiton.validator.xwork2.field;
23  
24  import java.beans.PropertyChangeListener;
25  import java.beans.PropertyChangeSupport;
26  import java.io.File;
27  import java.util.Collection;
28  
29  public class ValidatorBean {
30  
31      public static class ValidatorBeanEntry {
32  
33          protected int intValue;
34  
35          protected String stringValue;
36  
37          protected String stringValue2;
38  
39          public ValidatorBeanEntry(int intValue, String stringValue) {
40              this.intValue = intValue;
41              this.stringValue = stringValue;
42          }
43  
44          public ValidatorBeanEntry(int intValue, String stringValue, String stringValue2) {
45              this.intValue = intValue;
46              this.stringValue = stringValue;
47              this.stringValue2 = stringValue2;
48          }
49  
50          public int getIntValue() {
51              return intValue;
52          }
53  
54          public void setIntValue(int intValue) {
55              this.intValue = intValue;
56          }
57  
58          public String getStringValue() {
59              return stringValue;
60          }
61  
62          public void setStringValue(String stringValue) {
63              this.stringValue = stringValue;
64          }
65  
66          public String getStringValue2() {
67              return stringValue2;
68          }
69  
70          public void setStringValue2(String stringValue2) {
71              this.stringValue2 = stringValue2;
72          }
73      }
74  
75      protected File existingFile;
76  
77      protected File notExistingFile;
78  
79      protected File existingDirectory;
80  
81      protected File notExistingDirectory;
82  
83      protected Collection<ValidatorBeanEntry> entries;
84  
85      protected String stringValue;
86  
87      protected ValidatorBeanEntry entry;
88  
89      PropertyChangeSupport p;
90  
91      public ValidatorBean() {
92          p = new PropertyChangeSupport(this);
93      }
94  
95      public void addPropertyChangeListener(PropertyChangeListener listener) {
96          p.addPropertyChangeListener(listener);
97      }
98  
99      public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
100         p.addPropertyChangeListener(propertyName, listener);
101     }
102 
103     public void removePropertyChangeListener(PropertyChangeListener listener) {
104         p.removePropertyChangeListener(listener);
105     }
106 
107     public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
108         p.removePropertyChangeListener(propertyName, listener);
109     }
110 
111     public String getStringValue() {
112         return stringValue;
113     }
114 
115     public File getExistingFile() {
116         return existingFile;
117     }
118 
119     public File getNotExistingFile() {
120         return notExistingFile;
121     }
122 
123     public File getExistingDirectory() {
124         return existingDirectory;
125     }
126 
127     public File getNotExistingDirectory() {
128         return notExistingDirectory;
129     }
130 
131     public ValidatorBeanEntry getEntry() {
132         return entry;
133     }
134 
135     public Collection<ValidatorBeanEntry> getEntries() {
136         return entries;
137     }
138 
139     public void setStringValue(String stringValue) {
140         String old = this.stringValue;
141         this.stringValue = stringValue;
142         p.firePropertyChange("stringValue", old, existingFile);
143     }
144 
145     public void setExistingFile(File existingFile) {
146         File old = this.existingFile;
147         this.existingFile = existingFile;
148         p.firePropertyChange("existingFile", old, existingFile);
149     }
150 
151     public void setNotExistingFile(File notExistingFile) {
152         File old = this.notExistingFile;
153         this.notExistingFile = notExistingFile;
154         p.firePropertyChange("notExistingFile", old, notExistingFile);
155     }
156 
157     public void setExistingDirectory(File existingDirectory) {
158         File old = this.existingDirectory;
159         this.existingDirectory = existingDirectory;
160         p.firePropertyChange("existingDirectory", old, existingDirectory);
161     }
162 
163     public void setNotExistingDirectory(File notExistingDirectory) {
164         File old = this.notExistingDirectory;
165         this.notExistingDirectory = notExistingDirectory;
166         p.firePropertyChange("notExistingDirectory", old, notExistingDirectory);
167     }
168 
169     public void setEntries(Collection<ValidatorBeanEntry> entries) {
170         this.entries = entries;
171         // set null oldValue to always fire event
172         // otherwise it could been not sent...
173         p.firePropertyChange("entries", null, entries);
174     }
175 
176     public void setEntry(ValidatorBeanEntry entry) {
177         this.entry = entry;
178         p.firePropertyChange("entry", null, entry);
179     }
180 }