001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.tools.ws.processor.model.java;
038:
039: import com.sun.tools.ws.resources.ModelMessages;
040: import com.sun.tools.ws.wscompile.ErrorReceiver;
041: import com.sun.tools.ws.wscompile.WsimportOptions;
042: import com.sun.tools.ws.processor.model.Parameter;
043:
044: import java.util.ArrayList;
045: import java.util.List;
046: import java.util.Iterator;
047:
048: /**
049: * @author WS Development Team
050: */
051: public class JavaMethod {
052:
053: private final ErrorReceiver errorReceiver;
054: private final String name;
055: private final List<JavaParameter> parameters = new ArrayList<JavaParameter>();
056: private final List<String> exceptions = new ArrayList<String>();
057: private final WsimportOptions options;
058: private JavaType returnType;
059:
060: public JavaMethod(String name, WsimportOptions options,
061: ErrorReceiver receiver) {
062: this .name = name;
063: this .returnType = null;
064: this .errorReceiver = receiver;
065: this .options = options;
066: }
067:
068: public String getName() {
069: return name;
070: }
071:
072: public JavaType getReturnType() {
073: return returnType;
074: }
075:
076: public void setReturnType(JavaType returnType) {
077: this .returnType = returnType;
078: }
079:
080: private boolean hasParameter(String paramName) {
081: for (JavaParameter parameter : parameters) {
082: if (paramName.equals(parameter.getName())) {
083: return true;
084: }
085: }
086: return false;
087: }
088:
089: private Parameter getParameter(String paramName) {
090: for (JavaParameter parameter : parameters) {
091: if (paramName.equals(parameter.getName())) {
092: return parameter.getParameter();
093: }
094: }
095: return null;
096: }
097:
098: public void addParameter(JavaParameter param) {
099: // verify that this member does not already exist
100: if (hasParameter(param.getName())) {
101: if (options.isExtensionMode()) {
102: param.setName(getUniqueName(param.getName()));
103: } else {
104: Parameter duplicParam = getParameter(param.getName());
105: if (param.getParameter().isEmbedded()) {
106: errorReceiver.error(param.getParameter()
107: .getLocator(), ModelMessages
108: .MODEL_PARAMETER_NOTUNIQUE_WRAPPER(param
109: .getName(), param.getParameter()
110: .getEntityName()));
111: errorReceiver
112: .error(
113: duplicParam.getLocator(),
114: ModelMessages
115: .MODEL_PARAMETER_NOTUNIQUE_WRAPPER(
116: param.getName(),
117: duplicParam
118: .getEntityName()));
119: } else {
120: errorReceiver.error(param.getParameter()
121: .getLocator(), ModelMessages
122: .MODEL_PARAMETER_NOTUNIQUE(param.getName(),
123: param.getParameter()
124: .getEntityName()));
125: errorReceiver.error(duplicParam.getLocator(),
126: ModelMessages.MODEL_PARAMETER_NOTUNIQUE(
127: param.getName(), duplicParam
128: .getEntityName()));
129: }
130: return;
131: }
132: }
133: parameters.add(param);
134: }
135:
136: public List<JavaParameter> getParametersList() {
137: return parameters;
138: }
139:
140: public void addException(String exception) {
141: // verify that this exception does not already exist
142: if (!exceptions.contains(exception)) {
143: exceptions.add(exception);
144: }
145: }
146:
147: /** TODO: NB uses it, remove it once we expose it thru some API **/
148: public Iterator<String> getExceptions() {
149: return exceptions.iterator();
150: }
151:
152: private String getUniqueName(String param) {
153: int parmNum = 0;
154: while (hasParameter(param)) {
155: param = param + Integer.toString(parmNum++);
156: }
157: return param;
158: }
159: }
|