View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.api.registry;
17  
18  import java.io.Serializable;
19  import java.util.Collection;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlAnyElement;
24  import javax.xml.bind.annotation.XmlElement;
25  import javax.xml.bind.annotation.XmlRootElement;
26  import javax.xml.bind.annotation.XmlType;
27  
28  import org.kuali.rice.core.api.CoreConstants;
29  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
30  import org.kuali.rice.core.api.mo.ModelBuilder;
31  import org.w3c.dom.Element;
32  
33  /**
34   * Immutable implementation of the {@link ServiceEndpointContract} interface.
35   * Represents a service endpoint that has been published to the service registry.
36   * Includes both a {@link ServiceInfo} and {@link ServiceDescriptor} which
37   * compose the two different pieces of information about a service endpoint.
38   * 
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   *
41   */
42  @XmlRootElement(name = ServiceEndpoint.Constants.ROOT_ELEMENT_NAME)
43  @XmlAccessorType(XmlAccessType.NONE)
44  @XmlType(name = ServiceEndpoint.Constants.TYPE_NAME, propOrder = {
45  		ServiceEndpoint.Elements.INFO,
46  		ServiceEndpoint.Elements.DESCRIPTOR,
47  		CoreConstants.CommonElements.FUTURE_ELEMENTS
48  })
49  public final class ServiceEndpoint extends AbstractDataTransferObject implements ServiceEndpointContract {
50  
51  	private static final long serialVersionUID = -2295962329997871877L;
52      
53  	@XmlElement(name = Elements.INFO, required = false)
54      private final ServiceInfo info;
55  	
56      @XmlElement(name = Elements.DESCRIPTOR, required = false)
57      private final ServiceDescriptor descriptor;
58      
59      @SuppressWarnings("unused")
60      @XmlAnyElement
61      private final Collection<Element> _futureElements = null;
62  
63      /**
64       * Private constructor used only by JAXB.
65       */
66      private ServiceEndpoint() {
67          this.info = null;
68      	this.descriptor = null;
69      }
70      
71      private ServiceEndpoint(Builder builder) {
72          this.info = builder.getInfo().build();
73          this.descriptor = builder.getDescriptor().build();
74      }
75      
76      @Override
77      public ServiceInfo getInfo() {
78          return this.info;
79      }
80      
81      @Override
82      public ServiceDescriptor getDescriptor() {
83          return this.descriptor;
84      }
85  
86      /**
87       * A builder which can be used to construct {@link ServiceEndpoint} instances.  Enforces the constraints of the {@link ServiceEndpointContract}.
88       */
89      public final static class Builder implements Serializable, ModelBuilder, ServiceEndpointContract {
90  
91  		private static final long serialVersionUID = -1783718474634197837L;
92  
93  		private ServiceInfo.Builder info;
94          private ServiceDescriptor.Builder descriptor;
95  
96          private Builder(ServiceInfo.Builder info, ServiceDescriptor.Builder descriptor) {
97              setInfo(info);
98              setDescriptor(descriptor);
99          }
100 
101         public static Builder create(ServiceInfo.Builder info, ServiceDescriptor.Builder descriptor) {
102             return new Builder(info, descriptor);
103         }
104 
105         public static Builder create(ServiceEndpointContract contract) {
106             if (contract == null) {
107                 throw new IllegalArgumentException("contract was null");
108             }
109             Builder builder = create(ServiceInfo.Builder.create(contract.getInfo()), ServiceDescriptor.Builder.create(contract.getDescriptor()));
110             return builder;
111         }
112 
113         public ServiceEndpoint build() {
114             return new ServiceEndpoint(this);
115         }
116 
117         @Override
118         public ServiceInfo.Builder getInfo() {
119             return this.info;
120         }
121         
122         @Override
123         public ServiceDescriptor.Builder getDescriptor() {
124             return this.descriptor;
125         }
126         
127         public void setInfo(ServiceInfo.Builder info) {
128             if (info == null) {
129             	throw new IllegalArgumentException("info was null");
130             }
131             this.info = info;
132         }
133 
134         public void setDescriptor(ServiceDescriptor.Builder descriptor) {
135         	if (descriptor == null) {
136             	throw new IllegalArgumentException("descriptor was null");
137             }
138             this.descriptor = descriptor;
139         }
140         
141     }
142 
143 
144     /**
145      * Defines some internal constants used on this class.
146      */
147     static class Constants {
148 
149         final static String ROOT_ELEMENT_NAME = "serviceEndpoint";
150         final static String TYPE_NAME = "ServiceEndpointType";
151 
152     }
153 
154 
155     /**
156      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
157      */
158     static class Elements {
159 
160         final static String INFO = "info";
161         final static String DESCRIPTOR = "descriptor";
162 
163     }
164     
165 }