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.support.editor.inspectors.httpheaders;
14  
15  import java.beans.PropertyChangeEvent;
16  import java.beans.PropertyChangeListener;
17  import java.beans.PropertyChangeSupport;
18  
19  import org.apache.commons.lang.NotImplementedException;
20  
21  import com.eviware.soapui.model.ModelItem;
22  import com.eviware.soapui.support.editor.inspectors.AbstractXmlInspector;
23  import com.eviware.soapui.support.types.StringToStringsMap;
24  
25  public interface HttpHeadersInspectorModel
26  {
27  	public StringToStringsMap getHeaders();
28  
29  	public void addPropertyChangeListener( PropertyChangeListener listener );
30  
31  	public void setHeaders( StringToStringsMap headers );
32  
33  	public void removePropertyChangeListener( PropertyChangeListener listener );
34  
35  	public boolean isReadOnly();
36  
37  	public void release();
38  
39  	public void setInspector( AbstractXmlInspector inspector );
40  
41  	public static abstract class AbstractHeadersModel<T extends ModelItem> implements HttpHeadersInspectorModel,
42  			PropertyChangeListener
43  	{
44  		private boolean readOnly;
45  		private PropertyChangeSupport propertyChangeSupport;
46  		private final T modelItem;
47  		private final String propertyName;
48  
49  		protected AbstractHeadersModel( boolean readOnly, T modelItem, String propertyName )
50  		{
51  			this.readOnly = readOnly;
52  			this.modelItem = modelItem;
53  			this.propertyName = propertyName;
54  			propertyChangeSupport = new PropertyChangeSupport( this );
55  			modelItem.addPropertyChangeListener( propertyName, this );
56  		}
57  
58  		public void addPropertyChangeListener( PropertyChangeListener listener )
59  		{
60  			propertyChangeSupport.addPropertyChangeListener( listener );
61  		}
62  
63  		public boolean isReadOnly()
64  		{
65  			return readOnly;
66  		}
67  
68  		public void removePropertyChangeListener( PropertyChangeListener listener )
69  		{
70  			propertyChangeSupport.removePropertyChangeListener( listener );
71  		}
72  
73  		public void propertyChange( PropertyChangeEvent evt )
74  		{
75  			propertyChangeSupport.firePropertyChange( evt );
76  		}
77  
78  		public void release()
79  		{
80  			modelItem.removePropertyChangeListener( propertyName, this );
81  		}
82  
83  		public T getModelItem()
84  		{
85  			return modelItem;
86  		}
87  
88  		public void setHeaders( StringToStringsMap headers )
89  		{
90  			if( !readOnly )
91  				throw new NotImplementedException();
92  		}
93  
94  		public void setInspector( AbstractXmlInspector inspector )
95  		{
96  		}
97  	}
98  }