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