View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 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.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 AbstractModelItemTreeNode<MockOperation>
    31  {
    32  	private List<MockResponseTreeNode> mockResponseNodes = new ArrayList<MockResponseTreeNode>();
    33
    34     public MockOperationTreeNode(MockOperation mockOperation, SoapUITreeModel treeModel )
    35     {
    36        super( mockOperation, mockOperation.getMockService(), treeModel );
    37
    38        for( int c = 0; c < mockOperation.getMockResponseCount(); c++ )
    39        {
    40        	MockResponse mockResponse = mockOperation.getMockResponseAt( c );
    41        	mockResponseNodes.add( new MockResponseTreeNode( mockResponse, getTreeModel() ));
    42        }
    43
    44        treeModel.mapModelItems( mockResponseNodes );
    45     }
    46
    47  	@Override
    48  	public void release()
    49  	{
    50  		super.release();
    51
    52  		for( MockResponseTreeNode treeNode : mockResponseNodes )
    53  			treeNode.release();
    54  	}
    55
    56  	public int getChildCount()
    57     {
    58        return mockResponseNodes.size();
    59     }
    60
    61     public int getIndexOfChild(Object child)
    62     {
    63     	return mockResponseNodes.indexOf( child );
    64     }
    65
    66     public SoapUITreeNode getChildNode(int index)
    67     {
    68        return mockResponseNodes.get( index );
    69     }
    70
    71  	public void mockResponseAdded( MockResponse mockResponse )
    72  	{
    73  		MockResponseTreeNode treeNode = new MockResponseTreeNode( mockResponse, getTreeModel() );
    74  		mockResponseNodes.add( treeNode );
    75  		getTreeModel().notifyNodeInserted( treeNode );
    76  	}
    77
    78  	public void mockResponseRemoved( MockResponse mockResponse )
    79  	{
    80  		SoapUITreeNode treeNode = getTreeModel().getTreeNode( mockResponse );
    81  		if( mockResponseNodes.contains( treeNode ))
    82  		{
    83  		   getTreeModel().notifyNodeRemoved( treeNode );
    84  		   mockResponseNodes.remove( treeNode );
    85  		}
    86  		else throw new RuntimeException( "Removing unkown mockResponse; " + mockResponse.getName() );
    87  	}
    88  }