View Javadoc

1   /**
2    * Copyright 2005-2012 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.kew.impl.extension;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.CoreConstants;
20  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
21  import org.kuali.rice.kew.api.extension.ExtensionDefinition;
22  import org.kuali.rice.kew.api.extension.ExtensionRepositoryService;
23  import org.kuali.rice.kew.rule.bo.RuleAttribute;
24  import org.kuali.rice.kew.rule.service.RuleAttributeService;
25  import org.w3c.dom.Element;
26  
27  import javax.xml.bind.annotation.XmlAccessType;
28  import javax.xml.bind.annotation.XmlAccessorType;
29  import javax.xml.bind.annotation.XmlAnyElement;
30  import javax.xml.bind.annotation.XmlElement;
31  import javax.xml.bind.annotation.XmlRootElement;
32  import javax.xml.bind.annotation.XmlType;
33  import java.util.Collection;
34  
35  /**
36   * Reference implementation of the {@code ExtensionRepositoryService}.  This implementation
37   * essentially sits on top of the legacy "RuleAttribute" service.
38   *
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   */
41  @XmlRootElement(name = ExtensionRepositoryServiceImpl.Constants.ROOT_ELEMENT_NAME)
42  @XmlAccessorType(XmlAccessType.NONE)
43  @XmlType(name = ExtensionRepositoryServiceImpl.Constants.TYPE_NAME, propOrder = {
44      ExtensionRepositoryServiceImpl.Elements.RULE_ATTRIBUTE_SERVICE,
45      CoreConstants.CommonElements.FUTURE_ELEMENTS
46  })
47  public class ExtensionRepositoryServiceImpl implements ExtensionRepositoryService {
48  
49      /**
50       * Private constructor used only by JAXB.
51       *
52       */
53      private ExtensionRepositoryServiceImpl() {
54          this.ruleAttributeService = null;
55      }
56  
57      @XmlElement(name = Elements.RULE_ATTRIBUTE_SERVICE, required = true)
58      private RuleAttributeService ruleAttributeService;
59  
60  
61      @Override
62      public ExtensionDefinition getExtensionById(String id) throws RiceIllegalArgumentException {
63          if (StringUtils.isBlank(id)) {
64              throw new RiceIllegalArgumentException("id was null or blank");
65          }
66          RuleAttribute ruleAttribute = ruleAttributeService.findByRuleAttributeId(id);
67          return translateFromRuleAttribute(ruleAttribute);
68      }
69  
70  
71      @Override
72      public ExtensionDefinition getExtensionByName(String name) throws RiceIllegalArgumentException {
73          if (StringUtils.isBlank(name)) {
74              throw new RiceIllegalArgumentException("name was null or blank");
75          }
76          RuleAttribute ruleAttribute = ruleAttributeService.findByName(name);
77          return translateFromRuleAttribute(ruleAttribute);
78      }
79  
80      private ExtensionDefinition translateFromRuleAttribute(RuleAttribute ruleAttribute) {
81          return RuleAttribute.to(ruleAttribute);
82      }
83  
84      /**
85           * Sets the rule attribute service.
86           * @param ruleAttributeService the rule attribute service to set.
87           */
88      public void setRuleAttributeService(RuleAttributeService ruleAttributeService) {
89          this.ruleAttributeService = ruleAttributeService;
90      }
91  
92      @SuppressWarnings("unused")
93      @XmlAnyElement
94      private final Collection<Element> _futureElements = null;
95  
96      /**
97       * Defines some internal constants used on this class.
98       *
99       */
100     static class Constants {
101         static final String ROOT_ELEMENT_NAME = "extensionRepositoryService";
102         static final String TYPE_NAME = "ExtensionRepositoryService";
103     }
104 
105     /**
106      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
107      *
108      */
109     static class Elements {
110         static final String RULE_ATTRIBUTE_SERVICE = "ruleAttributeService";
111     }
112 }