001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.model.support;
014:
015: import java.util.Collection;
016: import java.util.Map;
017: import java.util.Set;
018:
019: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
020: import com.eviware.soapui.model.iface.SubmitContext;
021: import com.eviware.soapui.model.testsuite.TestCase;
022: import com.eviware.soapui.model.testsuite.TestRunContext;
023: import com.eviware.soapui.model.testsuite.TestStep;
024: import com.eviware.soapui.model.testsuite.TestStepProperty;
025: import com.eviware.soapui.support.types.StringToObjectMap;
026:
027: /**
028: * Base-class for submit contexts
029: *
030: * @author ole.matzura
031: */
032:
033: public abstract class AbstractSubmitContext implements SubmitContext,
034: Map<String, Object> {
035: private StringToObjectMap properties;
036:
037: public AbstractSubmitContext() {
038: setProperty(TestRunContext.RUN_COUNT, 0);
039: setProperty(TestRunContext.THREAD_INDEX, 0);
040: }
041:
042: public AbstractSubmitContext(PropertiesMap properties) {
043: this ();
044:
045: if (properties != null && properties.size() > 0)
046: this .properties.putAll(properties);
047: }
048:
049: public Object getProperty(String name, TestStep testStep,
050: WsdlTestCase testCase) {
051: if (properties != null && properties.containsKey(name))
052: return properties.get(name);
053:
054: if (testCase != null) {
055: int ix = name.indexOf(PROPERTY_SEPARATOR);
056: if (ix > 0) {
057: String teststepname = name.substring(0, ix);
058: TestStep refTestStep = testCase
059: .getTestStepByName(teststepname);
060: if (refTestStep != null) {
061: TestStepProperty property = refTestStep
062: .getProperty(name.substring(ix + 1));
063: return property == null ? null : property
064: .getValue();
065: }
066: }
067:
068: if (testCase.getSearchProperties()) {
069: ix = testStep == null ? testCase.getTestStepCount() - 1
070: : testCase.getIndexOfTestStep(testStep);
071: if (ix >= testCase.getTestStepCount())
072: ix = testCase.getTestStepCount() - 1;
073:
074: while (ix >= 0) {
075: TestStepProperty property = testCase.getTestStepAt(
076: ix).getProperty(name);
077: if (property != null)
078: return property.getValue();
079:
080: ix--;
081: }
082: }
083: }
084:
085: return null;
086: }
087:
088: public Object removeProperty(String name) {
089: return properties == null ? null : properties.remove(name);
090: }
091:
092: public void setProperty(String name, Object value) {
093: if (properties == null)
094: properties = new StringToObjectMap();
095:
096: properties.put(name, value);
097: }
098:
099: public void setProperty(String name, Object value, TestCase testCase) {
100: int ix = name.indexOf(PROPERTY_SEPARATOR);
101: if (ix > 0) {
102: String teststepname = name.substring(0, ix);
103: TestStep refTestStep = testCase
104: .getTestStepByName(teststepname);
105: if (refTestStep != null) {
106: TestStepProperty property = refTestStep
107: .getProperty(name.substring(ix + 1));
108: if (property != null && !property.isReadOnly()) {
109: property.setValue(value.toString());
110: return;
111: }
112: }
113: }
114:
115: if (properties == null)
116: properties = new StringToObjectMap();
117:
118: properties.put(name, value);
119: }
120:
121: public boolean hasProperty(String name) {
122: return properties == null ? false : properties
123: .containsKey(name);
124: }
125:
126: public void resetProperties() {
127: if (properties != null)
128: properties.clear();
129: }
130:
131: public void clear() {
132: properties.clear();
133: }
134:
135: public Object clone() {
136: return properties.clone();
137: }
138:
139: public boolean containsKey(Object key) {
140: return properties.containsKey(key);
141: }
142:
143: public boolean containsValue(Object value) {
144: return properties.containsValue(value);
145: }
146:
147: public Set<Entry<String, Object>> entrySet() {
148: return properties.entrySet();
149: }
150:
151: public boolean equals(Object o) {
152: return properties.equals(o);
153: }
154:
155: public Object get(Object key) {
156: return properties.get(key);
157: }
158:
159: public int hashCode() {
160: return properties.hashCode();
161: }
162:
163: public boolean isEmpty() {
164: return properties.isEmpty();
165: }
166:
167: public Set<String> keySet() {
168: return properties.keySet();
169: }
170:
171: public Object put(String key, Object value) {
172: return properties.put(key, value);
173: }
174:
175: public void putAll(Map<? extends String, ? extends Object> m) {
176: properties.putAll(m);
177: }
178:
179: public Object remove(Object key) {
180: return properties.remove(key);
181: }
182:
183: public int size() {
184: return properties.size();
185: }
186:
187: public String toString() {
188: return properties.toString();
189: }
190:
191: public Collection<Object> values() {
192: return properties.values();
193: }
194:
195: public StringToObjectMap getProperties() {
196: return properties;
197: }
198: }
|