001 /**
002 * Copyright 2005-2012 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.kuali.rice.ksb.api.bus.ServiceConfiguration;
032 import org.w3c.dom.Element;
033
034 /**
035 * Immutable implementation of the {@link ServiceDescriptorContract} interface.
036 * Includes a serialized XML representation of the {@link ServiceConfiguration}
037 * for the service.
038 *
039 * @author Kuali Rice Team (rice.collab@kuali.org)
040 *
041 */
042 @XmlRootElement(name = ServiceDescriptor.Constants.ROOT_ELEMENT_NAME)
043 @XmlAccessorType(XmlAccessType.NONE)
044 @XmlType(name = ServiceDescriptor.Constants.TYPE_NAME, propOrder = {
045 ServiceDescriptor.Elements.ID,
046 ServiceDescriptor.Elements.DESCRIPTOR,
047 CoreConstants.CommonElements.VERSION_NUMBER,
048 CoreConstants.CommonElements.FUTURE_ELEMENTS
049 })
050 public final class ServiceDescriptor extends AbstractDataTransferObject
051 implements ServiceDescriptorContract
052 {
053
054 private static final long serialVersionUID = 4555599272613878634L;
055
056 @XmlElement(name = Elements.ID, required = false)
057 private final String id;
058
059 @XmlElement(name = Elements.DESCRIPTOR, required = false)
060 private final String descriptor;
061
062 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
063 private final Long versionNumber;
064
065 @SuppressWarnings("unused")
066 @XmlAnyElement
067 private final Collection<Element> _futureElements = null;
068
069 /**
070 * Private constructor used only by JAXB.
071 *
072 */
073 private ServiceDescriptor() {
074 this.id = null;
075 this.descriptor = null;
076 this.versionNumber = null;
077 }
078
079 private ServiceDescriptor(Builder builder) {
080 this.id = builder.getId();
081 this.descriptor = builder.getDescriptor();
082 this.versionNumber = builder.getVersionNumber();
083 }
084
085 @Override
086 public String getId() {
087 return this.id;
088 }
089
090 @Override
091 public String getDescriptor() {
092 return this.descriptor;
093 }
094
095 @Override
096 public Long getVersionNumber() {
097 return this.versionNumber;
098 }
099
100
101 /**
102 * A builder which can be used to construct {@link ServiceDescriptor} instances. Enforces the constraints of the {@link ServiceDescriptorContract}.
103 *
104 */
105 public final static class Builder
106 implements Serializable, ModelBuilder, ServiceDescriptorContract
107 {
108
109 private static final long serialVersionUID = 4439417051199359358L;
110
111 private String id;
112 private String descriptor;
113 private Long versionNumber;
114
115 private Builder() {
116 }
117
118 public static Builder create() {
119 return new Builder();
120 }
121
122 public static Builder create(ServiceDescriptorContract contract) {
123 if (contract == null) {
124 throw new IllegalArgumentException("contract was null");
125 }
126 Builder builder = create();
127 builder.setId(contract.getId());
128 builder.setDescriptor(contract.getDescriptor());
129 builder.setVersionNumber(contract.getVersionNumber());
130 return builder;
131 }
132
133 public ServiceDescriptor build() {
134 return new ServiceDescriptor(this);
135 }
136
137 @Override
138 public String getId() {
139 return this.id;
140 }
141
142 @Override
143 public String getDescriptor() {
144 return this.descriptor;
145 }
146
147 @Override
148 public Long getVersionNumber() {
149 return this.versionNumber;
150 }
151
152 public void setId(String id) {
153 this.id = id;
154 }
155
156 public void setDescriptor(String descriptor) {
157 this.descriptor = descriptor;
158 }
159
160 public void setVersionNumber(Long versionNumber) {
161 this.versionNumber = versionNumber;
162 }
163
164 }
165
166
167 /**
168 * Defines some internal constants used on this class.
169 *
170 */
171 static class Constants {
172
173 final static String ROOT_ELEMENT_NAME = "serviceDescriptor";
174 final static String TYPE_NAME = "ServiceDescriptorType";
175 }
176
177
178 /**
179 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
180 *
181 */
182 static class Elements {
183
184 final static String ID = "id";
185 final static String DESCRIPTOR = "descriptor";
186
187 }
188
189 }
190