View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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.support;
14  
15  import java.io.File;
16  import java.io.IOException;
17  
18  import com.eviware.soapui.config.AttachmentConfig;
19  import com.eviware.soapui.impl.support.AbstractHttpRequest;
20  import com.eviware.soapui.impl.support.AbstractHttpRequestInterface;
21  import com.eviware.soapui.impl.wsdl.WsdlAttachmentContainer;
22  
23  /***
24   * Attachment for a WsdlRequest
25   * 
26   * @author ole.matzura
27   */
28  
29  public class RequestFileAttachment extends FileAttachment<AbstractHttpRequest<?>>
30  {
31  	public RequestFileAttachment( AttachmentConfig config, AbstractHttpRequestInterface<?> request )
32  	{
33  		super( ( AbstractHttpRequest<?> )request, config );
34  	}
35  
36  	public RequestFileAttachment( File file, boolean cache, AbstractHttpRequest<?> request ) throws IOException
37  	{
38  		super( request, file, cache, request.getConfig().addNewAttachment() );
39  	}
40  
41  	public AttachmentEncoding getEncoding()
42  	{
43  		AbstractHttpRequestInterface<?> request = getModelItem();
44  		if( request instanceof WsdlAttachmentContainer && ( ( WsdlAttachmentContainer )request ).isEncodeAttachments() )
45  			return ( ( WsdlAttachmentContainer )request ).getAttachmentEncoding( getPart() );
46  		else
47  			return AttachmentEncoding.NONE;
48  	}
49  
50  	@Override
51  	public AttachmentType getAttachmentType()
52  	{
53  		if( getModelItem() == null || getPart() == null || getModelItem().getAttachmentPart( getPart() ) == null )
54  			return AttachmentType.UNKNOWN;
55  		else
56  			return getModelItem().getAttachmentPart( getPart() ).getAttachmentType();
57  	}
58  }