View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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 javax.xml.namespace.QName;
16  
17  import org.apache.xmlbeans.XmlString;
18  
19  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
20  import com.eviware.soapui.model.ModelItem;
21  import com.eviware.soapui.model.testsuite.RenameableTestProperty;
22  import com.eviware.soapui.model.testsuite.TestStep;
23  import com.eviware.soapui.model.testsuite.TestStepProperty;
24  
25  /****
26   * Default implementation of TestStepProperty interface 
27   * 
28   * @author Ole.Matzura
29   */
30  
31  public class DefaultTestStepProperty implements TestStepProperty, RenameableTestProperty
32  {
33  	private String name;
34  	private boolean isReadOnly;
35  	private String description;
36  	private PropertyHandler handler;
37  	private final WsdlTestStep testStep;
38  	
39  	public DefaultTestStepProperty(String name, boolean isReadOnly, PropertyHandler handler, WsdlTestStep testStep )
40  	{
41  		this.name = name;
42  		this.isReadOnly = isReadOnly;
43  		this.handler = handler;
44  		this.testStep = testStep;
45  	}
46  	
47  	public DefaultTestStepProperty(String name, WsdlTestStep testStep)
48  	{
49  		this( name, false, new SimplePropertyHandler(), testStep );
50  	}
51  
52  	public DefaultTestStepProperty(String name, boolean isReadOnly, WsdlTestStep testStep)
53  	{
54  		this( name, isReadOnly, new SimplePropertyHandler(), testStep );
55  	}
56  
57  	public String getDescription()
58  	{
59  		return description;
60  	}
61  
62  	public void setDescription(String description)
63  	{
64  		this.description = description;
65  	}
66  
67  	public String getName()
68  	{
69  		return name;
70  	}
71  	
72  	public void setName( String name )
73  	{
74  		this.name = name;
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( this );
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( this, 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( DefaultTestStepProperty property );
122 		
123 		public void setValue( DefaultTestStepProperty property, 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( DefaultTestStepProperty property )
135 		{
136 			return null;
137 		}
138 
139 		public void setValue(DefaultTestStepProperty property, 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(DefaultTestStepProperty property)
155 		{
156 			return value;
157 		}
158 
159 		public void setValue(DefaultTestStepProperty property,String value)
160 		{
161 			this.value = value;
162 		}}
163 
164 	public QName getType()
165 	{
166 		return XmlString.type.getName();
167 	}
168 
169 	public ModelItem getModelItem()
170 	{
171 		return testStep;
172 	}
173 
174 	public String getDefaultValue()
175 	{
176 		return null;
177 	}
178 }