001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.j2mews.sg;
028:
029: import java.io.*;
030: import java.util.*;
031: import java.text.*;
032:
033: import javax.xml.namespace.QName;
034: import com.sun.xml.rpc.processor.model.Model;
035: import com.sun.xml.rpc.processor.model.AbstractType;
036: import com.sun.xml.rpc.processor.model.java.*;
037: import com.sun.xml.rpc.encoding.InternalEncodingConstants;
038: import com.sun.xml.rpc.wsdl.document.soap.SOAPConstants;
039: import com.sun.xml.rpc.processor.model.soap.*;
040: import com.sun.xml.rpc.processor.model.*;
041: import com.sun.xml.rpc.processor.model.literal.*;
042: import com.sun.xml.rpc.processor.generator.*;
043: import com.sun.xml.rpc.processor.*;
044: import com.sun.xml.rpc.processor.config.Configuration;
045: import com.sun.xml.rpc.processor.model.Service;
046: import com.sun.xml.rpc.processor.ProcessorOptions;
047: import com.sun.xml.rpc.processor.util.GeneratedFileInfo;
048:
049: import org.netbeans.modules.schema2beansdev.gen.*;
050:
051: /**
052: * Generate the Remote Interface.
053: *
054: */
055: public class RemoteInterfaceGenerator extends AbstractGenerator
056: implements ProcessorAction {
057: public RemoteInterfaceGenerator() {
058: }
059:
060: protected String getFullClassName() {
061: JavaInterface intf = port.getJavaInterface();
062: return env.getNames().customJavaTypeClassName(intf);
063: }
064:
065: protected File getSourceFile() {
066: return env.getNames().sourceFileForClass(fullClassName,
067: fullClassName, sourceDir, env);
068: }
069:
070: protected String getSourceFileType() {
071: return GeneratorConstants.FILE_TYPE_REMOTE_INTERFACE;
072: }
073:
074: protected void generateClass() throws java.io.IOException {
075: jw.write("public interface ", className,
076: " extends java.rmi.Remote ");
077: jw.begin();
078:
079: JavaInterface intf = port.getJavaInterface();
080: for (Iterator it = intf.getMethods(); it.hasNext();) {
081: JavaMethod method = (JavaMethod) it.next();
082: generateUserMethod(method);
083: }
084:
085: jw.end(); // end interface
086: }
087:
088: protected void generateUserMethod(JavaMethod method)
089: throws IOException {
090: String methodName = method.getName();
091: JavaType returnType = getExpandedReturnType(method);
092: String returnTypeName = javaTypeToString(returnType);
093: boolean voidReturnType = (returnType == null || "void"
094: .equals(returnTypeName));
095: jw.write("public ");
096: if (voidReturnType) {
097: jw.write("void");
098: } else {
099: jw.write(returnTypeName);
100: }
101: jw.write(" ");
102: jw.write(methodName);
103: jw.write("(");
104: jw.setFirst(", ");
105: List parameterList = getExpandedParametersList(method);
106: for (Iterator parameters = parameterList.iterator(); parameters
107: .hasNext();) {
108: JavaParameter parameter = (JavaParameter) parameters.next();
109: JavaType parameterType = parameter.getType();
110: String paramTypeName = javaTypeToString(parameterType);
111: jw.writeNext(paramTypeName, " ", parameter.getName());
112: }
113: jw.write(")");
114: jw.write(" throws java.rmi.RemoteException");
115: for (Iterator exceptions = method.getExceptions(); exceptions
116: .hasNext();) {
117: String exceptionName = (String) exceptions.next();
118: jw.write(", ");
119: jw.write(exceptionName);
120: }
121: jw.eol();
122: jw.cr();
123: }
124: }
|