J2EEClientDeployWriter.java

00001 /*
00002  * Copyright 2001-2004 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00040 package org.objectweb.jonas_ws.wsgen.generator.ews.wsdltoj2ee.writer;
00041 
00042 import java.io.IOException;
00043 import java.io.PrintWriter;
00044 import java.util.Iterator;
00045 import java.util.List;
00046 
00047 import javax.wsdl.Definition;
00048 import javax.wsdl.Port;
00049 import javax.wsdl.Service;
00050 import javax.wsdl.extensions.UnknownExtensibilityElement;
00051 import javax.wsdl.extensions.soap.SOAPBinding;
00052 import javax.xml.namespace.QName;
00053 
00054 import org.apache.axis.Constants;
00055 import org.apache.axis.constants.Style;
00056 import org.apache.axis.enum.Use;
00057 import org.apache.axis.utils.Messages;
00058 import org.apache.axis.wsdl.symbolTable.BindingEntry;
00059 import org.apache.axis.wsdl.symbolTable.SymbolTable;
00060 import org.apache.axis.wsdl.toJava.Emitter;
00061 import org.apache.axis.wsdl.toJava.Utils;
00062 import org.apache.geronimo.ews.ws4j2ee.context.webservices.client.interfaces.ServiceReferanceContext;
00063 import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFHandler;
00064 import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFInitParam;
00065 import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFSOAPHeader;
00066 
00067 import org.objectweb.jonas_ws.wsgen.generator.ews.wsdltoj2ee.wscf.JOnASWSCFHandler;
00068 
00074 public class J2EEClientDeployWriter extends JOnASDeployWriter {
00075 
00079     private static final String WSDD_PREFIX = "deploy-client-";
00080 
00087     public J2EEClientDeployWriter(Emitter emitter, Definition definition, SymbolTable symbolTable) {
00088         super(emitter, definition, symbolTable);
00089     }
00090 
00096     public void generate() throws IOException {
00097 
00098         if (!emitter.isServerSide()) {
00099             super.generate();
00100         }
00101     }
00102 
00108     protected void writeDeployServices(PrintWriter pw) throws IOException {
00109 
00110         int sRefIndex = getJonasWSContext().getServiceReferanceContextCount();
00111         // should only have 1 service-ref
00112         if (sRefIndex == 1) {
00113 
00114             ServiceReferanceContext ctx = getJonasWSContext().getServiceReferanceContext(0);
00115             QName desiredServiceQName = ctx.getServcieQName();
00116 
00117             Service myService = getDefinition().getService(desiredServiceQName);
00118 
00119             // Generate only if there is a Service
00120             if (myService != null) {
00121                 pw.println();
00122                 pw.println("  <!-- " + Messages.getMessage("wsdlService00", myService.getQName().getLocalPart()) + " -->");
00123                 pw.println();
00124 
00125                 for (Iterator portIterator = myService.getPorts().values().iterator(); portIterator.hasNext();) {
00126                     Port myPort = (Port) portIterator.next();
00127                     BindingEntry bEntry = getSymbolTable().getBindingEntry(myPort.getBinding().getQName());
00128 
00129                     // If this isn't an SOAP binding, skip it
00130                     if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) {
00131                         continue;
00132                     }
00133 
00134                     writeDeployPort(pw, myPort, bEntry, ctx);
00135                 }
00136             }
00137         }
00138     }
00139 
00147     protected void writeDeployPort(PrintWriter pw, Port port, BindingEntry bEntry, ServiceReferanceContext ctx) {
00148 
00149         String serviceName = port.getName();
00150         boolean hasLiteral = bEntry.hasLiteral();
00151         boolean hasMIME = Utils.hasMIME(bEntry);
00152 
00153 
00154         Use use = Use.DEFAULT;
00155         String styleStr = "";
00156         Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator();
00157 
00158         // iterate throught extensibilityElements of given Port's Binding
00159         while (iterator.hasNext()) {
00160             Object obj = iterator.next();
00161 
00162             if (obj instanceof SOAPBinding) {
00163                 use = Use.ENCODED;
00164             } else if (obj instanceof UnknownExtensibilityElement) {
00165 
00166                 // TODO After WSDL4J supports soap12, change this code
00167                 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
00168                 QName name = unkElement.getElementType();
00169 
00170                 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && name.getLocalPart().equals("binding")) {
00171                     use = Use.ENCODED;
00172                 }
00173             }
00174         }
00175 
00176         if (getSymbolTable().isWrapped()) {
00177             styleStr = " style=\"" + Style.WRAPPED + "\"";
00178             use = Use.LITERAL;
00179         } else {
00180             styleStr = " style=\"" + bEntry.getBindingStyle().getName() + "\"";
00181             if (hasLiteral) {
00182                 use = Use.LITERAL;
00183             }
00184         }
00185 
00186         String useStr = " use=\"" + use + "\"";
00187 
00188         pw.println("  <service name=\"" + serviceName + "\" " + styleStr + useStr + " provider=\"java:Noop\">");
00189 
00190         // MIME attachments don't work with multiref, so turn it off.
00191         if (hasMIME) {
00192             pw.println("      <parameter name=\"sendMultiRefs\" value=\"false\"/>");
00193         }
00194 
00195         //writeDeployBinding(pw, bEntry);
00196         writeDeployTypes(pw, bEntry.getBinding(), hasLiteral, hasMIME, use);
00197 
00198         WSCFHandler[] handlers = ctx.getHandlers();
00199         if (handlers != null) {
00200             pw.println("    <handlerInfoChain>");
00201             for (int i = 0; i < handlers.length; i++) {
00202                 writeHandlerForPort(pw, (JOnASWSCFHandler) handlers[i], port);
00203             }
00204             pw.println("    </handlerInfoChain>");
00205         }
00206         pw.println("  </service>");
00207     }
00208 
00215     private void writeHandlerForPort(PrintWriter pw, JOnASWSCFHandler handler, Port port) {
00216 
00221         List ports = handler.getPortNames();
00222         if (ports.isEmpty()) {
00223             // handler applied for all ports
00224             writeHandler(pw, handler);
00225         } else if (ports.contains(port.getName())) {
00226             // handler applied for current port
00227             writeHandler(pw, handler);
00228         }
00229     }
00235     private void writeHandler(PrintWriter pw, JOnASWSCFHandler handler) {
00236 
00237         pw.println("      <handlerInfo classname=\"" + handler.getHandlerClass() + "\">");
00238         WSCFInitParam[] param = handler.getInitParam();
00239         for (int i = 0; i < param.length; i++) {
00240             pw.println("        <parameter name=\"" + param[i].getParamName() + "\" value=\"" + param[i].getParamValue()
00241                     + "\"/>");
00242         }
00243         WSCFSOAPHeader[] headers = handler.getSoapHeader();
00244         for (int i = 0; i < headers.length; i++) {
00245             pw.println("        <header xmlns:ns=\"" + headers[i].getNamespaceURI() + "\" qname=\"ns:" + headers[i].getLocalpart()
00246                     + "\"/>");
00247         }
00248         pw.println("      </handlerInfo>");
00249         String[] roles = handler.getSoapRole();
00250         for (int i = 0; i < roles.length; i++) {
00251             pw.println("      <role soapActorName=\"" + roles[i] + "\"/>");
00252         }
00253     }
00254 
00258     protected String getPrefix() {
00259         return WSDD_PREFIX;
00260     }
00261 }

Generated on Tue Feb 15 15:06:02 2005 for JOnAS by  doxygen 1.3.9.1