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