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 com.eviware.soapui.model.testsuite.TestStep;
016: import com.eviware.soapui.model.testsuite.TestStepProperty;
017:
018: /***
019: * Default implementation of TestStepProperty interface
020: *
021: * @author Ole.Matzura
022: */
023:
024: public class DefaultTestStepProperty implements TestStepProperty {
025: private final String name;
026: private boolean isReadOnly;
027: private String description;
028: private PropertyHandler handler;
029: private final TestStep testStep;
030:
031: public DefaultTestStepProperty(String name, boolean isReadOnly,
032: PropertyHandler handler, TestStep testStep) {
033: this .name = name;
034: this .isReadOnly = isReadOnly;
035: this .handler = handler;
036: this .testStep = testStep;
037: }
038:
039: public DefaultTestStepProperty(String name, TestStep testStep) {
040: this (name, false, new SimplePropertyHandler(), testStep);
041: }
042:
043: public DefaultTestStepProperty(String name, boolean isReadOnly,
044: TestStep testStep) {
045: this (name, isReadOnly, new SimplePropertyHandler(), testStep);
046: }
047:
048: public String getDescription() {
049: return description;
050: }
051:
052: public void setDescription(String description) {
053: this .description = description;
054: }
055:
056: public String getName() {
057: return name;
058: }
059:
060: public void setIsReadOnly(boolean isReadOnly) {
061: this .isReadOnly = isReadOnly;
062: }
063:
064: public boolean isReadOnly() {
065: return isReadOnly;
066: }
067:
068: public void setPropertyHandler(PropertyHandler handler) {
069: this .handler = handler;
070: }
071:
072: public String getValue() {
073: return handler == null ? null : handler.getValue();
074: }
075:
076: public void setValue(String value) {
077: if (isReadOnly())
078: throw new RuntimeException(
079: "Trying to set read-only property [" + getName()
080: + "]");
081:
082: if (handler != null) {
083: handler.setValue(value);
084: }
085: }
086:
087: public TestStep getTestStep() {
088: return testStep;
089: }
090:
091: /**
092: * Handler for providing and setting property values
093: *
094: * @author Ole.Matzura
095: */
096:
097: public interface PropertyHandler {
098: public String getValue();
099:
100: public void setValue(String value);
101: }
102:
103: /**
104: * Empty implementation of PropertyHandler interface
105: *
106: * @author Ole.Matzura
107: */
108:
109: public static class PropertyHandlerAdapter implements
110: PropertyHandler {
111: public String getValue() {
112: return null;
113: }
114:
115: public void setValue(String value) {
116: }
117: }
118:
119: /**
120: * Simple implementation of PropertyHandler interface
121: *
122: * @author Ole.Matzura
123: */
124:
125: public static class SimplePropertyHandler implements
126: PropertyHandler {
127: private String value;
128:
129: public String getValue() {
130: return value;
131: }
132:
133: public void setValue(String value) {
134: this.value = value;
135: }
136: }
137: }
|