001    /*
002     * Copyright 2007-2008 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.kns.datadictionary;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.kns.bo.BusinessObject;
020    import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
021    
022    /**
023     * This is a description of what this class does - wliang don't forget to fill this in. 
024     * 
025     * @author Kuali Rice Team (rice.collab@kuali.org)
026     *
027     */
028    public class InactivationBlockingDefinition extends DataDictionaryDefinitionBase implements InactivationBlockingMetadata {
029            private static final long serialVersionUID = -8765429636173190984L;
030            
031            protected  Class<? extends BusinessObject> blockingReferenceBusinessObjectClass;
032        protected  String blockedReferencePropertyName;
033        protected  Class<? extends BusinessObject> blockedBusinessObjectClass;
034        protected  String inactivationBlockingDetectionServiceBeanName;
035        protected  String relationshipLabel;
036        protected Class<? extends BusinessObject> businessObjectClass;
037    
038        public InactivationBlockingDefinition() {
039        }    
040    
041        /**
042         * This overridden method ...
043         * 
044         * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
045         */
046        @SuppressWarnings("unchecked")
047            public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
048            if (StringUtils.isBlank(inactivationBlockingDetectionServiceBeanName)) {
049                    if (StringUtils.isBlank(blockedReferencePropertyName)) {
050                            // the default inactivation blocking detection service (used when inactivationBlockingDetectionServiceBeanName is blank) requires that the property name be set
051                        throw new AttributeValidationException("inactivationBlockingDetectionServiceBeanName and  blockedReferencePropertyName can't both be blank in InactivationBlockingDefinition for class " +
052                                rootBusinessObjectClass.getClass().getName());
053                    }
054            }
055            if (getBlockedBusinessObjectClass() == null) {
056                    throw new AttributeValidationException("Unable to determine blockedReferenceBusinessObjectClass in InactivationBlockingDefinition for class " +
057                                rootBusinessObjectClass.getClass().getName());
058            }
059            if (!BusinessObject.class.isAssignableFrom(getBlockedBusinessObjectClass())) {
060                throw new AttributeValidationException("InactivationBlockingDefinitions must block a reference of type BusinessObject.  Class name: " +
061                        rootBusinessObjectClass.getClass().getName() + " blockedReferencePropertyName " + blockedReferencePropertyName + 
062                        " class that should have been a BusinessObject: " + getBlockedBusinessObjectClass());
063            }
064        }
065    
066        /**
067         * This overridden method ...
068         * 
069         * @see org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata#getBlockedReferencePropertyName()
070         */
071        public String getBlockedReferencePropertyName() {
072            return this.blockedReferencePropertyName;
073        }
074    
075        public void setBlockedReferencePropertyName(String blockedReferencePropertyName) {
076            this.blockedReferencePropertyName = blockedReferencePropertyName;
077        }
078    
079        /**
080         * This overridden method ...
081         * 
082         * @see org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata#getBlockedBusinessObjectClass()
083         */
084        public Class<? extends BusinessObject> getBlockedBusinessObjectClass() {
085            return this.blockedBusinessObjectClass;
086        }
087    
088        public void setBlockedBusinessObjectClass(Class<? extends BusinessObject> blockedBusinessObjectClass) {
089            this.blockedBusinessObjectClass = blockedBusinessObjectClass;
090        }
091    
092        /**
093         * This overridden method ...
094         * 
095         * @see org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata#getInactivationBlockingDetectionServiceBeanName()
096         */
097        public String getInactivationBlockingDetectionServiceBeanName() {
098            return this.inactivationBlockingDetectionServiceBeanName;
099        }
100    
101        public void setInactivationBlockingDetectionServiceBeanName(String inactivationBlockingDetectionServiceImpl) {
102            this.inactivationBlockingDetectionServiceBeanName = inactivationBlockingDetectionServiceImpl;
103        }
104    
105        /**
106         * This overridden method ...
107         * 
108         * @see org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata#getBlockingReferenceBusinessObjectClass()
109         */
110        public Class<? extends BusinessObject> getBlockingReferenceBusinessObjectClass() {
111            return this.blockingReferenceBusinessObjectClass;
112        }
113    
114        public void setBlockingReferenceBusinessObjectClass(Class<? extends BusinessObject> blockingReferenceBusinessObjectClass) {
115            this.blockingReferenceBusinessObjectClass = blockingReferenceBusinessObjectClass;
116        }
117    
118            public String getRelationshipLabel() {
119                    return this.relationshipLabel;
120            }
121    
122            public void setRelationshipLabel(String relationshipLabel) {
123                    this.relationshipLabel = relationshipLabel;
124            }
125    
126            public Class<? extends BusinessObject> getBusinessObjectClass() {
127                    return this.businessObjectClass;
128            }
129    
130            public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
131                    this.businessObjectClass = businessObjectClass;
132            }
133            
134            @Override
135            public String toString() {
136                    return "InactivationBlockingDefinition: blockedClass=" + blockedBusinessObjectClass.getName() 
137                                    + " /blockingReferenceProperty=" + blockedReferencePropertyName
138                                    + " /blockingClass=" + blockingReferenceBusinessObjectClass.getName();
139            }
140    }