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.panels.request.components.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, PropertyChangeListener
    39  	{
    40  		private boolean readOnly;
    41  		private PropertyChangeSupport propertyChangeSupport;
    42  		private final T modelItem;
    43  		private final String propertyName;
    44
    45  		protected AbstractHeadersModel( boolean readOnly, T modelItem, String propertyName )
    46  		{
    47  			this.readOnly = readOnly;
    48  			this.modelItem = modelItem;
    49  			this.propertyName = propertyName;
    50  			propertyChangeSupport = new PropertyChangeSupport( this );
    51  			modelItem.addPropertyChangeListener( propertyName, this );
    52  		}
    53
    54  		public void addPropertyChangeListener( PropertyChangeListener listener )
    55  		{
    56  			propertyChangeSupport.addPropertyChangeListener( listener );
    57  		}
    58
    59  		public boolean isReadOnly()
    60  		{
    61  			return readOnly;
    62  		}
    63
    64  		public void removePropertyChangeListener( PropertyChangeListener listener )
    65  		{
    66  			propertyChangeSupport.removePropertyChangeListener( listener );
    67  		}
    68
    69  		public void propertyChange( PropertyChangeEvent evt )
    70  		{
    71  			propertyChangeSupport.firePropertyChange( evt );
    72  		}
    73
    74  		public void release()
    75  		{
    76  			modelItem.removePropertyChangeListener( propertyName, this );
    77  		}
    78
    79  		public T getModelItem()
    80  		{
    81  			return modelItem;
    82  		}
    83
    84  		public void setHeaders( StringToStringMap headers )
    85  		{
    86  			if( !readOnly )
    87  				throw new NotImplementedException();
    88  		}
    89  	}
    90  }