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: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
023:
024: /**
025: * ChartCodeEOK is the key class for retrieving|building fin_coa_cd element to|from an xml document
026: * <p>Title: </p>
027: * <p>Description: </p>
028: * <p>Copyright: Copyright (c) 2001</p>
029: * <p>Company: UIS - Indiana University</p>
030: * @author Xiaofeng Qi
031: * @version 1.0
032: */
033: public class ChartCodeEOK {
034: public final static String CHART_CODE_EOK = "financial_chart_of_accounts_eok";
035: public final static String CHART_CD_TAG = "fin_coa_cd";
036: public final static String VALUE = "value";
037: private final static String ROUTE_CONTROL_ATTR = "route-control";
038: private final static String ROUTE_CONTROL_TRUE = "yes";
039:
040: /* default route control*/
041: public boolean routeControl = true;
042:
043: //default fin_coa_cd value attribute
044: public String chart_cd_value = "";
045:
046: //constructors
047: public ChartCodeEOK(String chartCode, boolean routeControl)
048: throws Exception {
049: if ((chartCode == null) || chartCode.equals("")) {
050: throw new Exception("Empty chartcode not allowed");
051: }
052:
053: this .chart_cd_value = chartCode;
054: this .routeControl = routeControl;
055: }
056:
057: /**
058: * create a ChartCodeEOK object from a JDOM element
059: * @param keyElement a JDOM element
060: */
061: public ChartCodeEOK(Element rootElement) throws Exception {
062: // check if the element is a valid one for us
063: if ((rootElement == null)
064: || !rootElement.getName().equals(CHART_CODE_EOK)) {
065: throw new WorkflowRuntimeException(
066: "Invalid ChartCodeEOK element "
067: + rootElement.getName());
068: }
069:
070: String routeCtrlVal = rootElement
071: .getAttributeValue(ROUTE_CONTROL_ATTR);
072:
073: if ((routeCtrlVal != null)
074: && routeCtrlVal.trim().equals(ROUTE_CONTROL_TRUE)) {
075: routeControl = true;
076: } else {
077: routeControl = false;
078: }
079:
080: Element fin_coa_cd = rootElement.getChild(CHART_CD_TAG);
081:
082: if (fin_coa_cd == null) {
083: throw new WorkflowRuntimeException(
084: "<fin_coa_cd> tag missing. ");
085: }
086:
087: String fin_coa_cd_value = fin_coa_cd.getAttributeValue(VALUE);
088:
089: if ((fin_coa_cd_value == null)
090: || fin_coa_cd_value.trim().equals("")) {
091: throw new WorkflowRuntimeException(
092: "<fin_coa_cd> value missing");
093: }
094:
095: chart_cd_value = fin_coa_cd_value.trim();
096: }
097:
098: /**
099: * Returns the doc type key in the XML format.
100: * @return String representing XML for key.
101: */
102: public String getSerializedForm() {
103: XMLOutputter out = new XMLOutputter();
104:
105: return out.outputString(buildJdom());
106: }
107:
108: /**
109: * Construct the JDOM Element for this key
110: * @return Element the JDOM element for this ChartCodeEOK object
111: */
112: public Element buildJdom() {
113: Element root = new Element(CHART_CODE_EOK);
114:
115: if (this .routeControl) {
116: root.setAttribute(ROUTE_CONTROL_ATTR, ROUTE_CONTROL_TRUE);
117: }
118:
119: Element fin_coa_cd = new Element(CHART_CD_TAG);
120: fin_coa_cd.setAttribute(VALUE, this .chart_cd_value);
121:
122: root.addContent(fin_coa_cd);
123:
124: return root;
125: }
126:
127: //getters and setters
128: public String getChart_cd_value() {
129: return chart_cd_value;
130: }
131:
132: public boolean isRouteControl() {
133: return routeControl;
134: }
135:
136: public String toString() {
137: StringBuffer sb = new StringBuffer("[fin_coa_cd=");
138: sb.append(chart_cd_value);
139: sb.append("]");
140:
141: return sb.toString();
142: }
143: }
144:
145: /*
146: * Copyright 2003 The Trustees of Indiana University. All rights reserved.
147: *
148: * This file is part of the EDEN software package.
149: * For license information, see the LICENSE file in the top level directory
150: * of the EDEN source distribution.
151: */
|