wsdldefinitions.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 580 行 · 第 1/2 页

JAVA
580
字号
        if (_targetNamespace != null)          name = new QName(_targetNamespace, message.getName());        else          name = new QName(message.getName());        _messageMap.put(name, message);      }    }    if (_portTypes != null) {      for (WSDLPortType portType : _portTypes) {        QName name = null;        if (_targetNamespace != null)          name = new QName(_targetNamespace, portType.getName());        else          name = new QName(portType.getName());        _portTypeMap.put(name, portType);      }    }    if (_bindings != null) {       for (WSDLBinding binding : _bindings) {        QName name = null;        if (_targetNamespace != null)          name = new QName(_targetNamespace, binding.getName());        else          name = new QName(binding.getName());        _bindingMap.put(name, binding);      }    }    resolveImports(u);    for (WSDLMessage message : getMessages()) {      for (WSDLPart part : message.getParts()) {        Type type = getType(part.getElement());        if (type == null)          throw new WSDLValidationException(L.l("Element type {0} for part {1} of message {2} is not defined in this WSDL's schema", part.getElement(), part.getName(), message.getName()));        part.setType(type);      }    }    // check that all the messages referenced by operations are defined    for (WSDLPortType portType : getPortTypes()) {      portType.setDefinitions(this);      for (WSDLOperation operation : portType.getOperations()) {        operation.setPortType(portType);        for (WSDLOperationInput input : operation.getInputs()) {          WSDLMessage message = getMessage(input.getMessageName());          if (message == null)            throw new WSDLValidationException(L.l("Input message {0} for operation {1} is not defined in this WSDL", input.getMessageName(), operation.getName()));          input.setMessage(message);        }        for (WSDLOperationOutput output : operation.getOutputs()) {          WSDLMessage message = getMessage(output.getMessageName());          if (message == null)            throw new WSDLValidationException(L.l("Output message {0} for operation {1} is not defined in this WSDL", output.getMessageName(), operation.getName()));          output.setMessage(message);        }        for (WSDLOperationFault fault : operation.getFaults()) {          WSDLMessage message = getMessage(fault.getMessageName());          if (message == null)            throw new WSDLValidationException(L.l("Fault message {0} for operation {1} is not defined in this WSDL", fault.getMessageName(), operation.getName()));          fault.setMessage(message);        }      }    }    // assign the binding to a portType and check that all     // the operations are defined    for (WSDLBinding binding : getBindings()) {       WSDLPortType portType = getPortType(binding.getType());      if (portType == null)        throw new WSDLValidationException(L.l("PortType {0} for binding {1} is not defined in this WSDL", binding.getType(), binding.getName()));      binding.setPortType(portType);      for (WSDLBindingOperation bindingOp : binding.getOperations()) {        WSDLOperation operation = portType.getOperation(bindingOp.getName());        if (operation == null)          throw new WSDLValidationException(L.l("PortType {0} has no operation {1} for binding {2}", portType.getName(), bindingOp.getName(), binding.getName()));        bindingOp.setOperation(operation);      }    }  }  public WSDLMessage getMessage(QName name)  {    return _messageMap.get(name);  }  public WSDLPortType getPortType(QName name)  {    return _portTypeMap.get(name);  }  public WSDLBinding getBinding(QName name)  {    return _bindingMap.get(name);  }  public Type getType(QName typeName)  {    if (_types == null)      return null;    for (int i = 0; i < _types.size(); i++) {      WSDLTypes types = _types.get(i);      Type type = types.getType(typeName);             if (type != null)        return type;    }    return null;  }  public void resolveImports(Unmarshaller u)    throws JAXBException  {    if (_types == null)      return;    for (int i = 0; i < _types.size(); i++) {      WSDLTypes types = _types.get(i);      types.resolveImports(u);    }  }  public void writeJAXBClasses(File outputDirectory, String pkg)    throws IOException  {    if (_types == null)      return;    for (int i = 0; i < _types.size(); i++) {      WSDLTypes types = _types.get(i);      types.writeJAXBClasses(outputDirectory, pkg);    }  }    public void generateJava(Unmarshaller u,                            File sourceDir, File classDir,                            String pkg)    throws WSDLValidationException, JAXBException, IOException  {    for (WSDLService service : getServices()) {       for (WSDLPort port : service.getPorts()) {        WSDLBinding binding = getBinding(port.getBinding());        if (binding == null)          throw new WSDLValidationException(L.l("Binding {0} for port {1} not defined in this WSDL", port.getBinding(), port.getName()));        WSDLPortType portType = binding.getPortType();        File dir = new File(sourceDir, pkg.replace(".", File.separator));        dir.mkdirs();        File output = new File(dir, portType.getName() + ".java");        WriteStream os = null;        try {          os = Vfs.openWrite(output.toString());          JavaWriter out = new JavaWriter(os);          out.println("package " + pkg + ";");          out.println();          out.println("import java.math.BigDecimal;");          out.println("import java.math.BigInteger;");          out.println("import java.util.List;");          out.println("import javax.jws.WebMethod;");          out.println("import javax.jws.WebParam;");          out.println("import javax.jws.WebResult;");          out.println("import javax.jws.WebService;");          out.println("import javax.xml.datatype.XMLGregorianCalendar;");          out.println("import javax.xml.ws.RequestWrapper;");          out.println("import javax.xml.ws.ResponseWrapper;");          out.println();          out.print("@WebService(name=\"" + portType.getName() + "\",");          out.println("targetNamespace=\"" + getTargetNamespace() + "\")");          out.println("public interface " + portType.getName() + "{");          out.pushDepth();          for (WSDLBindingOperation bindingOp : binding.getOperations()) {            bindingOp.generateJava(out);            out.println();            out.println();          }          out.popDepth();          out.println("}");        }        finally {          if (os != null)            os.close();        }        output = new File(dir, portType.getName() + "Service.java");        os = null;        try {          os = Vfs.openWrite(output.toString());          JavaWriter out = new JavaWriter(os);          out.println("package " + pkg + ";");          out.println();          out.println("import java.net.URL;");          out.println("import javax.xml.namespace.QName;");          out.println("import javax.xml.ws.Service;");          out.println();          out.println("public class " + portType.getName() + "Service");          out.println("  extends Service");          out.println("{");          out.pushDepth();          out.print("public " + portType.getName() + "Service");          out.println("(URL wsdlDocumentLocation, QName serviceName)");          out.println("{");          out.pushDepth();          out.println("super(wsdlDocumentLocation, serviceName);");          out.popDepth();          out.println("}");          out.popDepth();          out.println("}");        }        finally {          if (os != null)            os.close();        }      }    }    writeJAXBClasses(sourceDir, pkg);    File dir = new File(sourceDir, pkg.replace(".", File.separator));    File[] sources = dir.listFiles(new FilenameFilter() {      public boolean accept(File dir, String name)       {        return name.endsWith(".java");      }    });    if (sources.length == 0) {      // XXX Warning message?      System.out.println(" No sources found in " + dir + "!!!!!!");      return;    }    com.sun.tools.javac.Main javac = new com.sun.tools.javac.Main();    String[] args = new String[2 + sources.length];    args[0] = "-d";    args[1] = classDir.getAbsolutePath();    for (int i = 0; i < sources.length; i++)      args[i + 2] = sources[i].getAbsolutePath();    javac.compile(args);  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?