1515 * limitations under the License.
1616 */
1717
18-
1918package org .apache .commons .beanutils ;
2019
21-
2220import java .io .Serializable ;
2321import java .lang .reflect .Constructor ;
2422import java .lang .reflect .InvocationTargetException ;
2523import java .util .HashMap ;
2624
27-
2825/**
2926 * <p>Minimal implementation of the <code>DynaClass</code> interface. Can be
3027 * used as a convenience base class for more sophisticated implementations.</p> *
3431 * used to associate the DynaBean instance with this DynaClass.</p>
3532 *
3633 */
37-
3834public class BasicDynaClass implements DynaClass , Serializable {
3935
40-
41-
42-
4336 private static final long serialVersionUID = 1L ;
4437
45-
4638 /**
4739 * The method signature of the constructor we will use to create
4840 * new DynaBean instances.
4941 */
5042 protected static Class <?>[] constructorTypes = { DynaClass .class };
5143
52-
5344 /**
5445 * The constructor of the <code>dynaBeanClass</code> that we will use
5546 * for creating new instances.
5647 */
5748 protected transient Constructor <?> constructor = null ;
5849
59-
6050 /**
6151 * The argument values to be passed to the constructore we will use
6252 * to create new DynaBean instances.
6353 */
6454 protected Object [] constructorValues = { this };
6555
66-
67-
68-
6956 /**
7057 * The <code>DynaBean</code> implementation class we will use for
7158 * creating new instances.
7259 */
7360 protected Class <?> dynaBeanClass = BasicDynaBean .class ;
7461
75-
7662 /**
7763 * The "name" of this DynaBean class.
7864 */
7965 protected String name = this .getClass ().getName ();
8066
81-
8267 /**
8368 * The set of dynamic properties that are part of this DynaClass.
8469 */
8570 protected DynaProperty [] properties = {};
8671
87-
8872 /**
8973 * The set of dynamic properties that are part of this DynaClass,
9074 * keyed by the property name. Individual descriptor instances will
9175 * be the same instances as those in the <code>properties</code> list.
9276 */
9377 protected HashMap <String , DynaProperty > propertiesMap = new HashMap <>();
9478
95-
9679 /**
9780 * Construct a new BasicDynaClass with default parameters.
9881 */
9982 public BasicDynaClass () {
100-
10183 this (null , null , null );
102-
10384 }
10485
105-
10686 /**
10787 * Construct a new BasicDynaClass with the specified parameters.
10888 *
10989 * @param name Name of this DynaBean class
11090 * @param dynaBeanClass The implementation class for new instances
11191 */
11292 public BasicDynaClass (final String name , final Class <?> dynaBeanClass ) {
113-
11493 this (name , dynaBeanClass , null );
115-
11694 }
11795
118-
11996 /**
12097 * Construct a new BasicDynaClass with the specified parameters.
12198 *
@@ -125,7 +102,6 @@ public BasicDynaClass(final String name, final Class<?> dynaBeanClass) {
125102 */
126103 public BasicDynaClass (final String name , Class <?> dynaBeanClass ,
127104 final DynaProperty [] properties ) {
128-
129105 if (name != null ) {
130106 this .name = name ;
131107 }
@@ -136,12 +112,8 @@ public BasicDynaClass(final String name, Class<?> dynaBeanClass,
136112 if (properties != null ) {
137113 setProperties (properties );
138114 }
139-
140115 }
141116
142-
143-
144-
145117 /**
146118 * Return the Class object we will use to create new instances in the
147119 * <code>newInstance()</code> method. This Class <strong>MUST</strong>
@@ -150,12 +122,9 @@ public BasicDynaClass(final String name, Class<?> dynaBeanClass,
150122 * @return The class of the {@link DynaBean}
151123 */
152124 public Class <?> getDynaBeanClass () {
153-
154125 return this .dynaBeanClass ;
155-
156126 }
157127
158-
159128 /**
160129 * <p>Return an array of <code>ProperyDescriptors</code> for the properties
161130 * currently defined in this DynaClass. If no properties are defined, a
@@ -169,12 +138,9 @@ public Class<?> getDynaBeanClass() {
169138 */
170139 @ Override
171140 public DynaProperty [] getDynaProperties () {
172-
173141 return properties ;
174-
175142 }
176143
177-
178144 /**
179145 * Return a property descriptor for the specified property, if it exists;
180146 * otherwise, return <code>null</code>.
@@ -186,34 +152,26 @@ public DynaProperty[] getDynaProperties() {
186152 */
187153 @ Override
188154 public DynaProperty getDynaProperty (final String name ) {
189-
190155 if (name == null ) {
191156 throw new IllegalArgumentException
192157 ("No property name specified" );
193158 }
194159 return propertiesMap .get (name );
195-
196160 }
197161
198-
199162 /**
200163 * Return the name of this DynaClass (analogous to the
201- * <code>getName()</code> method of <code>java.lang.Class</code), which
164+ * <code>getName()</code> method of <code>java.lang.Class</code> ), which
202165 * allows the same <code>DynaClass</code> implementation class to support
203166 * different dynamic classes, with different sets of properties.
204167 *
205168 * @return the name of the DynaClass
206169 */
207170 @ Override
208171 public String getName () {
209-
210172 return this .name ;
211-
212173 }
213174
214-
215-
216-
217175 /**
218176 * Instantiate and return a new DynaBean instance, associated
219177 * with this DynaClass.
@@ -228,7 +186,6 @@ public String getName() {
228186 @ Override
229187 public DynaBean newInstance ()
230188 throws IllegalAccessException , InstantiationException {
231-
232189 try {
233190 // Refind the constructor after a deserialization (if needed)
234191 if (constructor == null ) {
@@ -240,12 +197,8 @@ public DynaBean newInstance()
240197 throw new InstantiationException
241198 (e .getTargetException ().getMessage ());
242199 }
243-
244200 }
245201
246-
247-
248-
249202 /**
250203 * Set the Class object we will use to create new instances in the
251204 * <code>newInstance()</code> method. This Class <strong>MUST</strong>
@@ -256,7 +209,6 @@ public DynaBean newInstance()
256209 * implement the <code>DynaBean</code> interface
257210 */
258211 protected void setDynaBeanClass (final Class <?> dynaBeanClass ) {
259-
260212 // Validate the argument type specified
261213 if (dynaBeanClass .isInterface ()) {
262214 throw new IllegalArgumentException
@@ -268,7 +220,6 @@ protected void setDynaBeanClass(final Class<?> dynaBeanClass) {
268220 ("Class " + dynaBeanClass .getName () +
269221 " does not implement DynaBean" );
270222 }
271-
272223 // Identify the Constructor we will use in newInstance()
273224 try {
274225 this .constructor = dynaBeanClass .getConstructor (constructorTypes );
@@ -278,24 +229,19 @@ protected void setDynaBeanClass(final Class<?> dynaBeanClass) {
278229 " does not have an appropriate constructor" );
279230 }
280231 this .dynaBeanClass = dynaBeanClass ;
281-
282232 }
283233
284-
285234 /**
286235 * Set the list of dynamic properties supported by this DynaClass.
287236 *
288237 * @param properties List of dynamic properties to be supported
289238 */
290239 protected void setProperties (final DynaProperty [] properties ) {
291-
292240 this .properties = properties ;
293241 propertiesMap .clear ();
294242 for (final DynaProperty propertie : properties ) {
295243 propertiesMap .put (propertie .getName (), propertie );
296244 }
297-
298245 }
299246
300-
301247}
0 commit comments