KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > builder > ToStringStyle


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.lang.builder;
17
18 import java.io.Serializable JavaDoc;
19 import java.lang.reflect.Array JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.commons.lang.ClassUtils;
24 import org.apache.commons.lang.ObjectUtils;
25 import org.apache.commons.lang.SystemUtils;
26
27 /**
28  * <p>Controls <code>String</code> formatting for {@link ToStringBuilder}.
29  * The main public interface is always via <code>ToStringBuilder</code>.</p>
30  *
31  * <p>These classes are intended to be used as <code>Singletons</code>.
32  * There is no need to instantiate a new style each time. A program
33  * will generally use one of the predefined constants on this class.
34  * Alternatively, the {@link StandardToStringStyle} class can be used
35  * to set the individual settings. Thus most styles can be achieved
36  * without subclassing.</p>
37  *
38  * <p>If required, a subclass can override as many or as few of the
39  * methods as it requires. Each object type (from <code>boolean</code>
40  * to <code>long</code> to <code>Object</code> to <code>int[]</code>) has
41  * its own methods to output it. Most have two versions, detail and summary.
42  *
43  * <p>For example, the detail version of the array based methods will
44  * output the whole array, whereas the summary method will just output
45  * the array length.</p>
46  *
47  * <p>If you want to format the output of certain objects, such as dates, you
48  * must create a subclass and override a method.
49  * <pre>
50  * public class MyStyle extends ToStringStyle {
51  * protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
52  * if (value instanceof Date) {
53  * value = new SimpleDateFormat("yyyy-MM-dd").format(value);
54  * }
55  * buffer.append(value);
56  * }
57  * }
58  * </pre>
59  * </p>
60  *
61  * @author Stephen Colebourne
62  * @author Gary Gregory
63  * @author Pete Gieser
64  * @author Masato Tezuka
65  * @since 1.0
66  * @version $Id: ToStringStyle.java 161243 2005-04-14 04:30:28Z ggregory $
67  */

68 public abstract class ToStringStyle implements Serializable JavaDoc {
69
70     /**
71      * The default toString style.
72      */

73     public static final ToStringStyle DEFAULT_STYLE = new DefaultToStringStyle();
74     
75     /**
76      * The multi line toString style.
77      */

78     public static final ToStringStyle MULTI_LINE_STYLE = new MultiLineToStringStyle();
79     
80     /**
81      * The no field names toString style.
82      */

83     public static final ToStringStyle NO_FIELD_NAMES_STYLE = new NoFieldNameToStringStyle();
84     
85     /**
86      * The short prefix toString style.
87      * @since 2.1
88      */

89     public static final ToStringStyle SHORT_PREFIX_STYLE = new ShortPrefixToStringStyle();
90
91     /**
92      * The simple toString style.
93      */

94     public static final ToStringStyle SIMPLE_STYLE = new SimpleToStringStyle();
95     
96     /**
97      * Whether to use the field names, the default is <code>true</code>.
98      */

99     private boolean useFieldNames = true;
100     
101     /**
102      * Whether to use the class name, the default is <code>true</code>.
103      */

104     private boolean useClassName = true;
105     
106     /**
107      * Whether to use short class names, the default is <code>false</code>.
108      */

109     private boolean useShortClassName = false;
110     
111     /**
112      * Whether to use the identity hash code, the default is <code>true</code>.
113      */

114     private boolean useIdentityHashCode = true;
115
116     /**
117      * The content start <code>'['</code>.
118      */

119     private String JavaDoc contentStart = "[";
120     
121     /**
122      * The content end <code>']'</code>.
123      */

124     private String JavaDoc contentEnd = "]";
125     
126     /**
127      * The field name value separator <code>'='</code>.
128      */

129     private String JavaDoc fieldNameValueSeparator = "=";
130     
131     /**
132      * Whether the field separator should be added before any other fields.
133      */

134     private boolean fieldSeparatorAtStart = false;
135     
136     /**
137      * Whether the field separator should be added after any other fields.
138      */

139     private boolean fieldSeparatorAtEnd = false;
140     
141     /**
142      * The field separator <code>','</code>.
143      */

144     private String JavaDoc fieldSeparator = ",";
145     
146     /**
147      * The array start <code>'{'</code>.
148      */

149     private String JavaDoc arrayStart = "{";
150     
151     /**
152      * The array separator <code>','</code>.
153      */

154     private String JavaDoc arraySeparator = ",";
155     
156     /**
157      * The detail for array content.
158      */

159     private boolean arrayContentDetail = true;
160     
161     /**
162      * The array end <code>'}'</code>.
163      */

164     private String JavaDoc arrayEnd = "}";
165     
166     /**
167      * The value to use when fullDetail is <code>null</code>,
168      * the default value is <code>true</code>.
169      */

170     private boolean defaultFullDetail = true;
171     
172     /**
173      * The <code>null</code> text <code>'&lt;null&gt;'</code>.
174      */

175     private String JavaDoc nullText = "<null>";
176     
177     /**
178      * The summary size text start <code>'<size'</code>.
179      */

180     private String JavaDoc sizeStartText = "<size=";
181     
182     /**
183      * The summary size text start <code>'&gt;'</code>.
184      */

185     private String JavaDoc sizeEndText = ">";
186     
187     /**
188      * The summary object text start <code>'&lt;'</code>.
189      */

190     private String JavaDoc summaryObjectStartText = "<";
191     
192     /**
193      * The summary object text start <code>'&gt;'</code>.
194      */

195     private String JavaDoc summaryObjectEndText = ">";
196
197     //----------------------------------------------------------------------------
198

199     /**
200      * <p>Constructor.</p>
201      */

202     protected ToStringStyle() {
203         super();
204     }
205
206     //----------------------------------------------------------------------------
207

208     /**
209      * <p>Append to the <code>toString</code> the superclass toString.</p>
210      *
211      * <p>A <code>null</code> <code>superToString</code> is ignored.</p>
212      *
213      * @param buffer the <code>StringBuffer</code> to populate
214      * @param superToString the <code>super.toString()</code>
215      * @since 2.0
216      */

217     public void appendSuper(StringBuffer JavaDoc buffer, String JavaDoc superToString) {
218         appendToString(buffer, superToString);
219     }
220
221     /**
222      * <p>Append to the <code>toString</code> another toString.</p>
223      *
224      * <p>A <code>null</code> <code>toString</code> is ignored.</p>
225      *
226      * @param buffer the <code>StringBuffer</code> to populate
227      * @param toString the additional <code>toString</code>
228      * @since 2.0
229      */

230     public void appendToString(StringBuffer JavaDoc buffer, String JavaDoc toString) {
231         if (toString != null) {
232             int pos1 = toString.indexOf(contentStart) + contentStart.length();
233             int pos2 = toString.lastIndexOf(contentEnd);
234             if (pos1 != pos2 && pos1 >= 0 && pos2 >= 0) {
235                 String JavaDoc data = toString.substring(pos1, pos2);
236                 if (fieldSeparatorAtStart) {
237                     removeLastFieldSeparator(buffer);
238                 }
239                 buffer.append(data);
240                 appendFieldSeparator(buffer);
241             }
242         }
243     }
244
245     /**
246      * <p>Append to the <code>toString</code> the start of data indicator.</p>
247      *
248      * @param buffer the <code>StringBuffer</code> to populate
249      * @param object the <code>Object</code> to build a <code>toString</code> for
250      */

251     public void appendStart(StringBuffer JavaDoc buffer, Object JavaDoc object) {
252         if (object != null) {
253             appendClassName(buffer, object);
254             appendIdentityHashCode(buffer, object);
255             appendContentStart(buffer);
256             if (fieldSeparatorAtStart) {
257                 appendFieldSeparator(buffer);
258             }
259         }
260     }
261
262     /**
263      * <p>Append to the <code>toString</code> the end of data indicator.</p>
264      *
265      * @param buffer the <code>StringBuffer</code> to populate
266      * @param object the <code>Object</code> to build a
267      * <code>toString</code> for.
268      */

269     public void appendEnd(StringBuffer JavaDoc buffer, Object JavaDoc object) {
270         if (this.fieldSeparatorAtEnd == false) {
271             removeLastFieldSeparator(buffer);
272         }
273         appendContentEnd(buffer);
274     }
275
276     /**
277      * <p>Remove the last field separator from the buffer.</p>
278      *
279      * @param buffer the <code>StringBuffer</code> to populate
280      * @since 2.0
281      */

282     protected void removeLastFieldSeparator(StringBuffer JavaDoc buffer) {
283         int len = buffer.length();
284         int sepLen = fieldSeparator.length();
285         if (len > 0 && sepLen > 0 && len >= sepLen) {
286             boolean match = true;
287             for (int i = 0; i < sepLen; i++) {
288                 if (buffer.charAt(len - 1 - i) != fieldSeparator.charAt(sepLen - 1 - i)) {
289                     match = false;
290                     break;
291                 }
292             }
293             if (match) {
294                 buffer.setLength(len - sepLen);
295             }
296         }
297     }
298
299     //----------------------------------------------------------------------------
300

301     /**
302      * <p>Append to the <code>toString</code> an <code>Object</code>
303      * value, printing the full <code>toString</code> of the
304      * <code>Object</code> passed in.</p>
305      *
306      * @param buffer the <code>StringBuffer</code> to populate
307      * @param fieldName the field name
308      * @param value the value to add to the <code>toString</code>
309      * @param fullDetail <code>true</code> for detail, <code>false</code>
310      * for summary info, <code>null</code> for style decides
311      */

312     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, Object JavaDoc value, Boolean JavaDoc fullDetail) {
313         appendFieldStart(buffer, fieldName);
314
315         if (value == null) {
316             appendNullText(buffer, fieldName);
317
318         } else {
319             appendInternal(buffer, fieldName, value, isFullDetail(fullDetail));
320         }
321
322         appendFieldEnd(buffer, fieldName);
323     }
324
325     /**
326      * <p>Append to the <code>toString</code> an <code>Object</code>,
327      * correctly interpreting its type.</p>
328      *
329      * <p>This method performs the main lookup by Class type to correctly
330      * route arrays, <code>Collections</code>, <code>Maps</code> and
331      * <code>Objects</code> to the appropriate method.</p>
332      *
333      * <p>Either detail or summary views can be specified.</p>
334      *
335      * <p>If a cycle is detected, an object will be appended with the
336      * <code>Object.toString()</code> format.</p>
337      *
338      * @param buffer the <code>StringBuffer</code> to populate
339      * @param fieldName the field name, typically not used as already appended
340      * @param value the value to add to the <code>toString</code>,
341      * not <code>null</code>
342      * @param detail output detail or not
343      */

344     protected void appendInternal(StringBuffer JavaDoc buffer, String JavaDoc fieldName, Object JavaDoc value, boolean detail) {
345         if (ReflectionToStringBuilder.isRegistered(value)
346             && !(value instanceof Number JavaDoc || value instanceof Boolean JavaDoc || value instanceof Character JavaDoc)) {
347             ObjectUtils.appendIdentityToString(buffer, value);
348
349         } else if (value instanceof Collection JavaDoc) {
350             if (detail) {
351                 appendDetail(buffer, fieldName, (Collection JavaDoc) value);
352             } else {
353                 appendSummarySize(buffer, fieldName, ((Collection JavaDoc) value).size());
354             }
355
356         } else if (value instanceof Map JavaDoc) {
357             if (detail) {
358                 appendDetail(buffer, fieldName, (Map JavaDoc) value);
359             } else {
360                 appendSummarySize(buffer, fieldName, ((Map JavaDoc) value).size());
361             }
362
363         } else if (value instanceof long[]) {
364             if (detail) {
365                 appendDetail(buffer, fieldName, (long[]) value);
366             } else {
367                 appendSummary(buffer, fieldName, (long[]) value);
368             }
369
370         } else if (value instanceof int[]) {
371             if (detail) {
372                 appendDetail(buffer, fieldName, (int[]) value);
373             } else {
374                 appendSummary(buffer, fieldName, (int[]) value);
375             }
376
377         } else if (value instanceof short[]) {
378             if (detail) {
379                 appendDetail(buffer, fieldName, (short[]) value);
380             } else {
381                 appendSummary(buffer, fieldName, (short[]) value);
382             }
383
384         } else if (value instanceof byte[]) {
385             if (detail) {
386                 appendDetail(buffer, fieldName, (byte[]) value);
387             } else {
388                 appendSummary(buffer, fieldName, (byte[]) value);
389             }
390
391         } else if (value instanceof char[]) {
392             if (detail) {
393                 appendDetail(buffer, fieldName, (char[]) value);
394             } else {
395                 appendSummary(buffer, fieldName, (char[]) value);
396             }
397
398         } else if (value instanceof double[]) {
399             if (detail) {
400                 appendDetail(buffer, fieldName, (double[]) value);
401             } else {
402                 appendSummary(buffer, fieldName, (double[]) value);
403             }
404
405         } else if (value instanceof float[]) {
406             if (detail) {
407                 appendDetail(buffer, fieldName, (float[]) value);
408             } else {
409                 appendSummary(buffer, fieldName, (float[]) value);
410             }
411
412         } else if (value instanceof boolean[]) {
413             if (detail) {
414                 appendDetail(buffer, fieldName, (boolean[]) value);
415             } else {
416                 appendSummary(buffer, fieldName, (boolean[]) value);
417             }
418
419         } else if (value.getClass().isArray()) {
420             if (detail) {
421                 appendDetail(buffer, fieldName, (Object JavaDoc[]) value);
422             } else {
423                 appendSummary(buffer, fieldName, (Object JavaDoc[]) value);
424             }
425
426         } else {
427             if (detail) {
428                 appendDetail(buffer, fieldName, value);
429             } else {
430                 appendSummary(buffer, fieldName, value);
431             }
432         }
433     }
434
435     /**
436      * <p>Append to the <code>toString</code> an <code>Object</code>
437      * value, printing the full detail of the <code>Object</code>.</p>
438      *
439      * @param buffer the <code>StringBuffer</code> to populate
440      * @param fieldName the field name, typically not used as already appended
441      * @param value the value to add to the <code>toString</code>,
442      * not <code>null</code>
443      */

444     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, Object JavaDoc value) {
445         buffer.append(value);
446     }
447
448     /**
449      * <p>Append to the <code>toString</code> a <code>Collection</code>.</p>
450      *
451      * @param buffer the <code>StringBuffer</code> to populate
452      * @param fieldName the field name, typically not used as already appended
453      * @param coll the <code>Collection</code> to add to the
454      * <code>toString</code>, not <code>null</code>
455      */

456     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, Collection JavaDoc coll) {
457         buffer.append(coll);
458     }
459
460     /**
461      * <p>Append to the <code>toString</code> a <code>Map<code>.</p>
462      *
463      * @param buffer the <code>StringBuffer</code> to populate
464      * @param fieldName the field name, typically not used as already appended
465      * @param map the <code>Map</code> to add to the <code>toString</code>,
466      * not <code>null</code>
467      */

468     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, Map JavaDoc map) {
469         buffer.append(map);
470     }
471
472     /**
473      * <p>Append to the <code>toString</code> an <code>Object</code>
474      * value, printing a summary of the <code>Object</code>.</P>
475      *
476      * @param buffer the <code>StringBuffer</code> to populate
477      * @param fieldName the field name, typically not used as already appended
478      * @param value the value to add to the <code>toString</code>,
479      * not <code>null</code>
480      */

481     protected void appendSummary(StringBuffer JavaDoc buffer, String JavaDoc fieldName, Object JavaDoc value) {
482         buffer.append(summaryObjectStartText);
483         buffer.append(getShortClassName(value.getClass()));
484         buffer.append(summaryObjectEndText);
485     }
486
487     //----------------------------------------------------------------------------
488

489     /**
490      * <p>Append to the <code>toString</code> a <code>long</code>
491      * value.</p>
492      *
493      * @param buffer the <code>StringBuffer</code> to populate
494      * @param fieldName the field name
495      * @param value the value to add to the <code>toString</code>
496      */

497     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, long value) {
498         appendFieldStart(buffer, fieldName);
499         appendDetail(buffer, fieldName, value);
500         appendFieldEnd(buffer, fieldName);
501     }
502
503     /**
504      * <p>Append to the <code>toString</code> a <code>long</code>
505      * value.</p>
506      *
507      * @param buffer the <code>StringBuffer</code> to populate
508      * @param fieldName the field name, typically not used as already appended
509      * @param value the value to add to the <code>toString</code>
510      */

511     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, long value) {
512         buffer.append(value);
513     }
514
515     //----------------------------------------------------------------------------
516

517     /**
518      * <p>Append to the <code>toString</code> an <code>int</code>
519      * value.</p>
520      *
521      * @param buffer the <code>StringBuffer</code> to populate
522      * @param fieldName the field name
523      * @param value the value to add to the <code>toString</code>
524      */

525     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, int value) {
526         appendFieldStart(buffer, fieldName);
527         appendDetail(buffer, fieldName, value);
528         appendFieldEnd(buffer, fieldName);
529     }
530
531     /**
532      * <p>Append to the <code>toString</code> an <code>int</code>
533      * value.</p>
534      *
535      * @param buffer the <code>StringBuffer</code> to populate
536      * @param fieldName the field name, typically not used as already appended
537      * @param value the value to add to the <code>toString</code>
538      */

539     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, int value) {
540         buffer.append(value);
541     }
542
543     //----------------------------------------------------------------------------
544

545     /**
546      * <p>Append to the <code>toString</code> a <code>short</code>
547      * value.</p>
548      *
549      * @param buffer the <code>StringBuffer</code> to populate
550      * @param fieldName the field name
551      * @param value the value to add to the <code>toString</code>
552      */

553     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, short value) {
554         appendFieldStart(buffer, fieldName);
555         appendDetail(buffer, fieldName, value);
556         appendFieldEnd(buffer, fieldName);
557     }
558
559     /**
560      * <p>Append to the <code>toString</code> a <code>short</code>
561      * value.</p>
562      *
563      * @param buffer the <code>StringBuffer</code> to populate
564      * @param fieldName the field name, typically not used as already appended
565      * @param value the value to add to the <code>toString</code>
566      */

567     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, short value) {
568         buffer.append(value);
569     }
570
571     //----------------------------------------------------------------------------
572

573     /**
574      * <p>Append to the <code>toString</code> a <code>byte</code>
575      * value.</p>
576      *
577      * @param buffer the <code>StringBuffer</code> to populate
578      * @param fieldName the field name
579      * @param value the value to add to the <code>toString</code>
580      */

581     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, byte value) {
582         appendFieldStart(buffer, fieldName);
583         appendDetail(buffer, fieldName, value);
584         appendFieldEnd(buffer, fieldName);
585     }
586
587     /**
588      * <p>Append to the <code>toString</code> a <code>byte</code>
589      * value.</p>
590      *
591      * @param buffer the <code>StringBuffer</code> to populate
592      * @param fieldName the field name, typically not used as already appended
593      * @param value the value to add to the <code>toString</code>
594      */

595     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, byte value) {
596         buffer.append(value);
597     }
598
599     //----------------------------------------------------------------------------
600

601     /**
602      * <p>Append to the <code>toString</code> a <code>char</code>
603      * value.</p>
604      *
605      * @param buffer the <code>StringBuffer</code> to populate
606      * @param fieldName the field name
607      * @param value the value to add to the <code>toString</code>
608      */

609     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, char value) {
610         appendFieldStart(buffer, fieldName);
611         appendDetail(buffer, fieldName, value);
612         appendFieldEnd(buffer, fieldName);
613     }
614
615     /**
616      * <p>Append to the <code>toString</code> a <code>char</code>
617      * value.</p>
618      *
619      * @param buffer the <code>StringBuffer</code> to populate
620      * @param fieldName the field name, typically not used as already appended
621      * @param value the value to add to the <code>toString</code>
622      */

623     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, char value) {
624         buffer.append(value);
625     }
626
627     //----------------------------------------------------------------------------
628

629     /**
630      * <p>Append to the <code>toString</code> a <code>double</code>
631      * value.</p>
632      *
633      * @param buffer the <code>StringBuffer</code> to populate
634      * @param fieldName the field name
635      * @param value the value to add to the <code>toString</code>
636      */

637     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, double value) {
638         appendFieldStart(buffer, fieldName);
639         appendDetail(buffer, fieldName, value);
640         appendFieldEnd(buffer, fieldName);
641     }
642
643     /**
644      * <p>Append to the <code>toString</code> a <code>double</code>
645      * value.</p>
646      *
647      * @param buffer the <code>StringBuffer</code> to populate
648      * @param fieldName the field name, typically not used as already appended
649      * @param value the value to add to the <code>toString</code>
650      */

651     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, double value) {
652         buffer.append(value);
653     }
654
655     //----------------------------------------------------------------------------
656

657     /**
658      * <p>Append to the <code>toString</code> a <code>float</code>
659      * value.</p>
660      *
661      * @param buffer the <code>StringBuffer</code> to populate
662      * @param fieldName the field name
663      * @param value the value to add to the <code>toString</code>
664      */

665     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, float value) {
666         appendFieldStart(buffer, fieldName);
667         appendDetail(buffer, fieldName, value);
668         appendFieldEnd(buffer, fieldName);
669     }
670
671     /**
672      * <p>Append to the <code>toString</code> a <code>float</code>
673      * value.</p>
674      *
675      * @param buffer the <code>StringBuffer</code> to populate
676      * @param fieldName the field name, typically not used as already appended
677      * @param value the value to add to the <code>toString</code>
678      */

679     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, float value) {
680         buffer.append(value);
681     }
682
683     //----------------------------------------------------------------------------
684

685     /**
686      * <p>Append to the <code>toString</code> a <code>boolean</code>
687      * value.</p>
688      *
689      * @param buffer the <code>StringBuffer</code> to populate
690      * @param fieldName the field name
691      * @param value the value to add to the <code>toString</code>
692      */

693     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, boolean value) {
694         appendFieldStart(buffer, fieldName);
695         appendDetail(buffer, fieldName, value);
696         appendFieldEnd(buffer, fieldName);
697     }
698
699     /**
700      * <p>Append to the <code>toString</code> a <code>boolean</code>
701      * value.</p>
702      *
703      * @param buffer the <code>StringBuffer</code> to populate
704      * @param fieldName the field name, typically not used as already appended
705      * @param value the value to add to the <code>toString</code>
706      */

707     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, boolean value) {
708         buffer.append(value);
709     }
710
711     /**
712      * <p>Append to the <code>toString</code> an <code>Object</code>
713      * array.</p>
714      *
715      * @param buffer the <code>StringBuffer</code> to populate
716      * @param fieldName the field name
717      * @param array the array to add to the toString
718      * @param fullDetail <code>true</code> for detail, <code>false</code>
719      * for summary info, <code>null</code> for style decides
720      */

721     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, Object JavaDoc[] array, Boolean JavaDoc fullDetail) {
722         appendFieldStart(buffer, fieldName);
723
724         if (array == null) {
725             appendNullText(buffer, fieldName);
726
727         } else if (isFullDetail(fullDetail)) {
728             appendDetail(buffer, fieldName, array);
729
730         } else {
731             appendSummary(buffer, fieldName, array);
732         }
733
734         appendFieldEnd(buffer, fieldName);
735     }
736
737     //----------------------------------------------------------------------------
738

739     /**
740      * <p>Append to the <code>toString</code> the detail of an
741      * <code>Object</code> array.</p>
742      *
743      * @param buffer the <code>StringBuffer</code> to populate
744      * @param fieldName the field name, typically not used as already appended
745      * @param array the array to add to the <code>toString</code>,
746      * not <code>null</code>
747      */

748     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, Object JavaDoc[] array) {
749         buffer.append(arrayStart);
750         for (int i = 0; i < array.length; i++) {
751             Object JavaDoc item = array[i];
752             if (i > 0) {
753                 buffer.append(arraySeparator);
754             }
755             if (item == null) {
756                 appendNullText(buffer, fieldName);
757
758             } else {
759                 appendInternal(buffer, fieldName, item, arrayContentDetail);
760             }
761         }
762         buffer.append(arrayEnd);
763     }
764
765     /**
766      * <p>Append to the <code>toString</code> the detail of an array type.</p>
767      *
768      * @param buffer the <code>StringBuffer</code> to populate
769      * @param fieldName the field name, typically not used as already appended
770      * @param array the array to add to the <code>toString</code>,
771      * not <code>null</code>
772      * @since 2.0
773      */

774     protected void reflectionAppendArrayDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, Object JavaDoc array) {
775         buffer.append(arrayStart);
776         int length = Array.getLength(array);
777         for (int i = 0; i < length; i++) {
778             Object JavaDoc item = Array.get(array, i);
779             if (i > 0) {
780                 buffer.append(arraySeparator);
781             }
782             if (item == null) {
783                 appendNullText(buffer, fieldName);
784
785             } else {
786                 appendInternal(buffer, fieldName, item, arrayContentDetail);
787             }
788         }
789         buffer.append(arrayEnd);
790     }
791
792     /**
793      * <p>Append to the <code>toString</code> a summary of an
794      * <code>Object</code> array.</p>
795      *
796      * @param buffer the <code>StringBuffer</code> to populate
797      * @param fieldName the field name, typically not used as already appended
798      * @param array the array to add to the <code>toString</code>,
799      * not <code>null</code>
800      */

801     protected void appendSummary(StringBuffer JavaDoc buffer, String JavaDoc fieldName, Object JavaDoc[] array) {
802         appendSummarySize(buffer, fieldName, array.length);
803     }
804
805     //----------------------------------------------------------------------------
806

807     /**
808      * <p>Append to the <code>toString</code> a <code>long</code>
809      * array.</p>
810      *
811      * @param buffer the <code>StringBuffer</code> to populate
812      * @param fieldName the field name
813      * @param array the array to add to the <code>toString</code>
814      * @param fullDetail <code>true</code> for detail, <code>false</code>
815      * for summary info, <code>null</code> for style decides
816      */

817     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, long[] array, Boolean JavaDoc fullDetail) {
818         appendFieldStart(buffer, fieldName);
819
820         if (array == null) {
821             appendNullText(buffer, fieldName);
822
823         } else if (isFullDetail(fullDetail)) {
824             appendDetail(buffer, fieldName, array);
825
826         } else {
827             appendSummary(buffer, fieldName, array);
828         }
829
830         appendFieldEnd(buffer, fieldName);
831     }
832
833     /**
834      * <p>Append to the <code>toString</code> the detail of a
835      * <code>long</code> array.</p>
836      *
837      * @param buffer the <code>StringBuffer</code> to populate
838      * @param fieldName the field name, typically not used as already appended
839      * @param array the array to add to the <code>toString</code>,
840      * not <code>null</code>
841      */

842     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, long[] array) {
843         buffer.append(arrayStart);
844         for (int i = 0; i < array.length; i++) {
845             if (i > 0) {
846                 buffer.append(arraySeparator);
847             }
848             appendDetail(buffer, fieldName, array[i]);
849         }
850         buffer.append(arrayEnd);
851     }
852
853     /**
854      * <p>Append to the <code>toString</code> a summary of a
855      * <code>long</code> array.</p>
856      *
857      * @param buffer the <code>StringBuffer</code> to populate
858      * @param fieldName the field name, typically not used as already appended
859      * @param array the array to add to the <code>toString</code>,
860      * not <code>null</code>
861      */

862     protected void appendSummary(StringBuffer JavaDoc buffer, String JavaDoc fieldName, long[] array) {
863         appendSummarySize(buffer, fieldName, array.length);
864     }
865
866     //----------------------------------------------------------------------------
867

868     /**
869      * <p>Append to the <code>toString</code> an <code>int</code>
870      * array.</p>
871      *
872      * @param buffer the <code>StringBuffer</code> to populate
873      * @param fieldName the field name
874      * @param array the array to add to the <code>toString</code>
875      * @param fullDetail <code>true</code> for detail, <code>false</code>
876      * for summary info, <code>null</code> for style decides
877      */

878     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, int[] array, Boolean JavaDoc fullDetail) {
879         appendFieldStart(buffer, fieldName);
880
881         if (array == null) {
882             appendNullText(buffer, fieldName);
883
884         } else if (isFullDetail(fullDetail)) {
885             appendDetail(buffer, fieldName, array);
886
887         } else {
888             appendSummary(buffer, fieldName, array);
889         }
890
891         appendFieldEnd(buffer, fieldName);
892     }
893
894     /**
895      * <p>Append to the <code>toString</code> the detail of an
896      * <code>int</code> array.</p>
897      *
898      * @param buffer the <code>StringBuffer</code> to populate
899      * @param fieldName the field name, typically not used as already appended
900      * @param array the array to add to the <code>toString</code>,
901      * not <code>null</code>
902      */

903     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, int[] array) {
904         buffer.append(arrayStart);
905         for (int i = 0; i < array.length; i++) {
906             if (i > 0) {
907                 buffer.append(arraySeparator);
908             }
909             appendDetail(buffer, fieldName, array[i]);
910         }
911         buffer.append(arrayEnd);
912     }
913
914     /**
915      * <p>Append to the <code>toString</code> a summary of an
916      * <code>int</code> array.</p>
917      *
918      * @param buffer the <code>StringBuffer</code> to populate
919      * @param fieldName the field name, typically not used as already appended
920      * @param array the array to add to the <code>toString</code>,
921      * not <code>null</code>
922      */

923     protected void appendSummary(StringBuffer JavaDoc buffer, String JavaDoc fieldName, int[] array) {
924         appendSummarySize(buffer, fieldName, array.length);
925     }
926
927     //----------------------------------------------------------------------------
928

929     /**
930      * <p>Append to the <code>toString</code> a <code>short</code>
931      * array.</p>
932      *
933      * @param buffer the <code>StringBuffer</code> to populate
934      * @param fieldName the field name
935      * @param array the array to add to the <code>toString</code>
936      * @param fullDetail <code>true</code> for detail, <code>false</code>
937      * for summary info, <code>null</code> for style decides
938      */

939     public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, short[] array, Boolean JavaDoc fullDetail) {
940         appendFieldStart(buffer, fieldName);
941
942         if (array == null) {
943             appendNullText(buffer, fieldName);
944
945         } else if (isFullDetail(fullDetail)) {
946             appendDetail(buffer, fieldName, array);
947
948         } else {
949             appendSummary(buffer, fieldName, array);
950         }
951
952         appendFieldEnd(buffer, fieldName);
953     }
954
955     /**
956      * <p>Append to the <code>toString</code> the detail of a
957      * <code>short</code> array.</p>
958      *
959      * @param buffer the <code>StringBuffer</code> to populate
960      * @param fieldName the field name, typically not used as already appended
961      * @param array the array to add to the <code>toString</code>,
962      * not <code>null</code>
963      */

964     protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, short[] array) {
965         buffer.append(arrayStart);
966         for (int i = 0; i < array.length; i++) {
967             if (i > 0) {
968                 buffer.append(arraySeparator);
969             }
970             appendDetail(buffer, fieldName, array[i]);
971         }
972         buffer.append(arrayEnd);
973     }
974
975     /**
976      * <p>Append to the <code>toString</code> a summary of a
977      * <code>short</code> array.</p>
978      *
979      * @param buffer the <code>StringBuffer</code> to populate
980      * @param fieldName the field name, typically not used as already appended
981      * @param array the array to add to the <code>toString</code>,
982      * not <code>null</code>
983      */

984     protected void appendSummary(StringBuffer JavaDoc buffer, String JavaDoc fieldName, short[] array) {
985         appendSummarySize(buffer, fieldName, array.length);
986     }
987
988     //----------------------------------------------------------------------------
989

990     /**
991      * <p>Append to the <code>toString</code> a <code>byte</code>
992      * array.</p>
993      *
994      * @param buffer the <code>StringBuffer</code> to populate
995      * @param fieldName the field name
996      * @param array the array to add to the <code>toString</code>
997      * @param fullDetail <code>true</code> for detail, <code>false</code>
998      * for summary info, <code>null</code> for style decides
999      */

1000    public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, byte[] array, Boolean JavaDoc fullDetail) {
1001        appendFieldStart(buffer, fieldName);
1002
1003        if (array == null) {
1004            appendNullText(buffer, fieldName);
1005
1006        } else if (isFullDetail(fullDetail)) {
1007            appendDetail(buffer, fieldName, array);
1008
1009        } else {
1010            appendSummary(buffer, fieldName, array);
1011        }
1012
1013        appendFieldEnd(buffer, fieldName);
1014    }
1015
1016    /**
1017     * <p>Append to the <code>toString</code> the detail of a
1018     * <code>byte</code> array.</p>
1019     *
1020     * @param buffer the <code>StringBuffer</code> to populate
1021     * @param fieldName the field name, typically not used as already appended
1022     * @param array the array to add to the <code>toString</code>,
1023     * not <code>null</code>
1024     */

1025    protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, byte[] array) {
1026        buffer.append(arrayStart);
1027        for (int i = 0; i < array.length; i++) {
1028            if (i > 0) {
1029                buffer.append(arraySeparator);
1030            }
1031            appendDetail(buffer, fieldName, array[i]);
1032        }
1033        buffer.append(arrayEnd);
1034    }
1035
1036    /**
1037     * <p>Append to the <code>toString</code> a summary of a
1038     * <code>byte</code> array.</p>
1039     *
1040     * @param buffer the <code>StringBuffer</code> to populate
1041     * @param fieldName the field name, typically not used as already appended
1042     * @param array the array to add to the <code>toString</code>,
1043     * not <code>null</code>
1044     */

1045    protected void appendSummary(StringBuffer JavaDoc buffer, String JavaDoc fieldName, byte[] array) {
1046        appendSummarySize(buffer, fieldName, array.length);
1047    }
1048
1049    //----------------------------------------------------------------------------
1050

1051    /**
1052     * <p>Append to the <code>toString</code> a <code>char</code>
1053     * array.</p>
1054     *
1055     * @param buffer the <code>StringBuffer</code> to populate
1056     * @param fieldName the field name
1057     * @param array the array to add to the <code>toString</code>
1058     * @param fullDetail <code>true</code> for detail, <code>false</code>
1059     * for summary info, <code>null</code> for style decides
1060     */

1061    public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, char[] array, Boolean JavaDoc fullDetail) {
1062        appendFieldStart(buffer, fieldName);
1063
1064        if (array == null) {
1065            appendNullText(buffer, fieldName);
1066
1067        } else if (isFullDetail(fullDetail)) {
1068            appendDetail(buffer, fieldName, array);
1069
1070        } else {
1071            appendSummary(buffer, fieldName, array);
1072        }
1073
1074        appendFieldEnd(buffer, fieldName);
1075    }
1076
1077    /**
1078     * <p>Append to the <code>toString</code> the detail of a
1079     * <code>char</code> array.</p>
1080     *
1081     * @param buffer the <code>StringBuffer</code> to populate
1082     * @param fieldName the field name, typically not used as already appended
1083     * @param array the array to add to the <code>toString</code>,
1084     * not <code>null</code>
1085     */

1086    protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, char[] array) {
1087        buffer.append(arrayStart);
1088        for (int i = 0; i < array.length; i++) {
1089            if (i > 0) {
1090                buffer.append(arraySeparator);
1091            }
1092            appendDetail(buffer, fieldName, array[i]);
1093        }
1094        buffer.append(arrayEnd);
1095    }
1096
1097    /**
1098     * <p>Append to the <code>toString</code> a summary of a
1099     * <code>char</code> array.</p>
1100     *
1101     * @param buffer the <code>StringBuffer</code> to populate
1102     * @param fieldName the field name, typically not used as already appended
1103     * @param array the array to add to the <code>toString</code>,
1104     * not <code>null</code>
1105     */

1106    protected void appendSummary(StringBuffer JavaDoc buffer, String JavaDoc fieldName, char[] array) {
1107        appendSummarySize(buffer, fieldName, array.length);
1108    }
1109
1110    //----------------------------------------------------------------------------
1111

1112    /**
1113     * <p>Append to the <code>toString</code> a <code>double</code>
1114     * array.</p>
1115     *
1116     * @param buffer the <code>StringBuffer</code> to populate
1117     * @param fieldName the field name
1118     * @param array the array to add to the toString
1119     * @param fullDetail <code>true</code> for detail, <code>false</code>
1120     * for summary info, <code>null</code> for style decides
1121     */

1122    public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, double[] array, Boolean JavaDoc fullDetail) {
1123        appendFieldStart(buffer, fieldName);
1124
1125        if (array == null) {
1126            appendNullText(buffer, fieldName);
1127
1128        } else if (isFullDetail(fullDetail)) {
1129            appendDetail(buffer, fieldName, array);
1130
1131        } else {
1132            appendSummary(buffer, fieldName, array);
1133        }
1134
1135        appendFieldEnd(buffer, fieldName);
1136    }
1137
1138    /**
1139     * <p>Append to the <code>toString</code> the detail of a
1140     * <code>double</code> array.</p>
1141     *
1142     * @param buffer the <code>StringBuffer</code> to populate
1143     * @param fieldName the field name, typically not used as already appended
1144     * @param array the array to add to the <code>toString</code>,
1145     * not <code>null</code>
1146     */

1147    protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, double[] array) {
1148        buffer.append(arrayStart);
1149        for (int i = 0; i < array.length; i++) {
1150            if (i > 0) {
1151                buffer.append(arraySeparator);
1152            }
1153            appendDetail(buffer, fieldName, array[i]);
1154        }
1155        buffer.append(arrayEnd);
1156    }
1157
1158    /**
1159     * <p>Append to the <code>toString</code> a summary of a
1160     * <code>double</code> array.</p>
1161     *
1162     * @param buffer the <code>StringBuffer</code> to populate
1163     * @param fieldName the field name, typically not used as already appended
1164     * @param array the array to add to the <code>toString</code>,
1165     * not <code>null</code>
1166     */

1167    protected void appendSummary(StringBuffer JavaDoc buffer, String JavaDoc fieldName, double[] array) {
1168        appendSummarySize(buffer, fieldName, array.length);
1169    }
1170
1171    //----------------------------------------------------------------------------
1172

1173    /**
1174     * <p>Append to the <code>toString</code> a <code>float</code>
1175     * array.</p>
1176     *
1177     * @param buffer the <code>StringBuffer</code> to populate
1178     * @param fieldName the field name
1179     * @param array the array to add to the toString
1180     * @param fullDetail <code>true</code> for detail, <code>false</code>
1181     * for summary info, <code>null</code> for style decides
1182     */

1183    public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, float[] array, Boolean JavaDoc fullDetail) {
1184        appendFieldStart(buffer, fieldName);
1185
1186        if (array == null) {
1187            appendNullText(buffer, fieldName);
1188
1189        } else if (isFullDetail(fullDetail)) {
1190            appendDetail(buffer, fieldName, array);
1191
1192        } else {
1193            appendSummary(buffer, fieldName, array);
1194        }
1195
1196        appendFieldEnd(buffer, fieldName);
1197    }
1198
1199    /**
1200     * <p>Append to the <code>toString</code> the detail of a
1201     * <code>float</code> array.</p>
1202     *
1203     * @param buffer the <code>StringBuffer</code> to populate
1204     * @param fieldName the field name, typically not used as already appended
1205     * @param array the array to add to the <code>toString</code>,
1206     * not <code>null</code>
1207     */

1208    protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, float[] array) {
1209        buffer.append(arrayStart);
1210        for (int i = 0; i < array.length; i++) {
1211            if (i > 0) {
1212                buffer.append(arraySeparator);
1213            }
1214            appendDetail(buffer, fieldName, array[i]);
1215        }
1216        buffer.append(arrayEnd);
1217    }
1218
1219    /**
1220     * <p>Append to the <code>toString</code> a summary of a
1221     * <code>float</code> array.</p>
1222     *
1223     * @param buffer the <code>StringBuffer</code> to populate
1224     * @param fieldName the field name, typically not used as already appended
1225     * @param array the array to add to the <code>toString</code>,
1226     * not <code>null</code>
1227     */

1228    protected void appendSummary(StringBuffer JavaDoc buffer, String JavaDoc fieldName, float[] array) {
1229        appendSummarySize(buffer, fieldName, array.length);
1230    }
1231
1232    //----------------------------------------------------------------------------
1233

1234    /**
1235     * <p>Append to the <code>toString</code> a <code>boolean</code>
1236     * array.</p>
1237     *
1238     * @param buffer the <code>StringBuffer</code> to populate
1239     * @param fieldName the field name
1240     * @param array the array to add to the toString
1241     * @param fullDetail <code>true</code> for detail, <code>false</code>
1242     * for summary info, <code>null</code> for style decides
1243     */

1244    public void append(StringBuffer JavaDoc buffer, String JavaDoc fieldName, boolean[] array, Boolean JavaDoc fullDetail) {
1245        appendFieldStart(buffer, fieldName);
1246
1247        if (array == null) {
1248            appendNullText(buffer, fieldName);
1249
1250        } else if (isFullDetail(fullDetail)) {
1251            appendDetail(buffer, fieldName, array);
1252
1253        } else {
1254            appendSummary(buffer, fieldName, array);
1255        }
1256
1257        appendFieldEnd(buffer, fieldName);
1258    }
1259
1260    /**
1261     * <p>Append to the <code>toString</code> the detail of a
1262     * <code>boolean</code> array.</p>
1263     *
1264     * @param buffer the <code>StringBuffer</code> to populate
1265     * @param fieldName the field name, typically not used as already appended
1266     * @param array the array to add to the <code>toString</code>,
1267     * not <code>null</code>
1268     */

1269    protected void appendDetail(StringBuffer JavaDoc buffer, String JavaDoc fieldName, boolean[] array) {
1270        buffer.append(arrayStart);
1271        for (int i = 0; i < array.length; i++) {
1272            if (i > 0) {
1273                buffer.append(arraySeparator);
1274            }
1275            appendDetail(buffer, fieldName, array[i]);
1276        }
1277        buffer.append(arrayEnd);
1278    }
1279
1280    /**
1281     * <p>Append to the <code>toString</code> a summary of a
1282     * <code>boolean</code> array.</p>
1283     *
1284     * @param buffer the <code>StringBuffer</code> to populate
1285     * @param fieldName the field name, typically not used as already appended
1286     * @param array the array to add to the <code>toString</code>,
1287     * not <code>null</code>
1288     */

1289    protected void appendSummary(StringBuffer JavaDoc buffer, String JavaDoc fieldName, boolean[] array) {
1290        appendSummarySize(buffer, fieldName, array.length);
1291    }
1292
1293    //----------------------------------------------------------------------------
1294

1295    /**
1296     * <p>Append to the <code>toString</code> the class name.</p>
1297     *
1298     * @param buffer the <code>StringBuffer</code> to populate
1299     * @param object the <code>Object</code> whose name to output
1300     */

1301    protected void appendClassName(StringBuffer JavaDoc buffer, Object JavaDoc object) {
1302        if (useClassName && object != null) {
1303            if (useShortClassName) {
1304                buffer.append(getShortClassName(object.getClass()));
1305            } else {
1306                buffer.append(object.getClass().getName());
1307            }
1308        }
1309    }
1310
1311    /**
1312     * <p>Append the {@link System#identityHashCode(java.lang.Object)}.</p>
1313     *
1314     * @param buffer the <code>StringBuffer</code> to populate
1315     * @param object the <code>Object</code> whose id to output
1316     */

1317    protected void appendIdentityHashCode(StringBuffer JavaDoc buffer, Object JavaDoc object) {
1318        if (this.isUseIdentityHashCode() && object!=null) {
1319            buffer.append('@');
1320            buffer.append(Integer.toHexString(System.identityHashCode(object)));
1321        }
1322    }
1323
1324    /**
1325     * <p>Append to the <code>toString</code> the content start.</p>
1326     *
1327     * @param buffer the <code>StringBuffer</code> to populate
1328     */

1329    protected void appendContentStart(StringBuffer JavaDoc buffer) {
1330        buffer.append(contentStart);
1331    }
1332
1333    /**
1334     * <p>Append to the <code>toString</code> the content end.</p>
1335     *
1336     * @param buffer the <code>StringBuffer</code> to populate
1337     */

1338    protected void appendContentEnd(StringBuffer JavaDoc buffer) {
1339        buffer.append(contentEnd);
1340    }
1341
1342    /**
1343     * <p>Append to the <code>toString</code> an indicator for <code>null</code>.</p>
1344     *
1345     * <p>The default indicator is <code>'&lt;null&gt;'</code>.</p>
1346     *
1347     * @param buffer the <code>StringBuffer</code> to populate
1348     * @param fieldName the field name, typically not used as already appended
1349     */

1350    protected void appendNullText(StringBuffer JavaDoc buffer, String JavaDoc fieldName) {
1351        buffer.append(nullText);
1352    }
1353
1354    /**
1355     * <p>Append to the <code>toString</code> the field separator.</p>
1356     *
1357     * @param buffer the <code>StringBuffer</code> to populate
1358     */

1359    protected void appendFieldSeparator(StringBuffer JavaDoc buffer) {
1360        buffer.append(fieldSeparator);
1361    }
1362
1363    /**
1364     * <p>Append to the <code>toString</code> the field start.</p>
1365     *
1366     * @param buffer the <code>StringBuffer</code> to populate
1367     * @param fieldName the field name
1368     */

1369    protected void appendFieldStart(StringBuffer JavaDoc buffer, String JavaDoc fieldName) {
1370        if (useFieldNames && fieldName != null) {
1371            buffer.append(fieldName);
1372            buffer.append(fieldNameValueSeparator);
1373        }
1374    }
1375
1376    /**
1377     * <p>Append to the <code>toString<code> the field end.</p>
1378     *
1379     * @param buffer the <code>StringBuffer</code> to populate
1380     * @param fieldName the field name, typically not used as already appended
1381     */

1382    protected void appendFieldEnd(StringBuffer JavaDoc buffer, String JavaDoc fieldName) {
1383        appendFieldSeparator(buffer);
1384    }
1385
1386    /**
1387     * <p>Append to the <code>toString</code> a size summary.</p>
1388     *
1389     * <p>The size summary is used to summarize the contents of
1390     * <code>Collections</code>, <code>Maps</code> and arrays.</p>
1391     *
1392     * <p>The output consists of a prefix, the passed in size
1393     * and a suffix.</p>
1394     *
1395     * <p>The default format is <code>'&lt;size=n&gt;'<code>.</p>
1396     *
1397     * @param buffer the <code>StringBuffer</code> to populate
1398     * @param fieldName the field name, typically not used as already appended
1399     * @param size the size to append
1400     */

1401    protected void appendSummarySize(StringBuffer JavaDoc buffer, String JavaDoc fieldName, int size) {
1402        buffer.append(sizeStartText);
1403        buffer.append(size);
1404        buffer.append(sizeEndText);
1405    }
1406
1407    /**
1408     * <p>Is this field to be output in full detail.</p>
1409     *
1410     * <p>This method converts a detail request into a detail level.
1411     * The calling code may request full detail (<code>true</code>),
1412     * but a subclass might ignore that and always return
1413     * <code>false</code>. The calling code may pass in
1414     * <code>null</code> indicating that it doesn't care about
1415     * the detail level. In this case the default detail level is
1416     * used.</p>
1417     *
1418     * @param fullDetailRequest the detail level requested
1419     * @return whether full detail is to be shown
1420     */

1421    protected boolean isFullDetail(Boolean JavaDoc fullDetailRequest) {
1422        if (fullDetailRequest == null) {
1423            return defaultFullDetail;
1424        }
1425        return fullDetailRequest.booleanValue();
1426    }
1427
1428    /**
1429     * <p>Gets the short class name for a class.</p>
1430     *
1431     * <p>The short class name is the classname excluding
1432     * the package name.</p>
1433     *
1434     * @param cls the <code>Class</code> to get the short name of
1435     * @return the short name
1436     */

1437    protected String JavaDoc getShortClassName(Class JavaDoc cls) {
1438        return ClassUtils.getShortClassName(cls);
1439    }
1440
1441    // Setters and getters for the customizable parts of the style
1442
// These methods are not expected to be overridden, except to make public
1443
// (They are not public so that immutable subclasses can be written)
1444
//---------------------------------------------------------------------
1445

1446    /**
1447     * <p>Gets whether to use the class name.</p>
1448     *
1449     * @return the current useClassName flag
1450     */

1451    protected boolean isUseClassName() {
1452        return useClassName;
1453    }
1454
1455    /**
1456     * <p>Sets whether to use the class name.</p>
1457     *
1458     * @param useClassName the new useClassName flag
1459     */

1460    protected void setUseClassName(boolean useClassName) {
1461        this.useClassName = useClassName;
1462    }
1463
1464    //---------------------------------------------------------------------
1465

1466    /**
1467     * <p>Gets whether to output short or long class names.</p>
1468     *
1469     * @return the current useShortClassName flag
1470     * @since 2.0
1471     */

1472    protected boolean isUseShortClassName() {
1473        return useShortClassName;
1474    }
1475
1476    /**
1477     * <p>Gets whether to output short or long class names.</p>
1478     *
1479     * @return the current shortClassName flag
1480     * @deprecated Use {@link #isUseShortClassName()}
1481     * Method will be removed in Commons Lang 3.0.
1482     */

1483    protected boolean isShortClassName() {
1484        return useShortClassName;
1485    }
1486
1487    /**
1488     * <p>Sets whether to output short or long class names.</p>
1489     *
1490     * @param useShortClassName the new useShortClassName flag
1491     * @since 2.0
1492     */

1493    protected void setUseShortClassName(boolean useShortClassName) {
1494        this.useShortClassName = useShortClassName;
1495    }
1496
1497    /**
1498     * <p>Sets whether to output short or long class names.</p>
1499     *
1500     * @param shortClassName the new shortClassName flag
1501     * @deprecated Use {@link #setUseShortClassName(boolean)}
1502     * Method will be removed in Commons Lang 3.0.
1503     */

1504    protected void setShortClassName(boolean shortClassName) {
1505        this.useShortClassName = shortClassName;
1506    }
1507
1508    //---------------------------------------------------------------------
1509

1510    /**
1511     * <p>Gets whether to use the identity hash code.</p>
1512     *
1513     * @return the current useIdentityHashCode flag
1514     */

1515    protected boolean isUseIdentityHashCode() {
1516        return useIdentityHashCode;
1517    }
1518
1519    /**
1520     * <p>Sets whether to use the identity hash code.</p>
1521     *
1522     * @param useIdentityHashCode the new useIdentityHashCode flag
1523     */

1524    protected void setUseIdentityHashCode(boolean useIdentityHashCode) {
1525        this.useIdentityHashCode = useIdentityHashCode;
1526    }
1527
1528    //---------------------------------------------------------------------
1529

1530    /**
1531     * <p>Gets whether to use the field names passed in.</p>
1532     *
1533     * @return the current useFieldNames flag
1534     */

1535    protected boolean isUseFieldNames() {
1536        return useFieldNames;
1537    }
1538
1539    /**
1540     * <p>Sets whether to use the field names passed in.</p>
1541     *
1542     * @param useFieldNames the new useFieldNames flag
1543     */

1544    protected void setUseFieldNames(boolean useFieldNames) {
1545        this.useFieldNames = useFieldNames;
1546    }
1547
1548    //---------------------------------------------------------------------
1549

1550    /**
1551     * <p>Gets whether to use full detail when the caller doesn't
1552     * specify.</p>
1553     *
1554     * @return the current defaultFullDetail flag
1555     */

1556    protected boolean isDefaultFullDetail() {
1557        return defaultFullDetail;
1558    }
1559
1560    /**
1561     * <p>Sets whether to use full detail when the caller doesn't
1562     * specify.</p>
1563     *
1564     * @param defaultFullDetail the new defaultFullDetail flag
1565     */

1566    protected void setDefaultFullDetail(boolean defaultFullDetail) {
1567        this.defaultFullDetail = defaultFullDetail;
1568    }
1569
1570    //---------------------------------------------------------------------
1571

1572    /**
1573     * <p>Gets whether to output array content detail.</p>
1574     *
1575     * @return the current array content detail setting
1576     */

1577    protected boolean isArrayContentDetail() {
1578        return arrayContentDetail;
1579    }
1580
1581    /**
1582     * <p>Sets whether to output array content detail.</p>
1583     *
1584     * @param arrayContentDetail the new arrayContentDetail flag
1585     */

1586    protected void setArrayContentDetail(boolean arrayContentDetail) {
1587        this.arrayContentDetail = arrayContentDetail;
1588    }
1589
1590    //---------------------------------------------------------------------
1591

1592    /**
1593     * <p>Gets the array start text.</p>
1594     *
1595     * @return the current array start text
1596     */

1597    protected String JavaDoc getArrayStart() {
1598        return arrayStart;
1599    }
1600
1601    /**
1602     * <p>Sets the array start text.</p>
1603     *
1604     * <p><code>null</code> is accepted, but will be converted to
1605     * an empty String.</p>
1606     *
1607     * @param arrayStart the new array start text
1608     */

1609    protected void setArrayStart(String JavaDoc arrayStart) {
1610        if (arrayStart == null) {
1611            arrayStart = "";
1612        }
1613        this.arrayStart = arrayStart;
1614    }
1615
1616    //---------------------------------------------------------------------
1617

1618    /**
1619     * <p>Gets the array end text.</p>
1620     *
1621     * @return the current array end text
1622     */

1623    protected String JavaDoc getArrayEnd() {
1624        return arrayEnd;
1625    }
1626
1627    /**
1628     * <p>Sets the array end text.</p>
1629     *
1630     * <p><code>null</code> is accepted, but will be converted to
1631     * an empty String.</p>
1632     *
1633     * @param arrayEnd the new array end text
1634     */

1635    protected void setArrayEnd(String JavaDoc arrayEnd) {
1636        if (arrayEnd == null) {
1637            arrayEnd = "";
1638        }
1639        this.arrayEnd = arrayEnd;
1640    }
1641
1642    //---------------------------------------------------------------------
1643

1644    /**
1645     * <p>Gets the array separator text.</p>
1646     *
1647     * @return the current array separator text
1648     */

1649    protected String JavaDoc getArraySeparator() {
1650        return arraySeparator;
1651    }
1652
1653    /**
1654     * <p>Sets the array separator text.</p>
1655     *
1656     * <p><code>null</code> is accepted, but will be converted to
1657     * an empty String.</p>
1658     *
1659     * @param arraySeparator the new array separator text
1660     */

1661    protected void setArraySeparator(String JavaDoc arraySeparator) {
1662        if (arraySeparator == null) {
1663            arraySeparator = "";
1664        }
1665        this.arraySeparator = arraySeparator;
1666    }
1667
1668    //---------------------------------------------------------------------
1669

1670    /**
1671     * <p>Gets the content start text.</p>
1672     *
1673     * @return the current content start text
1674     */

1675    protected String JavaDoc getContentStart() {
1676        return contentStart;
1677    }
1678
1679    /**
1680     * <p>Sets the content start text.</p>
1681     *
1682     * <p><code>null</code> is accepted, but will be converted to
1683     * an empty String.</p>
1684     *
1685     * @param contentStart the new content start text
1686     */

1687    protected void setContentStart(String JavaDoc contentStart) {
1688        if (contentStart == null) {
1689            contentStart = "";
1690        }
1691        this.contentStart = contentStart;
1692    }
1693
1694    //---------------------------------------------------------------------
1695

1696    /**
1697     * <p>Gets the content end text.</p>
1698     *
1699     * @return the current content end text
1700     */

1701    protected String JavaDoc getContentEnd() {
1702        return contentEnd;
1703    }
1704
1705    /**
1706     * <p>Sets the content end text.</p>
1707     *
1708     * <p><code>null</code> is accepted, but will be converted to
1709     * an empty String.</p>
1710     *
1711     * @param contentEnd the new content end text
1712     */

1713    protected void setContentEnd(String JavaDoc contentEnd) {
1714        if (contentEnd == null) {
1715            contentEnd = "";
1716        }
1717        this.contentEnd = contentEnd;
1718    }
1719
1720    //---------------------------------------------------------------------
1721

1722    /**
1723     * <p>Gets the field name value separator text.</p>
1724     *
1725     * @return the current field name value separator text
1726     */

1727    protected String JavaDoc getFieldNameValueSeparator() {
1728        return fieldNameValueSeparator;
1729    }
1730
1731    /**
1732     * <p>Sets the field name value separator text.</p>
1733     *
1734     * <p><code>null</code> is accepted, but will be converted to
1735     * an empty String.</p>
1736     *
1737     * @param fieldNameValueSeparator the new field name value separator text
1738     */

1739    protected void setFieldNameValueSeparator(String JavaDoc fieldNameValueSeparator) {
1740        if (fieldNameValueSeparator == null) {
1741            fieldNameValueSeparator = "";
1742        }
1743        this.fieldNameValueSeparator = fieldNameValueSeparator;
1744    }
1745
1746    //---------------------------------------------------------------------
1747

1748    /**
1749     * <p>Gets the field separator text.</p>
1750     *
1751     * @return the current field separator text
1752     */

1753    protected String JavaDoc getFieldSeparator() {
1754        return fieldSeparator;
1755    }
1756
1757    /**
1758     * <p>Sets the field separator text.</p>
1759     *
1760     * <p><code>null</code> is accepted, but will be converted to
1761     * an empty String.</p>
1762     *
1763     * @param fieldSeparator the new field separator text
1764     */

1765    protected void setFieldSeparator(String JavaDoc fieldSeparator) {
1766        if (fieldSeparator == null) {
1767            fieldSeparator = "";
1768        }
1769        this.fieldSeparator = fieldSeparator;
1770    }
1771
1772    //---------------------------------------------------------------------
1773

1774    /**
1775     * <p>Gets whether the field separator should be added at the start
1776     * of each buffer.</p>
1777     *
1778     * @return the fieldSeparatorAtStart flag
1779     * @since 2.0
1780     */

1781    protected boolean isFieldSeparatorAtStart() {
1782        return fieldSeparatorAtStart;
1783    }
1784
1785    /**
1786     * <p>Sets whether the field separator should be added at the start
1787     * of each buffer.</p>
1788     *
1789     * @param fieldSeparatorAtStart the fieldSeparatorAtStart flag
1790     * @since 2.0
1791     */

1792    protected void setFieldSeparatorAtStart(boolean fieldSeparatorAtStart) {
1793        this.fieldSeparatorAtStart = fieldSeparatorAtStart;
1794    }
1795
1796    //---------------------------------------------------------------------
1797

1798    /**
1799     * <p>Gets whether the field separator should be added at the end
1800     * of each buffer.</p>
1801     *
1802     * @return fieldSeparatorAtEnd flag
1803     * @since 2.0
1804     */

1805    protected boolean isFieldSeparatorAtEnd() {
1806        return fieldSeparatorAtEnd;
1807    }
1808
1809    /**
1810     * <p>Sets whether the field separator should be added at the end
1811     * of each buffer.</p>
1812     *
1813     * @param fieldSeparatorAtEnd the fieldSeparatorAtEnd flag
1814     * @since 2.0
1815     */

1816    protected void setFieldSeparatorAtEnd(boolean fieldSeparatorAtEnd) {
1817        this.fieldSeparatorAtEnd = fieldSeparatorAtEnd;
1818    }
1819
1820    //---------------------------------------------------------------------
1821

1822    /**
1823     * <p>Gets the text to output when <code>null</code> found.</p>
1824     *
1825     * @return the current text to output when null found
1826     */

1827    protected String JavaDoc getNullText() {
1828        return nullText;
1829    }
1830
1831    /**
1832     * <p>Sets the text to output when <code>null</code> found.</p>
1833     *
1834     * <p><code>null</code> is accepted, but will be converted to
1835     * an empty String.</p>
1836     *
1837     * @param nullText the new text to output when null found
1838     */

1839    protected void setNullText(String JavaDoc nullText) {
1840        if (nullText == null) {
1841            nullText = "";
1842        }
1843        this.nullText = nullText;
1844    }
1845
1846    //---------------------------------------------------------------------
1847

1848    /**
1849     * <p>Gets the start text to output when a <code>Collection</code>,
1850     * <code>Map</code> or array size is output.</p>
1851     *
1852     * <p>This is output before the size value.</p>
1853     *
1854     * @return the current start of size text
1855     */

1856    protected String JavaDoc getSizeStartText() {
1857        return sizeStartText;
1858    }
1859
1860    /**
1861     * <p>Sets the start text to output when a <code>Collection</code>,
1862     * <code>Map</code> or array size is output.</p>
1863     *
1864     * <p>This is output before the size value.</p>
1865     *
1866     * <p><code>null</code> is accepted, but will be converted to
1867     * an empty String.</p>
1868     *
1869     * @param sizeStartText the new start of size text
1870     */

1871    protected void setSizeStartText(String JavaDoc sizeStartText) {
1872        if (sizeStartText == null) {
1873            sizeStartText = "";
1874        }
1875        this.sizeStartText = sizeStartText;
1876    }
1877
1878    //---------------------------------------------------------------------
1879

1880    /**
1881     * <p>Gets the end text to output when a <code>Collection</code>,
1882     * <code>Map</code> or array size is output.</p>
1883     *
1884     * <p>This is output after the size value.</p>
1885     *
1886     * @return the current end of size text
1887     */

1888    protected String JavaDoc getSizeEndText() {
1889        return sizeEndText;
1890    }
1891
1892    /**
1893     * <p>Sets the end text to output when a <code>Collection</code>,
1894     * <code>Map</code> or array size is output.</p>
1895     *
1896     * <p>This is output after the size value.</p>
1897     *
1898     * <p><code>null</code> is accepted, but will be converted to
1899     * an empty String.</p>
1900     *
1901     * @param sizeEndText the new end of size text
1902     */

1903    protected void setSizeEndText(String JavaDoc sizeEndText) {
1904        if (sizeEndText == null) {
1905            sizeEndText = "";
1906        }
1907        this.sizeEndText = sizeEndText;
1908    }
1909
1910    //---------------------------------------------------------------------
1911

1912    /**
1913     * <p>Gets the start text to output when an <code>Object</code> is
1914     * output in summary mode.</p>
1915     *
1916     * <p>This is output before the size value.</p>
1917     *
1918     * @return the current start of summary text
1919     */

1920    protected String JavaDoc getSummaryObjectStartText() {
1921        return summaryObjectStartText;
1922    }
1923
1924    /**
1925     * <p>Sets the start text to output when an <code>Object</code> is
1926     * output in summary mode.</p>
1927     *
1928     * <p>This is output before the size value.</p>
1929     *
1930     * <p><code>null</code> is accepted, but will be converted to
1931     * an empty String.</p>
1932     *
1933     * @param summaryObjectStartText the new start of summary text
1934     */

1935    protected void setSummaryObjectStartText(String JavaDoc summaryObjectStartText) {
1936        if (summaryObjectStartText == null) {
1937            summaryObjectStartText = "";
1938        }
1939        this.summaryObjectStartText = summaryObjectStartText;
1940    }
1941
1942    //---------------------------------------------------------------------
1943

1944    /**
1945     * <p>Gets the end text to output when an <code>Object</code> is
1946     * output in summary mode.</p>
1947     *
1948     * <p>This is output after the size value.</p>
1949     *
1950     * @return the current end of summary text
1951     */

1952    protected String JavaDoc getSummaryObjectEndText() {
1953        return summaryObjectEndText;
1954    }
1955
1956    /**
1957     * <p>Sets the end text to output when an <code>Object</code> is
1958     * output in summary mode.</p>
1959     *
1960     * <p>This is output after the size value.</p>
1961     *
1962     * <p><code>null</code> is accepted, but will be converted to
1963     * an empty String.</p>
1964     *
1965     * @param summaryObjectEndText the new end of summary text
1966     */

1967    protected void setSummaryObjectEndText(String JavaDoc summaryObjectEndText) {
1968        if (summaryObjectEndText == null) {
1969            summaryObjectEndText = "";
1970        }
1971        this.summaryObjectEndText = summaryObjectEndText;
1972    }
1973
1974    //----------------------------------------------------------------------------
1975

1976    /**
1977     * <p>Default <code>ToStringStyle</code>.</p>
1978     *
1979     * <p>This is an inner class rather than using
1980     * <code>StandardToStringStyle</code> to ensure its immutability.</p>
1981     */

1982    private static final class DefaultToStringStyle extends ToStringStyle {
1983
1984        /**
1985         * <p>Constructor.</p>
1986         *
1987         * <p>Use the static constant rather than instantiating.</p>
1988         */

1989        private DefaultToStringStyle() {
1990            super();
1991        }
1992
1993        /**
1994         * <p>Ensure <code>Singleton</code> after serialization.</p>
1995         *
1996         * @return the singleton
1997         */

1998        private Object JavaDoc readResolve() {
1999            return ToStringStyle.DEFAULT_STYLE;
2000        }
2001
2002    }
2003
2004    //----------------------------------------------------------------------------
2005

2006    /**
2007     * <p><code>ToStringStyle</code> that does not print out
2008     * the field names.</p>
2009     *
2010     * <p>This is an inner class rather than using
2011     * <code>StandardToStringStyle</code> to ensure its immutability.
2012     */

2013    private static final class NoFieldNameToStringStyle extends ToStringStyle {
2014
2015        /**
2016         * <p>Constructor.</p>
2017         *
2018         * <p>Use the static constant rather than instantiating.</p>
2019         */

2020        private NoFieldNameToStringStyle() {
2021            super();
2022            this.setUseFieldNames(false);
2023        }
2024
2025        /**
2026         * <p>Ensure <code>Singleton</code> after serialization.</p>
2027         *
2028         * @return the singleton
2029         */

2030        private Object JavaDoc readResolve() {
2031            return ToStringStyle.NO_FIELD_NAMES_STYLE;
2032        }
2033
2034    }
2035
2036    //----------------------------------------------------------------------------
2037

2038    /**
2039     * <p><code>ToStringStyle</code> that prints out the short
2040     * class name and no identity hashcode.</p>
2041     *
2042     * <p>This is an inner class rather than using
2043     * <code>StandardToStringStyle</code> to ensure its immutability.</p>
2044     */

2045    private static final class ShortPrefixToStringStyle extends ToStringStyle {
2046
2047        /**
2048         * <p>Constructor.</p>
2049         *
2050         * <p>Use the static constant rather than instantiating.</p>
2051         */

2052        private ShortPrefixToStringStyle() {
2053            super();
2054            this.setUseShortClassName(true);
2055            this.setUseIdentityHashCode(false);
2056        }
2057
2058        /**
2059         * <p>Ensure <code>Singleton</ode> after serialization.</p>
2060         * @return the singleton
2061         */

2062        private Object JavaDoc readResolve() {
2063            return ToStringStyle.SHORT_PREFIX_STYLE;
2064        }
2065
2066    }
2067
2068    /**
2069     * <p><code>ToStringStyle</code> that does not print out the
2070     * classname, identity hashcode, content start or field name.</p>
2071     *
2072     * <p>This is an inner class rather than using
2073     * <code>StandardToStringStyle</code> to ensure its immutability.</p>
2074     */

2075    private static final class SimpleToStringStyle extends ToStringStyle {
2076
2077        /**
2078         * <p>Constructor.</p>
2079         *
2080         * <p>Use the static constant rather than instantiating.</p>
2081         */

2082        private SimpleToStringStyle() {
2083            super();
2084            this.setUseClassName(false);
2085            this.setUseIdentityHashCode(false);
2086            this.setUseFieldNames(false);
2087            this.setContentStart("");
2088            this.setContentEnd("");
2089        }
2090
2091        /**
2092         * <p>Ensure <code>Singleton</ode> after serialization.</p>
2093         * @return the singleton
2094         */

2095        private Object JavaDoc readResolve() {
2096            return ToStringStyle.SIMPLE_STYLE;
2097        }
2098
2099    }
2100
2101    //----------------------------------------------------------------------------
2102

2103    /**
2104     * <p><code>ToStringStyle</code> that outputs on multiple lines.</p>
2105     *
2106     * <p>This is an inner class rather than using
2107     * <code>StandardToStringStyle</code> to ensure its immutability.</p>
2108     */

2109    private static final class MultiLineToStringStyle extends ToStringStyle {
2110
2111        /**
2112         * <p>Constructor.</p>
2113         *
2114         * <p>Use the static constant rather than instantiating.</p>
2115         */

2116        private MultiLineToStringStyle() {
2117            super();
2118            this.setContentStart("[");
2119            this.setFieldSeparator(SystemUtils.LINE_SEPARATOR + " ");
2120            this.setFieldSeparatorAtStart(true);
2121            this.setContentEnd(SystemUtils.LINE_SEPARATOR + "]");
2122        }
2123
2124        /**
2125         * <p>Ensure <code>Singleton</code> after serialization.</p>
2126         *
2127         * @return the singleton
2128         */

2129        private Object JavaDoc readResolve() {
2130            return ToStringStyle.MULTI_LINE_STYLE;
2131        }
2132
2133    }
2134
2135}
2136
Popular Tags