View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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 sun.reflect.generics.reflectiveObjects.NotImplementedException;
20  
21  import com.eviware.soapui.model.ModelItem;
22  import com.eviware.soapui.support.types.StringToStringMap;
23  
24  public interface HttpHeadersInspectorModel
25  {
26  	public StringToStringMap getHeaders();
27  
28  	public void addPropertyChangeListener( PropertyChangeListener listener );
29  
30  	public void setHeaders( StringToStringMap headers );
31  
32  	public void removePropertyChangeListener( PropertyChangeListener listener );
33  
34  	public boolean isReadOnly();
35  
36  	public void release();
37  
38  	public static abstract class AbstractHeadersModel<T extends ModelItem> implements HttpHeadersInspectorModel,
39  			PropertyChangeListener
40  	{
41  		private boolean readOnly;
42  		private PropertyChangeSupport propertyChangeSupport;
43  		private final T modelItem;
44  		private final String propertyName;
45  
46  		protected AbstractHeadersModel( boolean readOnly, T modelItem, String propertyName )
47  		{
48  			this.readOnly = readOnly;
49  			this.modelItem = modelItem;
50  			this.propertyName = propertyName;
51  			propertyChangeSupport = new PropertyChangeSupport( this );
52  			modelItem.addPropertyChangeListener( propertyName, this );
53  		}
54  
55  		public void addPropertyChangeListener( PropertyChangeListener listener )
56  		{
57  			propertyChangeSupport.addPropertyChangeListener( listener );
58  		}
59  
60  		public boolean isReadOnly()
61  		{
62  			return readOnly;
63  		}
64  
65  		public void removePropertyChangeListener( PropertyChangeListener listener )
66  		{
67  			propertyChangeSupport.removePropertyChangeListener( listener );
68  		}
69  
70  		public void propertyChange( PropertyChangeEvent evt )
71  		{
72  			propertyChangeSupport.firePropertyChange( evt );
73  		}
74  
75  		public void release()
76  		{
77  			modelItem.removePropertyChangeListener( propertyName, this );
78  		}
79  
80  		public T getModelItem()
81  		{
82  			return modelItem;
83  		}
84  
85  		public void setHeaders( StringToStringMap headers )
86  		{
87  			if( !readOnly )
88  				throw new NotImplementedException();
89  		}
90  	}
91  }