001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package javax.xml.ws.wsaddressing;
021
022 import org.w3c.dom.Element;
023
024 import javax.xml.namespace.QName;
025 import javax.xml.ws.spi.Provider;
026 import java.util.ArrayList;
027 import java.util.List;
028
029 public final class W3CEndpointReferenceBuilder {
030 private String address;
031 private QName serviceName;
032 private QName endpointName;
033 private String wsdlDocumentLocation;
034 private List<Element> referenceParameters;
035 private List<Element> metadataElements;
036
037 public W3CEndpointReferenceBuilder() {
038 }
039
040 public W3CEndpointReferenceBuilder address(String address) {
041 this.address = address;
042 return this;
043 }
044
045 public W3CEndpointReferenceBuilder serviceName(QName serviceName) {
046 this.serviceName = serviceName;
047 return this;
048 }
049
050 public W3CEndpointReferenceBuilder endpointName(QName endpointName) {
051 //TODO NLS enable
052 if (this.serviceName == null) {
053 throw new IllegalStateException("The endpoint qname cannot be set before the service qname.");
054 }
055
056 this.endpointName = endpointName;
057 return this;
058 }
059
060 public W3CEndpointReferenceBuilder wsdlDocumentLocation(String wsdlDocumentLocation) {
061 this.wsdlDocumentLocation = wsdlDocumentLocation;
062 return this;
063 }
064
065 public W3CEndpointReferenceBuilder referenceParameter(Element referenceParameter) {
066 //TODO NLS enable
067 if (referenceParameter == null) {
068 throw new IllegalArgumentException("A reference parameter cannot be null.");
069 }
070
071 if (this.referenceParameters == null) {
072 this.referenceParameters = new ArrayList<Element>();
073 }
074
075 this.referenceParameters.add(referenceParameter);
076 return this;
077 }
078
079 public W3CEndpointReferenceBuilder metadata(Element metadataElement) {
080 //TODO NLS enable
081 if (metadataElement == null) {
082 throw new IllegalArgumentException("A metadata element cannot be null.");
083 }
084
085 if (this.metadataElements == null) {
086 this.metadataElements = new ArrayList<Element>();
087 }
088
089 this.metadataElements.add(metadataElement);
090 return this;
091 }
092
093 public W3CEndpointReference build() {
094 return Provider.provider().createW3CEndpointReference(address,
095 serviceName,
096 endpointName,
097 metadataElements,
098 wsdlDocumentLocation,
099 referenceParameters);
100 }
101
102 @Override
103 public String toString() {
104 // TODO Auto-generated method stub
105 return super.toString();
106 }
107 }