001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.fulcrum.yaafi.interceptor.util;
021
022 /**
023 * Creates a string representation of java.lang.reflect.Method
024 *
025 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
026 */
027 public class DefaultToStringBuilderImpl implements InterceptorToStringBuilder
028 {
029 /** the target object */
030 private Object target;
031
032 /** the output for a NULL value **/
033 private static final String NULL_STRING = "<null>";
034
035 /**
036 * Constructor
037 */
038 public DefaultToStringBuilderImpl()
039 {
040 // nothing to do
041 }
042
043 /**
044 * Constructor
045 *
046 * @param target the object to print
047 */
048 public DefaultToStringBuilderImpl(Object target)
049 {
050 this.target = target;
051 }
052
053 /**
054 * @see org.apache.fulcrum.yaafi.interceptor.util.InterceptorToStringBuilder#setTarget(java.lang.Object)
055 */
056 public void setTarget(Object target)
057 {
058 this.target = target;
059 }
060
061 /**
062 * @see org.apache.fulcrum.yaafi.interceptor.util.InterceptorToStringBuilder#setMaxArgLength(int)
063 */
064 public void setMaxArgLength(int maxArgLength)
065 {
066 // not supported
067 }
068
069 /**
070 * @see org.apache.fulcrum.yaafi.interceptor.util.InterceptorToStringBuilder#setMode(int)
071 */
072 public void setMode(int mode)
073 {
074 // not supported
075 }
076
077 /**
078 * @see java.lang.Object#toString()
079 */
080 public String toString()
081 {
082 String result = null;
083
084 try
085 {
086 if( this.target == null )
087 {
088 result = NULL_STRING;
089 }
090 else
091 {
092 result = this.target.toString();
093 }
094 }
095 catch (Throwable t)
096 {
097 t.printStackTrace();
098 result = "<" + t + ">";
099 }
100
101 return result;
102 }
103 }