001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ksb.api.registry;
017
018 import java.io.Serializable;
019 import java.util.Collection;
020
021 import javax.xml.bind.annotation.XmlAccessType;
022 import javax.xml.bind.annotation.XmlAccessorType;
023 import javax.xml.bind.annotation.XmlAnyElement;
024 import javax.xml.bind.annotation.XmlElement;
025 import javax.xml.bind.annotation.XmlRootElement;
026 import javax.xml.bind.annotation.XmlType;
027
028 import org.kuali.rice.core.api.CoreConstants;
029 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
030 import org.kuali.rice.core.api.mo.ModelBuilder;
031 import org.w3c.dom.Element;
032
033 /**
034 * Immutable implementation of the {@link ServiceEndpointContract} interface.
035 * Represents a service endpoint that has been published to the service registry.
036 * Includes both a {@link ServiceInfo} and {@link ServiceDescriptor} which
037 * compose the two different pieces of information about a service endpoint.
038 *
039 * @author Kuali Rice Team (rice.collab@kuali.org)
040 *
041 */
042 @XmlRootElement(name = ServiceEndpoint.Constants.ROOT_ELEMENT_NAME)
043 @XmlAccessorType(XmlAccessType.NONE)
044 @XmlType(name = ServiceEndpoint.Constants.TYPE_NAME, propOrder = {
045 ServiceEndpoint.Elements.INFO,
046 ServiceEndpoint.Elements.DESCRIPTOR,
047 CoreConstants.CommonElements.FUTURE_ELEMENTS
048 })
049 public final class ServiceEndpoint extends AbstractDataTransferObject implements ServiceEndpointContract {
050
051 private static final long serialVersionUID = -2295962329997871877L;
052
053 @XmlElement(name = Elements.INFO, required = false)
054 private final ServiceInfo info;
055
056 @XmlElement(name = Elements.DESCRIPTOR, required = false)
057 private final ServiceDescriptor descriptor;
058
059 @SuppressWarnings("unused")
060 @XmlAnyElement
061 private final Collection<Element> _futureElements = null;
062
063 /**
064 * Private constructor used only by JAXB.
065 */
066 private ServiceEndpoint() {
067 this.info = null;
068 this.descriptor = null;
069 }
070
071 private ServiceEndpoint(Builder builder) {
072 this.info = builder.getInfo().build();
073 this.descriptor = builder.getDescriptor().build();
074 }
075
076 @Override
077 public ServiceInfo getInfo() {
078 return this.info;
079 }
080
081 @Override
082 public ServiceDescriptor getDescriptor() {
083 return this.descriptor;
084 }
085
086 /**
087 * A builder which can be used to construct {@link ServiceEndpoint} instances. Enforces the constraints of the {@link ServiceEndpointContract}.
088 */
089 public final static class Builder implements Serializable, ModelBuilder, ServiceEndpointContract {
090
091 private static final long serialVersionUID = -1783718474634197837L;
092
093 private ServiceInfo.Builder info;
094 private ServiceDescriptor.Builder descriptor;
095
096 private Builder(ServiceInfo.Builder info, ServiceDescriptor.Builder descriptor) {
097 setInfo(info);
098 setDescriptor(descriptor);
099 }
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 }