1 23 package com.sun.appserv.management.ext.logging; 24 25 import java.util.Map ; 26 import java.util.List ; 27 import java.util.HashMap ; 28 import java.util.Date ; 29 30 import java.util.logging.Level ; 31 32 import java.io.Serializable ; 33 34 import javax.management.openmbean.CompositeData ; 35 import javax.management.openmbean.CompositeDataSupport ; 36 import javax.management.openmbean.CompositeType ; 37 import javax.management.openmbean.OpenType ; 38 import javax.management.openmbean.ArrayType ; 39 import javax.management.openmbean.SimpleType ; 40 import javax.management.openmbean.OpenDataException ; 41 42 import com.sun.appserv.management.util.jmx.OpenMBeanUtil; 43 import com.sun.appserv.management.util.misc.ArrayUtil; 44 import com.sun.appserv.management.util.misc.ObjectUtil; 45 import com.sun.appserv.management.util.stringifier.ArrayStringifier; 46 47 51 public final class LogQueryResultImpl 52 implements LogQueryResult 53 { 54 private String [] mFieldNames; 55 private LogQueryEntry[] mEntries; 56 57 public 58 LogQueryResultImpl( 59 final String [] fieldNames, 60 final LogQueryEntry[] entries ) 61 { 62 mFieldNames = fieldNames; 63 mEntries = entries; 64 } 65 66 71 public 72 LogQueryResultImpl( final List <Serializable []> records ) 73 { 74 mFieldNames = (String [])records.get( 0 ); 75 76 mEntries = new LogQueryEntry[ records.size() - 1 ]; 77 for( int i = 1; i < mEntries.length; ++i ) 78 { 79 mEntries[ i ] = new LogQueryEntryImpl( records.get( i ) ); 80 } 81 } 82 83 public String [] 84 getFieldNames() 85 { 86 return mFieldNames; 87 } 88 89 public LogQueryEntry[] 90 getEntries() 91 { 92 return mEntries; 93 } 94 95 private static final String FIELD_DELIM = "\t"; 96 private static final String NEWLINE = System.getProperty( "line.separator" );; 97 101 public String 102 toString() 103 { 104 final StringBuilder builder = new StringBuilder (); 105 106 for( final String s : getFieldNames() ) 107 { 108 builder.append( s ); 109 builder.append( FIELD_DELIM ); 110 } 111 builder.replace( builder.length() - 1, builder.length(), NEWLINE ); 112 113 for ( final LogQueryEntry entry : getEntries() ) 114 { 115 final Object [] fields = entry.getFields(); 116 for( final Object o : fields ) 117 { 118 builder.append( o.toString() ); 119 builder.append( FIELD_DELIM ); 120 } 121 builder.replace( builder.length() - 1, builder.length(), NEWLINE ); 122 } 123 124 return builder.toString(); 125 } 126 127 public int 128 hashCode() 129 { 130 return ObjectUtil.hashCode( getFieldNames(), getEntries() ); 131 } 132 133 public boolean 134 equals( final Object rhs ) 135 { 136 boolean equal = rhs instanceof LogQueryResult; 137 138 if ( equal ) 139 { 140 final LogQueryResult r = (LogQueryResult)rhs; 141 142 equal = ArrayUtil.arraysEqual( getFieldNames(), r.getFieldNames() ) && 143 ArrayUtil.arraysEqual( getEntries(), r.getEntries() ); 144 145 } 146 147 return equal; 148 } 149 150 151 } 152 153 154 155 156 157 | Popular Tags |