| 1 16 17 package org.apache.axis2.deployment; 18 19 import org.apache.axis2.deployment.util.DeploymentData; 20 import org.apache.axis2.description.*; 21 import org.apache.axis2.engine.AxisConfigurationImpl; 22 import org.apache.axis2.engine.AxisFault; 23 import org.apache.axis2.engine.MessageReceiver; 24 import org.apache.axis2.transport.TransportListener; 25 import org.apache.axis2.transport.TransportSender; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import javax.xml.namespace.QName ; 30 import javax.xml.stream.XMLInputFactory; 31 import javax.xml.stream.XMLStreamConstants; 32 import javax.xml.stream.XMLStreamException; 33 import javax.xml.stream.XMLStreamReader; 34 import java.io.InputStream ; 35 import java.util.ArrayList ; 36 37 46 public class DeploymentParser implements DeploymentConstants { 47 48 private Log log = LogFactory.getLog(getClass()); 49 private static final String MODULEXMLST = "module"; 51 private static final String SERVICEXMLST = "service"; 53 54 private XMLStreamReader pullparser; 55 56 59 private DeploymentEngine dpengine; 60 61 67 public DeploymentParser(InputStream inputStream, DeploymentEngine engine) 68 throws XMLStreamException { 69 this.dpengine = engine; 70 pullparser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream); 71 } 72 73 public void parseServiceXML(ServiceDescription axisService) throws DeploymentException { 74 boolean END_DOCUMENT = false; 76 try { 78 while (!END_DOCUMENT) { 79 int eventType = pullparser.next(); 80 if (eventType == XMLStreamConstants.END_DOCUMENT) { 81 END_DOCUMENT = true; 82 } else if (eventType == XMLStreamConstants.START_ELEMENT) { 83 String ST = pullparser.getLocalName(); 84 if (ST.equals(SERVICEXMLST)) { 85 procesServiceXML(axisService); 86 } 87 break; 88 } 89 } 90 } catch (XMLStreamException e) { 91 throw new DeploymentException("parser Exception", e); 92 } 93 } 94 95 98 public void processGlobalConfig(AxisConfigurationImpl axisGlobal, String starttag) 99 throws DeploymentException { 100 String START_TAG = starttag; 101 try { 102 boolean END_DOCUMENT = false; 103 while (!END_DOCUMENT) { 104 int eventType = pullparser.next(); 105 if (eventType == XMLStreamConstants.END_DOCUMENT) { 106 END_DOCUMENT = true; 108 break; 109 } else if (eventType == XMLStreamConstants.START_ELEMENT) { 110 String ST = pullparser.getLocalName(); if (START_TAG.equals(ST)) { 112 } else if (PARAMETERST.equals(ST)) { 114 Parameter parameter = processParameter(); 115 axisGlobal.addParameter(parameter); 116 } else if (TRANSPORTSENDER.equals(ST)) { 117 TransportOutDescription transportout = proccessTrasnsportOUT(); 118 dpengine.getAxisConfig().addTransportOut(transportout); 119 } else if (TRANSPORTRECEIVER.equals(ST)) { 120 TransportInDescription transportin = proccessTrasnsportIN(); 121 dpengine.getAxisConfig().addTransportIn(transportin); 122 } else if (TYPEMAPPINGST.equals(ST)) { 123 throw new UnsupportedOperationException ("Type Mappings are not allowed in axis2.xml"); 124 } else if (MESSAGERECEIVER.equals(ST)) { 125 int attribCount = pullparser.getAttributeCount(); 126 if (attribCount == 2) { 127 String attname = pullparser.getAttributeLocalName(0); 128 String attvalue = pullparser.getAttributeValue(0); 129 if (MEP.equals(attname)) { 130 String name = attvalue; 131 attname = pullparser.getAttributeLocalName(1); 132 attvalue = pullparser.getAttributeValue(1); 133 if (CLASSNAME.equals(attname)) { 134 try { 135 Class messageReceiver = null; 136 ClassLoader loader1 = 137 Thread.currentThread().getContextClassLoader(); 138 if (attvalue != null && !"".equals(attvalue)) { 139 messageReceiver = 140 Class.forName(attvalue, true, loader1); 141 axisGlobal.addMessageReceiver( 142 name, 143 (MessageReceiver) messageReceiver.newInstance()); 144 } 145 } catch (ClassNotFoundException e) { 146 throw new DeploymentException( 147 "Error in loading messageRecivers " , e); 148 } catch (IllegalAccessException e) { 149 throw new DeploymentException( 150 "Error in loading messageRecivers " , e); 151 } catch (InstantiationException e) { 152 throw new DeploymentException( 153 "Error in loading messageRecivers " , e); 154 } 155 } else 156 throw new UnsupportedOperationException ( 157 "invalid attributes in axis2.xml (messageReceiver elemet) " 158 + attname); 159 } else 160 throw new UnsupportedOperationException ( 161 "invalid attributes in axis2.xml (messageReceiver elemet) " 162 + attname); 163 } else 164 throw new UnsupportedOperationException ("invalid attributes in axis2.xml (messageReceiver elemet)"); 165 166 } else if (MODULEST.equals(ST)) { 167 int attribCount = pullparser.getAttributeCount(); 168 if (attribCount > 0) { 169 for (int i = 0; i < attribCount; i++) { 170 String attname = pullparser.getAttributeLocalName(i); 171 String attvalue = pullparser.getAttributeValue(i); 172 if (REF.equals(attname)) { 173 DeploymentData.getInstance().addModule(new QName (attvalue)); 174 } 175 } 176 } 177 } else if (PHASE_ORDER.equals(ST)) { 178 int attribCount = pullparser.getAttributeCount(); 179 DeploymentData tempdata = DeploymentData.getInstance(); 180 if (attribCount > 0) { 181 for (int i = 0; i < attribCount; i++) { 182 String attname = pullparser.getAttributeLocalName(i); 183 String attvalue = pullparser.getAttributeValue(i); 184 if (TYPE.equals(attname)) { 185 if (INFLOWST.equals(attvalue)) { 186 tempdata.setINPhases(processPhaseOrder()); 187 } else if (OUTFLOWST.equals(attvalue)) { 188 tempdata.setOUTPhases(processPhaseOrder()); 189 } else if (IN_FAILTFLOW.equals(attvalue)) { 190 tempdata.setIN_FaultPhases(processPhaseOrder()); 191 } else if (OUT_FAILTFLOW.equals(attvalue)) { 192 tempdata.setOUT_FaultPhases(processPhaseOrder()); 193 } else { 194 throw new DeploymentException( 195 "un defined flow type " + ST); 196 } 197 } 198 } 199 } else { 200 throw new DeploymentException( 201 "Flow type is a required attribute in " + ST); 202 } 203 } else { 204 throw new UnsupportedOperationException ( 205 ST + " element is not allowed in the axis2.xml"); 206 } 207 } else if (eventType == XMLStreamConstants.END_ELEMENT) { 208 String endtagname = pullparser.getLocalName(); 209 if (START_TAG.equals(endtagname)) { 210 END_DOCUMENT = true; 211 break; 212 } 213 } 214 } 215 } catch (XMLStreamException e) { 216 throw new DeploymentException("parser Exception", e); 217 } catch (AxisFault e) { 218 throw new DeploymentException(e); 219 } 220 } 221 222 public TransportInDescription proccessTrasnsportIN() throws DeploymentException { 223 TransportInDescription transportin = null; 224 String attname = pullparser.getAttributeLocalName(0); 225 String attvalue = pullparser.getAttributeValue(0); 226 227 int attribCount = pullparser.getAttributeCount(); 228 for (int i = 0; i < attribCount; i++) { 229 attname = pullparser.getAttributeLocalName(i); 230 attvalue = pullparser.getAttributeValue(i); 231 if (ATTNAME.equals(attname)) { 232 transportin = new TransportInDescription(new QName (attvalue)); 233 } else if (transportin != null && CLASSNAME.equals(attname)) { 234 Class reciever = null; 235 try { 236 reciever = 237 Class.forName( 238 attvalue, 239 true, 240 Thread.currentThread().getContextClassLoader()); 241 TransportListener trnsrecievr = (TransportListener) reciever.newInstance(); 242 transportin.setReciver(trnsrecievr); 243 } catch (ClassNotFoundException e) { 244 throw new DeploymentException(e); 245 } catch (IllegalAccessException e) { 246 throw new DeploymentException(e); 247 } catch (InstantiationException e) { 248 throw new DeploymentException(e); 249 } 250 } 251 } 252 boolean END_TRANSPORTS = false; 253 try { 254 while (!END_TRANSPORTS) { 255 int eventType = pullparser.next(); 256 if (eventType == XMLStreamConstants.END_DOCUMENT) { 257 END_TRANSPORTS = true; 258 } else if (eventType == XMLStreamConstants.START_ELEMENT) { 259 String tagnae = pullparser.getLocalName(); 260 if (transportin != null && PARAMETERST.equals(tagnae)) { 261 Parameter parameter = processParameter(); 262 transportin.addParameter(parameter); 263 } else if (transportin != null && INFLOWST.equals(tagnae)) { 264 Flow inFlow = processInFlow(); 265 transportin.setInFlow(inFlow); 266 } else if (transportin != null && OUTFLOWST.equals(tagnae)) { 267 throw new DeploymentException( 268 "OUTFlow dose not support in AxisTransportIN " + tagnae); 269 } else if (transportin != null && IN_FAILTFLOW.equals(tagnae)) { 270 Flow faultFlow = processInFaultFlow(); 271 transportin.setFaultFlow(faultFlow); 272 } else { 273 throw new DeploymentException("Unknown element " + tagnae); 274 } 275 } else if (eventType == XMLStreamConstants.END_ELEMENT) { 276 String endtagname = pullparser.getLocalName(); 277 if (TRANSPORTRECEIVER.equals(endtagname)) { 278 END_TRANSPORTS = true; 279 break; 280 } 281 } 282 } 283 } catch (XMLStreamException e) { 284 throw new DeploymentException("parser Exception", e); 285 } catch (Exception e) { 286 throw new DeploymentException(e); 287 } 288 return transportin; 289 } 290 291 public TransportOutDescription proccessTrasnsportOUT() throws DeploymentException { 292 TransportOutDescription transportout = null; 293 String attname; 294 String attvalue; 295 int attribCount = pullparser.getAttributeCount(); 296 for (int i = 0; i < attribCount; i++) { 297 attname = pullparser.getAttributeLocalName(i); 298 attvalue = pullparser.getAttributeValue(i); 299 if (ATTNAME.equals(attname)) { 300 transportout = new TransportOutDescription(new QName (attvalue)); 301 } else if (transportout != null && CLASSNAME.equals(attname)) { 302 Class sender = null; 303 try { 304 sender = 305 Class.forName( 306 attvalue, 307 true, 308 Thread.currentThread().getContextClassLoader()); 309 TransportSender transportSender = (TransportSender) sender.newInstance(); 310 transportout.setSender(transportSender); 311 } catch (ClassNotFoundException e) { 312 throw new DeploymentException(e); 313 } catch (IllegalAccessException e) { 314 throw new DeploymentException(e); 315 } catch (InstantiationException e) { 316 throw new DeploymentException(e); 317 } 318 } 319 } 320 boolean END_TRANSPORTS = false; 321 try { 322 while (!END_TRANSPORTS) { 323 int eventType = pullparser.next(); 324 if (eventType == XMLStreamConstants.END_DOCUMENT) { 325 END_TRANSPORTS = true; 326 } else if (eventType == XMLStreamConstants.START_ELEMENT) { 327 String tagnae = pullparser.getLocalName(); 328 if (transportout != null && PARAMETERST.equals(tagnae)) { 329 Parameter parameter = processParameter(); 330 transportout.addParameter(parameter); 331 } else if (transportout != null && INFLOWST.equals(tagnae)) { 332 throw new DeploymentException( 333 "InFlow dose not support in TransportOutDescription " + tagnae); 334 } else if (transportout != null && OUTFLOWST.equals(tagnae)) { 335 Flow outFlow = processOutFlow(); 336 transportout.setOutFlow(outFlow); 337 } else if (transportout != null && OUT_FAILTFLOW.equals(tagnae)) { 338 Flow faultFlow = processOutFaultFlow(); 339 transportout.setFaultFlow(faultFlow); 340 } else { 341 throw new DeploymentException("Unknown element " + tagnae); 342 } 343 } else if (eventType == XMLStreamConstants.END_ELEMENT) { 344 String endtagname = pullparser.getLocalName(); 345 if (TRANSPORTSENDER.equals(endtagname)) { 346 END_TRANSPORTS = true; 347 break; 348 } 349 } 350 } 351 } catch (XMLStreamException e) { 352 throw new DeploymentException("parser Exception", e); 353 } catch (Exception e) { 354 throw new DeploymentException(e); 355 } 356 return transportout; 357 } 358 359 362 private void procesServiceXML(ServiceDescription axisService) throws DeploymentException { 363 int attribCount = pullparser.getAttributeCount(); 364 if (attribCount >= 1) { 365 for (int i = 0; i < attribCount; i++) { 366 String attname = pullparser.getAttributeLocalName(i); 367 String attvalue = pullparser.getAttributeValue(i); 368 if (ATQNAME.equals(attname)) { 369 if (attvalue == null || attvalue.trim().equals("")) { 370 axisService.setName( 371 new QName ( 372 getAxisServiceName( 373 dpengine.getCurrentFileItem().getServiceName()))); 374 } else { 375 axisService.setName(new QName (attvalue)); 376 } 377 } else { 378 throw new DeploymentException( 379 attname 380 + " Bad arguments for the service" 381 + getAxisServiceName(dpengine.getCurrentFileItem().getServiceName())); 382 } 383 } 384 } else { 385 axisService.setName( 387 new QName (getAxisServiceName(dpengine.getCurrentFileItem().getServiceName()))); 388 } 389 boolean END_DOCUMENT = false; 390 try { 391 while (!END_DOCUMENT) { 392 int eventType = pullparser.next(); 393 if (eventType == XMLStreamConstants.END_DOCUMENT) { 394 END_DOCUMENT = true; 396 break; 397 } else if (eventType == XMLStreamConstants.START_ELEMENT) { 398 String ST = pullparser.getLocalName(); if (PARAMETERST.equals(ST)) { 400 Parameter parameter = processParameter(); 401 axisService.addParameter(parameter); 402 } else if (DESCRIPTION.equals(ST)) { 404 String desc = processDescription(); 405 axisService.setServiceDescription(desc); 406 } else if (TYPEMAPPINGST.equals(ST)) { 407 throw new UnsupportedOperationException ("Type mapping dose not implemented yet "); 408 } else if (BEANMAPPINGST.equals(ST)) { 410 throw new UnsupportedOperationException ("Bean mapping dose not implemented yet "); 411 } else if (OPRATIONST.equals(ST)) { 413 OperationDescription operation = processOperation(axisService); 414 DeploymentData.getInstance().setOperationPhases(operation); 415 if (operation.getMessageReciever() == null) { 416 try { 417 420 ClassLoader loader1 = 421 Thread.currentThread().getContextClassLoader(); 422 Class messageReceiver = 423 Class.forName( 424 "org.apache.axis2.receivers.RawXMLINOutMessageReceiver", 425 true, 426 loader1); 427 operation.setMessageReciever( 428 (MessageReceiver) messageReceiver.newInstance()); 429 } catch (ClassNotFoundException e) { 430 throw new DeploymentException( 431 "Error in loading messageRecivers " + e.getMessage()); 432 } catch (IllegalAccessException e) { 433 throw new DeploymentException( 434 "Error in loading messageRecivers " + e.getMessage()); 435 } catch (InstantiationException e) { 436 throw new DeploymentException( 437 "Error in loading messageRecivers " + e.getMessage()); 438 } 439 } 440 axisService.addOperation(operation); 441 } else if (INFLOWST.equals(ST)) { 442 Flow inFlow = processInFlow(); 443 axisService.setInFlow(inFlow); 444 } else if (OUTFLOWST.equals(ST)) { 445 Flow outFlow = processOutFlow(); 446 axisService.setOutFlow(outFlow); 447 } else if (IN_FAILTFLOW.equals(ST)) { 448 Flow faultFlow = processInFaultFlow(); 449 axisService.setFaultInFlow(faultFlow); 450 } else if (OUT_FAILTFLOW.equals(ST)) { 451 Flow faultFlow = processOutFaultFlow(); 452 axisService.setFaultOutFlow(faultFlow); 453 } else if (MODULEST.equals(ST)) { 454 attribCount = pullparser.getAttributeCount(); 455 if (attribCount > 0) { 456 for (int i = 0; i < attribCount; i++) { 457 String attname = pullparser.getAttributeLocalName(i); 458 String attvalue = pullparser.getAttributeValue(i); 459 if (REF.equals(attname)) { 460 if (dpengine.getModule(new QName (attvalue)) == null) { 461 throw new DeploymentException( 462 ST 463 + " module is invalid or dose not have bean deployed"); 464 } else { 465 dpengine.getCurrentFileItem().addModule( 466 new QName (attvalue)); 467 } 468 } 469 } 470 } 471 472 } else { 473 throw new DeploymentException( 474 "parser Exception : un supported element" + ST); 475 } 476 } 477 } 478 } catch (XMLStreamException e) { 479 throw new DeploymentException("parser Exception", e); 480 } catch (AxisFault axisFault) { 481 throw new DeploymentException(axisFault); 482 } 483 } 484 485 private String processDescription() throws DeploymentException { 486 String desc = ""; 487 boolean END_DESC = false; 488 try { 489 while (!END_DESC) { 490 int eventType = pullparser.next(); 491 if (eventType == XMLStreamConstants.END_DOCUMENT) { 492 END_DESC = true; 493 } else if (eventType == XMLStreamConstants.END_ELEMENT) { 494 String endtagname = pullparser.getLocalName(); 495 if (DESCRIPTION.equals(endtagname)) { 496 END_DESC = true; 497 break; 498 } 499 500 } else if (eventType == XMLStreamConstants.CHARACTERS) { 501 desc += pullparser.getText(); 502 } 503 } 504 } catch (XMLStreamException e) { 505 throw new DeploymentException("parser Exception", e); 506 } catch (Exception e) { 507 throw new DeploymentException(e); 508 } 509 return desc; 510 } 511 512 private Parameter processParameter() throws DeploymentException { 513 Parameter parameter = new ParameterImpl(); 514 int attribCount = pullparser.getAttributeCount(); 515 if (attribCount == 2) { for (int i = 0; i < attribCount; i++) { 517 String attname = pullparser.getAttributeLocalName(i); 518 String attvalue = pullparser.getAttributeValue(i); 519 if (ATTNAME.equals(attname)) { 520 parameter.setName(attvalue); 521 } else if (ATTLOCKED.equals(attname)) { 522 String boolval = getValue(attvalue); 523 if (boolval.equals("true")) { 524 parameter.setLocked(true); 525 &nb
|