001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kew.impl.extension; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.rice.core.api.CoreConstants; 020 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; 021 import org.kuali.rice.kew.api.extension.ExtensionDefinition; 022 import org.kuali.rice.kew.api.extension.ExtensionRepositoryService; 023 import org.kuali.rice.kew.rule.bo.RuleAttribute; 024 import org.kuali.rice.kew.rule.service.RuleAttributeService; 025 import org.w3c.dom.Element; 026 027 import javax.xml.bind.annotation.XmlAccessType; 028 import javax.xml.bind.annotation.XmlAccessorType; 029 import javax.xml.bind.annotation.XmlAnyElement; 030 import javax.xml.bind.annotation.XmlElement; 031 import javax.xml.bind.annotation.XmlRootElement; 032 import javax.xml.bind.annotation.XmlType; 033 import java.util.Collection; 034 035 /** 036 * Reference implementation of the {@code ExtensionRepositoryService}. This implementation 037 * essentially sits on top of the legacy "RuleAttribute" service. 038 * 039 * @author Kuali Rice Team (rice.collab@kuali.org) 040 */ 041 @XmlRootElement(name = ExtensionRepositoryServiceImpl.Constants.ROOT_ELEMENT_NAME) 042 @XmlAccessorType(XmlAccessType.NONE) 043 @XmlType(name = ExtensionRepositoryServiceImpl.Constants.TYPE_NAME, propOrder = { 044 ExtensionRepositoryServiceImpl.Elements.RULE_ATTRIBUTE_SERVICE, 045 CoreConstants.CommonElements.FUTURE_ELEMENTS 046 }) 047 public class ExtensionRepositoryServiceImpl implements ExtensionRepositoryService { 048 049 /** 050 * Private constructor used only by JAXB. 051 * 052 */ 053 private ExtensionRepositoryServiceImpl() { 054 this.ruleAttributeService = null; 055 } 056 057 @XmlElement(name = Elements.RULE_ATTRIBUTE_SERVICE, required = true) 058 private RuleAttributeService ruleAttributeService; 059 060 061 @Override 062 public ExtensionDefinition getExtensionById(String id) throws RiceIllegalArgumentException { 063 if (StringUtils.isBlank(id)) { 064 throw new RiceIllegalArgumentException("id was null or blank"); 065 } 066 RuleAttribute ruleAttribute = ruleAttributeService.findByRuleAttributeId(id); 067 return translateFromRuleAttribute(ruleAttribute); 068 } 069 070 071 @Override 072 public ExtensionDefinition getExtensionByName(String name) throws RiceIllegalArgumentException { 073 if (StringUtils.isBlank(name)) { 074 throw new RiceIllegalArgumentException("name was null or blank"); 075 } 076 RuleAttribute ruleAttribute = ruleAttributeService.findByName(name); 077 return translateFromRuleAttribute(ruleAttribute); 078 } 079 080 private ExtensionDefinition translateFromRuleAttribute(RuleAttribute ruleAttribute) { 081 return RuleAttribute.to(ruleAttribute); 082 } 083 084 /** 085 * Sets the rule attribute service. 086 * @param ruleAttributeService the rule attribute service to set. 087 */ 088 public void setRuleAttributeService(RuleAttributeService ruleAttributeService) { 089 this.ruleAttributeService = ruleAttributeService; 090 } 091 092 @SuppressWarnings("unused") 093 @XmlAnyElement 094 private final Collection<Element> _futureElements = null; 095 096 /** 097 * Defines some internal constants used on this class. 098 * 099 */ 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 }