001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.core.datadictionary;
017:
018: import org.apache.commons.lang.StringUtils;
019: import org.apache.commons.logging.Log;
020: import org.apache.commons.logging.LogFactory;
021: import org.kuali.core.datadictionary.exception.AttributeValidationException;
022: import org.kuali.core.datadictionary.exception.ClassValidationException;
023:
024: public class ApcRuleDefinition extends DataDictionaryDefinitionBase {
025:
026: private String attributeName;
027: private String parameterNamespace;
028: private String parameterDetailType;
029: private String parameterName;
030: private String errorMessage;
031:
032: // logger
033: private static Log LOG = LogFactory
034: .getLog(ReferenceDefinition.class);
035:
036: public ApcRuleDefinition() {
037: LOG.debug("creating new ApcRuleDefinition");
038: }
039:
040: public void completeValidation(Class rootBusinessObjectClass,
041: Class otherBusinessObjectClass,
042: ValidationCompletionUtils validationCompletionUtils) {
043:
044: // make sure the rootBusinessObjectClass is actually a descendent of BusinessObject
045: if (!validationCompletionUtils
046: .isBusinessObjectClass(rootBusinessObjectClass)) {
047: throw new ClassValidationException(
048: "RootBusinessObject is not a descendent of BusinessObject. "
049: + "rootBusinessObjectClass = '"
050: + rootBusinessObjectClass.getName() + "' "
051: + "(" + getParseLocation() + ")");
052: }
053:
054: // make sure the attributeName is actually a property of the BO
055: if (!validationCompletionUtils.isPropertyOf(
056: rootBusinessObjectClass, attributeName)) {
057: throw new AttributeValidationException(
058: "unable to find attribute '" + attributeName
059: + "' in rootBusinessObjectClass '"
060: + rootBusinessObjectClass.getName() + "' ("
061: + getParseLocation() + ")");
062: }
063:
064: // make sure that the member referencec by attributeName is actually a string
065: Class attributeClass = validationCompletionUtils
066: .getAttributeClass(rootBusinessObjectClass,
067: attributeName);
068: if (!attributeClass.equals(String.class)) {
069: throw new AttributeValidationException("the attribute '"
070: + attributeName + "' in rootBusinessObjectClass '"
071: + rootBusinessObjectClass.getName()
072: + "' is of type '" + attributeClass.getName()
073: + "'. These attributes may only be string. ("
074: + getParseLocation() + ")");
075: }
076:
077: }
078:
079: public String getParameterNamespace() {
080: return parameterNamespace;
081: }
082:
083: public void setParameterNamespace(String parameterNamespace) {
084: if (StringUtils.isBlank(parameterNamespace)) {
085: throw new IllegalArgumentException(
086: "invalid (blank) parameterNamespace");
087: }
088: if (LOG.isDebugEnabled()) {
089: LOG.debug("calling parameterNamespace '"
090: + parameterNamespace + "'");
091: }
092: this .parameterNamespace = parameterNamespace;
093: }
094:
095: public String getParameterName() {
096: return parameterName;
097: }
098:
099: void setParameterName(String parameterName) {
100: if (StringUtils.isBlank(parameterName)) {
101: throw new IllegalArgumentException(
102: "invalid (blank) parameterName");
103: }
104: if (LOG.isDebugEnabled()) {
105: LOG.debug("calling parameterName '" + parameterName + "'");
106: }
107: this .parameterName = parameterName;
108: }
109:
110: public String getAttributeName() {
111: return attributeName;
112: }
113:
114: public void setAttributeName(String attributeName) {
115: if (StringUtils.isBlank(attributeName)) {
116: throw new IllegalArgumentException(
117: "invalid (blank) attributeName");
118: }
119: if (LOG.isDebugEnabled()) {
120: LOG.debug("calling setAttributeName '" + attributeName
121: + "'");
122: }
123: this .attributeName = attributeName;
124: }
125:
126: public String getErrorMessage() {
127: return errorMessage;
128: }
129:
130: public void setErrorMessage(String errorMessage) {
131: if (StringUtils.isBlank(errorMessage)) {
132: throw new IllegalArgumentException(
133: "invalid (blank) errorMessage");
134: }
135: if (LOG.isDebugEnabled()) {
136: LOG.debug("calling setErrorMessage '" + errorMessage + "'");
137: }
138: this .errorMessage = errorMessage;
139: }
140:
141: /**
142: * @see java.lang.Object#toString()
143: */
144: public String toString() {
145: return "ApcRuleDefinition for attribute " + getAttributeName();
146: }
147:
148: public String getParameterDetailType() {
149: return this .parameterDetailType;
150: }
151:
152: public void setParameterDetailType(String parameterDetailType) {
153: if (StringUtils.isBlank(parameterDetailType)) {
154: throw new IllegalArgumentException(
155: "invalid (blank) parameterDetailType");
156: }
157: if (LOG.isDebugEnabled()) {
158: LOG.debug("calling setParameterDetailType '"
159: + parameterDetailType + "'");
160: }
161: this.parameterDetailType = parameterDetailType;
162: }
163: }
|