1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.ws.processor.model;
  27 
  28 import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
  29 import com.sun.tools.internal.ws.wsdl.document.PortType;
  30 import com.sun.tools.internal.ws.wsdl.document.soap.SOAPStyle;
  31 import com.sun.tools.internal.ws.wsdl.framework.Entity;
  32 
  33 import javax.xml.namespace.QName;
  34 import java.util.ArrayList;
  35 import java.util.HashMap;
  36 import java.util.List;
  37 import java.util.Map;
  38 
  39 /**
  40  * @author WS Development Team
  41  */
  42 public class Port extends ModelObject {
  43 
  44     public Port(Entity entity) {
  45         super(entity);
  46     }
  47 
  48     public Port(QName name, Entity entity) {
  49         super(entity);
  50         _name = name;
  51     }
  52 
  53     public QName getName() {
  54         return _name;
  55     }
  56 
  57     public void setName(QName n) {
  58         _name = n;
  59     }
  60 
  61     public void addOperation(Operation operation) {
  62         _operations.add(operation);
  63         operationsByName.put(operation.getUniqueName(), operation);
  64     }
  65 
  66     public Operation getOperationByUniqueName(String name) {
  67         if (operationsByName.size() != _operations.size()) {
  68             initializeOperationsByName();
  69         }
  70         return operationsByName.get(name);
  71     }
  72 
  73     private void initializeOperationsByName() {
  74         operationsByName = new HashMap<String, Operation>();
  75         if (_operations != null) {
  76             for (Operation operation : _operations) {
  77                 if (operation.getUniqueName() != null &&
  78                         operationsByName.containsKey(operation.getUniqueName())) {
  79 
  80                     throw new ModelException("model.uniqueness");
  81                 }
  82                 operationsByName.put(operation.getUniqueName(), operation);
  83             }
  84         }
  85     }
  86 
  87     /* serialization */
  88     public List<Operation> getOperations() {
  89         return _operations;
  90     }
  91 
  92     /* serialization */
  93     public void setOperations(List<Operation> l) {
  94         _operations = l;
  95     }
  96 
  97     public JavaInterface getJavaInterface() {
  98         return _javaInterface;
  99     }
 100 
 101     public void setJavaInterface(JavaInterface i) {
 102         _javaInterface = i;
 103     }
 104 
 105     public String getAddress() {
 106         return _address;
 107     }
 108 
 109     public void setAddress(String s) {
 110         _address = s;
 111     }
 112 
 113     public String getServiceImplName() {
 114         return _serviceImplName;
 115     }
 116 
 117     public void setServiceImplName(String name) {
 118         _serviceImplName = name;
 119     }
 120 
 121     public void accept(ModelVisitor visitor) throws Exception {
 122         visitor.visit(this);
 123     }
 124 
 125     public boolean isProvider() {
 126         JavaInterface intf = getJavaInterface();
 127         if (intf != null) {
 128             String sei = intf.getName();
 129             if (sei.equals(javax.xml.ws.Provider.class.getName())) {
 130                 return true;
 131             }
 132         }
 133         return false;
 134     }
 135 
 136     /**
 137      * XYZ_Service.getABC() method name
 138      *
 139      * @return Returns the portGetterName.
 140      */
 141     public String getPortGetter() {
 142         return portGetter;
 143     }
 144 
 145     /**
 146      * @param portGetterName The portGetterName to set.
 147      */
 148     public void setPortGetter(String portGetterName) {
 149         this.portGetter = portGetterName;
 150     }
 151 
 152     public SOAPStyle getStyle() {
 153         return _style;
 154     }
 155 
 156     public void setStyle(SOAPStyle s) {
 157         _style = s;
 158     }
 159 
 160     public boolean isWrapped() {
 161         return _isWrapped;
 162     }
 163 
 164     public void setWrapped(boolean isWrapped) {
 165         _isWrapped = isWrapped;
 166     }
 167 
 168     private SOAPStyle _style = null;
 169     private boolean _isWrapped = true;
 170 
 171     private String portGetter;
 172     private QName _name;
 173     private List<Operation> _operations = new ArrayList<Operation>();
 174     private JavaInterface _javaInterface;
 175     private String _address;
 176     private String _serviceImplName;
 177     private Map<String, Operation> operationsByName = new HashMap<String, Operation>();
 178     public Map<QName, PortType> portTypes = new HashMap<QName, PortType>();
 179 }