001: /*
002: * Copyright 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.module.chart.bo;
017:
018: import java.util.LinkedHashMap;
019:
020: import org.apache.commons.lang.StringUtils;
021: import org.kuali.core.bo.KualiCode;
022: import org.kuali.core.bo.PersistableBusinessObjectBase;
023: import org.kuali.core.inquiry.KualiInquirableImpl;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.kfs.service.KualiCodeService;
026:
027: public class KualiSystemCode extends PersistableBusinessObjectBase
028: implements KualiCode {
029:
030: static {
031: KualiInquirableImpl.HACK_LIST.add(KualiSystemCode.class);
032: }
033:
034: private String code;
035: private String name;
036: private boolean active;
037: protected String className;
038: private boolean codeRetrieved;
039:
040: public KualiSystemCode() {
041: this .active = true;
042: this .codeRetrieved = false;
043: this .className = this .getClass().getName();
044: }
045:
046: public KualiSystemCode(String code) {
047: this .code = code;
048: this .active = true;
049: this .codeRetrieved = false;
050: this .className = this .getClass().getName();
051: }
052:
053: /**
054: * @return Getter for the Code.
055: */
056: public String getCode() {
057: return code;
058: }
059:
060: /**
061: * @param code - Setter for the Code.
062: */
063: public void setCode(String code) {
064: this .code = code;
065: }
066:
067: /**
068: * @return Getter for the Name.
069: */
070: public String getName() {
071: if (!codeRetrieved && getCode() != null) {
072: KualiSystemCode code = (KualiSystemCode) SpringContext
073: .getBean(KualiCodeService.class).getSystemCode(
074: this .getClass(), getCode());
075: code.setCodeRetrieved(true);
076: this .name = code.getName();
077: this .active = code.isActive();
078: this .codeRetrieved = true;
079: }
080: return name;
081: }
082:
083: /**
084: * @param name - Setter for the name.
085: */
086: public void setName(String name) {
087: this .name = name;
088: }
089:
090: /**
091: * @return Getter for the active field.
092: */
093: public boolean isActive() {
094: if (!codeRetrieved && getCode() != null) {
095: KualiSystemCode code = (KualiSystemCode) SpringContext
096: .getBean(KualiCodeService.class).getSystemCode(
097: this .getClass(), getCode());
098: code.setCodeRetrieved(true);
099: name = code.getName();
100: active = code.isActive();
101: codeRetrieved = true;
102: }
103: return active;
104: }
105:
106: /**
107: * @param name - Setter for the active field.
108: */
109: public void setActive(boolean a) {
110: this .active = a;
111: }
112:
113: /**
114: * @return Returns the className.
115: */
116: public String getClassName() {
117: return className;
118: }
119:
120: /**
121: * @param ojbConcreteClass The ojbConcreteClass to set.
122: */
123: public void setClassName(String ojbConcreteClass) {
124: this .className = ojbConcreteClass;
125: }
126:
127: /**
128: * @return Returns the codeRetrieved.
129: */
130: public boolean isCodeRetrieved() {
131: return codeRetrieved;
132: }
133:
134: /**
135: * @param codeRetrieved The codeRetrieved to set.
136: */
137: public void setCodeRetrieved(boolean codeRetrieved) {
138: this .codeRetrieved = codeRetrieved;
139: }
140:
141: /**
142: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
143: */
144: final protected LinkedHashMap toStringMapper() {
145: LinkedHashMap m = new LinkedHashMap();
146:
147: m.put("code", getCode());
148:
149: return m;
150: }
151:
152: /**
153: * Implements equals comparing code to code.
154: *
155: * @see java.lang.Object#equals(java.lang.Object)
156: */
157: public boolean equals(Object obj) {
158: if (obj instanceof KualiSystemCode) {
159: return StringUtils.equals(this .getCode(),
160: ((KualiSystemCode) obj).getCode());
161: }
162: return false;
163: }
164:
165: /**
166: * Overriding equals requires writing a hashCode method.
167: *
168: * @see java.lang.Object#hashCode()
169: */
170: public int hashCode() {
171: int hashCode = 0;
172:
173: if (getCode() != null) {
174: hashCode = getCode().hashCode();
175: }
176:
177: return hashCode;
178: }
179:
180: }
|