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.model.support;
    14
    15  import com.eviware.soapui.model.testsuite.TestStep;
    16  import com.eviware.soapui.model.testsuite.TestStepProperty;
    17
    18  /****
    19   * Default implementation of TestStepProperty interface
    20   *
    21   * @author Ole.Matzura
    22   */
    23
    24  public class DefaultTestStepProperty implements TestStepProperty
    25  {
    26  	private final String name;
    27  	private boolean isReadOnly;
    28  	private String description;
    29  	private PropertyHandler handler;
    30  	private final TestStep testStep;
    31
    32  	public DefaultTestStepProperty(String name, boolean isReadOnly, PropertyHandler handler, TestStep testStep )
    33  	{
    34  		this.name = name;
    35  		this.isReadOnly = isReadOnly;
    36  		this.handler = handler;
    37  		this.testStep = testStep;
    38  	}
    39
    40  	public DefaultTestStepProperty(String name, TestStep testStep)
    41  	{
    42  		this( name, false, new SimplePropertyHandler(), testStep );
    43  	}
    44
    45  	public DefaultTestStepProperty(String name, boolean isReadOnly, TestStep testStep)
    46  	{
    47  		this( name, isReadOnly, new SimplePropertyHandler(), testStep );
    48  	}
    49
    50  	public String getDescription()
    51  	{
    52  		return description;
    53  	}
    54
    55  	public void setDescription(String description)
    56  	{
    57  		this.description = description;
    58  	}
    59
    60  	public String getName()
    61  	{
    62  		return name;
    63  	}
    64
    65  	public void setIsReadOnly( boolean isReadOnly )
    66  	{
    67  		this.isReadOnly = isReadOnly;
    68  	}
    69
    70  	public boolean isReadOnly()
    71  	{
    72  		return isReadOnly;
    73  	}
    74
    75  	public void setPropertyHandler( PropertyHandler handler )
    76  	{
    77  		this.handler = handler;
    78  	}
    79
    80  	public String getValue()
    81  	{
    82  		return handler == null ? null : handler.getValue();
    83  	}
    84
    85  	public void setValue( String value )
    86  	{
    87  		if( isReadOnly() )
    88  			throw new RuntimeException( "Trying to set read-only property [" + getName() + "]" );
    89
    90  		if( handler != null )
    91  		{
    92  			handler.setValue( value );
    93  		}
    94  	}
    95
    96  	public TestStep getTestStep()
    97  	{
    98  		return testStep;
    99  	}
    100
    101 	/***
    102 	 * Handler for providing and setting property values
    103 	 *
    104 	 * @author Ole.Matzura
    105 	 */
    106
    107 	public interface PropertyHandler
    108 	{
    109 		public String getValue();
    110
    111 		public void setValue( String value );
    112 	}
    113
    114 	/***
    115 	 * Empty implementation of PropertyHandler interface
    116 	 *
    117 	 * @author Ole.Matzura
    118 	 */
    119
    120 	public static class PropertyHandlerAdapter implements PropertyHandler
    121 	{
    122 		public String getValue()
    123 		{
    124 			return null;
    125 		}
    126
    127 		public void setValue(String value)
    128 		{
    129 		}
    130 	}
    131
    132 	/***
    133 	 * Simple implementation of PropertyHandler interface
    134 	 *
    135 	 * @author Ole.Matzura
    136 	 */
    137
    138 	public static class SimplePropertyHandler implements PropertyHandler
    139 	{
    140 		private String value;
    141
    142 		public String getValue()
    143 		{
    144 			return value;
    145 		}
    146
    147 		public void setValue(String value)
    148 		{
    149 			this.value = value;
    150 		}}
    151 }