1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 package org.coach.tracing.server; 26 27 import java.util.*; 28 import org.coach.idltree.*; 29 import org.coach.tracing.api.*; 30 31 public class DbToXml 32 { 33 private EventDataBase db; 34 35 public DbToXml(EventDataBase db) 36 { 37 this.db = db; 38 } 39 40 public String getXmlEventAt(long index) 41 { 42 EventRecord tr = null; 43 44 tr = db.getEventAt(index); 45 46 return tr.toXml(db); 47 } 48 49 public String getXmlEvent(long key_id) 50 { 51 EventRecord tr = null; 52 53 tr = db.readEvent(key_id); 54 55 return tr.toXml(db); 56 } 57 58 public String getXmlEvents(long index, int len, Hashtable operation_filter, Hashtable entity_filter, Hashtable toself_filter, String filter_unmatched, long hide_to) 59 { 60 EventRecord[] er = null; 61 EventRecord ser = null; 62 StringBuffer sb = new StringBuffer (); 63 int cnt = 0; 64 int visibles = 0; 65 long offset = 0; 66 67 sb.append ("<trace_events>\n"); 68 69 71 index += hide_to; 72 73 er = db.getEvents(index, index + len); 74 75 while ( visibles < len ) 76 { 77 try 78 { 79 if ( cnt == len ) 80 { 81 index += len; 82 83 er = db.getEvents(index, index + len); 84 85 cnt = 0; 86 } 87 88 ser = er[cnt++]; 89 90 long link_key = ser.getTraceRecord().linkKey; 91 92 94 if ( filter_unmatched.equals("false") || link_key != -1 ) 95 { 96 98 if (!operation_filter.containsKey (ser.getTraceRecord().op_name) ) 99 { 100 102 String identity_key = Long.toString(ser.getTraceRecord().identityKey); 103 104 EventRecord peer = null; 105 106 if ( link_key != -1 ) 107 { 108 peer = db.readEvent(link_key); 109 110 String peer_identity_key = Long.toString(peer.getTraceRecord().identityKey); 111 112 if ( !entity_filter.containsKey(identity_key) && !entity_filter.containsKey(peer_identity_key) ) 113 { 114 116 if ( toself_filter.containsKey (identity_key) && toself_filter.containsKey(peer_identity_key) ) 117 { 118 121 122 if ( !((String )toself_filter.get(identity_key)).equals((String )toself_filter.get(peer_identity_key)) ) 123 { 124 sb.append (ser.toXml(db)); 125 visibles++; 126 127 if ( visibles == 1 ) 128 offset = ser.getCurrentIndex(); 129 } 130 else 131 cnt++; } 133 else 134 { 135 sb.append (ser.toXml(db)); 136 visibles++; 137 138 if ( visibles == 1 ) 139 offset = ser.getCurrentIndex(); 140 } 141 } 142 else 143 cnt++; } 145 else 146 { 147 149 if ( !entity_filter.containsKey(identity_key) ) 150 { 151 sb.append (ser.toXml(db)); 152 153 visibles++; 154 155 if ( visibles == 1 ) 156 offset = ser.getCurrentIndex(); 157 } 158 } 159 } 160 else if ( link_key != -1 ) 161 cnt++; } 163 } 164 catch (Exception _ex) 165 { 166 break; 167 } 168 } 169 170 sb.append ("<count>" + Long.toString(db.getEventCount() - hide_to ) + "</count>\n"); 171 sb.append ("<offset>" + Long.toString(offset) + "</offset>\n"); 172 173 sb.append ("</trace_events>\n"); 174 175 return sb.toString(); 176 } 177 178 public String getXmlIdentities(long[] keys) throws org.coach.tracing.api.InvalidKey 179 { 180 StringBuffer sb = new StringBuffer (); 181 182 sb.append ("<trace_entities>\n"); 183 184 for (int i = 0; i < keys.length; i++) 185 { 186 try 187 { 188 sb.append ("<entity id='" + keys[i] + "'>\n"); 189 sb.append (" <identityHierarchy>\n"); 190 191 Identity id = null; 192 193 long identityKey = keys[i]; 194 195 while(identityKey != -1) 196 { 197 try 198 { 199 id = db.getIdentity(new Long (identityKey)); 200 201 if ( id == null ) 202 break; 203 204 sb.append (" <" + EventRecord.getIdentityKindName(id.kind) + " name='" + id.name + "' type='" + id.type + "'/>\n"); 205 } 206 catch (Exception _ex) 207 { 208 break; 209 } 210 211 identityKey = id.linkKey; 212 } 213 214 sb.append (" </identityHierarchy>\n"); 215 216 sb.append ("</entity>\n"); 217 } 218 catch (Exception _ex) 219 { 220 break; 221 } 222 } 223 224 sb.append ("</trace_entities>\n"); 225 226 return sb.toString(); 227 } 228 229 public String getXmlParameterValues(long parameterKey) 230 { 231 IdlNode idlNode = db.readValue(parameterKey); 232 233 if (idlNode == null) 234 { 235 237 XmlWriter w = new XmlWriter(); 238 239 return w.toString(); 240 } 241 242 XmlWriter w = new XmlWriter(); 243 244 XmlNode.write(idlNode, w); 245 246 return w.toString(); 247 } 248 } 249 250 | Popular Tags |