Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
272   659   83   12,95
108   417   0,31   21
21     3,95  
1    
 
  AbstractValueObjectTest       Line # 41 272 83 87,8% 0.8778055
 
  (32)
 
1    /* $Id: AbstractValueObjectTest.java,v 1.14 2008/07/26 08:00:23 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the 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 Public License for more details.
16    */
17   
18    package org.qedeq.kernel.test;
19   
20    import java.lang.reflect.Constructor;
21    import java.lang.reflect.Field;
22    import java.lang.reflect.InvocationTargetException;
23    import java.lang.reflect.Method;
24    import java.util.ArrayList;
25    import java.util.HashSet;
26    import java.util.List;
27    import java.util.Set;
28   
29    import org.qedeq.base.test.QedeqTestCase;
30    import org.qedeq.kernel.base.list.Element;
31    import org.qedeq.kernel.dto.list.DefaultAtom;
32   
33   
34    /**
35    * Basis for value object tests.
36    * @see #testAll()
37    *
38    * @version $Revision: 1.14 $
39    * @author Michael Meyling
40    */
 
41    public abstract class AbstractValueObjectTest extends QedeqTestCase {
42   
43    /** Set of all methods to check. */
44    private Set methodsToCheck;
45   
46    /** Set of already checked methods. */
47    private Set checkedMethods;
48   
 
49  40 toggle protected void setUp() throws Exception {
50  40 methodsToCheck = new HashSet();
51  40 checkedMethods = new HashSet();
52   
53  40 final Class clazz = getTestedClass();
54   
55  40 Method[] methods = clazz.getDeclaredMethods();
56  472 for (int i = 0; i < methods.length; i++) {
57  432 getMethodsToCheck().add(methods[i].getName());
58    }
59    }
60   
61    /**
62    * Return the value object class to test.
63    *
64    * @return Class to test.
65    */
66    protected abstract Class getTestedClass();
67   
68    /**
69    * Test everything we could. This includes getter and setter, but
70    * the combination of <code>add</code>, <code>size</code> and
71    * <code>get(int)</code> is possible too.
72    * <p>
73    * This method also tests <code>equal</code>, <code>hashCode</code>
74    * and <code>toString</code>.
75    * <p>
76    * Preconditions for using this method are the following.
77    * <ul>
78    * <li>For every attribute of the tested class exists a combination
79    * of getter and setter with matching names or a triple of
80    * <code>add</code>, <code>size</code>, <code>get(int)</code>.</li>
81    * <li>Every attribute is of type {@link String}, {@link Integer},
82    * {@link Boolean}, {@link List} or fulfills the preconditions for
83    * itself.</li>
84    * </ul>
85    *
86    * @throws Exception Something went wrong. Perhaps the preconditions were
87    * violated.
88    */
 
89  32 toggle public void testAll() throws Exception {
90  32 checkGetterAndSetter();
91  32 checkToString();
92  32 checkHashCode();
93  32 checkEquals();
94  32 checkAllChecked();
95    }
96   
97    /**
98    * Check the setters and getters and <code>add</code>, <code>size</code> and
99    * <code>get(int)</code>.
100    * If the attribute names don't match the method names we have a problem.
101    *
102    * @throws Exception Something went wrong. Perhaps the preconditions in {@link #testAll()}
103    * were violated.
104    */
 
105  32 toggle protected void checkGetterAndSetter() throws Exception {
106  32 final Class clazz = getTestedClass();
107  32 Field[] attrs = clazz.getDeclaredFields();
108  32 if (attrs.length == 0) {
109  0 fail("no attributes found in class " + clazz.getName());
110    }
111    // iterate over every attribute of the value object
112  111 for (int i = 0; i < attrs.length; i++) {
113  79 String attrName = attrs[i].getName();
114  79 if (attrName.startsWith("__")) { // because of clover, ignore those attributes
115  0 continue;
116    }
117  79 boolean tested = false;
118  79 tested = tested || testGetSetAdd(clazz, attrs[i]);
119  79 tested = tested || testAddSizeGet(clazz, attrs[i]);
120  79 if (!tested) {
121  0 fail("could not test attribute " + attrName + " in class " + clazz.getName());
122    }
123    }
124    }
125   
126    /**
127    * Tests getter and setter methods for an attribute of a class. Also tests an <code>add</code>
128    * method for list attributes.
129    *
130    * @param clazz Attribute is in this class.
131    * @param attr Test methods for this attribute.
132    * @return Did this test match? If <code>true</code> all those methods were tested.
133    * @throws Exception Test failure.
134    */
 
135  79 toggle protected boolean testGetSetAdd(final Class clazz, final Field attr) throws Exception {
136  79 final Method[] methods = clazz.getDeclaredMethods();
137  79 final String attrName = attr.getName();
138  79 Method getter = null;
139  79 Method setter = null;
140  79 Method adder = null;
141  1061 for (int j = 0; j < methods.length; j++) {
142  982 if (methods[j].getName().equals("get" + getUName(attrName))) {
143  67 getter = methods[j];
144    }
145  982 if (methods[j].getName().equals("set" + getUName(attrName))) {
146  67 setter = methods[j];
147    }
148  982 if ((methods[j].getName() + "List").equals("add" + getUName(attrName))) {
149  17 adder = methods[j];
150    }
151    }
152    // are getter and setter known?
153  79 if (getter == null || setter == null) {
154  12 return false;
155    }
156  67 final Object vo = getObject(clazz);
157  67 final Object result1 = getter.invoke(vo, new Object[0]);
158  67 assertNull(result1);
159  67 final Object value = getFilledObject(getter.getReturnType(), clazz, attrName);
160  67 setter.invoke(vo, new Object[] {value});
161  67 final Object result2 = getter.invoke(vo, new Object[0]);
162  67 assertEquals(value, result2);
163  67 if (adder != null) {
164  5 final Method size1 = result2.getClass().getMethod("size", new Class[0]);
165  5 final int number1 = ((Integer) size1.invoke(result2, new Object[0])).intValue();
166   
167  5 final Object add = getFilledObject(adder.getParameterTypes()[0], clazz, attrName);
168  5 adder.invoke(vo, new Object[] {add});
169   
170  5 final Object result3 = getter.invoke(vo, new Object[0]);
171  5 final Method size2 = result3.getClass().getMethod("size", new Class[0]);
172  5 final int number2 = ((Integer) size2.invoke(result3, new Object[0])).intValue();
173  5 assertEquals(number1 + 1, number2);
174  5 addChecked(adder);
175  5 removeMethodToCheck(adder.getName());
176    }
177  67 setter.invoke(vo, new Object[] {null});
178  67 final Object result4 = getter.invoke(vo, new Object[0]);
179  67 assertNull(result4);
180  67 addChecked(setter);
181  67 removeMethodToCheck(setter.getName());
182  67 addChecked(getter);
183  67 removeMethodToCheck(getter.getName());
184  67 return true;
185    }
186   
 
187  175 toggle protected void addChecked(Method adder) {
188  175 checkedMethods.add(adder.getName());
189    }
190   
191    /**
192    * Tests <code>add</code>, <code>get</code> and <code>size</code> methods for an attribute of a
193    * class.
194    *
195    * @param clazz Attribute is in this class.
196    * @param attr Test methods for this attribute.
197    * @return Did this test match? If <code>true</code> all those methods were tested.
198    * @throws Exception Test failure.
199    */
 
200  12 toggle protected boolean testAddSizeGet(final Class clazz, final Field attr) throws Exception {
201  12 final Method[] methods = clazz.getDeclaredMethods();
202  12 final String attrName = attr.getName();
203  12 Method getter = null;
204  12 Method setter = null;
205    // check if attribute could be set by "add"
206  12 Method size = null;
207  84 for (int j = 0; j < methods.length; j++) {
208  72 if (methods[j].getName().equals("add")) {
209  12 setter = methods[j];
210    }
211  72 if (methods[j].getName().equals("get")) {
212  12 getter = methods[j];
213    }
214  72 if (methods[j].getName().equals("size")) {
215  12 size = methods[j];
216    }
217    }
218  12 if (getter == null || setter == null || size == null) { // testable?
219  0 return false;
220    }
221  12 final Object vo = getObject(clazz);
222  12 try {
223  12 getter.invoke(vo, new Object[] {new Integer(0)});
224  0 fail("IndexOutOfBoundsException expected");
225    } catch (InvocationTargetException e) {
226  12 if (!(e.getCause() instanceof IndexOutOfBoundsException)) {
227  0 fail("IndexOutOfBoundsException expected");
228    }
229    }
230  12 final Object zero = size.invoke(vo, new Object[0]);
231  12 assertEquals(new Integer(0), zero);
232  12 final Object value = getFilledObject(getter.getReturnType(), clazz, attrName);
233  12 setter.invoke(vo, new Object[] {value});
234  12 final Object result2 = getter.invoke(vo, new Object[] {new Integer(0)});
235  12 assertEquals(value, result2);
236  12 final Object one = size.invoke(vo, new Object[0]);
237  12 assertEquals(new Integer(1), one);
238  12 assertFalse(vo.equals(getFilledObject(getter.getReturnType(), clazz, attrName)));
239  12 addChecked(setter);
240  12 removeMethodToCheck(setter.getName());
241  12 addChecked(getter);
242  12 removeMethodToCheck(getter.getName());
243  12 addChecked(size);
244  12 removeMethodToCheck(size.getName());
245  12 return true;
246    }
247   
248    /**
249    * Test the <code>toString</code> method. This method is also tested with other check methods.
250    *
251    * @throws Exception Something went wrong. Perhaps the preconditions in {@link #testAll()}
252    * were violated.
253    */
 
254  32 toggle protected void checkToString() throws Exception {
255    {
256  32 final Object vo1 = getObject(getTestedClass());
257  32 assertNotNull(vo1.toString());
258  32 final Object vo2 = getObject(getTestedClass());
259  32 assertEquals(vo1.toString(), vo2.toString());
260    }
261    {
262  32 final Object vo1 = getFilledObject(getTestedClass());
263  32 assertNotNull(vo1.toString());
264  32 final Object vo2 = getFilledObject(getTestedClass());
265  32 assertEquals(vo1.toString(), vo2.toString());
266    }
267  32 removeMethodToCheck("toString");
268    }
269   
270    /**
271    * Remove method from list of methods to test. Be careful: overloaded
272    * methods must be tested within one method!
273    *
274    * @param name Remove this method name.
275    */
 
276  296 toggle protected final void removeMethodToCheck(final String name) {
277  296 getMethodsToCheck().remove(name);
278    }
279   
280    /**
281    * Test the <code>hashCode</code> method. This method is also tested with other check methods.
282    *
283    * @throws Exception Something went wrong. Perhaps the preconditions in {@link #testAll()}
284    * were violated.
285    */
 
286  32 toggle protected void checkHashCode() throws Exception {
287    {
288  32 final Object vo1 = getObject(getTestedClass());
289  32 final Object vo2 = getObject(getTestedClass());
290  32 assertTrue(vo1.hashCode() == vo2.hashCode());
291  32 final Method[] methods = getTestedClass().getDeclaredMethods();
292  328 for (int i = 0; i < methods.length; i++) {
293  296 if (methods[i].getName().startsWith("set")) {
294  67 final Method setter = methods[i];
295  67 if (setter.getParameterTypes().length > 1) {
296  0 continue;
297    }
298  67 final Class setClazz = setter.getParameterTypes()[0];
299  67 final Object value1 = getFilledObject(setClazz, getTestedClass(),
300    setter.getName());
301  67 setter.invoke(vo1, new Object[] {value1});
302  67 assertTrue(vo1.hashCode() != vo2.hashCode());
303  67 setter.invoke(vo2, new Object[] {value1});
304  67 assertTrue(vo1.hashCode() == vo2.hashCode());
305  67 final Object value2 = getFilledObject(setClazz, getTestedClass(),
306    setter.getName());
307  67 setter.invoke(vo2, new Object[] {value2});
308  67 assertTrue(vo1.hashCode() == vo2.hashCode());
309    }
310    }
311    }
312    {
313  32 final Object vo1 = getFilledObject(getTestedClass());
314  32 final Object vo2 = getFilledObject(getTestedClass());
315  32 assertEquals(vo1.hashCode(), vo2.hashCode());
316    }
317  32 removeMethodToCheck("hashCode");
318    }
319   
320    /**
321    * Test the <code>equals</code> method. This method is also tested with other check methods.
322    *
323    * @throws Exception Something went wrong. Perhaps the preconditions in {@link #testAll()}
324    * were violated.
325    */
 
326  32 toggle protected void checkEquals() throws Exception {
327  32 checkEqualsFillUp();
328  32 checkEqualsForEachSetter();
329    {
330  32 final Object vo1 = getFilledObject(getTestedClass());
331  32 final Object vo2 = getFilledObject(getTestedClass());
332  32 final Object vo3 = getEmptyObject(getTestedClass(), null, null);
333  32 assertTrue(vo1.equals(vo1));
334  32 assertTrue(vo1.equals(vo2));
335  32 assertTrue(vo2.equals(vo1));
336  32 assertFalse(vo1.equals(null));
337  32 assertFalse(vo1.equals(vo3));
338    }
339    {
340  32 Field[] attrs = getTestedClass().getDeclaredFields();
341  111 for (int i = 0; i < attrs.length; i++) {
342  79 if (attrs[i].getName().startsWith("__")) { // because of clover
343  0 continue;
344    }
345  79 final Object vo1 = getFilledObject(attrs[i].getType(), getTestedClass(), "",
346    attrs[i].getName());
347  79 final Object vo2 = getFilledObject(attrs[i].getType(), getTestedClass(), "",
348    attrs[i].getName());
349  79 assertTrue(vo1.equals(vo1));
350  79 assertTrue(vo1.equals(vo2));
351  79 assertTrue(vo2.equals(vo1));
352    }
353    }
354  32 removeMethodToCheck("equals");
355    }
356   
357    /**
358    * Check equals after calling setter on empty object.
359    *
360    * @throws Exception
361    */
 
362  32 toggle protected void checkEqualsForEachSetter() throws Exception {
363    {
364  32 final Method[] methods = getTestedClass().getDeclaredMethods();
365  328 for (int i = 0; i < methods.length; i++) {
366  296 final Object vo1 = getObject(getTestedClass());
367  296 final Object vo2 = getObject(getTestedClass());
368  296 if (methods[i].getName().startsWith("set")
369    || methods[i].getName().startsWith("add")) {
370  84 final Method setter = methods[i];
371  84 if (setter.getParameterTypes().length > 1) {
372  0 continue;
373    }
374  84 final Class setClazz = setter.getParameterTypes()[0];
375  84 setter.invoke(vo1, new Object[] {null});
376  84 if (methods[i].getName().startsWith("set")) {
377  67 assertTrue(vo1.equals(vo2));
378  67 assertTrue(vo2.equals(vo1));
379    } else {
380  17 assertFalse(vo1.equals(vo2));
381  17 assertFalse(vo2.equals(vo1));
382    }
383  84 final Object value1 = getFilledObject(setClazz, getTestedClass(), setter.getName());
384  84 setter.invoke(vo2, new Object[] {value1});
385  84 assertFalse(vo1.equals(vo2));
386  84 assertFalse(vo2.equals(vo1));
387  84 assertTrue(vo1.hashCode() != vo2.hashCode());
388  84 assertFalse(vo1.toString().equals(vo2.toString()));
389    }
390    }
391    }
392    }
393   
394    /**
395    * Check equals during successive fill up by calling setters.
396    *
397    * @throws Exception
398    */
 
399  32 toggle protected void checkEqualsFillUp() throws Exception {
400    {
401  32 final Object vo1 = getObject(getTestedClass());
402  32 final Object vo2 = getObject(getTestedClass());
403  32 assertTrue(vo1.equals(vo1));
404  32 assertTrue(vo1.equals(vo2));
405  32 assertTrue(vo2.equals(vo1));
406  32 assertFalse(vo1.equals(null));
407   
408  32 final Method[] methods = getTestedClass().getDeclaredMethods();
409  328 for (int i = 0; i < methods.length; i++) {
410  296 if (methods[i].getName().startsWith("set")
411    || methods[i].getName().startsWith("add")) {
412  84 final Method setter = methods[i];
413  84 if (setter.getParameterTypes().length > 1) {
414  0 continue;
415    }
416  84 final Class setClazz = setter.getParameterTypes()[0];
417  84 final Object value1 = getFilledObject(setClazz, getTestedClass(),
418    setter.getName());
419  84 setter.invoke(vo1, new Object[] {value1});
420  84 assertFalse(vo1.equals(vo2));
421  84 assertFalse(vo2.equals(vo1));
422  84 assertFalse(vo1.equals(null));
423  84 setter.invoke(vo2, new Object[] {value1});
424  84 assertTrue(vo1.equals(vo2));
425  84 assertTrue(vo2.equals(vo1));
426  84 assertTrue(vo2.equals(vo1));
427  84 final Object value2 = getFilledObject(setClazz, getTestedClass(),
428    setter.getName());
429  84 setter.invoke(vo2, new Object[] {value2});
430  84 if (methods[i].getName().startsWith("set")) {
431  67 assertTrue(vo1.equals(vo2));
432  67 assertTrue(vo2.equals(vo1));
433    } else {
434  17 assertFalse(vo1.equals(vo2));
435  17 assertFalse(vo2.equals(vo1));
436  17 setter.invoke(vo1, new Object[] {value2});
437  17 assertTrue(vo1.equals(vo2));
438  17 assertTrue(vo2.equals(vo1));
439    }
440    }
441  296 assertTrue(vo1.hashCode() == vo2.hashCode());
442  296 assertTrue(vo1.toString().equals(vo2.toString()));
443    }
444    }
445    }
446   
447    /**
448    * Test if all methods of the value object were tested..
449    */
 
450  32 toggle protected void checkAllChecked() {
451  32 if (!getMethodsToCheck().isEmpty()) {
452  0 final String[] missing = (String[]) getMethodsToCheck().toArray(new String[0]);
453  0 final StringBuffer buffer
454    = new StringBuffer("tests for following methods are missing: ");
455  0 for (int i = 0; i < missing.length; i++) {
456  0 if (i > 0) {
457  0 buffer.append(", ");
458    }
459  0 buffer.append("\"" + missing[i] + "\"");
460    }
461  0 fail(buffer.toString());
462    }
463    }
464   
 
465  760 toggle protected Set getMethodsToCheck() {
466  760 return methodsToCheck;
467    }
468   
469    /**
470    * Creates an data filled instance of a class.
471    *
472    * @param clazz Create instance of this class.
473    * @return Object filled by its setters.
474    * @throws Exception Something went wrong. Perhaps the preconditions in {@link #testAll()} were
475    * violated.
476    */
 
477  192 toggle protected final Object getFilledObject(final Class clazz) throws Exception {
478  192 return getFilledObject(clazz, null, "", "");
479    }
480   
481    /**
482    * Creates an data filled instance of a class.
483    *
484    * @param clazz Create instance of this class.
485    * @param parent This is the class that contains an element of <code>clazz</code>.
486    * Maybe <code>null</code>.
487    * @param attribute Attribute name of parent that shall be filled.
488    * @return Object filled by its setters.
489    * @throws Exception Something went wrong. Perhaps the preconditions in {@link #testAll()}
490    * were violated.
491    */
 
492  7133 toggle protected final Object getFilledObject(final Class clazz, final Class parent,
493    final String attribute) throws Exception {
494  7133 return getFilledObject(clazz, parent, attribute, "");
495    }
496   
497    /**
498    * Creates an data filled instance of a class.
499    *
500    * @param clazz Create instance of this class.
501    * @param parent This is the class that contains an element of <code>clazz</code>.
502    * Maybe <code>null</code>.
503    * @param attribute Attribute name of parent that shall be filled.
504    * @param ignore Fill every attribute but not this one. Could be empty, but shouldn't be
505    * <code>null</code>.
506    * @return Object filled by its setters.
507    * @throws Exception Something went wrong. Perhaps the preconditions in {@link #testAll()}
508    * were violated.
509    */
 
510  7483 toggle protected final Object getFilledObject(final Class clazz, final Class parent,
511    final String attribute, final String ignore) throws Exception {
512   
513  7483 final Object vo = getObject(clazz, parent, attribute);
514  7483 final Class voClazz = vo.getClass();
515   
516  7483 if (clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Boolean.class)
517    || clazz.equals(List.class)) {
518  3595 return vo;
519    }
520   
521  3888 Method[] methods = voClazz.getDeclaredMethods();
522    // boolean found = false;
523  33653 for (int i = 0; i < methods.length; i++) {
524    // System.out.println("\t" + methods[i].getName());
525  29765 if (methods[i].getName().startsWith("set") && !methods[i].equals("set"
526    + getUName(ignore))) {
527  5082 final Method setter = methods[i];
528  5082 if (setter.getParameterTypes().length > 1) {
529  0 fail("setter with more than one parameter found: " + setter.getName());
530    }
531  5082 final Class setClazz = setter.getParameterTypes()[0];
532  5082 final Object value = getFilledObject(setClazz, clazz, setter.getName());
533    // System.out.println(clazz.getName() + "." + setter.getName());
534    // System.out.println(value.getClass()+ ":" + value);
535  5082 setter.invoke(vo, new Object[] {value});
536    // found = true;
537  24683 } else if (methods[i].getName().equals("add")) {
538  1569 final Method adder = methods[i];
539  1569 if (adder.getParameterTypes().length > 1) {
540  0 final StringBuffer buffer = new StringBuffer("in class \"" + clazz
541    + "\" method \"add\" with more than one parameter found: "
542    + adder.getName());
543  0 for (int j = 0; j < adder.getParameterTypes().length; j++) {
544  0 buffer.append(" " + adder.getParameterTypes()[j]);
545    }
546  0 fail(buffer.toString());
547    }
548  1569 final Class setClazz = adder.getParameterTypes()[0];
549  1569 if (setClazz != clazz) {
550  1569 final Object value = getFilledObject(setClazz, clazz, adder.getName());
551  1569 adder.invoke(vo, new Object[] {value});
552    // found = true;
553    }
554    }
555    }
556    /*
557    if (!found) {
558    fail("nothing to set in object of class " + clazz.getName());
559    }
560    */
561  3888 return vo;
562    }
563   
564    /**
565    * Get (if possible) empty instance of an class.
566    *
567    * @param clazz For this class an instance is wanted.
568    * @return Just the result of the default constructor (if existing).
569    * @throws Exception Something went wrong. Perhaps the preconditions in {@link #testAll()}
570    * were violated.
571    */
 
572  863 toggle protected Object getObject(final Class clazz) throws Exception {
573  863 return getObject(clazz, null, "");
574    }
575   
576    /**
577    * Get (if possible) empty instance of an class.
578    *
579    * @param clazz For this class an instance is wanted.
580    * @param parent This class has <code>clazz</code> as an attribute. Maybe <code>null</code>.
581    * @param attribute Attribute name of parent that shall be filled.
582    * @return Just the result of the default constructor (if existing).
583    * @throws Exception Something went wrong. Perhaps the preconditions in {@link #testAll()}
584    * were violated.
585    */
 
586  8346 toggle protected Object getObject(final Class clazz, final Class parent, final String attribute)
587    throws Exception {
588  8346 final Object vo = getEmptyObject(clazz, parent, attribute);
589  8346 if (vo == null) {
590  0 fail("no default constructor for " + clazz.getName() + " found");
591    }
592  8346 return vo;
593    }
594   
595    /**
596    * Gets an implementation for an abstract class.
597    *
598    * @param clazz Get implementation for this class.
599    * @return Concrete class, if any.
600    */
601    protected abstract Class abstractToConcreteClass(Class clazz);
602   
603    /**
604    * Get (if possible) empty instance of an class. This method could be overwritten to get more
605    * objects.
606    *
607    * @param clazz For this class an instance is wanted.
608    * @param parent This class has <code>clazz</code> as an attribute. Maybe <code>null</code>.
609    * @param attribute Attribute name of parent that shall be filled.
610    * @return Just the result of the default constructor (if existing). Might be
611    * <code>null</code>.
612    * @throws Exception Something went wrong. Perhaps the preconditions in {@link #testAll()}
613    * were violated.
614    */
 
615  8378 toggle protected Object getEmptyObject(Class clazz, final Class parent, final String attribute)
616    throws Exception {
617   
618  8378 if (abstractToConcreteClass(clazz) != null) {
619  366 clazz = abstractToConcreteClass(clazz);
620    }
621  8378 if (clazz.equals(Element.class)) { // application specific
622  317 return new DefaultAtom((parent != null ? parent.getName() + ":" : "") + attribute);
623  8061 } else if (clazz.equals(String.class)) {
624  3456 return (parent != null ? parent.getName() + ":" : "") + new String("StringAtom:"
625    + attribute);
626  4605 } else if (clazz.equals(Integer.class)) {
627  0 return new Integer(10);
628  4605 } else if (clazz.equals(Boolean.class)) {
629  115 return new Boolean("true");
630  4490 } else if (clazz.equals(List.class)) {
631  24 return new ArrayList();
632    }
633  4466 Constructor[] constructors = clazz.getConstructors();
634  4466 Constructor constructor = null;
635  10654 for (int j = 0; j < constructors.length; j++) {
636  6188 if (constructors[j].getParameterTypes().length == 0) {
637  4466 constructor = constructors[j];
638    }
639    }
640  4466 if (constructor == null) {
641  0 return null;
642    }
643  4466 return constructor.newInstance(new Object[0]);
644    }
645   
646    /**
647    * Get name with first letter upper case.
648    *
649    * @param name
650    * @return Name with first letter upper case.
651    */
 
652  8028 toggle public static final String getUName(final String name) {
653  8028 if (name.length() > 0) {
654  2996 return name.substring(0, 1).toUpperCase() + name.substring(1);
655    }
656  5032 return "";
657    }
658   
659    }