01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.jaxb;
19:
20: import javax.xml.bind.JAXBElement;
21:
22: import org.apache.commons.lang.SystemUtils;
23: import org.apache.commons.lang.builder.ToStringBuilder;
24: import org.apache.commons.lang.builder.ToStringStyle;
25:
26: /*
27: * Override default styles to recognise JAXBElement as needing introspection
28: */
29: public class JAXBToStringStyle {
30:
31: public static final ToStringStyle MULTI_LINE_STYLE = new JAXBToStringStyleImpl(
32: true);
33:
34: public static final ToStringStyle SIMPLE_STYLE = new JAXBToStringStyleImpl(
35: false);
36:
37: public static final ToStringStyle DEFAULT_STYLE = new JAXBToStringStyleImpl();
38:
39: }
40:
41: class JAXBToStringStyleImpl extends ToStringStyle {
42: JAXBToStringStyleImpl() {
43: super ();
44: }
45:
46: JAXBToStringStyleImpl(boolean multiLine) {
47: super ();
48: if (multiLine) {
49: this .setContentStart("[");
50: this .setFieldSeparator(SystemUtils.LINE_SEPARATOR + " ");
51: this .setFieldSeparatorAtStart(true);
52: this .setContentEnd(SystemUtils.LINE_SEPARATOR + "]");
53: } else {
54: // simple
55: this .setUseClassName(false);
56: this .setUseIdentityHashCode(false);
57: this .setUseFieldNames(false);
58: this .setContentStart("");
59: this .setContentEnd("");
60: }
61: }
62:
63: /*
64: * Introspect into JAXBElement as a special case as it does not have a
65: * toString() and we loose the content
66: *
67: * @see org.apache.commons.lang.builder.ToStringStyle
68: */
69: @Override
70: protected void appendDetail(StringBuffer buffer, String fieldName,
71: Object value) {
72: if (value instanceof JAXBElement) {
73: buffer.append(ToStringBuilder.reflectionToString(value,
74: this));
75: } else {
76: buffer.append(value);
77: }
78: }
79: }
|