Coverage Report - org.kuali.rice.ksb.api.bus.support.RestServiceConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
RestServiceConfiguration
70%
12/17
50%
2/4
1.286
RestServiceConfiguration$1
N/A
N/A
1.286
RestServiceConfiguration$Builder
100%
17/17
100%
2/2
1.286
RestServiceConfiguration$Constants
0%
0/1
N/A
1.286
RestServiceConfiguration$Elements
0%
0/1
N/A
1.286
 
 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 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  3
 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  
      * Private constructor used only by JAXB.
 49  
      */
 50  
         private RestServiceConfiguration() {
 51  7
                 super();
 52  7
                 this.resourceClass = null;
 53  7
                 this.resourceToClassNameMap = null;
 54  7
         }
 55  
         
 56  
         private RestServiceConfiguration(Builder builder) {
 57  3
                 super(builder);
 58  3
                 this.resourceClass = builder.getResourceClass();
 59  3
                 if (builder.getResourceToClassNameMap() != null) {
 60  1
                         this.resourceToClassNameMap = new HashMap<String, String>(builder.getResourceToClassNameMap());
 61  
                 } else {
 62  2
                         this.resourceToClassNameMap = Collections.emptyMap();
 63  
                 }
 64  3
         }
 65  
         
 66  
         public static RestServiceConfiguration fromServiceDefinition(RestServiceDefinition restServiceDefinition) {
 67  3
                 return Builder.create(restServiceDefinition).build();
 68  
         }
 69  
                 
 70  
         public String getResourceClass() {
 71  0
                 return this.resourceClass;
 72  
         }
 73  
         
 74  
         /**
 75  
          * Returns a map of resource names to resource classes.  Can be null if
 76  
          * there are no mapped resources on this service configuration.
 77  
          * 
 78  
          * @return the resource to class name map, or null if no resources have
 79  
          * been mapped
 80  
          */
 81  
         public Map<String, String> getResourceToClassNameMap() {
 82  0
                 return this.resourceToClassNameMap;
 83  
         }
 84  
         
 85  
         /**
 86  
          * @param className
 87  
          * @return true if this service contains a resource for the given class name
 88  
          */
 89  
         public boolean hasClass(String className) {
 90  0
                 if (resourceToClassNameMap == null) {
 91  0
                         return false;
 92  
                 }
 93  0
                 return resourceToClassNameMap.containsValue(className);
 94  
         }
 95  
         
 96  84
         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  3
                         return resourceClass;
 105  
                 }
 106  
 
 107  
                 public void setResourceClass(String resourceClass) {
 108  3
                         this.resourceClass = resourceClass;
 109  3
                 }
 110  
 
 111  
                 public Map<String, String> getResourceToClassNameMap() {
 112  4
                         return resourceToClassNameMap;
 113  
                 }
 114  
 
 115  
                 public void setResourceToClassNameMap(Map<String, String> resourceToClassNameMap) {
 116  1
                         this.resourceToClassNameMap = resourceToClassNameMap;
 117  1
                 }
 118  
                 
 119  3
                 private Builder() {
 120  3
                 }
 121  
                 
 122  
                 public static Builder create() {
 123  3
                         return new Builder();
 124  
                 }
 125  
                 
 126  
                 public static Builder create(RestServiceDefinition restServiceDefinition) {
 127  3
                         Builder builder = create();
 128  3
                         builder.copyServiceDefinitionProperties(restServiceDefinition);
 129  3
                         builder.setResourceClass(restServiceDefinition.getResourceClass());
 130  3
                         if (restServiceDefinition.getResourceToClassNameMap() != null) {
 131  1
                                 builder.setResourceToClassNameMap(restServiceDefinition.getResourceToClassNameMap());
 132  
                         }
 133  3
                         return builder;
 134  
                 }
 135  
 
 136  
                 @Override
 137  
                 public RestServiceConfiguration build() {
 138  3
                         return new RestServiceConfiguration(this);
 139  
                 }
 140  
                 
 141  
         }
 142  
         
 143  
         /**
 144  
      * Defines some internal constants used on this class.
 145  
      */
 146  0
     static class Constants {
 147  
             final static String ROOT_ELEMENT_NAME = "restServiceConfiguration";
 148  
         final static String TYPE_NAME = "RestServiceConfigurationType";
 149  
     }
 150  
 
 151  
     /**
 152  
      * A private class which exposes constants which define the XML element names to use
 153  
      * when this object is marshalled to XML.
 154  
      */
 155  0
      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  
 }