Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 06e82b6ff3cff2181c5f24f772efd6cbca1ac3d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
/*******************************************************************************
 * Copyright (c) 2002-2005 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsi.internal.core.analyzer;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.wsdl.Binding;
import javax.wsdl.BindingOperation;
import javax.wsdl.Definition;
import javax.wsdl.Fault;
import javax.wsdl.Import;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.Types;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.xml.namespace.QName;

import org.apache.xerces.util.URI;
import org.eclipse.wst.wsi.internal.core.WSIException;
import org.eclipse.wst.wsi.internal.core.analyzer.config.WSDLElement;
import org.eclipse.wst.wsi.internal.core.wsdl.WSDLDocument;
import org.eclipse.wst.wsi.internal.core.wsdl.WSDLUtils;

/**
 * Provide a normalized set of data relating to the service under test.
 * For example, with endpoint correlation and wsdlElement of type "message" 
 * there could be multiple matches for most element types including WSDL Service.
 * (though the objective is to ensure filtering to a single service if at all possible). 
 * 
 * @author gturrell
 */

// ADD:could be better as a singleton?

public class CandidateInfo
{

  // Normalized fixed correlation data derived from the analyzer config and the wsdl,
  // representing what we know about the service from these two sources.  
  private Definition[] definitions = null;

  private Import[] imports = null;
  private Types[] types = null;

  private Message[] messages = null;
  private Operation[] operations = null;
  private PortType[] portTypes = null;
  private Binding[] bindings = null;
  private Port[] ports = null;

  private URI[] endPoints = null; // list obtainable from a port

  private WSDLDocument wsdlDocument; // reference probably not desirable here

  /**
   * Constructor for CandidateInfo.
   * Extract normalised entry data from wsdl, according to config wsdlElement & serviceLocation
   * @param serviceReference a ServiceReference object.
   * @param wsdlDocument a WSDL document.
   * @throws WSIException if problems occur creating CandidateInfo object.
   */
  public CandidateInfo(
    ServiceReference serviceReference,
    WSDLDocument wsdlDocument)
    throws WSIException
  {

    // ADD: check for null document?

    WSDLElement wsdlElement = serviceReference.getWSDLElement();

    this.wsdlDocument = wsdlDocument;

    /*
     * Generalised fields independent of wsdlElement:
     */
    // ADD: check whether these need to be either expanded or filtered down.
    // Assume WSDL4J pulls int the full tree at the root document for now		
    //this.imports = wsdlDocument.getImports();

    // ... or if only down to first level....
    this.imports =
      (Import[]) getAllImports(
        wsdlDocument.getDefinitions()).toArray(new Import[] {
    });

    /* Definitions. 
     * Note that the the first array element is for the root doc
     * which contains all WSDL elements in scope via <import> declarations,
     * as well as the root document itself. Therefore the second definitions 
     * array element and above are redundant, but *may* prove useful to the assertion
     * code.
     */

    this.definitions = new Definition[imports.length + 1];
    // allow room for root doc		

    this.definitions[0] = wsdlDocument.getDefinitions(); // root document    

    // Allocate array for types elements
    Types[] tempTypes = new Types[definitions.length];

    int typesCount = 0;

    if (definitions[0].getTypes() != null)
    {
      tempTypes[0] = this.definitions[0].getTypes(); // root document	
      typesCount++;
    }

    // Definitions from other (imported) wsdls correlating to the candidate
    // Only one level down for now
    for (int i = 0; i < imports.length; i++)
    {
      if (((definitions[i + 1] = imports[i].getDefinition()) != null)
        && (definitions[i + 1].getTypes() != null))
      {
        tempTypes[typesCount] = definitions[i + 1].getTypes();
        typesCount++;
      }
    }

    if (typesCount > 0)
    {
      this.types = new Types[typesCount];

      for (int i = 0; i < typesCount; i++)
        this.types[i] = tempTypes[i];
    }
    /* 
     * Populate element hierachy:
     * Port
     * Binding
     * PortType
     * operation(s)
     * message(s)
     */

    if (wsdlElement.isPort())
    {

      Port port = null;

      // Use parentElementName to qualify the port within a service.		
      QName serviceName = wsdlElement.getParentElementQName();
      Service[] s = wsdlDocument.getServices();
      String portName = wsdlElement.getName();
      for (int i = 0; i < s.length && port == null; i++)
      {
        if (s[i].getQName().equals(serviceName))
        {
          port = s[i].getPort(portName);
        }
      }

      if (port == null)
      {
        throw new WSIException(
          "WSDL Port \'"
            + portName
            + "\' for Service \'"
            + serviceName
            + "\' not found in service description");
      }
      else
      {
        this.ports = new Port[] { port };
        // ADD: do serviceLocation check for soapbind:address?
        descendents(port);
      }

      // ADD: the following could be instantiated here instead to refine context info
      // definitions 
      // imports 
      // types

    }

    else if (wsdlElement.isBinding())
    {
      if (wsdlElement.getQName() != null
        && wsdlElement.getQName().getLocalPart() != null
        && wsdlElement.getQName().getLocalPart().length() > 0)
      {
        Binding binding =
          wsdlDocument.getDefinitions().getBinding(wsdlElement.getQName());

        if (binding == null)
        {
          throw new WSIException(
            "WSDL Binding named \'"
              + wsdlElement.getQName()
              + "\' not found in service description");
        }
        else
        {
          this.bindings = new Binding[] { binding };

          // the rest ... below binding:	
          // portTypes from binding
          // operations from portTypes
          // messages from operations
          descendents(binding);

          // above binding:
          // ports
          // definitions, imports, types (future?)				
          // ancestors(bindings);
        }
      }
    }

    else if (wsdlElement.isPortType())
    {

      PortType portType =
        wsdlDocument.getDefinitions().getPortType(wsdlElement.getQName());
      this.portTypes = new PortType[] { portType };

      if (portType == null)
      {
        throw new WSIException(
          "WSDL PortType named \'"
            + wsdlElement.getQName()
            + "\' not found in service description");
      }
      else
      {
        this.portTypes = new PortType[] { portType };
        // the rest ... below portType:	
        descendents(portType);

        // above portType:
        // ports
        // definitions, imports, types (future) ?
        //ancestors(portTypes);		
      }
    }
    else if (wsdlElement.isOperation())
    {

      Operation operation = null;
      String configOpName = wsdlElement.getName();

      // Use parentElementName to qualify the operation within a portType.
      QName portTypeName = wsdlElement.getParentElementQName();
      PortType[] p = wsdlDocument.getPortTypes();
      for (int i = 0; i < p.length && operation == null; i++)
      {
        if (p[i].getQName().equals(portTypeName))
        {
          // wsdl4j available method call below implies that only 
          // name+inputname+outputname uniquely defines operation! 
          // Since we do not have <input> & <output> name information
          // available in the config, use this instead for now: - 
          // Get the first operation we find:
          Iterator opIt = p[i].getOperations().iterator();
          Operation op = null;
          while (opIt.hasNext() && operation == null)
          {
            op = (Operation) opIt.next();
            if (configOpName.equals(op.getName()))
            {
              operation = op;
            }
          }
        }
      }

      if (operation == null)
      {
        throw new WSIException(
          "No WSDL Operation named \'"
            + wsdlElement.getQName()
            + "\' found in service description");
      }
      else
      {
        this.operations = new Operation[] { operation };

        descendents(operation);
        //ancestors(operations);
      }
    }

    else if (wsdlElement.isMessage())
    {

      Message message =
        wsdlDocument.getDefinitions().getMessage(wsdlElement.getQName());
      if (message == null)
      {
        throw new WSIException(
          "No WSDL Message named \'"
            + wsdlElement.getQName()
            + "\' found in service description");
      }
      else
      {
        this.messages = new Message[] { message };

        //ancestors(messages); 
      }
    }

    else
    {
      throw new WSIException(
        "Unrecognised <WSDLElement type> in config: " + wsdlElement.getType());
    }

    // get info about the effective service location (s)
    //this.endPoints = deriveEndpoints(analyzerConfig, this.ports, this.definitions);
    this.endPoints =
      deriveEndpoints(serviceReference, this.ports, this.definitions);
  }

  /** 
     * ancestor code is not used at present.
     * 
     */
  /*   
     protected void ancestors(Port[] ports) {
     	// no ancestors of Port required (for now)
     } 	    
     protected void ancestors(Binding[] bindings) {	    
    		// Ports from Bindings  1-2-1
     	
     	// *** cheat for now - get ports from all services in the wsdl doc
     	// ADD: find correct mapping based on the supplied bindings
     	Service[] service = wsdlDocument.getServices();
     	HashSet set = new HashSet();
  		for (int i=0; i>service.length; i++) {
  			set.add(service[i].getPorts());  
  		}
  			
  		// assign the parent group and process the grandparents if any								
  		ancestors(this.ports = (Port[])set.toArray(this.ports = new Port[0]));
     }
     protected void ancestors(PortType[] portTypes) {	    
    		// Bindings from PortTypes  1-2-1
     	
     	// add have to start with all bindings in doc and search for those
     	// with the portType  
     	HashSet set = new HashSet();
  		for (int i=0; i>portTypes.length; i++) {
  		// set.add(portTypes[i].get());  
  		}
  			
  		// assign the parent group and process the grandparents if any								
  		ancestors(this.bindings = (Binding[])set.toArray(this.bindings = new Binding[0]));
     }
     protected void ancestors(Operation[] operations) {	    
    		// PortTypes from Operations  1-2-1
     	  
     	HashSet set = new HashSet();
  		for (int i=0; i>operations.length; i++) {
  			// set.add(operations[i].get());  
  		}
  			
  		// assign the parent group and process the grandparents if any								
  		ancestors(this.portTypes = (PortType[])set.toArray(this.portTypes = new PortType[0]));
     }
     protected void ancestors(Message[] messages) {	    
    		// Operations from Messages  1-2-1
     	// ADD fix it!  
     	HashSet set = new HashSet();
  		for (int i=0; i>messages.length; i++) {
  			// set.add(messages[i].get());  
  		}
  			
  		// assign the parent group 	
  		this.portTypes = (PortType[])set.toArray(this.portTypes = new PortType[0]);
     }
  */

  /**
   * Descendant method for completing candidate service context creation.
   * @param port  a Port object
   * @throws WSIException if port is null.
   */
  protected void descendents(Port port) throws WSIException
  {
    // Binding from Port  1-2-1

    if (port == null)
    {
      throw new WSIException("Internal error: expected a Port value");
    }
    else
    {
      this.bindings = new Binding[] { port.getBinding()};
      if (this.bindings[0] != null)
      {
        /* Assign the child group and process the grandchildren if any.
        * Null argument value passed into the following method would 
        * suggest a WSDL definition inconsistency
        * which will be picked up during Description Artifact TA testing.
        */
        descendents(this.bindings[0]);
      }
    }
  }

  /**
   * Descendant method for completing candidate service context creation.
   * @param binding  a Binding object
   * @throws WSIException if binding is null.
   */
  protected void descendents(Binding binding) throws WSIException
  {
    // portType from Binding 1-2-1

    if (binding == null)
    {
      throw new WSIException("Internal error: expected a Binding value");
    }
    else
    {
      this.portTypes = new PortType[] { binding.getPortType()};
      if (this.portTypes[0] != null)
      {
        /* Assign the child group and process the grandchildren if any.
        	* Null argument value passed into the following method would 
        	* suggest a WSDL definition inconsistency
        	* which will be picked up during Description Artifact TA testing.
        	*/
        descendents(this.portTypes[0]);

        // Get any messages that are referenced from headers and headerfaults

        BindingOperation bindingOperation;

        // Get reference to definition
        Definition definition = definitions[0];

        // If there are messages already, then get them as a collection
        HashSet messageSet = new HashSet();
        if (messages != null)
        {
          for (int i = 0; i < messages.length; i++)
          {
            messageSet.add(messages[i]);
          }
        }

        // Get the messages that are referenced only by a binding 
        HashSet bindingMessages = WSDLUtils.findMessages(definition, binding);

        // Add these messages to the complete message list  
        messageSet.addAll(bindingMessages);

        // Create array from message set
        this.messages =
          (Message[]) messageSet.toArray(this.messages = new Message[0]);
      }
    }
  }

  /**
   * Descendant method for completing candidate service context creation.
   * @param portType  a PortType object
   * @throws WSIException if portType is null.
   */
  protected void descendents(PortType portType) throws WSIException
  {
    // Operations from PortType 1-2-n

    if (portType == null)
    {
      throw new WSIException("Internal error: expected a PortType value");
    }
    else
    {
      this.operations =
        (Operation[]) (portType
          .getOperations()
          .toArray(this.operations = new Operation[0]));
      if (this.operations.length > 0)
      {
        descendents(this.operations);
      }
    }
  }

  /**
     * Descendant method for completing candidate service context creation.
     * @param operation  a Operation object
     * @throws WSIException if operation is null.
     */
  protected void descendents(Operation operation) throws WSIException
  {
    // Messages from Operation

    if (operation == null)
    {
      throw new WSIException("Internal error: expected an Operation value");
    }
    else
    {
      descendents(new Operation[] { operation });
    }
  }

  /**
   * Descendant method for completing candidate service context creation.
   * @param operations  an array of operations.
   * @throws WSIException if operations is null.
   */
  protected void descendents(Operation[] operations) throws WSIException
  {
    // Messages from Operations 1-2-n

    if (operations == null)
    {
      throw new WSIException("Internal error: expected an Operation[] value");
    }

    HashSet set = new HashSet();
    for (int i = 0; i < operations.length; i++)
    {
      if (operations[i].getInput() != null)
        set.add(operations[i].getInput().getMessage()); //1-2-1
      if (operations[i].getOutput() != null)
        set.add(operations[i].getOutput().getMessage()); //1-2-1

      // get messages associated with faults for this operation 
      // 1-2-n
      Iterator it = operations[i].getFaults().values().iterator();
      while (it.hasNext())
      {
        set.add(((Fault) it.next()).getMessage());
      }
    }
    this.messages = (Message[]) set.toArray(this.messages = new Message[0]);
    // no descendents of messages so stop.
  }

  /**
   * Provide a recursive non-repeating list of imports for the specified
   * WSDL document definition.
   */
  /*   private HashSet getAllImports(Definition rootDef) throws WSIException {
     	
     	HashSet importSet = new HashSet();
     	
     	Collection importList =  rootDef.getImports().values();
     	Iterator i = importList.iterator();
     	
     	while (i.hasNext()) {
     		Import nextImport = (Import)(i.next());
     		if (nextImport != null) {
     			// its a wsdl document
     			importSet.addAll(getAllImports(nextImport.getDefinition()));
     		}   			
     	}
     	
     	return (importSet);
     }
   */
  private HashSet getAllImports(Definition rootDef) throws WSIException
  {

    HashSet importSet = new HashSet();

    Map importMap = rootDef.getImports();
    Iterator i = importMap.values().iterator();

    while (i.hasNext())
    {
      List nextImportList = (List) (i.next());
      Iterator listIt = nextImportList.iterator();
      while (listIt.hasNext())
      {
        Import nextImport = (Import) listIt.next();
        if (nextImport != null)
        {
          // its a wsdl document
          importSet.add(nextImport);
          if (nextImport.getDefinition() != null)
          {
            HashSet subTreeImports = getAllImports(nextImport.getDefinition());
            Iterator subIt = subTreeImports.iterator();
            while (subIt.hasNext())
            {
              importSet.add((Import) (subIt.next()));
            }
          }
        }
      }
    }

    return (importSet);
  }

  /**
   * get all service location endpoint values
   * relevant to the service under test.
   * 
   * If the service location is specified in the config we use
   * just that.
   * Otherwise, if the port is specified, we get all endpoints
   * associated with that port.
   * If we have neither the service location value or the port,
   * then all endpoints in the definition are used.
   */
  private URI[] deriveEndpoints(
  //AnalyzerConfig analyzerConfig, 
  ServiceReference serviceReference, Port[] ports, Definition[] definitions)
  {

    URI[] endp = null;
    //Port port = null;	
    try
    {
      String serviceLocation = null;
      // try service location...
      //if ((serviceLocation = analyzerConfig.getServiceLocation()) != null) {      
      if ((serviceLocation = serviceReference.getServiceLocation()) != null)
      {
        endp = new URI[] { new URI(serviceLocation)};
      }
      //else if (analyzerConfig.getWSDLElement().isPort()) {
      else if (serviceReference.getWSDLElement().isPort())
      {
        if (ports.length != 1)
        {
          throw new WSIException("Internal error - expected 1-element Port array");
        }
        //else {
        //	port = ports[0]; // if Port was given in config, there is just one
        //}
        //QName soapAddress = new QName(WSIConstants.NS_URI_WSDL_SOAP, "address");
        Iterator i = ports[0].getExtensibilityElements().iterator();
        while (i.hasNext() && serviceLocation == null)
        {
          ExtensibilityElement extElem = (ExtensibilityElement) i.next();
          if (extElem instanceof SOAPAddress)
          {
            //if (extEl.getElementType().equals(soapAddress) {
            // this element is our SOAPAddress - get the location
            serviceLocation = ((SOAPAddress) extElem).getLocationURI();
            endp = new URI[] { new URI(serviceLocation)};
          }
        }
      }
      else
      { // no port info from config, so supply all in document
        // QName soapAddress = new QName(WSIConstants.NS_URI_WSDL_SOAP, "address");
        HashSet endpointSet = new HashSet();
        Iterator i = definitions[0].getExtensibilityElements().iterator();
        while (i.hasNext())
        {
          ExtensibilityElement extElem = (ExtensibilityElement) i.next();
          if (extElem instanceof SOAPAddress)
          {
            //if (extEl.getElementType().equals(soapAddress) {
            // this element is our SOAPAddress - get the location
            endpointSet.add(((SOAPAddress) extElem).getLocationURI());
          }
        }
        // Convert the derived List to a URI array
        endp = (URI[]) endpointSet.toArray(endp = new URI[0]);
      }
    }
    catch (Exception e)
    {
    }
    return endp;
  }

  /**
   * Returns the binding.
   * @return Binding
   */
  public Binding[] getBindings()
  {
    return bindings;
  }

  /**
   * Returns the endPoints.
   * @return URI[]
   */
  public URI[] getEndPoints()
  {
    // get list of matching endpoint(s) associated with service.
    return endPoints;
  }

  /**
  * Returns the endPoints matching the specified host and port.
  * @param hostAndPort  host and port location.
  * @return URI[] if matched, null otherwise.
  */
  public URI[] getEndPoints(String hostAndPort)
  {
    // get list of matching endpoints associated with service,
    // having the specified host and port configuration
    String port;

    Vector matchedEndpoints = new Vector();
    for (int i = 0; i < endPoints.length; i++)
    {
      // PB: If the endpoint does not contain a port number, then default it to "80"
      port =
        (endPoints[i].getPort() == -1)
          ? "80"
          : String.valueOf(endPoints[i].getPort());
      if (hostAndPort.equals(endPoints[i].getHost() + ":" + port))
      {
        matchedEndpoints.add(endPoints[i]);
      }
    }
    return (URI[]) matchedEndpoints.toArray(new URI[0]);
  }

  /**
   * Returns the operation.
   * @return Operation
   */
  public Operation[] getOperations()
  {
    return operations;
  }

  /**
   * Returns the portType.
   * @return PortType
   */
  public PortType[] getPortType()
  {
    return portTypes;
  }

  /**
   * Returns true if the hostAndPort matches at least one context endpoint.
   * @param hostAndPortString a host and port location.
   * @return true if the hostAndPort matches at least one context endpoint.
   * @throws WSIException if given hostandPort String does not convert to URI.
   */
  public boolean hasHostAndPort(String hostAndPortString) throws WSIException
  {
    URI hostAndPort;
    try
    {
      hostAndPort = new URI(hostAndPortString);
    }
    catch (Exception e)
    {
      throw new WSIException(
        "Could not convert string to URI: " + hostAndPortString);
    }
    String host = hostAndPort.getHost();
    int port = hostAndPort.getPort();
    for (int i = 0; i < this.endPoints.length; i++)
    {
      if (this.endPoints[i].getHost().equals(host)
        && this.endPoints[i].getPort() == port)
      {
        return true;
      }
    }
    return false; // for now
  }

  /**
   * Returns the definitions.
   * @return Definition[]
   */
  public Definition[] getDefinitions()
  {
    return definitions;
  }

  /**
   * Returns the imports.
   * @return Import[]
   */
  public Import[] getImports()
  {
    return imports;
  }

  /**
   * Returns the messages.
   * @return Message[]
   */
  public Message[] getMessages()
  {
    return messages;
  }

  /**
   * Returns the ports.
   * @return Port[]
   */
  public Port[] getPorts()
  {
    return ports;
  }

  /**
   * Returns the portTypes.
   * @return PortType[]
   */
  public PortType[] getPortTypes()
  {
    return portTypes;
  }

  /**
   * Returns the types.
   * @return Types[]
   */
  public Types[] getTypes()
  {
    return types;
  }
  /**
   * Returns the wsdlDocument.
   * @return WSDLDocument
   */
  public WSDLDocument getWsdlDocument()
  {
    return wsdlDocument;
  }

  /**
   * Return the definition element that contains the types element.
   * @param types a Types object.
   * @return the definition element that contains the types element.
   */
  public Definition getDefinition(Types types)
  {
    Definition definition = null;
    Types checkTypes;

    for (int i = 0; i < definitions.length && definition == null; i++)
    {
      if (((checkTypes = definitions[i].getTypes()) != null)
        && (checkTypes.equals(types)))
      {
        definition = definitions[i];
      }
    }

    return definition;
  }

  /**
   * Return the definition element that contains the binding element.
   * @param binding a Binding object.
   * @return the definition element that contains the binding element.
   */
  public Definition getDefinition(Binding binding)
  {
    Definition definition = null;

    for (int i = 0; i < definitions.length && definition == null; i++)
    {
      if (definitions[i].getBinding(binding.getQName()) != null)
        definition = definitions[i];
    }

    return definition;
  }

  /**
   * Return the definition element that contains the portType element.
   * @param portType a PortType object.
   * @return the definition element that contains the portType element.
   */
  public Definition getDefinition(PortType portType)
  {
    Definition definition = null;

    for (int i = 0; i < definitions.length && definition == null; i++)
    {
      if (definitions[i].getPortType(portType.getQName()) != null)
        definition = definitions[i];
    }

    return definition;
  }

  /**
   * Return the definition element that contains the message.
   * @param message a Message object.
   * @return the definition element that contains the message.
   */
  public Definition getDefinition(Message message)
  {
    Definition definition = null;

    for (int i = 0; i < definitions.length && definition == null; i++)
    {
      if (definitions[i].getMessage(message.getQName()) != null)
        definition = definitions[i];
    }

    return definition;
  }

}

Back to the top