1 16 17 package org.apache.ws.jaxme.pm.ino; 18 19 import org.xml.sax.Attributes ; 20 import org.xml.sax.ContentHandler ; 21 import org.xml.sax.Locator ; 22 import org.xml.sax.SAXException ; 23 24 25 29 public class InoResponseHandler implements ContentHandler { 30 33 public static final String INO_RESPONSE2_URI = 34 "http://namespaces.softwareag.com/tamino/response2"; 35 38 public static final String XQL_URI = "http://metalab.unc.edu/xql/"; 39 40 41 private boolean inInoMessage = false; 42 private boolean inInoMessageText; 43 private boolean inXqlResult; 44 private int level; 45 private String inoErrorCode; 46 private StringBuffer inoErrorMessage; 47 private Locator locator; 48 private ContentHandler resultHandler; 49 50 51 public InoResponseHandler() {} 52 53 public void setDocumentLocator(Locator l) { 54 locator = l; 55 } 56 57 61 public Locator getDocumentLocator() { 62 return locator; 63 } 64 65 public void startDocument() throws org.xml.sax.SAXException { 66 inInoMessage = false; 67 inInoMessageText = false; 68 inXqlResult = false; 69 level = 0; 70 if (inoObjectIdList != null) { 71 inoObjectIdList.clear(); 72 } 73 } 74 75 public void endDocument() throws org.xml.sax.SAXException { 76 } 77 78 public void startElement(String namespaceUri, String localName, 79 String qName, Attributes attr) throws SAXException { 80 if (inXqlResult) { 81 if (resultHandler != null) { 82 if (level == 2) { 83 resultHandler.startDocument(); 84 } 85 resultHandler.startElement(namespaceUri, localName, qName, attr); 86 } 87 } else if (inInoMessage) { 88 if (level == 2) { 89 if (INO_RESPONSE2_URI.equals(namespaceUri) && 90 "messagetext".equals(localName)) { 91 String c = attr.getValue(INO_RESPONSE2_URI, "code"); 92 if (c != null) { 93 inoErrorCode = c; 94 } 95 inInoMessageText = true; 96 } 97 } 98 } else if (level == 1) { 99 if (XQL_URI.equals(namespaceUri) && "result".equals(localName)) { 100 inXqlResult = true; 101 } else if (INO_RESPONSE2_URI.equals(namespaceUri)) { 102 if ("message".equals(localName)) { 103 String retval = attr.getValue(INO_RESPONSE2_URI, "returnvalue"); 104 if (retval == null || !retval.equals("0")) { 105 inoErrorCode = retval; 106 inoErrorMessage = new StringBuffer (); 107 inInoMessage = true; 108 } 109 } else if (inoObjectIdList != null && "object".equals(localName)) { 110 inoObjectIdList.add(attr.getValue(INO_RESPONSE2_URI, "id")); 111 } 112 } 113 } 114 ++level; 115 } 116 117 public void endElement(String namespaceUri, String localName, 118 String qName) throws SAXException { 119 level--; 120 if (inXqlResult) { 121 if (level == 1) { 122 inXqlResult = false; 123 } else { 124 if (resultHandler != null) { 125 resultHandler.endElement(namespaceUri, localName, qName); 126 if (level == 2) { 127 resultHandler.endDocument(); 128 } 129 } 130 } 131 } else if (inInoMessage) { 132 if (level == 1) { 133 if (inoErrorCode == null) { 134 inoErrorCode = "INOUNKNOWN"; 135 } 136 throw new InoException(inoErrorCode, inoErrorMessage.toString()); 137 } else if (level == 2) { 138 if (inInoMessageText) { 139 inInoMessageText = false; 140 } 141 } 142 } 143 } 144 145 public void startPrefixMapping(String namespaceUri, 146 String prefix) throws SAXException { 147 if (inXqlResult) { 148 if (resultHandler != null) { 149 resultHandler.startPrefixMapping(namespaceUri, prefix); 150 } 151 } 152 } 153 154 public void endPrefixMapping(String prefix) throws SAXException { 155 if (inXqlResult) { 156 if (resultHandler != null) { 157 resultHandler.endPrefixMapping(prefix); 158 } 159 } 160 } 161 162 public void ignorableWhitespace(char[] ch, int start, int len) throws SAXException { 163 if (inXqlResult) { 164 if (resultHandler != null) { 165 resultHandler.ignorableWhitespace(ch, start, len); 166 } 167 } 168 } 169 170 public void skippedEntity(String entity) throws SAXException { 171 if (inXqlResult) { 172 if (resultHandler != null) { 173 resultHandler.skippedEntity(entity); 174 } 175 } 176 } 177 178 public void processingInstruction(String target, String data) throws SAXException { 179 if (inXqlResult) { 180 if (resultHandler != null) { 181 resultHandler.processingInstruction(target, data); 182 } 183 } 184 } 185 186 public void characters(char[] ch, int start, int len) throws SAXException { 187 if (inXqlResult) { 188 if (resultHandler != null) { 189 resultHandler.characters(ch, start, len); 190 } 191 } else if (inInoMessageText) { 192 inoErrorMessage.append(ch, start, len); 193 } 194 } 195 196 208 public void setResultHandler(ContentHandler handler) { 209 resultHandler = handler; 210 } 211 212 225 public ContentHandler getResultHandler() { 226 return resultHandler; 227 } 228 229 private java.util.List inoObjectIdList; 230 242 public void setInoObjectIdList(java.util.List pList) { 243 inoObjectIdList = pList; 244 } 245 249 public java.util.List getInoObjectIdList() { return inoObjectIdList; } 250 } 251 | Popular Tags |