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 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 super();
37 this.resourceClass = null;
38 this.resourceToClassNameMap = null;
39 }
40
41 private RestServiceConfiguration(Builder builder) {
42 super(builder);
43 this.resourceClass = builder.getResourceClass();
44 if (builder.getResourceToClassNameMap() != null) {
45 this.resourceToClassNameMap = new HashMap<String, String>(builder.getResourceToClassNameMap());
46 } else {
47 this.resourceToClassNameMap = null;
48 }
49 }
50
51 public static RestServiceConfiguration fromServiceDefinition(RestServiceDefinition restServiceDefinition) {
52 return Builder.create(restServiceDefinition).build();
53 }
54
55 public String getResourceClass() {
56 return this.resourceClass;
57 }
58
59
60
61
62
63
64
65
66 public Map<String, String> getResourceToClassNameMap() {
67 return this.resourceToClassNameMap;
68 }
69
70
71
72
73
74 public boolean hasClass(String className) {
75 if (resourceToClassNameMap == null) {
76 return false;
77 }
78 return resourceToClassNameMap.containsValue(className);
79 }
80
81 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 return resourceClass;
90 }
91
92 public void setResourceClass(String resourceClass) {
93 this.resourceClass = resourceClass;
94 }
95
96 public Map<String, String> getResourceToClassNameMap() {
97 return resourceToClassNameMap;
98 }
99
100 public void setResourceToClassNameMap(Map<String, String> resourceToClassNameMap) {
101 this.resourceToClassNameMap = resourceToClassNameMap;
102 }
103
104 private Builder() {
105 }
106
107 public static Builder create() {
108 return new Builder();
109 }
110
111 public static Builder create(RestServiceDefinition restServiceDefinition) {
112 Builder builder = create();
113 builder.copyServiceDefinitionProperties(restServiceDefinition);
114 builder.setResourceClass(restServiceDefinition.getResourceClass());
115 if (restServiceDefinition.getResourceToClassNameMap() != null) {
116 builder.setResourceToClassNameMap(restServiceDefinition.getResourceToClassNameMap());
117 }
118 return builder;
119 }
120
121 @Override
122 public RestServiceConfiguration build() {
123 return new RestServiceConfiguration(this);
124 }
125
126 }
127
128
129
130
131 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 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 }