01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
11: */
12:
13: package com.eviware.soapui.impl.wsdl.panels.request.components;
14:
15: import java.beans.PropertyChangeEvent;
16: import java.beans.PropertyChangeListener;
17:
18: import org.apache.xmlbeans.SchemaTypeSystem;
19: import org.apache.xmlbeans.XmlBeans;
20:
21: import com.eviware.soapui.SoapUI;
22: import com.eviware.soapui.impl.wsdl.WsdlInterface;
23: import com.eviware.soapui.impl.wsdl.WsdlRequest;
24: import com.eviware.soapui.impl.wsdl.panels.request.components.editor.support.AbstractXmlDocument;
25: import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
26: import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
27: import com.eviware.soapui.model.iface.Response;
28:
29: /**
30: * XmlDocument for the response to a WsdlRequest
31: *
32: * @author ole.matzura
33: */
34:
35: public class ResponseXmlDocument extends AbstractXmlDocument implements
36: PropertyChangeListener {
37: private final WsdlRequest request;
38: private boolean settingResponse;
39:
40: public ResponseXmlDocument(WsdlRequest request) {
41: this .request = request;
42: request.addPropertyChangeListener(this );
43: }
44:
45: public String getXml() {
46: Response response = request.getResponse();
47: return response == null ? null : response.getContentAsString();
48: }
49:
50: public void setXml(String xml) {
51: WsdlResponse response = (WsdlResponse) request.getResponse();
52: if (response != null) {
53: try {
54: settingResponse = true;
55: response.setResponseContent(xml);
56: } finally {
57: settingResponse = false;
58: }
59: }
60: }
61:
62: public void propertyChange(PropertyChangeEvent evt) {
63: if (evt.getPropertyName().equals(WsdlRequest.RESPONSE_PROPERTY)
64: || (evt.getPropertyName().equals(
65: WsdlRequest.RESPONSE_CONTENT_PROPERTY) && !settingResponse)) {
66: Response oldResponse = (Response) evt.getOldValue();
67: Response newResponse = (Response) evt.getNewValue();
68:
69: fireXmlChanged(oldResponse == null ? null : oldResponse
70: .getContentAsString(), newResponse == null ? null
71: : newResponse.getContentAsString());
72: }
73: }
74:
75: public SchemaTypeSystem getTypeSystem() {
76: WsdlInterface iface = (WsdlInterface) request.getOperation()
77: .getInterface();
78: WsdlContext wsdlContext = iface.getWsdlContext();
79: try {
80: return wsdlContext.getSchemaTypeSystem();
81: } catch (Exception e1) {
82: SoapUI.logError(e1);
83: return XmlBeans.getBuiltinTypeSystem();
84: }
85: }
86:
87: public void release() {
88: request.removePropertyChangeListener(this);
89: }
90: }
|