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( handler != null && !isReadOnly() )
88  		{
89  			handler.setValue( value );
90  		}
91  	}
92  	
93  	public TestStep getTestStep()
94  	{
95  		return testStep;
96  	}
97  
98  	/***
99  	 * Handler for providing and setting property values
100 	 * 
101 	 * @author Ole.Matzura
102 	 */
103 	
104 	public interface PropertyHandler
105 	{
106 		public String getValue();
107 		
108 		public void setValue( String value );
109 	}
110 	
111 	/***
112 	 * Empty implementation of PropertyHandler interface
113 	 * 
114 	 * @author Ole.Matzura
115 	 */
116 	
117 	public static class PropertyHandlerAdapter implements PropertyHandler
118 	{
119 		public String getValue()
120 		{
121 			return null;
122 		}
123 
124 		public void setValue(String value)
125 		{
126 		}
127 	}
128 	
129 	/***
130 	 * Simple implementation of PropertyHandler interface
131 	 * 
132 	 * @author Ole.Matzura
133 	 */
134 	
135 	public static class SimplePropertyHandler implements PropertyHandler
136 	{
137 		private String value;
138 
139 		public String getValue()
140 		{
141 			return value;
142 		}
143 
144 		public void setValue(String value)
145 		{
146 			this.value = value;
147 		}}
148 }