001: /*
002: * Copyright 2005-2006 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:
017: package org.kuali.core.datadictionary;
018:
019: import org.apache.commons.lang.StringUtils;
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022: import org.kuali.core.datadictionary.exception.AttributeValidationException;
023:
024: /**
025: * Contains a pair of attributeNames, accessible as fieldTo and fieldFrom.
026: *
027: *
028: */
029: public class FieldPairDefinition extends DataDictionaryDefinitionBase {
030: // logger
031: private static Log log = LogFactory
032: .getLog(FieldPairDefinition.class);
033:
034: private String fieldTo;
035: private String fieldFrom;
036:
037: public FieldPairDefinition() {
038: log.debug("creating new FieldPairDefinition");
039: }
040:
041: public String getFieldFrom() {
042: return fieldFrom;
043: }
044:
045: public void setFieldFrom(String fieldFrom) {
046: if (StringUtils.isBlank(fieldFrom)) {
047: throw new IllegalArgumentException(
048: "invalid (blank) fieldFrom");
049: }
050:
051: this .fieldFrom = fieldFrom;
052: }
053:
054: public String getFieldTo() {
055: return fieldTo;
056: }
057:
058: public void setFieldTo(String fieldTo) {
059: if (StringUtils.isBlank(fieldTo)) {
060: throw new IllegalArgumentException(
061: "invalid (blank) fieldTo");
062: }
063:
064: this .fieldTo = fieldTo;
065: }
066:
067: /**
068: * Directly validate simple fields.
069: *
070: * @see org.kuali.core.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
071: */
072: public void completeValidation(Class rootBusinessObjectClass,
073: Class otherBusinessObjectClass,
074: ValidationCompletionUtils validationCompletionUtils) {
075: if (!validationCompletionUtils.isPropertyOf(
076: rootBusinessObjectClass, fieldTo)) {
077: throw new AttributeValidationException(
078: "unable to find attribute '" + fieldTo
079: + "' in rootBusinessObjectClass '"
080: + rootBusinessObjectClass.getName() + "' ("
081: + getParseLocation() + ")");
082: }
083:
084: if (!validationCompletionUtils.isPropertyOf(
085: otherBusinessObjectClass, fieldFrom)) {
086: throw new AttributeValidationException(
087: "unable to find attribute '" + fieldFrom
088: + "' in otherBusinessObjectClass '"
089: + otherBusinessObjectClass.getName()
090: + "' (" + getParseLocation() + ")");
091: }
092: }
093:
094: /**
095: * @see java.lang.Object#toString()
096: */
097: public String toString() {
098: return "FieldPairDefinition for (to,from) => (" + getFieldTo()
099: + "," + getFieldFrom() + ")";
100: }
101: }
|