View Javadoc

1   package org.kuali.rice.ksb.api.registry;
2   
3   import java.io.Serializable;
4   import java.util.Collection;
5   
6   import javax.xml.bind.annotation.XmlAccessType;
7   import javax.xml.bind.annotation.XmlAccessorType;
8   import javax.xml.bind.annotation.XmlAnyElement;
9   import javax.xml.bind.annotation.XmlElement;
10  import javax.xml.bind.annotation.XmlRootElement;
11  import javax.xml.bind.annotation.XmlType;
12  
13  import org.apache.commons.lang.builder.EqualsBuilder;
14  import org.apache.commons.lang.builder.HashCodeBuilder;
15  import org.apache.commons.lang.builder.ToStringBuilder;
16  import org.kuali.rice.core.api.CoreConstants;
17  import org.kuali.rice.core.api.mo.ModelBuilder;
18  import org.kuali.rice.core.api.mo.ModelObjectComplete;
19  import org.w3c.dom.Element;
20  
21  /**
22   * Immutable implementation of the {@link ServiceEndpointContract} interface.
23   * Represents a service endpoint that has been published to the service registry.
24   * Includes both a {@link ServiceInfo} and {@link ServiceDescriptor} which
25   * compose the two different pieces of information about a service endpoint.
26   * 
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   *
29   */
30  @XmlRootElement(name = ServiceEndpoint.Constants.ROOT_ELEMENT_NAME)
31  @XmlAccessorType(XmlAccessType.NONE)
32  @XmlType(name = ServiceEndpoint.Constants.TYPE_NAME, propOrder = {
33  		ServiceEndpoint.Elements.INFO,
34  		ServiceEndpoint.Elements.DESCRIPTOR,
35  		CoreConstants.CommonElements.FUTURE_ELEMENTS
36  })
37  public final class ServiceEndpoint implements ModelObjectComplete, ServiceEndpointContract {
38  
39  	private static final long serialVersionUID = -2295962329997871877L;
40      
41  	@XmlElement(name = Elements.INFO, required = false)
42      private final ServiceInfo info;
43  	
44      @XmlElement(name = Elements.DESCRIPTOR, required = false)
45      private final ServiceDescriptor descriptor;
46      
47      @SuppressWarnings("unused")
48      @XmlAnyElement
49      private final Collection<Element> _futureElements = null;
50  
51      /**
52       * Private constructor used only by JAXB.
53       */
54      private ServiceEndpoint() {
55          this.info = null;
56      	this.descriptor = null;
57      }
58      
59      private ServiceEndpoint(Builder builder) {
60          this.info = builder.getInfo().build();
61          this.descriptor = builder.getDescriptor().build();
62      }
63      
64      @Override
65      public ServiceInfo getInfo() {
66          return this.info;
67      }
68      
69      @Override
70      public ServiceDescriptor getDescriptor() {
71          return this.descriptor;
72      }
73  
74      @Override
75      public int hashCode() {
76          return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
77      }
78  
79      @Override
80      public boolean equals(Object object) {
81          return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
82      }
83  
84      @Override
85      public String toString() {
86          return ToStringBuilder.reflectionToString(this);
87      }
88  
89      /**
90       * A builder which can be used to construct {@link ServiceEndpoint} instances.  Enforces the constraints of the {@link ServiceEndpointContract}.
91       */
92      public final static class Builder implements Serializable, ModelBuilder, ServiceEndpointContract {
93  
94  		private static final long serialVersionUID = -1783718474634197837L;
95  
96  		private ServiceInfo.Builder info;
97          private ServiceDescriptor.Builder descriptor;
98  
99          private Builder(ServiceInfo.Builder info, ServiceDescriptor.Builder descriptor) {
100             setInfo(info);
101             setDescriptor(descriptor);
102         }
103 
104         public static Builder create(ServiceInfo.Builder info, ServiceDescriptor.Builder descriptor) {
105             return new Builder(info, descriptor);
106         }
107 
108         public static Builder create(ServiceEndpointContract contract) {
109             if (contract == null) {
110                 throw new IllegalArgumentException("contract was null");
111             }
112             Builder builder = create(ServiceInfo.Builder.create(contract.getInfo()), ServiceDescriptor.Builder.create(contract.getDescriptor()));
113             return builder;
114         }
115 
116         public ServiceEndpoint build() {
117             return new ServiceEndpoint(this);
118         }
119 
120         @Override
121         public ServiceInfo.Builder getInfo() {
122             return this.info;
123         }
124         
125         @Override
126         public ServiceDescriptor.Builder getDescriptor() {
127             return this.descriptor;
128         }
129         
130         public void setInfo(ServiceInfo.Builder info) {
131             if (info == null) {
132             	throw new IllegalArgumentException("info was null");
133             }
134             this.info = info;
135         }
136 
137         public void setDescriptor(ServiceDescriptor.Builder descriptor) {
138         	if (descriptor == null) {
139             	throw new IllegalArgumentException("descriptor was null");
140             }
141             this.descriptor = descriptor;
142         }
143         
144     }
145 
146 
147     /**
148      * Defines some internal constants used on this class.
149      */
150     static class Constants {
151 
152         final static String ROOT_ELEMENT_NAME = "serviceEndpoint";
153         final static String TYPE_NAME = "ServiceEndpointType";
154         final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS };
155 
156     }
157 
158 
159     /**
160      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
161      */
162     static class Elements {
163 
164         final static String INFO = "info";
165         final static String DESCRIPTOR = "descriptor";
166 
167     }
168     
169 }