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:
021: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
022: import edu.iu.uis.eden.exception.InvalidXmlException;
023: import edu.iu.uis.eden.services.InconsistentDocElementStateException;
024: import edu.iu.uis.eden.services.ServiceErrorConstants;
025:
026: /**
027: * <p>Title: ChartElement</p>
028: * <p>Description: Represents a chart element both in xml for documents and as a
029: * chart entity itself concerning validation. <br><BR>
030: * See IDocElement documentation for
031: * further explanation.</p>
032: * <p>Copyright: Copyright (c) 2002</p>
033: * <p>Company: Indiana University</p>
034: * @author Ryan Kirkendall
035: * @version 1.0
036: */
037: public class ChartElement implements IDocElement {
038: /**
039: *
040: */
041: private static final long serialVersionUID = -8383050303425266683L;
042: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
043: .getLogger(ChartElement.class);
044: private boolean routeControl;
045: private String chart;
046:
047: public ChartElement() {
048: LOG.debug("constructing . . .");
049: this .routeControl = true;
050: }
051:
052: public Element getXMLContent() {
053: LOG.debug("getXmlContent");
054:
055: if (this .isEmpty()) {
056: LOG.debug("chart null or empty returning empty String");
057:
058: return null;
059: }
060:
061: ChartCodeEOK chartEOK = null;
062:
063: try {
064: chartEOK = new ChartCodeEOK(chart, routeControl);
065: } catch (Exception ex) {
066: LOG.error(
067: "EOK threw exception loading chart values. ChartElement "
068: + "improperly tested.", ex);
069: //this should never happen if the class was properly unit tested
070: }
071:
072: return chartEOK.buildJdom();
073: }
074:
075: public void loadFromXMLContent(Element element, boolean allowBlank)
076: throws InvalidXmlException,
077: InconsistentDocElementStateException {
078: LOG.debug("loadFromXMLContent allowBlank = " + allowBlank);
079:
080: if (DocElementValidator.returnWithNoWorkDone(this , element,
081: allowBlank)) {
082: return;
083: }
084:
085: ChartCodeEOK chartEOK = null;
086:
087: try {
088: chartEOK = new ChartCodeEOK(element);
089: this .chart = chartEOK.getChart_cd_value();
090: this .routeControl = chartEOK.routeControl;
091: } catch (Exception ex) {
092: LOG.error("Document with invalid XML given ChartElement",
093: ex);
094: throw new InvalidXmlException(ex.getMessage());
095: }
096: }
097:
098: public WorkflowServiceErrorImpl validate() {
099: LOG.debug("validate");
100:
101: if (this .isEmpty()) {
102: LOG.debug("invalid");
103:
104: return new WorkflowServiceErrorImpl(
105: "Chart is null or blank",
106: ServiceErrorConstants.CHART_BLANK);
107: }
108:
109: LOG.debug("valid returning null");
110:
111: return null;
112: }
113:
114: /**
115: * Tell whether the objects value property/properties have values
116: *
117: * @return true when object is empty
118: */
119: public boolean isEmpty() {
120: LOG.debug("isEmpty()");
121:
122: if ((this .chart == null) || this .chart.trim().equals("")) {
123: LOG.debug("empty");
124:
125: return true;
126: }
127:
128: LOG.debug("not empty");
129:
130: return false;
131: }
132:
133: public String getElementName() {
134: LOG.debug("getElementName");
135:
136: return ChartCodeEOK.CHART_CODE_EOK;
137: }
138:
139: public void setRouteControl(boolean routeControl) {
140: LOG.debug("setRouteControl routeControl = " + routeControl);
141: this .routeControl = routeControl;
142: }
143:
144: public boolean isRouteControl() {
145: LOG.debug("isRouteControl = " + this .routeControl);
146:
147: return this .routeControl;
148: }
149:
150: /**
151: *
152: * @return String value of chart
153: */
154: public String getChart() {
155: LOG.debug("getChart = " + this .chart);
156:
157: return this .chart;
158: }
159:
160: /**
161: *
162: * @param chart String value of chart
163: */
164: public void setChart(String chart) {
165: LOG.debug("setChart chart = " + chart);
166: this .chart = chart;
167: }
168: }
169:
170: /*
171: * Copyright 2003 The Trustees of Indiana University. All rights reserved.
172: *
173: * This file is part of the EDEN software package.
174: * For license information, see the LICENSE file in the top level directory
175: * of the EDEN source distribution.
176: */
|