1 package com.quikj.server.framework; 2 3 import java.util.*; 4 5 import org.w3c.dom.*; 7 8 public class AceTraceInfoMessage implements AceLogMessageInterface 9 { 10 public static final String ATT_LOG_GROUP = "log_group"; 11 public static final String EL_TRACE_INFO = "trace_information"; 12 public static final String ATT_TRACE_ID = "id"; 13 public static final String EL_TRACE_CONSTRAINT = "trace_constraint"; 14 public static final String ATT_CONSTRAINT = "constraint"; 15 16 public AceTraceInfoMessage(int group, Hashtable trace_info) 18 { 19 formattedMessage = new StringBuffer ("<?xml version=\"1.0\" encoding=\"us-ascii\"?>" 20 + '\n' 21 + "<" 22 + AceLogMessageParser.TRACE_INFO_MESSAGE 23 + " " 24 + ATT_LOG_GROUP 25 + "=\"" + group + "\">" 26 + '\n'); 27 28 Enumeration keys = trace_info.keys(); 30 Enumeration constraint_list = trace_info.elements(); 31 32 while (keys.hasMoreElements() == true) 33 { 34 int id = ((Integer )(keys.nextElement())).intValue(); 35 String [] constraints = (String [])(constraint_list.nextElement()); 36 37 formattedMessage.append("<" + EL_TRACE_INFO 38 + " " + ATT_TRACE_ID + "=\"" + id + "\">" 39 + '\n'); 40 41 for (int i = 0; i < constraints.length; i++) 42 { 43 formattedMessage.append("<" + EL_TRACE_CONSTRAINT 44 + " " + ATT_CONSTRAINT + "=\"" + constraints[i] + "\"/>" 45 + '\n'); 46 } 47 48 formattedMessage.append("</" + EL_TRACE_INFO + ">" 49 + '\n'); 50 } 51 52 formattedMessage.append("</" 54 + AceLogMessageParser.TRACE_INFO_MESSAGE 55 + ">" 56 + '\n'); 57 } 58 59 public AceTraceInfoMessage(int group_mask, Node node) 61 throws AceException 62 { 63 String group_s = AceXMLHelper.getXMLAttribute(node, ATT_LOG_GROUP); 64 65 int msg_group; 66 try 67 { 68 msg_group = Integer.parseInt(group_s); 69 } 70 catch (NumberFormatException ex) 71 { 72 throw new AceException("The group is not an integer number (" 73 + group_s 74 + ")"); 75 76 } 77 78 79 if ((group_mask & msg_group) <= 0) { 81 return; 82 } 83 84 groupMatch = true; 85 86 controlInfo = new Hashtable(); 88 89 for (Node trace_info = node.getFirstChild(); 90 trace_info != null; 91 trace_info = trace_info.getNextSibling()) 92 { 93 if (trace_info.getNodeType() == Node.ELEMENT_NODE) 95 { 96 processTraceElement(trace_info); 97 } 98 } 99 } 100 101 public boolean groupMatch() 102 { 103 return groupMatch; 104 } 105 106 public String messageType() 107 { 108 return AceLogMessageParser.TRACE_INFO_MESSAGE; 109 } 110 111 public Hashtable getTraceInformation() 112 { 113 if (controlInfo == null) return null; 114 115 return controlInfo; 116 } 117 118 public String getFormattedMessage() 119 { 120 if (formattedMessage == null) return null; 121 122 return formattedMessage.toString(); 123 } 124 125 private void processTraceElement(Node trace_info) 126 throws AceException 127 { 128 String id_str = AceXMLHelper.processXMLElement(trace_info, 129 EL_TRACE_INFO, 130 ATT_TRACE_ID); 131 if (id_str == null) { 133 throw new AceException("Trace id is missing"); 134 } 135 136 int trace_id = 0; 137 try 138 { 139 trace_id = Integer.parseInt(id_str); 140 } 141 catch (NumberFormatException ex1) 142 { 143 throw new AceException("Trace id " 145 + id_str 146 + " is not an integer value"); 147 } 148 149 Vector constraints = new Vector(); 150 for (Node constraint_info = trace_info.getFirstChild(); 151 constraint_info != null; 152 constraint_info = constraint_info.getNextSibling()) 153 { 154 if (constraint_info.getNodeType() == Node.ELEMENT_NODE) 155 { 156 String constraint; 157 constraint = processConstraintElement(constraint_info); 158 if (constraint == null) 159 { 160 throw new AceException("Invalid constraint specification"); 161 } 162 constraints.addElement(constraint); 163 } 164 } 165 166 String [] cons_list = new String [constraints.size()]; 168 169 for (int i = 0; i < cons_list.length; i++) 170 { 171 cons_list[i] = (String )constraints.elementAt(i); 172 } 173 174 controlInfo.put(new Integer (trace_id), cons_list); 175 } 176 177 private String processConstraintElement(Node constraint_info) 178 throws AceException 179 { 180 return AceXMLHelper.processXMLElement(constraint_info, 181 EL_TRACE_CONSTRAINT, 182 ATT_CONSTRAINT); 183 } 184 185 private boolean groupMatch = false; 186 private Hashtable controlInfo = new Hashtable(); 187 private StringBuffer formattedMessage = null; 188 } 189 190 191 192 193 194 195 196 197 198 199 | Popular Tags |