1 23 package com.sun.appserv.management.util.stringifier; 24 25 28 public class InterfacesStringifier implements Stringifier 29 { 30 private final StringifierRegistry mRegistry; 31 private final Class <?>[] mInterfaces; 32 33 public 34 InterfacesStringifier( Class [] interfaces ) 35 { 36 this( StringifierRegistryImpl.DEFAULT, interfaces ); 37 } 38 39 public 40 InterfacesStringifier( StringifierRegistry registry, Class [] interfaces) 41 { 42 mRegistry = registry; 43 mInterfaces = interfaces; 44 } 45 46 private <T> String 47 stringifyAs( Object o, Class <T> theClass ) 48 { 49 String result = null; 50 if ( theClass.isAssignableFrom( o.getClass() ) ) 51 { 52 final Stringifier stringifier = mRegistry.lookup( theClass ); 53 if ( stringifier != null ) 54 { 55 result = stringifier.stringify( o ); 56 } 57 } 58 return( result ); 59 } 60 61 public String 62 stringify( Object o ) 63 { 64 String result = ""; 65 66 for( int i = 0; i < mInterfaces.length; ++i ) 67 { 68 final Class <?> intf = mInterfaces[ i ]; 69 70 final String s = stringifyAs( o, intf ); 71 if ( s != null ) 72 { 73 result = result + intf.getName() + ": " + s + "\n"; 74 } 75 } 76 77 if ( result == null || result.length() == 0) 78 { 79 result = o.toString(); 80 } 81 82 return( result ); 83 } 84 } 85 86 87 88 89 90 91 92 93 | Popular Tags |