001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package mocks.elements;
018:
019: import org.jdom.Element;
020: import org.jdom.output.XMLOutputter;
021:
022: /**
023: * OrgCDEOK is the key class for retrieving|building the org_cd element in an xml document
024: * <p>Title: </p>
025: * <p>Description: </p>
026: * <p>Copyright: Copyright (c) 2001</p>
027: * <p>Company: UIS - Indiana University</p>
028: * @author Xiaofeng Qi
029: * @version 1.0
030: */
031: public class OrgCodeEOK {
032: public final static String ORG_CODE_EOK = "university_organization_eok";
033: public final static String ORG_CD_TAG = "org_cd";
034: public final static String VALUE = "value";
035: private final String ROUTE_CONTROL_ATTR = "route-control";
036: private final String ROUTE_CONTROL_TRUE = "yes";
037:
038: /** Indicates if the key is being used as a route control - true by default*/
039: private boolean routeControl = true;
040:
041: //default of org_cd value
042: public String orgCd = "";
043:
044: //default chart_of_accounts_eok object
045: public ChartCodeEOK charteok;
046:
047: //constructors
048: //create an org_cd_eok with org_cd and route-control,
049: //and a charteok
050: public OrgCodeEOK(String orgCd, ChartCodeEOK charteok,
051: boolean isRouteControl) throws Exception {
052: if ((orgCd == null) || (charteok == null) || orgCd.equals("")) {
053: throw new Exception("Empty values for keys not allowed");
054: }
055:
056: this .orgCd = orgCd;
057: this .routeControl = isRouteControl;
058: this .charteok = charteok;
059: }
060:
061: public OrgCodeEOK(String orgCd, String chartCd,
062: boolean isRouteControl) throws Exception {
063: this (orgCd, new ChartCodeEOK(chartCd, isRouteControl),
064: isRouteControl);
065: }
066:
067: /**
068: * Construct an OrgCDEOK object from a JDOM element
069: * @param keyElement a JDOM element
070: */
071: public OrgCodeEOK(Element rootElement) throws Exception {
072: // check if root element is valid
073: if (!rootElement.getName().equals(OrgCodeEOK.ORG_CODE_EOK)) {
074: throw new Exception("Invalid OrgCodeEOK element "
075: + rootElement.getName());
076: }
077:
078: // set the route-control for this eok
079: String routeCtrlVal = rootElement
080: .getAttributeValue(this .ROUTE_CONTROL_ATTR);
081:
082: if ((routeCtrlVal != null)
083: && routeCtrlVal.trim().equalsIgnoreCase(
084: this .ROUTE_CONTROL_TRUE)) {
085: this .routeControl = true;
086: } else {
087: this .routeControl = false;
088: }
089:
090: //get children elements
091: // org_cd tag
092: Element orgCd = rootElement.getChild(OrgCodeEOK.ORG_CD_TAG);
093:
094: if (orgCd == null) {
095: throw new Exception("Missing <org_cd> tag");
096: }
097:
098: String orgVal = orgCd.getAttributeValue(VALUE);
099:
100: if ((orgVal == null) || orgVal.trim().equals("")) {
101: throw new Exception(
102: "Invalid org_cd element -- missing value for org_cd");
103: }
104:
105: this .orgCd = orgVal;
106:
107: this .charteok = new ChartCodeEOK(rootElement
108: .getChild(ChartCodeEOK.CHART_CODE_EOK));
109: }
110:
111: /**
112: * Construct the JDOM Element for this key
113: * @return Element the JDOM element for this OrgCodeEOK
114: */
115: public Element buildJdom() {
116: //build root element
117: Element keyJDOM = new Element(ORG_CODE_EOK);
118:
119: //set route-control for root element
120: if (this .routeControl) {
121: keyJDOM.setAttribute(this .ROUTE_CONTROL_ATTR,
122: ROUTE_CONTROL_TRUE);
123: }
124:
125: //build the org_cd tag
126: Element org_cd = new Element(ORG_CD_TAG);
127: org_cd.setAttribute(VALUE, this .orgCd);
128: keyJDOM.addContent(org_cd);
129: keyJDOM.addContent(charteok.buildJdom());
130:
131: return keyJDOM;
132: }
133:
134: public String getSerializedForm() {
135: XMLOutputter out = new XMLOutputter();
136:
137: return out.outputString(buildJdom());
138: }
139:
140: //getters
141: public String getOrg_cd_value() {
142: return orgCd;
143: }
144:
145: public ChartCodeEOK getCharteok() {
146: return charteok;
147: }
148:
149: public boolean isRouteControl() {
150: return this .routeControl;
151: }
152:
153: public String getChartCdValue() {
154: return this .charteok.getChart_cd_value();
155: }
156:
157: /**
158: * Create a printable representation of this object. Do not count
159: * on the format of this string being the same in future versions!
160: *
161: * @return a string representation of this object
162: */
163: public String toString() {
164: StringBuffer sb = new StringBuffer("[fin_coa_cd=");
165: sb.append(charteok.getChart_cd_value());
166: sb.append(",org_cd=");
167: sb.append(orgCd);
168: sb.append("]");
169:
170: return sb.toString();
171: }
172: }
173:
174: /*
175: * Copyright 2003 The Trustees of Indiana University. All rights reserved.
176: *
177: * This file is part of the EDEN software package.
178: * For license information, see the LICENSE file in the top level directory
179: * of the EDEN source distribution.
180: */
|