1 23 24 29 30 31 package com.sun.cli.jmx.support; 32 33 import javax.management.Attribute ; 34 35 import com.sun.cli.jmx.support.ResultsForGetSet; 36 37 import com.sun.cli.util.stringifier.*; 38 39 40 public class ResultsForGetSetStringifier implements Stringifier 41 { 42 final Options mOptions; 43 44 public static final class Options 45 { 46 final static Options DEFAULT = new Options(); 47 48 final boolean mIncludeObjectName; 49 final int mDisplayType; 50 51 public final static int DISPLAY_TERSE = 0; 52 public final static int DISPLAY_PRETTY = 1; 53 54 55 public 56 Options( boolean includeObjectName, int displayType ) 57 { 58 mIncludeObjectName = includeObjectName; 59 mDisplayType = DISPLAY_PRETTY; 60 } 61 62 public 63 Options( ) 64 { 65 this( true, DISPLAY_PRETTY ); 66 } 67 }; 68 69 public 70 ResultsForGetSetStringifier( ) 71 { 72 mOptions = Options.DEFAULT; 73 } 74 public 75 ResultsForGetSetStringifier( Options options ) 76 { 77 mOptions = options; 78 } 79 80 public String 81 stringify( Object o ) 82 { 83 final ResultsForGetSet result = (ResultsForGetSet)o; 84 85 String str = ""; 86 87 if ( mOptions.mIncludeObjectName ) 88 { 89 str = "---" + result.getName().toString() + "---"; 90 } 91 final boolean pretty = mOptions.mDisplayType == Options.DISPLAY_PRETTY; 92 93 final Stringifier attrS = new AttributeStringifier(); 94 final Object [] attrList = result.getAttributes().toArray(); 95 96 if ( pretty ) 97 { 98 str = str + "\n"; 99 } 100 101 if ( attrList.length == 0 ) 102 { 103 str = str + "<no attributes found>"; 104 } 105 else 106 { 107 String delim; 108 109 if ( pretty ) 110 delim = "\n"; 111 else 112 delim = ","; 113 114 str = str + ArrayStringifier.stringify( attrList , delim, attrS ); 115 } 116 117 return( str ); 118 } 119 } 120 | Popular Tags |