01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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.tree.nodes;
14:
15: import java.util.ArrayList;
16: import java.util.List;
17:
18: import com.eviware.soapui.model.mock.MockOperation;
19: import com.eviware.soapui.model.mock.MockResponse;
20: import com.eviware.soapui.model.tree.AbstractModelItemTreeNode;
21: import com.eviware.soapui.model.tree.SoapUITreeModel;
22: import com.eviware.soapui.model.tree.SoapUITreeNode;
23:
24: /**
25: * SoapUITreeNode for TestStep implementations
26: *
27: * @author Ole.Matzura
28: */
29:
30: public class MockOperationTreeNode extends
31: AbstractModelItemTreeNode<MockOperation> {
32: private List<MockResponseTreeNode> mockResponseNodes = new ArrayList<MockResponseTreeNode>();
33:
34: public MockOperationTreeNode(MockOperation mockOperation,
35: SoapUITreeModel treeModel) {
36: super (mockOperation, mockOperation.getMockService(), treeModel);
37:
38: for (int c = 0; c < mockOperation.getMockResponseCount(); c++) {
39: MockResponse mockResponse = mockOperation
40: .getMockResponseAt(c);
41: mockResponseNodes.add(new MockResponseTreeNode(
42: mockResponse, getTreeModel()));
43: }
44:
45: treeModel.mapModelItems(mockResponseNodes);
46: }
47:
48: @Override
49: public void release() {
50: super .release();
51:
52: for (MockResponseTreeNode treeNode : mockResponseNodes)
53: treeNode.release();
54: }
55:
56: public int getChildCount() {
57: return mockResponseNodes.size();
58: }
59:
60: public int getIndexOfChild(Object child) {
61: return mockResponseNodes.indexOf(child);
62: }
63:
64: public SoapUITreeNode getChildNode(int index) {
65: return mockResponseNodes.get(index);
66: }
67:
68: public void mockResponseAdded(MockResponse mockResponse) {
69: MockResponseTreeNode treeNode = new MockResponseTreeNode(
70: mockResponse, getTreeModel());
71: mockResponseNodes.add(treeNode);
72: getTreeModel().notifyNodeInserted(treeNode);
73: }
74:
75: public void mockResponseRemoved(MockResponse mockResponse) {
76: SoapUITreeNode treeNode = getTreeModel().getTreeNode(
77: mockResponse);
78: if (mockResponseNodes.contains(treeNode)) {
79: getTreeModel().notifyNodeRemoved(treeNode);
80: mockResponseNodes.remove(treeNode);
81: } else
82: throw new RuntimeException("Removing unkown mockResponse; "
83: + mockResponse.getName());
84: }
85: }
|