Skip to main content
summaryrefslogtreecommitdiffstats
blob: 98ef34175eac4bed0fe5778dc89d2bc017ac2e40 (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
/*******************************************************************************
 * 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.contentgenerator;

import java.util.Iterator;

import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.Port;
import org.eclipse.wst.wsdl.Service;
import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin;
import org.eclipse.wst.wsdl.ui.internal.util.WSDLEditorUtil;
import org.w3c.dom.Element;
import org.w3c.dom.Node;


public class PortGenerator extends AbstractGenerator
{
  protected Service service;
  protected String bindingName;

  public PortGenerator(Service service)
  {
    this.service = service;
  }

  public int getType()
  {
    return PORT_GENERATOR;
  }

  public Definition getDefinition()
  {
    return service.getEnclosingDefinition();
  }

  public Service getService()
  {
    return service;
  }

  public Node getParentNode()
  {
    return WSDLEditorUtil.getInstance().getElementForObject(service);
  }

  protected String getUndoDescription()
  {
    return WSDLEditorPlugin.getWSDLString("_UI_ACTION_ADD_PORT");
  }

  public void setRefName(String refName)
  {
    setBindingName(refName);
  }

  public String getRefName()
  {
    return bindingName;
  }

  public void setBindingName(String bindingName)
  {
    this.bindingName = bindingName;
  }

  public void generateContent()
  {
    Element portElement = null;
    for (Iterator i = service.getEPorts().iterator(); i.hasNext();)
    {
      Port port = (Port) i.next();
      if (port.getName().equals(name))
      {
        portElement = WSDLEditorUtil.getInstance().getElementForObject(port);
      }
    }

    boolean doGenerateContent = false;
    if (portElement == null)
    {
      Element serviceElement = WSDLEditorUtil.getInstance().getElementForObject(service);
      portElement = createWSDLElement(serviceElement, "port");
      portElement.setAttribute("name", name);
      doGenerateContent = true;
    }
    else
    {
      doGenerateContent = overwrite;
    }

    portElement.setAttribute("binding", bindingName != null ? bindingName : "");
    Port port = (Port) WSDLEditorUtil.getInstance().findModelObjectForElement(getDefinition(), portElement);
    newComponent = port;

    //portElement.
    bindingContentGenerator.generatePortContent(portElement, port);
  }
}

Back to the top