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.bus.support;
017
018 import java.util.ArrayList;
019 import java.util.Collections;
020 import java.util.List;
021
022 import javax.xml.bind.annotation.XmlAccessType;
023 import javax.xml.bind.annotation.XmlAccessorType;
024 import javax.xml.bind.annotation.XmlElement;
025 import javax.xml.bind.annotation.XmlElementWrapper;
026 import javax.xml.bind.annotation.XmlRootElement;
027 import javax.xml.bind.annotation.XmlType;
028
029 @XmlRootElement(name = JavaServiceConfiguration.Constants.ROOT_ELEMENT_NAME)
030 @XmlAccessorType(XmlAccessType.NONE)
031 @XmlType(name = JavaServiceConfiguration.Constants.TYPE_NAME, propOrder = {
032 JavaServiceConfiguration.Elements.SERVICE_INTERFACES
033 })
034 public final class JavaServiceConfiguration extends AbstractServiceConfiguration {
035
036 private static final long serialVersionUID = -4226512121638441108L;
037
038 @XmlElementWrapper(name = Elements.SERVICE_INTERFACES, required = false)
039 @XmlElement(name = Elements.SERVICE_INTERFACE, required = false)
040 private final List<String> serviceInterfaces;
041
042 /**
043 * Private constructor used only by JAXB.
044 */
045 private JavaServiceConfiguration() {
046 super();
047 this.serviceInterfaces = null;
048 }
049
050
051 private JavaServiceConfiguration(Builder builder) {
052 super(builder);
053 this.serviceInterfaces = builder.getServiceInterfaces() == null ? null : new ArrayList<String>(builder.getServiceInterfaces());
054 }
055
056 public static JavaServiceConfiguration fromServiceDefinition(JavaServiceDefinition javaServiceDefinition) {
057 return Builder.create(javaServiceDefinition).build();
058 }
059
060 public List<String> getServiceInterfaces() {
061 if (this.serviceInterfaces == null) {
062 return Collections.emptyList();
063 }
064 return Collections.unmodifiableList(this.serviceInterfaces);
065 }
066
067 public static final class Builder extends AbstractServiceConfiguration.Builder<JavaServiceConfiguration> {
068
069 private static final long serialVersionUID = 4300659121377259098L;
070
071 private List<String> serviceInterfaces;
072
073 public List<String> getServiceInterfaces() {
074 return serviceInterfaces;
075 }
076
077 public void setServiceInterfaces(List<String> serviceInterfaces) {
078 if (serviceInterfaces == null) {
079 this.serviceInterfaces = null;
080 } else {
081 this.serviceInterfaces = new ArrayList<String>(serviceInterfaces);
082 }
083 }
084
085 private Builder() {}
086
087 public static Builder create() {
088 return new Builder();
089 }
090
091 public static Builder create(JavaServiceDefinition javaServiceDefinition) {
092 Builder builder = create();
093 builder.copyServiceDefinitionProperties(javaServiceDefinition);
094 builder.setServiceInterfaces(javaServiceDefinition.getServiceInterfaces());
095 return builder;
096 }
097
098 @Override
099 public JavaServiceConfiguration build() {
100 return new JavaServiceConfiguration(this);
101 }
102
103 }
104
105 /**
106 * Defines some internal constants used on this class.
107 */
108 static class Constants {
109 final static String ROOT_ELEMENT_NAME = "javaServiceConfiguration";
110 final static String TYPE_NAME = "JavaServiceConfigurationType";
111 }
112
113 /**
114 * A private class which exposes constants which define the XML element names to use
115 * when this object is marshalled to XML.
116 */
117 static class Elements {
118 protected final static String SERVICE_INTERFACES = "serviceInterfaces";
119 protected final static String SERVICE_INTERFACE = "serviceInterface";
120 }
121
122 }