1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 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 */ 19 20 package org.apache.fulcrum.yaafi.interceptor.util; 21 22 /** 23 * Creates a string representation of java.lang.reflect.Method 24 * 25 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a> 26 */ 27 public class DefaultToStringBuilderImpl implements InterceptorToStringBuilder 28 { 29 /** the target object */ 30 private Object target; 31 32 /** the output for a NULL value **/ 33 private static final String NULL_STRING = "<null>"; 34 35 /** 36 * Constructor 37 */ 38 public DefaultToStringBuilderImpl() 39 { 40 // nothing to do 41 } 42 43 /** 44 * Constructor 45 * 46 * @param target the object to print 47 */ 48 public DefaultToStringBuilderImpl(Object target) 49 { 50 this.target = target; 51 } 52 53 /** 54 * @see org.apache.fulcrum.yaafi.interceptor.util.InterceptorToStringBuilder#setTarget(java.lang.Object) 55 */ 56 public void setTarget(Object target) 57 { 58 this.target = target; 59 } 60 61 /** 62 * @see org.apache.fulcrum.yaafi.interceptor.util.InterceptorToStringBuilder#setMaxArgLength(int) 63 */ 64 public void setMaxArgLength(int maxArgLength) 65 { 66 // not supported 67 } 68 69 /** 70 * @see org.apache.fulcrum.yaafi.interceptor.util.InterceptorToStringBuilder#setMode(int) 71 */ 72 public void setMode(int mode) 73 { 74 // not supported 75 } 76 77 /** 78 * @see java.lang.Object#toString() 79 */ 80 public String toString() 81 { 82 String result = null; 83 84 try 85 { 86 if( this.target == null ) 87 { 88 result = NULL_STRING; 89 } 90 else 91 { 92 result = this.target.toString(); 93 } 94 } 95 catch (Throwable t) 96 { 97 t.printStackTrace(); 98 result = "<" + t + ">"; 99 } 100 101 return result; 102 } 103 }