/*
* SoapUI, Copyright (C) 2004-2016 SmartBear Software
*
* Licensed under the EUPL, Version 1.1 or - as soon as they will be approved by the European Commission - subsequent
* versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the Licence for the specific language governing permissions and limitations
* under the Licence.
*/
package com.eviware.soapui.impl.support.components;
import com.eviware.soapui.SoapUI;
import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlRequest;
import com.eviware.soapui.impl.wsdl.submit.transports.http.DocumentContent;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
import com.eviware.soapui.support.editor.xml.support.AbstractXmlDocument;
import org.apache.xmlbeans.SchemaTypeSystem;
import org.apache.xmlbeans.XmlBeans;
import javax.annotation.Nonnull;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
/**
* XmlDocument for a WsdlRequest
*
* @author ole.matzura
*/
public class RequestXmlDocument extends AbstractXmlDocument implements PropertyChangeListener {
private final WsdlRequest request;
private boolean updating;
public RequestXmlDocument(WsdlRequest request) {
this.request = request;
request.addPropertyChangeListener(WsdlRequest.REQUEST_PROPERTY, this);
}
@Override
public void setDocumentContent(DocumentContent documentContent) {
if (!updating) {
updating = true;
request.setRequestContent(documentContent.getContentAsString());
fireContentChanged();
updating = false;
}
}
public void propertyChange(PropertyChangeEvent evt) {
if (!updating) {
updating = true;
fireContentChanged();
updating = false;
}
}
public SchemaTypeSystem getTypeSystem() {
WsdlInterface iface = request.getOperation().getInterface();
WsdlContext wsdlContext = iface.getWsdlContext();
try {
return wsdlContext.getSchemaTypeSystem();
} catch (Exception e1) {
SoapUI.logError(e1);
return XmlBeans.getBuiltinTypeSystem();
}
}
public void release() {
request.removePropertyChangeListener(WsdlRequest.REQUEST_PROPERTY, this);
}
@Nonnull
@Override
public DocumentContent getDocumentContent(Format format) {
return new DocumentContent(null, request.getRequestContent());
}
}