1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.api.bus.support;
17
18 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
19
20 import javax.xml.bind.annotation.XmlAccessType;
21 import javax.xml.bind.annotation.XmlAccessorType;
22 import javax.xml.bind.annotation.XmlElement;
23 import javax.xml.bind.annotation.XmlRootElement;
24 import javax.xml.bind.annotation.XmlType;
25 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
26 import java.util.Collections;
27 import java.util.HashMap;
28 import java.util.Map;
29
30 @XmlRootElement(name = RestServiceConfiguration.Constants.ROOT_ELEMENT_NAME)
31 @XmlAccessorType(XmlAccessType.NONE)
32 @XmlType(name = RestServiceConfiguration.Constants.TYPE_NAME, propOrder = {
33 RestServiceConfiguration.Elements.RESOURCE_CLASS,
34 RestServiceConfiguration.Elements.RESOURCE_TO_CLASS_NAME_MAP
35 })
36 public final class RestServiceConfiguration extends AbstractServiceConfiguration {
37
38 private static final long serialVersionUID = -4226512121638441108L;
39
40 @XmlElement(name = Elements.RESOURCE_CLASS, required = false)
41 private final String resourceClass;
42
43 @XmlJavaTypeAdapter(MapStringStringAdapter.class)
44 @XmlElement(name = Elements.RESOURCE_TO_CLASS_NAME_MAP, required = false)
45 private final Map<String, String> resourceToClassNameMap;
46
47
48
49
50 private RestServiceConfiguration() {
51 super();
52 this.resourceClass = null;
53 this.resourceToClassNameMap = null;
54 }
55
56 private RestServiceConfiguration(Builder builder) {
57 super(builder);
58 this.resourceClass = builder.getResourceClass();
59 if (builder.getResourceToClassNameMap() != null) {
60 this.resourceToClassNameMap = new HashMap<String, String>(builder.getResourceToClassNameMap());
61 } else {
62 this.resourceToClassNameMap = Collections.emptyMap();
63 }
64 }
65
66 public static RestServiceConfiguration fromServiceDefinition(RestServiceDefinition restServiceDefinition) {
67 return Builder.create(restServiceDefinition).build();
68 }
69
70 public String getResourceClass() {
71 return this.resourceClass;
72 }
73
74
75
76
77
78
79
80
81 public Map<String, String> getResourceToClassNameMap() {
82 return this.resourceToClassNameMap;
83 }
84
85
86
87
88
89 public boolean hasClass(String className) {
90 if (resourceToClassNameMap == null) {
91 return false;
92 }
93 return resourceToClassNameMap.containsValue(className);
94 }
95
96 public static final class Builder extends AbstractServiceConfiguration.Builder<RestServiceConfiguration> {
97
98 private static final long serialVersionUID = 4300659121377259098L;
99
100 private String resourceClass;
101 private Map<String, String> resourceToClassNameMap;
102
103 public String getResourceClass() {
104 return resourceClass;
105 }
106
107 public void setResourceClass(String resourceClass) {
108 this.resourceClass = resourceClass;
109 }
110
111 public Map<String, String> getResourceToClassNameMap() {
112 return resourceToClassNameMap;
113 }
114
115 public void setResourceToClassNameMap(Map<String, String> resourceToClassNameMap) {
116 this.resourceToClassNameMap = resourceToClassNameMap;
117 }
118
119 private Builder() {
120 }
121
122 public static Builder create() {
123 return new Builder();
124 }
125
126 public static Builder create(RestServiceDefinition restServiceDefinition) {
127 Builder builder = create();
128 builder.copyServiceDefinitionProperties(restServiceDefinition);
129 builder.setResourceClass(restServiceDefinition.getResourceClass());
130 if (restServiceDefinition.getResourceToClassNameMap() != null) {
131 builder.setResourceToClassNameMap(restServiceDefinition.getResourceToClassNameMap());
132 }
133 return builder;
134 }
135
136 @Override
137 public RestServiceConfiguration build() {
138 return new RestServiceConfiguration(this);
139 }
140
141 }
142
143
144
145
146 static class Constants {
147 final static String ROOT_ELEMENT_NAME = "restServiceConfiguration";
148 final static String TYPE_NAME = "RestServiceConfigurationType";
149 }
150
151
152
153
154
155 static class Elements {
156 protected final static String RESOURCE_CLASS = "resourceClass";
157 protected final static String RESOURCE_TO_CLASS_NAME_MAP = "resourceToClassNameMap";
158 }
159
160
161 }