View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package javax.xml.ws.wsaddressing;
21  
22  import org.w3c.dom.Element;
23  
24  import javax.xml.namespace.QName;
25  import javax.xml.ws.spi.Provider;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  public final class W3CEndpointReferenceBuilder {
30      private String address;
31      private QName serviceName;
32      private QName endpointName;
33      private String wsdlDocumentLocation;
34      private List<Element> referenceParameters;
35      private List<Element> metadataElements;
36      
37      public W3CEndpointReferenceBuilder() {
38      }
39      
40      public W3CEndpointReferenceBuilder address(String address) {
41          this.address = address;
42          return this;
43      }
44      
45      public W3CEndpointReferenceBuilder serviceName(QName serviceName) {
46          this.serviceName = serviceName;
47          return this;
48      }
49      
50      public W3CEndpointReferenceBuilder endpointName(QName endpointName) {
51          //TODO NLS enable
52          if (this.serviceName == null) {
53              throw new IllegalStateException("The endpoint qname cannot be set before the service qname.");
54          }
55          
56          this.endpointName = endpointName;
57          return this;
58      }
59      
60      public W3CEndpointReferenceBuilder wsdlDocumentLocation(String wsdlDocumentLocation) {
61          this.wsdlDocumentLocation = wsdlDocumentLocation;
62          return this;
63      }
64      
65      public W3CEndpointReferenceBuilder referenceParameter(Element referenceParameter) {
66          //TODO NLS enable
67          if (referenceParameter == null) {
68              throw new IllegalArgumentException("A reference parameter cannot be null.");
69          }
70          
71          if (this.referenceParameters == null) {
72              this.referenceParameters = new ArrayList<Element>();
73          }
74          
75          this.referenceParameters.add(referenceParameter);
76          return this;
77      }
78      
79      public W3CEndpointReferenceBuilder metadata(Element metadataElement) {
80          //TODO NLS enable
81          if (metadataElement == null) {
82              throw new IllegalArgumentException("A metadata element cannot be null.");
83          }
84          
85          if (this.metadataElements == null) {
86              this.metadataElements = new ArrayList<Element>();
87          }
88          
89          this.metadataElements.add(metadataElement);
90          return this;
91      }
92      
93      public W3CEndpointReference build() {
94          return Provider.provider().createW3CEndpointReference(address,
95                  serviceName,
96                  endpointName,
97                  metadataElements,
98                  wsdlDocumentLocation,
99                  referenceParameters);
100     }
101 
102     @Override
103     public String toString() {
104         // TODO Auto-generated method stub
105         return super.toString();
106     }
107 }