View Javadoc

1   /**
2    * Copyright 2005-2011 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.bus.support;
17  
18  import java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.List;
21  
22  import javax.xml.bind.annotation.XmlAccessType;
23  import javax.xml.bind.annotation.XmlAccessorType;
24  import javax.xml.bind.annotation.XmlElement;
25  import javax.xml.bind.annotation.XmlElementWrapper;
26  import javax.xml.bind.annotation.XmlRootElement;
27  import javax.xml.bind.annotation.XmlType;
28  
29  @XmlRootElement(name = JavaServiceConfiguration.Constants.ROOT_ELEMENT_NAME)
30  @XmlAccessorType(XmlAccessType.NONE)
31  @XmlType(name = JavaServiceConfiguration.Constants.TYPE_NAME, propOrder = {
32  		JavaServiceConfiguration.Elements.SERVICE_INTERFACES
33  })
34  public final class JavaServiceConfiguration extends AbstractServiceConfiguration {
35  
36  	private static final long serialVersionUID = -4226512121638441108L;
37  
38  	@XmlElementWrapper(name = Elements.SERVICE_INTERFACES, required = false)
39  	@XmlElement(name = Elements.SERVICE_INTERFACE, required = false)
40  	private final List<String> serviceInterfaces;
41  	
42  	/**
43       * Private constructor used only by JAXB.
44       */
45  	private JavaServiceConfiguration() {
46  		super();
47  		this.serviceInterfaces = null;
48  	}
49  
50  	
51  	private JavaServiceConfiguration(Builder builder) {
52  		super(builder);
53  		this.serviceInterfaces = builder.getServiceInterfaces() == null ? null : new ArrayList<String>(builder.getServiceInterfaces());
54  	}
55  	
56  	public static JavaServiceConfiguration fromServiceDefinition(JavaServiceDefinition javaServiceDefinition) {
57  		return Builder.create(javaServiceDefinition).build();
58  	}
59  		
60  	public List<String> getServiceInterfaces() {
61  		if (this.serviceInterfaces == null) {
62  			return Collections.emptyList();
63  		}
64  		return Collections.unmodifiableList(this.serviceInterfaces);
65  	}
66  		
67  	public static final class Builder extends AbstractServiceConfiguration.Builder<JavaServiceConfiguration> {
68  
69  		private static final long serialVersionUID = 4300659121377259098L;
70  
71  		private List<String> serviceInterfaces;
72  				
73  		public List<String> getServiceInterfaces() {
74  			return serviceInterfaces;
75  		}
76  		
77  		public void setServiceInterfaces(List<String> serviceInterfaces) {
78  			if (serviceInterfaces == null) {
79  				this.serviceInterfaces = null;
80  			} else {
81  				this.serviceInterfaces = new ArrayList<String>(serviceInterfaces);
82  			}
83  		}
84  		
85  		private Builder() {}
86  		
87  		public static Builder create() {
88  			return new Builder();
89  		}
90  		
91  		public static Builder create(JavaServiceDefinition javaServiceDefinition) {
92  			Builder builder = create();
93  			builder.copyServiceDefinitionProperties(javaServiceDefinition);
94  			builder.setServiceInterfaces(javaServiceDefinition.getServiceInterfaces());
95  			return builder;
96  		}
97  
98  		@Override
99  		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 }