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