DefinitionWrapper.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */


  20. package org.openspcoop2.utils.wsdl;

  21. import java.io.ByteArrayOutputStream;
  22. import java.io.File;
  23. import java.io.IOException;
  24. import java.io.OutputStream;
  25. import java.io.Writer;
  26. import java.net.URI;
  27. import java.util.ArrayList;
  28. import java.util.HashMap;
  29. import java.util.Iterator;
  30. import java.util.List;
  31. import java.util.Map;

  32. import javax.wsdl.Binding;
  33. import javax.wsdl.BindingFault;
  34. import javax.wsdl.BindingInput;
  35. import javax.wsdl.BindingOperation;
  36. import javax.wsdl.BindingOutput;
  37. import javax.wsdl.Definition;
  38. import javax.wsdl.Fault;
  39. import javax.wsdl.Import;
  40. import javax.wsdl.Input;
  41. import javax.wsdl.Message;
  42. import javax.wsdl.Operation;
  43. import javax.wsdl.Output;
  44. import javax.wsdl.Part;
  45. import javax.wsdl.Port;
  46. import javax.wsdl.PortType;
  47. import javax.wsdl.Service;
  48. import javax.wsdl.Types;
  49. import javax.wsdl.WSDLException;
  50. import javax.wsdl.extensions.ExtensibilityElement;
  51. import javax.wsdl.extensions.ExtensionRegistry;
  52. import javax.wsdl.extensions.soap.SOAPAddress;
  53. import javax.wsdl.extensions.soap12.SOAP12Address;
  54. import javax.xml.namespace.QName;

  55. import org.openspcoop2.utils.xml.AbstractXMLUtils;
  56. import org.openspcoop2.utils.xml.DynamicNamespaceContext;
  57. import org.openspcoop2.utils.xml.XPathExpressionEngine;
  58. import org.openspcoop2.utils.xml.XPathReturnType;
  59. import org.w3c.dom.Document;
  60. import org.w3c.dom.Element;
  61. import org.w3c.dom.Node;
  62. import org.w3c.dom.NodeList;


  63. /**
  64.  * Classe utilizzata per leggere/modificare i wsdl
  65.  *
  66.  *
  67.  * @author Poli Andrea (apoli@link.it)
  68.  * @author Lezza Aldo (lezza@openspcoop.org)
  69.  * @author $Author$
  70.  * @version $Rev$, $Date$
  71.  */

  72. public class DefinitionWrapper implements javax.wsdl.Definition{

  73.     /**
  74.      *
  75.      */
  76.     private static final long serialVersionUID = 1L;
  77.    
  78.     /** WSDL Definitorio */
  79.     private javax.wsdl.Definition wsdlDefinition = null;
  80.     private Document wsdlDefinitionNode = null;
  81.    
  82.     /** Eventuale Path del wsdl caricato */
  83.     private String path;
  84.    
  85.    
  86.     private AbstractXMLUtils xmlUtils = null;
  87.     private WSDLUtilities wsdlUtilities = null;
  88.    
  89.    
  90.     /** ---------------------------- Costruttori --------------------------- */
  91.     /** NOTA: le importsDocument riguardano i WSDL Imports e non gli xsd imports!!!!!!! */
  92.    
  93.     /**
  94.      * Costruttore. Inizializza questo WSDLWrapper leggendo il WSDL dal path.
  95.      * @param file Il file dal quale leggere il WSDL.
  96.      */
  97.     public DefinitionWrapper(File file,AbstractXMLUtils xmlUtils)throws WSDLException{
  98.         this(file,xmlUtils,false,true);
  99.     }
  100.     public DefinitionWrapper(File file,AbstractXMLUtils xmlUtils,boolean verbose,boolean importsDocument)throws WSDLException{
  101.         this.xmlUtils = xmlUtils;
  102.         this.wsdlUtilities = WSDLUtilities.getInstance(this.xmlUtils);
  103.         if (file != null){
  104.             this.wsdlDefinition = this.wsdlUtilities.readWSDLFromFile(file,verbose,importsDocument);
  105.             this.path = file.getAbsolutePath();
  106.             try {
  107.                 this.wsdlDefinitionNode = xmlUtils.newDocument(file);
  108.             }catch(Throwable t) {}
  109.         }else{
  110.             throw new WSDLException("WSDL(File file)","File wsdl non fornitp");
  111.         }
  112.     }
  113.    
  114.     /**
  115.      * Costruttore. Inizializza questo WSDLWrapper leggendo il WSDL dal path.
  116.      * @param path Il path dal quale leggere il WSDL.
  117.      */
  118.     public DefinitionWrapper(String path,AbstractXMLUtils xmlUtils)throws WSDLException{
  119.         this(path,xmlUtils,false,true);
  120.     }
  121.     public DefinitionWrapper(String path,AbstractXMLUtils xmlUtils,boolean verbose,boolean importsDocument)throws WSDLException{
  122.         this.xmlUtils = xmlUtils;
  123.         this.wsdlUtilities = WSDLUtilities.getInstance(this.xmlUtils);
  124.         if (path != null){
  125.             this.wsdlDefinition = this.wsdlUtilities.readWSDLFromLocation(path,verbose,importsDocument);
  126.             this.path = path;
  127.             try {
  128.                 this.wsdlDefinitionNode = xmlUtils.newDocument(new File(path));
  129.             }catch(Throwable t) {}
  130.         }else{
  131.             throw new WSDLException("WSDL(String path)","Location del wsdl non fornita");
  132.         }
  133.     }

  134.     /**
  135.      * Costruttore. Inizializza questo WSDLWrapper leggendo il WSDL da bytes.
  136.      * @param bytes I bytes da cui leggere il WSDL.
  137.      */
  138.     public DefinitionWrapper(byte[] bytes,AbstractXMLUtils xmlUtils)throws WSDLException{
  139.         this(bytes,xmlUtils,false,true);
  140.     }
  141.     public DefinitionWrapper(byte[] bytes,AbstractXMLUtils xmlUtils,boolean verbose,boolean importsDocument)throws WSDLException{
  142.         this.xmlUtils = xmlUtils;
  143.         this.wsdlUtilities = WSDLUtilities.getInstance(this.xmlUtils);
  144.         if (bytes != null){
  145.             this.wsdlDefinition = this.wsdlUtilities.readWSDLFromBytes(bytes,verbose,importsDocument);
  146.             try {
  147.                 this.wsdlDefinitionNode = xmlUtils.newDocument(bytes);
  148.             }catch(Throwable t) {}
  149.         }else{
  150.             throw new WSDLException("WSDL(byte[] bytes)","Bytes del wsdl non forniti");
  151.         }
  152.     }

  153.     /**
  154.      * Costruttore. Inizializza questo WSDLWrapper da un documento WSDL gia' letto.
  155.      * @param doc Il Document con il WSDL gia' parsato.
  156.      */
  157.     public DefinitionWrapper(Document doc,AbstractXMLUtils xmlUtils)throws WSDLException{
  158.         this(doc,xmlUtils,false,true);
  159.     }
  160.     public DefinitionWrapper(Document doc,AbstractXMLUtils xmlUtils,boolean verbose,boolean importsDocument) throws WSDLException {
  161.         this.xmlUtils = xmlUtils;
  162.         this.wsdlUtilities = WSDLUtilities.getInstance(this.xmlUtils);
  163.         if (doc != null){
  164.             this.wsdlDefinition = this.wsdlUtilities.readWSDLFromDocument(doc,verbose,importsDocument);
  165.             this.wsdlDefinitionNode = doc;
  166.         }else{
  167.             throw new WSDLException("WSDL(Document doc)","Document del wsdl non fornito");
  168.         }
  169.     }

  170.     /**
  171.      * Costruttore. Inizializza questo WSDLWrapper da un documento WSDL gia' letto in un elemento XML.
  172.      * @param el L'elemento root del documento XML.
  173.      */
  174.     public DefinitionWrapper(Element el,AbstractXMLUtils xmlUtils)throws WSDLException{
  175.         this(el,xmlUtils,false,true);
  176.     }
  177.     public DefinitionWrapper(Element el,AbstractXMLUtils xmlUtils,boolean verbose,boolean importsDocument) throws WSDLException{
  178.         this.xmlUtils = xmlUtils;
  179.         this.wsdlUtilities = WSDLUtilities.getInstance(this.xmlUtils);
  180.         if (el != null){
  181.             this.wsdlDefinition = this.wsdlUtilities.readWSDLFromElement(el,verbose,importsDocument);
  182.             this.wsdlDefinitionNode = el.getOwnerDocument();
  183.         }else{
  184.             throw new WSDLException("WSDL(Element el)","Element del wsdl non fornito");
  185.         }
  186.     }
  187.     /**
  188.      * Costruttore. Inizializza questo WSDLWrapper da un documento WSDL letto da una URI.
  189.      * @param uri La URI da cui leggere il WSDL.
  190.      */
  191.     public DefinitionWrapper(URI uri,AbstractXMLUtils xmlUtils)throws WSDLException{
  192.         this(uri,xmlUtils, false,true);
  193.     }
  194.     public DefinitionWrapper(URI uri,AbstractXMLUtils xmlUtils,boolean verbose,boolean importsDocument) throws WSDLException{
  195.         this.xmlUtils = xmlUtils;
  196.         this.wsdlUtilities = WSDLUtilities.getInstance(this.xmlUtils);
  197.         if (uri != null){
  198.             this.wsdlDefinition = this.wsdlUtilities.readWSDLFromURI(uri,verbose,importsDocument);
  199.             this.path = uri.getPath();
  200.         }else{
  201.             throw new WSDLException("WSDL(URI uri)","URI del wsdl non fornita");
  202.         }
  203.     }
  204.     /**
  205.      * Costruttore. Inizializza questo WSDLWrapper da un documento WSDL letto da una URI.
  206.      * @param wsdl il WSDL.
  207.      */
  208.     public DefinitionWrapper(javax.wsdl.Definition wsdl,AbstractXMLUtils xmlUtils) throws WSDLException{
  209.         this.xmlUtils = xmlUtils;
  210.         this.wsdlUtilities = WSDLUtilities.getInstance(this.xmlUtils);
  211.         if(wsdl==null)
  212.             throw new WSDLException("WSDL(javax.wsdl.Definition wsdl)","WSDL non fornito");
  213.         this.wsdlDefinition = wsdl;
  214.     }
  215.    

  216.    
  217.    
  218.    
  219.     /**
  220.      * Ritorna la definizione di questo oggetto.
  221.      * @return La definizione di questo oggetto.
  222.      */
  223.     public Definition getWsdlDefinition() {
  224.         return this.wsdlDefinition;
  225.     }

  226.     /**
  227.      * Imposta la definizione di questo oggetto.
  228.      * @param myDef La definizione da aggiornare.
  229.      */
  230.     public void setWsdlDefinitio(Definition myDef) {
  231.         this.wsdlDefinition = myDef;
  232.     }
  233.    
  234.    
  235.    
  236.    
  237.    
  238.     /** ----------------- NAMESPACE -------------------------- */
  239.    
  240.     @Override
  241.     public void addNamespace(String arg0, String arg1) {
  242.         this.wsdlDefinition.addNamespace(arg0, arg1);
  243.     }
  244.    
  245.     @Override
  246.     public Map<?,?> getNamespaces() {
  247.         return this.wsdlDefinition.getNamespaces();
  248.     }
  249.    
  250.     @Override
  251.     public String getNamespace(String arg0) {
  252.         return this.wsdlDefinition.getNamespace(arg0);
  253.     }

  254.     @Override
  255.     public String removeNamespace(String arg0) {
  256.         return this.wsdlDefinition.removeNamespace(arg0);
  257.     }
  258.    
  259.    
  260.    
  261.    
  262.    
  263.    
  264.     /** ----------------- IMPORT -------------------------- */
  265.    
  266.     @Override
  267.     public void addImport(Import arg0) {
  268.         this.wsdlDefinition.addImport(arg0);
  269.     }
  270.    
  271.     @Override
  272.     public Import createImport() {
  273.         return this.wsdlDefinition.createImport();
  274.     }
  275.    
  276.     @Override
  277.     public Map<?,?> getImports() {
  278.         return this.wsdlDefinition.getImports();
  279.     }
  280.    
  281.     @Override
  282.     public List<?> getImports(String arg0) {
  283.         return this.wsdlDefinition.getImports(arg0);
  284.     }
  285.    
  286.     @Override
  287.     public Import removeImport(Import arg0) {
  288.         return this.wsdlDefinition.removeImport(arg0);
  289.     }
  290.    
  291.     public void removeAllImports() throws WSDLException{
  292.         try{
  293.             Map<?,?> importsMap = this.wsdlDefinition.getImports();
  294.             Iterator<?> importsIt = importsMap.values().iterator();
  295.             while(importsIt.hasNext()){
  296.                 List<?> imports = (List<?>) importsIt.next();
  297.                 for(int i = 0; i<imports.size(); i++){
  298.                     Import myimport = (Import) imports.get(i);
  299.                     this.wsdlDefinition.removeImport(myimport);
  300.                 }
  301.             }
  302.         }catch(Exception e){
  303.             throw new WSDLException("removeAllImports()","Rimozione di tutti gli import non riuscita");
  304.         }
  305.     }
  306.    
  307.    
  308.    
  309.    
  310.    
  311.    
  312.     /** ----------------- TYPES -------------------------- */
  313.    
  314.     @Override
  315.     public Types createTypes() {
  316.         return this.wsdlDefinition.createTypes();
  317.     }
  318.    
  319.     @Override
  320.     public Types getTypes() {
  321.         return this.wsdlDefinition.getTypes();
  322.     }
  323.    
  324.     @Override
  325.     public void setTypes(Types arg0) {
  326.         this.wsdlDefinition.setTypes(arg0);
  327.     }
  328.    
  329.    
  330.    
  331.    
  332.    
  333.    
  334.     /** ----------------- MESSAGE -------------------------- */
  335.    
  336.     @Override
  337.     public void addMessage(Message arg0) {
  338.         this.wsdlDefinition.addMessage(arg0);
  339.     }
  340.    
  341.     @Override
  342.     public Message createMessage() {
  343.         return this.wsdlDefinition.createMessage();
  344.     }
  345.    
  346.     @Override
  347.     public Part createPart() {
  348.         return this.wsdlDefinition.createPart();
  349.     }
  350.    
  351.     @Override
  352.     public Map<?,?> getMessages() {
  353.         //return this.wsdlDefinition.getMessages();
  354.         // BUG: vengono generati come messaggi anche quelli definiti negli input/output delle operations, anche se poi non definite realmente come messages nel wsdl.
  355.         // Per evitare il bug, controllo che siano definite le parts
  356.          Map<?,?> maps = this.wsdlDefinition.getMessages();
  357.          Map<QName,Message> results = new HashMap<QName, Message>();
  358.          Iterator<?> itMessages = maps.keySet().iterator();
  359.          while(itMessages.hasNext()){
  360.              QName key = (QName) itMessages.next();
  361.              Message message = (Message) maps.get(key);
  362.              if(message.getParts()!=null && message.getParts().size()>0){
  363.                  results.put(key, message);
  364.              }
  365.          }
  366.         return results;
  367.     }
  368.    
  369.     @Override
  370.     public Message getMessage(QName arg0) {
  371.         return this.wsdlDefinition.getMessage(arg0);
  372.     }
  373.    
  374.     @Override
  375.     public Message removeMessage(QName arg0) {
  376.         return this.wsdlDefinition.removeMessage(arg0);
  377.     }
  378.    
  379.     public void removeAllMessages() throws WSDLException{
  380.         try{
  381.             Map<?,?> m = this.wsdlDefinition.getMessages();
  382.             Iterator<?> it = m.values().iterator();
  383.             List<QName> v = new ArrayList<QName>();
  384.             while (it.hasNext()) {
  385.                 v.add(((Message) it.next()).getQName());
  386.             }
  387.             for (int i = 0, j = v.size(); i < j; i++)
  388.                 this.wsdlDefinition.removeMessage(v.get(i));
  389.         }catch(Exception e){
  390.             throw new WSDLException("removeAllMessages()","Rimozione di tutti i messaggi non riuscita");
  391.         }
  392.     }
  393.    
  394.    
  395.    
  396.    
  397.    
  398.    
  399.    
  400.     /** ----------------- PORT-TYPE -------------------------- */
  401.    
  402.     @Override
  403.     public void addPortType(PortType arg0) {
  404.         this.wsdlDefinition.addPortType(arg0);
  405.     }
  406.    
  407.     @Override
  408.     public PortType createPortType() {
  409.         return this.wsdlDefinition.createPortType();
  410.     }
  411.    
  412.     @Override
  413.     public Operation createOperation() {
  414.         return this.wsdlDefinition.createOperation();
  415.     }
  416.    
  417.     @Override
  418.     public Input createInput() {
  419.         return this.wsdlDefinition.createInput();
  420.     }

  421.     @Override
  422.     public Output createOutput() {
  423.         return this.wsdlDefinition.createOutput();
  424.     }
  425.    
  426.     @Override
  427.     public Map<?,?> getAllPortTypes() {
  428.         return this.wsdlDefinition.getAllPortTypes();
  429.     }
  430.    
  431.     @Override
  432.     public Map<?,?> getPortTypes() {
  433.         return this.wsdlDefinition.getPortTypes();
  434.     }
  435.    
  436.     @Override
  437.     public PortType getPortType(QName arg0) {
  438.         return this.wsdlDefinition.getPortType(arg0);
  439.     }
  440.    
  441.     public PortType getPortType(String name) throws WSDLException {
  442.         try{
  443.             Map<?,?> m = this.wsdlDefinition.getAllPortTypes();
  444.             //System.out.println("REMOVE SIZE: "+m.size());
  445.             Iterator<?> it = m.values().iterator();
  446.             while (it.hasNext()){
  447.                 PortType pt = (PortType)it.next();
  448.                 if(pt.getQName()!=null) {
  449.                     if(name.equals(pt.getQName().getLocalPart())) {
  450.                         return pt;
  451.                     }
  452.                 }
  453.             }
  454.             return null;
  455.         }catch(Exception e){
  456.             //System.out.println("ERRORE: "+e.getMessage());
  457.             throw new WSDLException("getPortType("+name+")","Ricerca fallita",e);
  458.         }
  459.     }

  460.     @Override
  461.     public PortType removePortType(QName arg0) {
  462.         return this.wsdlDefinition.removePortType(arg0);
  463.     }

  464.     public void removeAllPortTypes() throws WSDLException{
  465.         try{
  466.             Map<?,?> m = this.wsdlDefinition.getAllPortTypes();
  467.             //System.out.println("REMOVE SIZE: "+m.size());
  468.             Iterator<?> it = m.values().iterator();
  469.             List<QName> v = new ArrayList<QName>();
  470.             while (it.hasNext()){
  471.                 PortType pt = (PortType)it.next();
  472.                 v.add(pt.getQName());
  473.                 //System.out.println("ADD REMOVE: "+pt.getQName());
  474.             }
  475.             for (int i=0; i<v.size(); i++){
  476.                 //System.out.println("REMOVE: "+v.get(i));
  477.                 this.wsdlDefinition.removePortType(v.get(i));
  478.             }
  479.             m = this.wsdlDefinition.getAllPortTypes();
  480.             //System.out.println("SIZE AFTER REMOVE: "+m.size());
  481.         }catch(Exception e){
  482.             //System.out.println("ERRORE: "+e.getMessage());
  483.             throw new WSDLException("removeAllPortTypes()","Rimozione di tutti i port type non riuscita");
  484.         }
  485.     }
  486.    
  487.    
  488.    
  489.    
  490.    
  491.    
  492.     /** ----------------- BINDING -------------------------- */

  493.     @Override
  494.     public void addBinding(Binding arg0) {
  495.         this.wsdlDefinition.addBinding(arg0);
  496.     }

  497.     @Override
  498.     public Binding createBinding() {
  499.         return this.wsdlDefinition.createBinding();
  500.     }
  501.    
  502.     @Override
  503.     public Fault createFault() {
  504.         return this.wsdlDefinition.createFault();
  505.     }
  506.    
  507.     @Override
  508.     public BindingOperation createBindingOperation() {
  509.         return this.wsdlDefinition.createBindingOperation();
  510.     }
  511.    
  512.     @Override
  513.     public BindingFault createBindingFault() {
  514.         return this.wsdlDefinition.createBindingFault();
  515.     }

  516.     @Override
  517.     public BindingInput createBindingInput() {
  518.         return this.wsdlDefinition.createBindingInput();
  519.     }
  520.    
  521.     @Override
  522.     public BindingOutput createBindingOutput() {
  523.         return this.wsdlDefinition.createBindingOutput();
  524.     }
  525.    
  526.     @Override
  527.     public Map<?,?> getAllBindings() {
  528.         return this.wsdlDefinition.getAllBindings();
  529.     }
  530.    
  531.     @Override
  532.     public Binding getBinding(QName arg0) {
  533.         return this.wsdlDefinition.getBinding(arg0);
  534.     }
  535.    
  536.     public Binding getBinding(String name) throws WSDLException {
  537.         try{
  538.             Map<?,?> m = this.wsdlDefinition.getAllBindings();
  539.             Iterator<?> it = m.values().iterator();
  540.             while (it.hasNext()){
  541.                 Binding binding = (Binding)it.next();
  542.                 if(binding.getQName()!=null) {
  543.                     if(name.equals(binding.getQName().getLocalPart())) {
  544.                         return binding;
  545.                     }
  546.                 }
  547.             }
  548.             return null;
  549.         }catch(Exception e){
  550.             throw new WSDLException("getBinding("+name+")","Ricerca fallita",e);
  551.         }
  552.     }
  553.    
  554.     public Binding getBindingByPortType(String portType) throws WSDLException {
  555.         try{
  556.             Map<?,?> m = this.wsdlDefinition.getAllBindings();
  557.             Iterator<?> it = m.values().iterator();
  558.             while (it.hasNext()){
  559.                 Binding binding = (Binding)it.next();
  560.                 if(binding.getPortType()!=null && binding.getPortType().getQName()!=null) {
  561.                     if(portType.equals(binding.getPortType().getQName().getLocalPart())) {
  562.                         return binding;
  563.                     }
  564.                 }
  565.             }
  566.             return null;
  567.         }catch(Exception e){
  568.             throw new WSDLException("getBindingByPortType("+portType+")","Ricerca fallita",e);
  569.         }
  570.     }
  571.    
  572.     @Override
  573.     public Map<?,?> getBindings() {
  574.         return this.wsdlDefinition.getBindings();
  575.     }
  576.    
  577.     @Override
  578.     public Binding removeBinding(QName arg0) {
  579.         return this.wsdlDefinition.removeBinding(arg0);
  580.     }
  581.    
  582.     public void removeAllBindings() throws WSDLException{
  583.         try{
  584.             Map<?,?> m = this.wsdlDefinition.getAllBindings();
  585.             Iterator<?> it = m.values().iterator();
  586.             List<QName> v = new ArrayList<QName>();
  587.             while (it.hasNext()){
  588.                 v.add(((Binding)it.next()).getQName());
  589.             }
  590.             for (int i=0, j=v.size(); i<j; i++)
  591.                 this.wsdlDefinition.removeBinding(v.get(i));
  592.         }catch(Exception e){
  593.             throw new WSDLException("removeAllBindings()","Rimozione di tutti i bindings non riuscita");
  594.         }
  595.     }
  596.    
  597.     public Map<QName,QName> getMapPortTypesImplementedBinding(){
  598.         Map<QName,QName> list = new HashMap<QName,QName>();
  599.         java.util.Map<?,?> bindings = this.getAllBindings();
  600.         if(bindings==null || bindings.size()==0){
  601.             return list;
  602.         }
  603.         Iterator<?> it = bindings.keySet().iterator();
  604.         while(it.hasNext()) {
  605.             javax.xml.namespace.QName key = (javax.xml.namespace.QName) it.next();
  606.             Binding binding = (Binding) bindings.get(key);
  607.             list.put(binding.getQName(),binding.getPortType().getQName());
  608.         }
  609.         return list;
  610.     }
  611.    
  612.    
  613.    
  614.    
  615.    
  616.     /** ----------------- SERVICES -------------------------- */
  617.     @Override
  618.     public void addService(Service arg0) {
  619.         this.wsdlDefinition.addService(arg0);
  620.     }

  621.     @Override
  622.     public Service createService() {
  623.         return this.wsdlDefinition.createService();
  624.     }
  625.    
  626.     @Override
  627.     public Port createPort() {
  628.         return this.wsdlDefinition.createPort();
  629.     }

  630.     @Override
  631.     public Map<?,?> getAllServices() {
  632.         return this.wsdlDefinition.getAllServices();
  633.     }
  634.    
  635.     @Override
  636.     public Map<?,?> getServices() {
  637.         return this.wsdlDefinition.getServices();
  638.     }
  639.    
  640.     @Override
  641.     public Service getService(QName arg0) {
  642.         return this.wsdlDefinition.getService(arg0);
  643.     }

  644.     public Service getService(String name) throws WSDLException {
  645.         try{
  646.             Map<?,?> m = this.wsdlDefinition.getAllServices();
  647.             Iterator<?> it = m.values().iterator();
  648.             while (it.hasNext()){
  649.                 Service service = (Service)it.next();
  650.                 if(service.getQName()!=null) {
  651.                     if(name.equals(service.getQName().getLocalPart())) {
  652.                         return service;
  653.                     }
  654.                 }
  655.             }
  656.             return null;
  657.         }catch(Exception e){
  658.             throw new WSDLException("getService("+name+")","Ricerca fallita",e);
  659.         }
  660.     }
  661.        
  662.     @Override
  663.     public Service removeService(QName arg0) {
  664.         return this.wsdlDefinition.removeService(arg0);
  665.     }

  666.     public void removeAllServices() throws WSDLException{
  667.         try{
  668.             Map<?,?> m = this.wsdlDefinition.getAllServices();
  669.             Iterator<?> it = m.values().iterator();
  670.             List<QName> v = new ArrayList<QName>();
  671.             while (it.hasNext()){
  672.                 v.add(((Service)it.next()).getQName());
  673.             }
  674.             for (int i=0, j=v.size(); i<j; i++)
  675.                 this.wsdlDefinition.removeService(v.get(i));
  676.         }catch(Exception e){
  677.             throw new WSDLException("removeAllServices()","Rimozione di tutti i services non riuscita");
  678.         }
  679.     }


  680.    
  681.    
  682.    
  683.     /** ----------------- SERVICES - PORT -------------------------- */
  684.    
  685.     public Port getServicePort(String name) throws WSDLException {
  686.         try{
  687.             Map<?,?> m = this.wsdlDefinition.getAllServices();
  688.             Iterator<?> it = m.values().iterator();
  689.             while (it.hasNext()){
  690.                 Service service = (Service)it.next();
  691.                 Map<?,?> mPorts = service.getPorts();
  692.                 Iterator<?> itPorts = mPorts.values().iterator();
  693.                 while (itPorts.hasNext()){
  694.                     Port port = (Port)it.next();
  695.                     if(name.equals(port.getName())) {
  696.                         return port;
  697.                     }
  698.                 }
  699.             }
  700.             return null;
  701.         }catch(Exception e){
  702.             throw new WSDLException("getServicePort("+name+")","Ricerca fallita",e);
  703.         }
  704.     }
  705.    
  706.     public Port getServicePortByBindingName(String bindingName) throws WSDLException {
  707.         try{
  708.             Map<?,?> m = this.wsdlDefinition.getAllServices();
  709.             Iterator<?> it = m.values().iterator();
  710.             while (it.hasNext()){
  711.                 Service service = (Service)it.next();
  712.                 Map<?,?> mPorts = service.getPorts();
  713.                 Iterator<?> itPorts = mPorts.values().iterator();
  714.                 while (itPorts.hasNext()){
  715.                     Port port = (Port)itPorts.next();
  716.                     if(port.getBinding()!=null && port.getBinding().getQName()!=null) {
  717.                         if(bindingName.equals(port.getBinding().getQName().getLocalPart())) {
  718.                             return port;
  719.                         }
  720.                     }
  721.                 }
  722.             }
  723.             return null;
  724.         }catch(Exception e){
  725.             throw new WSDLException("getServicePortByBindingName("+bindingName+")","Ricerca fallita",e);
  726.         }
  727.     }
  728.    
  729.     public String getLocation(Port port) throws WSDLException {
  730.         if(port.getExtensibilityElements()!=null) {
  731.             for (Object object : port.getExtensibilityElements()) {
  732.                 if(object instanceof SOAPAddress) {
  733.                     return ((SOAPAddress)object).getLocationURI();
  734.                 }
  735.                 else if(object instanceof SOAP12Address) {
  736.                     return ((SOAP12Address)object).getLocationURI();
  737.                 }
  738.                 // System.out.println("ALTRO ["+object.getClass().getName()+"]");
  739.             }
  740.         }
  741.         return null;
  742.     }
  743.    
  744.     public void updateLocation(Port port, String location) throws WSDLException {
  745.         if(port.getExtensibilityElements()!=null) {
  746.             for (Object object : port.getExtensibilityElements()) {
  747.                 if(object instanceof SOAPAddress) {
  748.                     ((SOAPAddress)object).setLocationURI(location);
  749.                 }
  750.                 else if(object instanceof SOAP12Address) {
  751.                     ((SOAP12Address)object).setLocationURI(location);
  752.                 }
  753.                 // System.out.println("ALTRO ["+object.getClass().getName()+"]");
  754.             }
  755.         }
  756.     }


  757.    
  758.    
  759.     /** ----------------- OTHER ------------------------- */
  760.     @Override
  761.     public String getDocumentBaseURI() {
  762.         return this.wsdlDefinition.getDocumentBaseURI();
  763.     }

  764.     @Override
  765.     public void setDocumentBaseURI(String arg0) {
  766.         this.wsdlDefinition.setDocumentBaseURI(arg0);
  767.     }

  768.     @Override
  769.     public String getPrefix(String arg0) {
  770.         return this.wsdlDefinition.getPrefix(arg0);
  771.     }

  772.     @Override
  773.     public String getTargetNamespace() {
  774.         return this.wsdlDefinition.getTargetNamespace();
  775.     }
  776.    
  777.     @Override
  778.     public void setTargetNamespace(String arg0) {
  779.         this.wsdlDefinition.setTargetNamespace(arg0);
  780.     }
  781.    
  782.     @Override
  783.     public QName getQName() {
  784.         return this.wsdlDefinition.getQName();
  785.     }
  786.    
  787.     @Override
  788.     public void setQName(QName arg0) {
  789.         this.wsdlDefinition.setQName(arg0);
  790.     }
  791.    
  792.     @Override
  793.     public ExtensionRegistry getExtensionRegistry() {
  794.         return this.wsdlDefinition.getExtensionRegistry();
  795.     }
  796.    
  797.     @Override
  798.     public void setExtensionRegistry(ExtensionRegistry arg0) {
  799.         this.wsdlDefinition.setExtensionRegistry(arg0);
  800.     }

  801.     @Override
  802.     public Element getDocumentationElement() {
  803.         return this.wsdlDefinition.getDocumentationElement();
  804.     }
  805.    
  806.     @Override
  807.     public void setDocumentationElement(Element arg0) {
  808.         this.wsdlDefinition.setDocumentationElement(arg0);
  809.     }

  810.     @Override
  811.     public Object getExtensionAttribute(QName arg0) {
  812.         return this.wsdlDefinition.getExtensionAttribute(arg0);
  813.     }

  814.     @Override
  815.     public Map<?,?> getExtensionAttributes() {
  816.         return this.wsdlDefinition.getExtensionAttributes();
  817.     }
  818.    
  819.     @Override
  820.     public void setExtensionAttribute(QName arg0, Object arg1) {
  821.         this.wsdlDefinition.setExtensionAttribute(arg0, arg1);
  822.     }

  823.     @Override
  824.     public List<?> getNativeAttributeNames() {
  825.         return this.wsdlDefinition.getNativeAttributeNames();
  826.     }
  827.    
  828.     @Override
  829.     public void addExtensibilityElement(ExtensibilityElement arg0) {
  830.         this.wsdlDefinition.addExtensibilityElement(arg0);
  831.     }


  832.     @Override
  833.     public List<?> getExtensibilityElements() {
  834.         return this.wsdlDefinition.getExtensibilityElements();
  835.     }


  836.     @Override
  837.     public ExtensibilityElement removeExtensibilityElement(
  838.             ExtensibilityElement arg0) {
  839.         return this.wsdlDefinition.removeExtensibilityElement(arg0);
  840.     }

  841.     public String getPath() {
  842.         return this.path;
  843.     }

  844.     public void setPath(String path) {
  845.         this.path = path;
  846.     }

  847.    
  848.    
  849.    
  850.    
  851.    
  852.    
  853.     /** ----------------- WRITE TO ------------------------- */
  854.    
  855.     public byte[] toByteArray() throws WSDLException{
  856.         return toByteArray(false);
  857.     }
  858.     public byte[] toByteArray(boolean prettyPrint) throws WSDLException{
  859.         try{            
  860.             ByteArrayOutputStream bout = new ByteArrayOutputStream();
  861.             this.wsdlUtilities.writeWsdlTo(this.wsdlDefinition, bout,prettyPrint);
  862.             bout.flush();
  863.             bout.close();
  864.             return bout.toByteArray();
  865.         }catch(Exception e){
  866.             throw new WSDLException("toByteArray()","Conversione in byte[] non riuscita: "+e.getMessage());
  867.         }
  868.     }
  869.     @Override
  870.     public String toString() {
  871.         return toString(false);
  872.     }
  873.     public String toString(boolean prettyPrint) {
  874.         try{
  875.             return new String(this.toByteArray(prettyPrint));
  876.         }catch(Exception e){
  877.             return null;
  878.         }
  879.     }
  880.    
  881.     public void writeTo(OutputStream out) throws IOException,WSDLException,org.openspcoop2.utils.wsdl.WSDLException{
  882.         writeTo(out,false);
  883.     }
  884.     public void writeTo(OutputStream out,boolean prettyPrint) throws IOException,WSDLException,org.openspcoop2.utils.wsdl.WSDLException{
  885.         this.wsdlUtilities.writeWsdlTo(this.wsdlDefinition, out,prettyPrint);
  886.     }
  887.    
  888.     public void writeTo(Writer writer) throws IOException,WSDLException,org.openspcoop2.utils.wsdl.WSDLException{
  889.         writeTo(writer,false);
  890.     }
  891.     public void writeTo(Writer writer,boolean prettyPrint) throws IOException,WSDLException,org.openspcoop2.utils.wsdl.WSDLException{
  892.         this.wsdlUtilities.writeWsdlTo(this.wsdlDefinition, writer,prettyPrint);
  893.     }
  894.    
  895.     public void writeTo(File file) throws IOException,WSDLException,org.openspcoop2.utils.wsdl.WSDLException{
  896.         writeTo(file,false);
  897.     }
  898.     public void writeTo(File file,boolean prettyPrint) throws IOException,WSDLException,org.openspcoop2.utils.wsdl.WSDLException{
  899.         this.wsdlUtilities.writeWsdlTo(this.wsdlDefinition, file,prettyPrint);
  900.     }
  901.    
  902.     public void writeTo(String absoluteFilePath) throws IOException,WSDLException,org.openspcoop2.utils.wsdl.WSDLException{
  903.         writeTo(absoluteFilePath,false);
  904.     }
  905.     public void writeTo(String absoluteFilePath,boolean prettyPrint) throws IOException,WSDLException,org.openspcoop2.utils.wsdl.WSDLException{
  906.         this.wsdlUtilities.writeWsdlTo(this.wsdlDefinition, absoluteFilePath,prettyPrint);
  907.     }
  908.    
  909.    
  910.    
  911.    
  912.    
  913.    
  914.    
  915.     /** ----------------- VALIDATE ------------------------- */
  916.    
  917.     public void valida() throws org.openspcoop2.utils.wsdl.WSDLException{
  918.         valida(true);
  919.     }
  920.     public void valida(boolean validaBinding) throws org.openspcoop2.utils.wsdl.WSDLException{
  921.        
  922.         // Messages
  923.         Map<?, ?> messages = this.getMessages();
  924.         if(messages==null || messages.size()==0){
  925.             throw new org.openspcoop2.utils.wsdl.WSDLException("Messages non presenti");
  926.         }
  927.         Iterator<?> itMessages = messages.keySet().iterator();
  928.         while(itMessages.hasNext()){
  929.             javax.xml.namespace.QName keyMessage = (javax.xml.namespace.QName) itMessages.next();
  930.             int count = 0;
  931.             Iterator<?> itMessagesCheck = messages.keySet().iterator();
  932.             while(itMessagesCheck.hasNext()){
  933.                 javax.xml.namespace.QName keyMessageCheck = (javax.xml.namespace.QName) itMessagesCheck.next();
  934.                 if(keyMessageCheck.equals(keyMessage)){
  935.                     count++;
  936.                 }
  937.             }
  938.             if(count>1){
  939.                 throw new org.openspcoop2.utils.wsdl.WSDLException("Wsdl:message "+keyMessage+" definito piu' di una volta");
  940.             }
  941.         }
  942.        
  943.         // Port-types
  944.         Map<?, ?> porttypes = this.getAllPortTypes();
  945.         if(porttypes==null || porttypes.size()==0){
  946.             throw new org.openspcoop2.utils.wsdl.WSDLException("Port types non presenti");
  947.         }
  948.         Iterator<?> itPortTypes = porttypes.keySet().iterator();
  949.         while(itPortTypes.hasNext()){
  950.             javax.xml.namespace.QName keyPT = (javax.xml.namespace.QName) itPortTypes.next();
  951.             int count = 0;
  952.             Iterator<?> itPTCheck = porttypes.keySet().iterator();
  953.             while(itPTCheck.hasNext()){
  954.                 javax.xml.namespace.QName keyPTCheck = (javax.xml.namespace.QName) itPTCheck.next();
  955.                 if(keyPTCheck.equals(keyPT)){
  956.                     count++;
  957.                 }
  958.             }
  959.             if(count>1){
  960.                 throw new org.openspcoop2.utils.wsdl.WSDLException("Port type "+keyPT+" definito piu' di una volta");
  961.             }
  962.         }
  963.         Iterator<?> it = porttypes.keySet().iterator();
  964.         while(it.hasNext()){
  965.             javax.xml.namespace.QName key = (javax.xml.namespace.QName) it.next();
  966.             javax.wsdl.PortType pt = (javax.wsdl.PortType) porttypes.get(key);
  967.            
  968.             // operation port type
  969.             List<?> operations = pt.getOperations();
  970.             if(operations==null || operations.size()==0){
  971.                 throw new org.openspcoop2.utils.wsdl.WSDLException("Port type "+key+" non possiede operations");
  972.             }
  973.             Iterator<?> itOperations = operations.iterator();
  974.             while(itOperations.hasNext()){
  975.                 javax.wsdl.Operation op = (javax.wsdl.Operation) itOperations.next();
  976.                 String keyOp = op.getName();
  977.                 int count = 0;
  978.                 Iterator<?> itOperationsCheck = operations.iterator();
  979.                 while(itOperationsCheck.hasNext()){
  980.                     javax.wsdl.Operation opCheck = (javax.wsdl.Operation) itOperationsCheck.next();
  981.                     String keyOpCheck = opCheck.getName();
  982.                     if(keyOpCheck.equals(keyOp)){
  983.                         count++;
  984.                     }
  985.                 }
  986.                 if(count>1){
  987.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Port type "+key+" possiede l'operation "+keyOp+" definita piu' di una volta");
  988.                 }
  989.             }
  990.            
  991.             for(int i=0; i<operations.size();i++){
  992.                 javax.wsdl.Operation op = (javax.wsdl.Operation) operations.get(i);
  993.            
  994.                 Input input = op.getInput();
  995.                 Output output = op.getOutput();
  996.                
  997.                 String bindingWarning = "";
  998.                 try{
  999.                     java.util.Map<?,?> bindings = this.getAllBindings();
  1000.                     if(bindings!=null && bindings.size()>0){
  1001.                         bindingWarning = " (Verificare che il problema non sia dovuto a errori ereditati da una definizione del binding non corretta (es. port-type indicato nel binding inesistente))";
  1002.                     }
  1003.                 }catch(Throwable e){}
  1004.                
  1005.                 // INPUT
  1006.                 if(input==null){
  1007.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Non e' stato definito un input per l'operation "+op.getName()+" (Port type "+key+")"+bindingWarning);
  1008.                 }
  1009.                 if(input.getMessage()==null){
  1010.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Non e' stato definito un input message per l'operation "+op.getName()+" (Port type "+key+")"+bindingWarning);
  1011.                 }
  1012.                 if(input.getMessage().getQName()==null){
  1013.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Non e' stato definito un input message (QName) per l'operation "+op.getName()+" (Port type "+key+")"+bindingWarning);
  1014.                 }
  1015.                 QName messageInput = input.getMessage().getQName();
  1016.                 itMessages = messages.keySet().iterator();
  1017.                 boolean findMessageInput = false;
  1018.                 while(itMessages.hasNext()){
  1019.                     javax.xml.namespace.QName keyMessage = (javax.xml.namespace.QName) itMessages.next();
  1020.                     if(
  1021.                             ( (messageInput.getNamespaceURI()==null) && (messageInput.getPrefix()==null) )
  1022.                                 ||
  1023.                             ( "".equals(messageInput.getNamespaceURI()) && "".equals(messageInput.getPrefix()) )
  1024.                     ){ // workaroung necessario per axiomDocumentBuilder
  1025.                         if(keyMessage.getLocalPart().equals(messageInput.getLocalPart())){
  1026.                             findMessageInput = true;
  1027.                         }
  1028.                     }else{
  1029.                         if(keyMessage.equals(messageInput)){
  1030.                             findMessageInput = true;
  1031.                         }
  1032.                     }
  1033.                 }
  1034.                 if(!findMessageInput){
  1035.                    
  1036.                     // BUG: vengono generati come messaggi anche quelli definiti negli input/output delle operations, anche se poi non definite realmente come messages nel wsdl.
  1037.                     // Per evitare il bug, controllo che siano definite le parts nel metodo Map<?, ?> messages = this.getMessages();
  1038.                     // Purtroppo nel caso esistano davvero dei messaggi che però sono senza parts, questi non vengono trovati e si lancia l'errore seguente.
  1039.                     // Per sopperire all'errore si fa un controllo ulteriore tramite xpath
  1040.                     if(this.wsdlDefinitionNode!=null) {
  1041.                         XPathExpressionEngine xpathEngine = new XPathExpressionEngine();
  1042.                         DynamicNamespaceContext dnc = new DynamicNamespaceContext();
  1043.                         dnc.findPrefixNamespace(this.wsdlDefinitionNode);
  1044.                         try {
  1045.                             Object object = xpathEngine.getMatchPattern((Document)this.wsdlDefinitionNode, dnc, "//{http://schemas.xmlsoap.org/wsdl/}message", XPathReturnType.NODESET);
  1046.                             if(object instanceof NodeList) {
  1047.                                 NodeList nList = (NodeList) object;
  1048.                                 for (int j = 0; j < nList.getLength(); j++) {
  1049.                                     Node n = nList.item(j);
  1050.                                     if(n.getAttributes()!=null && n.getAttributes().getLength()>0) {
  1051.                                         Node nn = n.getAttributes().getNamedItem("name");
  1052.                                         if(nn!=null) {
  1053.                                             String value = nn.getNodeValue();
  1054.                                             //System.out.println("DDDDDD localName["+nn.getLocalName()+"] namespace["+nn.getNamespaceURI()+"] value["+nn.getNodeValue()+"] ["+nn.getClass().getName()+"]");
  1055.                                             if(messageInput.getLocalPart()!=null && messageInput.getLocalPart().equals(value)) {
  1056.                                                 findMessageInput = true;
  1057.                                                 break;
  1058.                                             }
  1059.                                         }
  1060.                                     }
  1061.                                 }
  1062.                             }
  1063.                         }catch(Throwable t) {}
  1064.                     }
  1065.                    
  1066.                     if(!findMessageInput){
  1067.                         throw new org.openspcoop2.utils.wsdl.WSDLException("E' stato associato un wsdl:message inesistente ("+messageInput+")  all'input dell'operation "+op.getName()+" (Port type "+key+")"+bindingWarning);
  1068.                     }
  1069.                 }
  1070.                
  1071.                 // OUTPUT
  1072.                 if(output!=null){
  1073.                     if(output.getMessage()==null){
  1074.                         throw new org.openspcoop2.utils.wsdl.WSDLException("Non e' stato definito un output message per l'operation "+op.getName()+" (Port type "+key+")"+bindingWarning);
  1075.                     }
  1076.                     if(output.getMessage().getQName()==null){
  1077.                         throw new org.openspcoop2.utils.wsdl.WSDLException("Non e' stato definito un output message (QName) per l'operation "+op.getName()+" (Port type "+key+")"+bindingWarning);
  1078.                     }
  1079.                    
  1080.                     QName messageOutput = input.getMessage().getQName();
  1081.                     itMessages = messages.keySet().iterator();
  1082.                     boolean findMessageOutput = false;
  1083.                     while(itMessages.hasNext()){
  1084.                         javax.xml.namespace.QName keyMessage = (javax.xml.namespace.QName) itMessages.next();
  1085.                         if(
  1086.                                 ( (messageOutput.getNamespaceURI()==null) && (messageOutput.getPrefix()==null) )
  1087.                                     ||
  1088.                                 ( "".equals(messageOutput.getNamespaceURI()) && "".equals(messageOutput.getPrefix()) )
  1089.                         ){ // workaroung necessario per axiomDocumentBuilder
  1090.                             if(keyMessage.getLocalPart().equals(messageOutput.getLocalPart())){
  1091.                                 findMessageOutput = true;
  1092.                             }
  1093.                         }else{
  1094.                             if(keyMessage.equals(messageOutput)){
  1095.                                 findMessageOutput = true;
  1096.                             }
  1097.                         }
  1098.                     }
  1099.                     if(!findMessageOutput){
  1100.                        
  1101.                         // BUG: vengono generati come messaggi anche quelli definiti negli input/output delle operations, anche se poi non definite realmente come messages nel wsdl.
  1102.                         // Per evitare il bug, controllo che siano definite le parts nel metodo Map<?, ?> messages = this.getMessages();
  1103.                         // Purtroppo nel caso esistano davvero dei messaggi che però sono senza parts, questi non vengono trovati e si lancia l'errore seguente.
  1104.                         // Per sopperire all'errore si fa un controllo ulteriore tramite xpath
  1105.                         if(this.wsdlDefinitionNode!=null) {
  1106.                             XPathExpressionEngine xpathEngine = new XPathExpressionEngine();
  1107.                             DynamicNamespaceContext dnc = new DynamicNamespaceContext();
  1108.                             dnc.findPrefixNamespace(this.wsdlDefinitionNode);
  1109.                             try {
  1110.                                 Object object = xpathEngine.getMatchPattern((Document)this.wsdlDefinitionNode, dnc, "//{http://schemas.xmlsoap.org/wsdl/}message", XPathReturnType.NODESET);
  1111.                                 if(object instanceof NodeList) {
  1112.                                     NodeList nList = (NodeList) object;
  1113.                                     for (int j = 0; j < nList.getLength(); j++) {
  1114.                                         Node n = nList.item(j);
  1115.                                         if(n.getAttributes()!=null && n.getAttributes().getLength()>0) {
  1116.                                             Node nn = n.getAttributes().getNamedItem("name");
  1117.                                             if(nn!=null) {
  1118.                                                 String value = nn.getNodeValue();
  1119.                                                 //System.out.println("DDDDDD localName["+nn.getLocalName()+"] namespace["+nn.getNamespaceURI()+"] value["+nn.getNodeValue()+"] ["+nn.getClass().getName()+"]");
  1120.                                                 if(messageOutput.getLocalPart()!=null && messageOutput.getLocalPart().equals(value)) {
  1121.                                                     findMessageOutput = true;
  1122.                                                     break;
  1123.                                                 }
  1124.                                             }
  1125.                                         }
  1126.                                     }
  1127.                                 }
  1128.                             }catch(Throwable t) {}
  1129.                         }
  1130.                        
  1131.                         if(!findMessageOutput){
  1132.                             throw new org.openspcoop2.utils.wsdl.WSDLException("E' stato associato un wsdl:message inesistente ("+messageOutput+") all'output dell'operation "+op.getName()+" (Port type "+key+")"+bindingWarning);
  1133.                         }
  1134.                     }
  1135.                 }
  1136.             }
  1137.         }
  1138.        
  1139.         if(validaBinding){
  1140.            
  1141.             java.util.Map<?,?> bindings = this.getAllBindings();
  1142.             if(bindings==null || bindings.size()==0){
  1143.                 throw new org.openspcoop2.utils.wsdl.WSDLException("Bindings non presenti");
  1144.             }
  1145.             Iterator<?> itBindings = bindings.keySet().iterator();
  1146.             while(itBindings.hasNext()){
  1147.                 javax.xml.namespace.QName keyBinding = (javax.xml.namespace.QName) itBindings.next();
  1148.                 int count = 0;
  1149.                 Iterator<?> itBindingsCheck = bindings.keySet().iterator();
  1150.                 while(itBindingsCheck.hasNext()){
  1151.                     javax.xml.namespace.QName keyBindingCheck = (javax.xml.namespace.QName) itBindingsCheck.next();
  1152.                     if(keyBindingCheck.equals(keyBinding)){
  1153.                         count++;
  1154.                     }
  1155.                 }
  1156.                 if(count>1){
  1157.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Wsdl:binding "+keyBinding+" definito piu' di una volta");
  1158.                 }
  1159.             }
  1160.             it = bindings.keySet().iterator();
  1161.             while(it.hasNext()) {
  1162.                 javax.xml.namespace.QName key = (javax.xml.namespace.QName) it.next();
  1163.                 Binding binding = (Binding) bindings.get(key);
  1164.                
  1165.                 if(binding.getPortType()==null){
  1166.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Non e' stato associato un port type al binding "+key);
  1167.                 }
  1168.                 if(binding.getPortType().getQName()==null){
  1169.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Non e' stato associato un port type (Qname) al binding "+key);
  1170.                 }
  1171.                
  1172.                 QName portTypeQname = binding.getPortType().getQName();
  1173.                 boolean findPT = false;
  1174.                 Iterator<?> itPT = this.getPortTypes().keySet().iterator();
  1175.                 while(itPT.hasNext()){
  1176.                     javax.xml.namespace.QName keyPT = (javax.xml.namespace.QName) itPT.next();
  1177.                     if(keyPT.equals(portTypeQname)){
  1178.                         findPT =  true;
  1179.                         break;
  1180.                     }
  1181.                 }
  1182.                 if(!findPT){
  1183.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Il port type "+portTypeQname+" associato al  binding "+key +" non esiste");
  1184.                 }
  1185.                
  1186.                
  1187.             }
  1188.            
  1189.             java.util.Map<?,?> services = this.getAllServices();
  1190.             if(services==null || services.size()==0){
  1191.                 throw new org.openspcoop2.utils.wsdl.WSDLException("Services non presenti");
  1192.             }
  1193.             Iterator<?> itServices = services.keySet().iterator();
  1194.             while(itServices.hasNext()){
  1195.                 javax.xml.namespace.QName keyService = (javax.xml.namespace.QName) itServices.next();
  1196.                 int count = 0;
  1197.                 Iterator<?> itServicesCheck = services.keySet().iterator();
  1198.                 while(itServicesCheck.hasNext()){
  1199.                     javax.xml.namespace.QName keyServiceCheck = (javax.xml.namespace.QName) itServicesCheck.next();
  1200.                     if(keyServiceCheck.equals(keyService)){
  1201.                         count++;
  1202.                     }
  1203.                 }
  1204.                 if(count>1){
  1205.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Wsdl:service "+keyService+" definito piu' di una volta");
  1206.                 }
  1207.             }
  1208.             it = services.keySet().iterator();
  1209.             while(it.hasNext()) {
  1210.                 javax.xml.namespace.QName keyService = (javax.xml.namespace.QName) it.next();
  1211.                 Service service = (Service) services.get(keyService);
  1212.                
  1213.                 java.util.Map<?,?> ports = service.getPorts();
  1214.                 if(ports==null || ports.size()==0){
  1215.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Ports non presenti per il service "+keyService);
  1216.                 }
  1217.                
  1218.                 Iterator<?> itPort = ports.keySet().iterator();
  1219.                 while(itPort.hasNext()) {
  1220.                     String keyPort = (String) itPort.next();
  1221.                     Port port = (Port) ports.get(keyPort);
  1222.                    
  1223.                     if(port.getBinding()==null){
  1224.                         throw new org.openspcoop2.utils.wsdl.WSDLException("Wsdl:port "+keyPort+" non possiede un binding associato (service "+keyService+")");
  1225.                     }
  1226.                     if(port.getBinding().getQName()==null){
  1227.                         throw new org.openspcoop2.utils.wsdl.WSDLException("Wsdl:port "+keyPort+" non possiede un binding (QName) associato (service "+keyService+")");
  1228.                     }
  1229.                    
  1230.                     QName bindingQName = port.getBinding().getQName();
  1231.                     boolean findBinding = false;
  1232.                     itBindings = this.getAllBindings().keySet().iterator();
  1233.                     while(itBindings.hasNext()){
  1234.                         javax.xml.namespace.QName keyBinding = (javax.xml.namespace.QName) itBindings.next();
  1235.                         if(keyBinding.equals(bindingQName)){
  1236.                             findBinding =  true;
  1237.                             break;
  1238.                         }
  1239.                     }
  1240.                     if(!findBinding){
  1241.                         throw new org.openspcoop2.utils.wsdl.WSDLException("Binding  "+bindingQName+" associato al  wsdl:port "+keyPort +" non esiste (service "+keyService+")");
  1242.                     }
  1243.                 }
  1244.             }
  1245.         }
  1246.     }
  1247.    
  1248.     public void validaBinding(List<String> portTypes) throws org.openspcoop2.utils.wsdl.WSDLException{
  1249.        
  1250.         java.util.Map<?,?> bindings = this.getAllBindings();
  1251.         if(bindings==null || bindings.size()==0){
  1252.             throw new org.openspcoop2.utils.wsdl.WSDLException("Bindings non presenti");
  1253.         }
  1254.         Iterator<?> itBindings = bindings.keySet().iterator();
  1255.         while(itBindings.hasNext()){
  1256.             javax.xml.namespace.QName keyBinding = (javax.xml.namespace.QName) itBindings.next();
  1257.             int count = 0;
  1258.             Iterator<?> itBindingsCheck = bindings.keySet().iterator();
  1259.             while(itBindingsCheck.hasNext()){
  1260.                 javax.xml.namespace.QName keyBindingCheck = (javax.xml.namespace.QName) itBindingsCheck.next();
  1261.                 if(keyBindingCheck.equals(keyBinding)){
  1262.                     count++;
  1263.                 }
  1264.             }
  1265.             if(count>1){
  1266.                 throw new org.openspcoop2.utils.wsdl.WSDLException("Wsdl:binding "+keyBinding+" definito piu' di una volta");
  1267.             }
  1268.         }
  1269.         Iterator<?> it = bindings.keySet().iterator();
  1270.         while(it.hasNext()) {
  1271.             javax.xml.namespace.QName key = (javax.xml.namespace.QName) it.next();
  1272.             Binding binding = (Binding) bindings.get(key);
  1273.            
  1274.             if( !(
  1275.                     ( (key.getNamespaceURI()==null) && (key.getPrefix()==null) )
  1276.                         ||
  1277.                     ( "".equals(key.getNamespaceURI()) && "".equals(key.getPrefix()) )
  1278.                 )
  1279.             ){ // workaroung necessario per axiomDocumentBuilder
  1280.            
  1281.                 if(binding.getPortType()==null){
  1282.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Non e' stato associato un port type al binding "+key);
  1283.                 }
  1284.                 if(binding.getPortType().getQName()==null){
  1285.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Non e' stato associato un port type (QName) al binding "+key);
  1286.                 }
  1287.                
  1288.                 QName portTypeQname = binding.getPortType().getQName();
  1289.                 boolean findPT = false;
  1290.                 for(int i=0; i<portTypes.size(); i++){
  1291.                     String keyPT = portTypes.get(i);
  1292.                     //System.out.println("CHECK ["+keyPT+"]==["+portTypes.get(i)+"]");
  1293.                     if(keyPT.equals(portTypeQname.getLocalPart())){
  1294.                         //System.out.println("FIND");
  1295.                         findPT =  true;
  1296.                         break;
  1297.                     }
  1298.                 }
  1299.                 if(!findPT){
  1300.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Il port type "+portTypeQname+" associato al  binding "+key +" non esiste");
  1301.                 }
  1302.             }
  1303.            
  1304.            
  1305.         }
  1306.        
  1307.         java.util.Map<?,?> services = this.getAllServices();
  1308.         if(services==null || services.size()==0){
  1309.             throw new org.openspcoop2.utils.wsdl.WSDLException("Services non presenti");
  1310.         }
  1311.         Iterator<?> itServices = services.keySet().iterator();
  1312.         while(itServices.hasNext()){
  1313.             javax.xml.namespace.QName keyService = (javax.xml.namespace.QName) itServices.next();
  1314.             int count = 0;
  1315.             Iterator<?> itServicesCheck = services.keySet().iterator();
  1316.             while(itServicesCheck.hasNext()){
  1317.                 javax.xml.namespace.QName keyServiceCheck = (javax.xml.namespace.QName) itServicesCheck.next();
  1318.                 if(keyServiceCheck.equals(keyService)){
  1319.                     count++;
  1320.                 }
  1321.             }
  1322.             if(count>1){
  1323.                 throw new org.openspcoop2.utils.wsdl.WSDLException("Wsdl:service "+keyService+" definito piu' di una volta");
  1324.             }
  1325.         }
  1326.         it = services.keySet().iterator();
  1327.         while(it.hasNext()) {
  1328.             javax.xml.namespace.QName keyService = (javax.xml.namespace.QName) it.next();
  1329.             Service service = (Service) services.get(keyService);
  1330.            
  1331.             java.util.Map<?,?> ports = service.getPorts();
  1332.             if(ports==null || ports.size()==0){
  1333.                 throw new org.openspcoop2.utils.wsdl.WSDLException("Ports non presenti per il service "+keyService);
  1334.             }
  1335.            
  1336.             Iterator<?> itPort = ports.keySet().iterator();
  1337.             while(itPort.hasNext()) {
  1338.                 String keyPort = (String) itPort.next();
  1339.                 Port port = (Port) ports.get(keyPort);
  1340.                
  1341.                 if(port.getBinding()==null){
  1342.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Wsdl:port "+keyPort+" non possiede un binding associato (service "+keyService+")");
  1343.                 }
  1344.                 if(port.getBinding().getQName()==null){
  1345.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Wsdl:port "+keyPort+" non possiede un binding (QName) associato (service "+keyService+")");
  1346.                 }
  1347.                
  1348.                 QName bindingQName = port.getBinding().getQName();
  1349.                 boolean findBinding = false;
  1350.                 itBindings = this.getAllBindings().keySet().iterator();
  1351.                 while(itBindings.hasNext()){
  1352.                     javax.xml.namespace.QName keyBinding = (javax.xml.namespace.QName) itBindings.next();
  1353.                     if(keyBinding.equals(bindingQName)){
  1354.                         findBinding =  true;
  1355.                         break;
  1356.                     }
  1357.                 }
  1358.                 if(!findBinding){
  1359.                     throw new org.openspcoop2.utils.wsdl.WSDLException("Binding  "+bindingQName+" associato al  wsdl:port "+keyPort +" non esiste (service "+keyService+")");
  1360.                 }
  1361.             }
  1362.         }
  1363.     }
  1364.    
  1365. }