View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  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.submit;
14  
15  import java.util.ArrayList;
16  import java.util.List;
17  
18  import com.eviware.soapui.impl.wsdl.WsdlOperation;
19  import com.eviware.soapui.model.iface.Attachment;
20  import com.eviware.soapui.model.iface.MessageExchange;
21  import com.eviware.soapui.support.types.StringToStringMap;
22  
23  /***
24   * MessageExchange for WSDL-based exchanges
25   * 
26   * @author ole.matzura
27   */
28  
29  public abstract class WsdlMessageExchange implements MessageExchange
30  {
31  	private StringToStringMap properties;
32  	private String[] messages;
33  
34  	public void addProperty( String name, String value )
35  	{
36  		if( properties == null )
37  			properties = new StringToStringMap();
38  		
39  		properties.put( name, value );
40  	}
41  	
42  	public StringToStringMap getProperties()
43  	{
44  		return properties;
45  	}
46  	
47  	public boolean hasResponse()
48  	{
49  		String responseContent = getResponseContent();
50  		return responseContent != null && responseContent.trim().length() > 0;
51  	}
52  	
53  	public abstract WsdlOperation getOperation();
54  
55  	public Attachment[] getResponseAttachmentsForPart( String name )
56  	{
57  		List<Attachment> result = new ArrayList<Attachment>();
58  		
59  		for( Attachment attachment : getResponseAttachments() )
60  		{
61  			if( attachment.getPart().equals( name ))
62  				result.add( attachment );
63  		}
64  		
65  		return result.toArray( new Attachment[result.size()] );
66  	}
67  	
68  	public Attachment[] getRequestAttachmentsForPart( String name )
69  	{
70  		List<Attachment> result = new ArrayList<Attachment>();
71  		
72  		for( Attachment attachment : getRequestAttachments() )
73  		{
74  			if( attachment.getPart().equals( name ))
75  				result.add( attachment );
76  		}
77  		
78  		return result.toArray( new Attachment[result.size()] );
79  	}
80  
81  	public boolean hasRequest( boolean ignoreEmpty )
82  	{
83  		String requestContent = getRequestContent();
84  		return !(requestContent == null || (ignoreEmpty && requestContent.trim().length() == 0 ));
85  	}
86  
87  	public String[] getMessages()
88  	{
89  		return messages;
90  	}
91  
92  	public void setMessages( String[] messages )
93  	{
94  		this.messages = messages;
95  	}
96  }