001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.testelement.property;
020:
021: import org.apache.jmeter.testelement.TestElement;
022:
023: /**
024: * @version $Revision: 493779 $
025: */
026: public class TestElementProperty extends MultiProperty {
027: private TestElement value;
028:
029: private transient TestElement savedValue = null;
030:
031: public TestElementProperty(String name, TestElement value) {
032: super (name);
033: this .value = value;
034: }
035:
036: public TestElementProperty() {
037: super ();
038: }
039:
040: /**
041: * Determines if two test elements are equal.
042: *
043: * @return true if the value is not null and equals the other Objects value;
044: * false otherwise (even if both values are null)
045: */
046: public boolean equals(Object o) {
047: if (o instanceof TestElementProperty) {
048: if (this == o)
049: return true;
050: if (value != null) {
051: return value.equals(((JMeterProperty) o)
052: .getObjectValue());
053: }
054: }
055: return false;
056: }
057:
058: public int hashCode() {
059: return value == null ? 0 : value.hashCode();
060: }
061:
062: /*
063: * (non-Javadoc) #getStringValue()
064: */
065: public String getStringValue() {
066: return value.toString();
067: }
068:
069: public void setObjectValue(Object v) {
070: if (v instanceof TestElement) {
071: value = (TestElement) v;
072: }
073: }
074:
075: /*
076: * (non-Javadoc) #getObjectValue()
077: */
078: public Object getObjectValue() {
079: return value;
080: }
081:
082: public TestElement getElement() {
083: return value;
084: }
085:
086: public void setElement(TestElement el) {
087: value = el;
088: }
089:
090: /*
091: * (non-Javadoc)
092: *
093: * @see java.lang.Object#clone()
094: */
095: public Object clone() {
096: TestElementProperty prop = (TestElementProperty) super .clone();
097: prop.value = (TestElement) value.clone();
098: return prop;
099: }
100:
101: /*
102: * (non-Javadoc) #mergeIn(JMeterProperty)
103: */
104: public void mergeIn(JMeterProperty prop) {
105: if (isEqualType(prop)) {
106: value.addTestElement((TestElement) prop.getObjectValue());
107: }
108: }
109:
110: /*
111: * (non-Javadoc) #recoverRunningVersion(TestElement)
112: */
113: public void recoverRunningVersion(TestElement owner) {
114: if (savedValue != null) {
115: value = savedValue;
116: }
117: value.recoverRunningVersion();
118: }
119:
120: /*
121: * (non-Javadoc) #setRunningVersion(boolean)
122: */
123: public void setRunningVersion(boolean runningVersion) {
124: super .setRunningVersion(runningVersion);
125: value.setRunningVersion(runningVersion);
126: if (runningVersion) {
127: savedValue = value;
128: } else {
129: savedValue = null;
130: }
131: }
132:
133: /*
134: * (non-Javadoc)
135: *
136: * @see MultiProperty#addProperty(JMeterProperty)
137: */
138: public void addProperty(JMeterProperty prop) {
139: value.setProperty(prop);
140: }
141:
142: /*
143: * (non-Javadoc)
144: *
145: * @see MultiProperty#clear()
146: */
147: public void clear() {
148: value.clear();
149:
150: }
151:
152: /*
153: * (non-Javadoc)
154: *
155: * @see MultiProperty#iterator()
156: */
157: public PropertyIterator iterator() {
158: return value.propertyIterator();
159: }
160: }
|