Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8059fc2c7c82ee05cecc727af413a52e1fc2a916 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsdl.ui.internal.commands;

import java.util.Iterator;

import org.eclipse.wst.wsdl.Fault;
import org.eclipse.wst.wsdl.Input;
import org.eclipse.wst.wsdl.Operation;
import org.eclipse.wst.wsdl.Output;
import org.eclipse.wst.wsdl.PortType;
import org.eclipse.wst.wsdl.WSDLElement;
import org.eclipse.wst.wsdl.WSDLFactory;
import org.eclipse.wst.wsdl.ui.internal.util.NameUtil;


public final class AddOperationCommand extends WSDLElementCommand
{
  private PortType portType;
  private String name;
  private Operation operation;
  private Operation originalOperation;
  private boolean copyInOutFault;
  
  private boolean createInput = false;
  private boolean createOutput = false;
  private boolean createFault = false;
  
  private final String DEFAULT_INPUT_NAME = "";
  private final String DEFAULT_OUTPUT_NAME = "";
  private final String DEFAULT_FAULT_NAME = "";
  
  public AddOperationCommand
		(PortType portType,  
		 String name)
	{
	  this.portType = portType;
	  this.name = name;
	}
  
  public AddOperationCommand
		(PortType portType,  
		 String name,
		 boolean createInput,
		 boolean createOutput,
		 boolean createFault)
	{
	  this.portType = portType;
	  this.name = name;
	  this.createInput = createInput;
	  this.createOutput = createOutput;
	  this.createFault = createFault;
	}
  
  /*
   * Constructor used to create an Operation based on the given Operation.  In essence, this will
   * create a copy of the given Operation.
   */
  public AddOperationCommand(PortType portType, Operation originalOperation, String name, boolean copyInOutFault) {
  	this.portType = portType;
  	this.originalOperation = originalOperation;
  	this.name = name;
  	this.copyInOutFault = copyInOutFault;
  }
  
  public void run()
  {
    operation = WSDLFactory.eINSTANCE.createOperation();
    operation.setName(name);
    operation.setEnclosingDefinition(portType.getEnclosingDefinition());
    portType.addOperation(operation);

    if (originalOperation == null) {    
    	WSDLElementCommand command = null;
    	if (createInput)
    	{
    		command = new AddInputCommand(operation,DEFAULT_INPUT_NAME,true);
    		command.run();
    	}
    
    	if (createOutput)
    	{
    		command = new AddOutputCommand(operation,DEFAULT_OUTPUT_NAME,true);
    		command.run();
    	}
    
    	if (createFault)
    	{
    		command = new AddFaultCommand(operation,DEFAULT_FAULT_NAME,true);
    		command.run();
    	}
    }
    else {
    	// Do necessary copying of data from original operation to new operation
    	// Paramater ordering? Documentation?  This part still needs to be worked on    	
    	// Copy 'kids' if necessary
    	if (copyInOutFault) {
    		WSDLElementCommand command = null;
        
        	if (originalOperation.getEOutput() != null)
        	{
        		Output output = originalOperation.getEOutput();
        		command = new AddOutputCommand(operation, output, NameUtil.buildUniqueOutputName(portType, operation.getName(), ""));
        		command.run();
        	}
        	
        	if (originalOperation.getEInput() != null)
        	{
        		Input input = originalOperation.getEInput();
        		command = new AddInputCommand(operation, input, NameUtil.buildUniqueInputName(portType, operation.getName(), ""));
        		command.run();
        	}
        
        	if (originalOperation.getEFaults() != null)
        	{
        		Iterator it = originalOperation.getEFaults().iterator();
        		while (it.hasNext()) {
        			Fault fault = (Fault) it.next();
        			command = new AddFaultCommand(operation, fault, NameUtil.buildUniqueFaultName(originalOperation, fault.getName()));
        			command.run();
        		}
        	}
    		
    	}
    }
  }
  
  public WSDLElement getWSDLElement()
  {
    return operation;
  }
  
  public void setName(String name)
  {
    this.name = name;
  }
}

Back to the top