1 28 29 package com.caucho.soap.wsdl; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.IntMap; 33 import com.caucho.util.L10N; 34 35 import org.xml.sax.Attributes ; 36 import org.xml.sax.SAXException ; 37 import org.xml.sax.helpers.DefaultHandler ; 38 39 import javax.xml.namespace.QName ; 40 import java.util.logging.Logger ; 41 42 45 public class WSDLContentHandler extends DefaultHandler { 46 private final static Logger log = Log.open(WSDLContentHandler.class); 47 private final static L10N L = new L10N(WSDLContentHandler.class); 48 49 private final static String WSDL = "http://schemas.xmlsoap.org/wsdl/"; 50 51 private final static int TOP = 0; 52 private final static int WSDL_DEFINITIONS = 1; 53 private final static int WSDL_IMPORT = 2; 54 private final static int WSDL_TYPES = 3; 55 private final static int WSDL_MESSAGE = 4; 56 private final static int WSDL_PORT_TYPE = 5; 57 private final static int WSDL_BINDING = 6; 58 private final static int WSDL_SERVICE = 7; 59 private final static int WSDL_PART = 8; 60 private final static int WSDL_OPERATION = 9; 61 private final static int WSDL_INPUT = 10; 62 private final static int WSDL_OUTPUT = 11; 63 private final static int WSDL_FAULT = 12; 64 private final static int WSDL_PORT = 13; 65 private final static int WSDL_BINDING_OPERATION = 14; 66 67 private final static IntMap _keywords = new IntMap(); 68 69 private int _state = TOP; 70 71 74 public void startElement (String uri, String localName, 75 String qName, Attributes attributes) 76 throws SAXException 77 { 78 QName qname = new QName (uri, localName); 79 80 switch (_state) { 81 case TOP: 82 switch (getKeyword(qname)) { 83 case WSDL_DEFINITIONS: 84 _state = WSDL_DEFINITIONS; 85 break; 86 87 default: 88 throw error(L.l("Expected <wsdl:descriptions> at <{0}>.", qName)); 89 } 90 break; 91 92 case WSDL_DEFINITIONS: 93 switch (getKeyword(qname)) { 94 case WSDL_IMPORT: 95 _state = WSDL_IMPORT; 96 break; 97 98 case WSDL_TYPES: 99 _state = WSDL_TYPES; 100 break; 101 102 case WSDL_MESSAGE: 103 _state = WSDL_MESSAGE; 104 break; 105 106 case WSDL_PORT_TYPE: 107 _state = WSDL_PORT_TYPE; 108 break; 109 110 case WSDL_BINDING: 111 _state = WSDL_BINDING; 112 break; 113 114 case WSDL_SERVICE: 115 _state = WSDL_SERVICE; 116 break; 117 118 default: 119 throw error(L.l("<{0}> is an unexpected tag.", qName)); 120 } 121 break; 122 123 case WSDL_MESSAGE: 124 switch (getKeyword(qname)) { 125 case WSDL_PART: 126 _state = WSDL_PART; 127 break; 128 129 default: 130 throw error(L.l("<{0}> is an unexpected tag.", qName)); 131 } 132 break; 133 134 case WSDL_PORT_TYPE: 135 switch (getKeyword(qname)) { 136 case WSDL_OPERATION: 137 _state = WSDL_OPERATION; 138 break; 139 140 default: 141 throw error(L.l("<{0}> is an unexpected tag.", qName)); 142 } 143 break; 144 145 case WSDL_BINDING: 146 switch (getKeyword(qname)) { 147 case WSDL_OPERATION: 148 _state = WSDL_BINDING_OPERATION; 149 break; 150 151 default: 152 throw error(L.l("<{0}> is an unexpected tag.", qName)); 153 } 154 break; 155 156 case WSDL_SERVICE: 157 switch (getKeyword(qname)) { 158 case WSDL_PORT: 159 _state = WSDL_PORT; 160 break; 161 162 default: 163 throw error(L.l("<{0}> is an unexpected tag.", qName)); 164 } 165 break; 166 167 default: 168 throw error(L.l("<{0}> is an unexpected tag.", qName)); 169 } 170 } 171 172 175 public void endElement (String uri, String localName, String qName) 176 throws SAXException 177 { 178 QName qname = new QName (uri, localName); 179 180 switch (_state) { 181 case WSDL_DEFINITIONS: 182 if (getKeyword(qname) == WSDL_DEFINITIONS) 183 _state = TOP; 184 else 185 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 186 break; 187 188 case WSDL_IMPORT: 189 if (getKeyword(qname) == WSDL_IMPORT) 190 _state = WSDL_DEFINITIONS; 191 else 192 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 193 break; 194 195 case WSDL_TYPES: 196 if (getKeyword(qname) == WSDL_TYPES) 197 _state = WSDL_DEFINITIONS; 198 else 199 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 200 break; 201 202 case WSDL_MESSAGE: 203 if (getKeyword(qname) == WSDL_MESSAGE) 204 _state = WSDL_DEFINITIONS; 205 else 206 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 207 break; 208 209 case WSDL_PORT_TYPE: 210 if (getKeyword(qname) == WSDL_PORT_TYPE) 211 _state = WSDL_DEFINITIONS; 212 else 213 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 214 break; 215 216 case WSDL_BINDING: 217 if (getKeyword(qname) == WSDL_BINDING) 218 _state = WSDL_DEFINITIONS; 219 else 220 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 221 break; 222 223 case WSDL_SERVICE: 224 if (getKeyword(qname) == WSDL_SERVICE) 225 _state = WSDL_DEFINITIONS; 226 else 227 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 228 break; 229 230 case WSDL_PART: 231 if (getKeyword(qname) == WSDL_PART) 232 _state = WSDL_MESSAGE; 233 else 234 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 235 break; 236 237 case WSDL_OPERATION: 238 if (getKeyword(qname) == WSDL_OPERATION) 239 _state = WSDL_PORT_TYPE; 240 else 241 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 242 break; 243 244 case WSDL_INPUT: 245 if (getKeyword(qname) == WSDL_INPUT) 246 _state = WSDL_OPERATION; 247 else 248 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 249 break; 250 251 case WSDL_OUTPUT: 252 if (getKeyword(qname) == WSDL_OUTPUT) 253 _state = WSDL_OPERATION; 254 else 255 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 256 break; 257 258 case WSDL_FAULT: 259 if (getKeyword(qname) == WSDL_FAULT) 260 _state = WSDL_OPERATION; 261 else 262 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 263 break; 264 265 case WSDL_PORT: 266 if (getKeyword(qname) == WSDL_PORT) 267 _state = WSDL_SERVICE; 268 else 269 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 270 break; 271 272 case WSDL_BINDING_OPERATION: 273 if (getKeyword(qname) == WSDL_OPERATION) 274 _state = WSDL_BINDING; 275 else 276 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 277 break; 278 279 default: 280 throw error(L.l("</{0}> is an unexpected end tag.", qName)); 281 } 282 } 283 284 287 private int getKeyword(QName qname) 288 { 289 return _keywords.get(qname); 290 } 291 292 295 private SAXException error(String msg) 296 { 297 return new SAXException (msg); 298 } 299 300 static { 301 _keywords.put(new QName (WSDL, "descriptions"), WSDL_DEFINITIONS); 302 _keywords.put(new QName (WSDL, "import"), WSDL_IMPORT); 303 _keywords.put(new QName (WSDL, "types"), WSDL_TYPES); 304 _keywords.put(new QName (WSDL, "message"), WSDL_MESSAGE); 305 _keywords.put(new QName (WSDL, "portType"), WSDL_PORT_TYPE); 306 _keywords.put(new QName (WSDL, "binding"), WSDL_BINDING); 307 _keywords.put(new QName (WSDL, "service"), WSDL_SERVICE); 308 _keywords.put(new QName (WSDL, "part"), WSDL_PART); 309 _keywords.put(new QName (WSDL, "operation"), WSDL_OPERATION); 310 _keywords.put(new QName (WSDL, "input"), WSDL_INPUT); 311 _keywords.put(new QName (WSDL, "output"), WSDL_OUTPUT); 312 _keywords.put(new QName (WSDL, "fault"), WSDL_FAULT); 313 _keywords.put(new QName (WSDL, "port"), WSDL_PORT); 314 } 315 } 316 | Popular Tags |