001: /*
002: * Copyright 2005-2006 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 edu.iu.uis.eden.xml.export;
018:
019: import java.io.StringReader;
020: import java.util.Iterator;
021:
022: import org.jdom.Document;
023: import org.jdom.Element;
024: import org.jdom.input.SAXBuilder;
025:
026: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
027: import edu.iu.uis.eden.export.ExportDataSet;
028: import edu.iu.uis.eden.routetemplate.RuleAttribute;
029: import edu.iu.uis.eden.util.Utilities;
030: import edu.iu.uis.eden.util.XmlHelper;
031: import edu.iu.uis.eden.xml.XmlConstants;
032:
033: /**
034: * Exports {@link RuleAttribute}s to XML.
035: *
036: * @see RuleAttribute
037: *
038: * @author ewestfal
039: */
040: public class RuleAttributeXmlExporter implements XmlExporter,
041: XmlConstants {
042:
043: protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
044: .getLogger(getClass());
045:
046: private ExportRenderer renderer = new ExportRenderer(
047: RULE_ATTRIBUTE_NAMESPACE);
048:
049: public Element export(ExportDataSet dataSet) {
050: if (!dataSet.getRuleAttributes().isEmpty()) {
051: Element rootElement = renderer.renderElement(null,
052: RULE_ATTRIBUTES);
053: rootElement.setAttribute(SCHEMA_LOCATION_ATTR,
054: RULE_ATTRIBUTE_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
055: for (Iterator iterator = dataSet.getRuleAttributes()
056: .iterator(); iterator.hasNext();) {
057: RuleAttribute template = (RuleAttribute) iterator
058: .next();
059: exportRuleAttribute(rootElement, template);
060: }
061: return rootElement;
062: }
063: return null;
064: }
065:
066: private void exportRuleAttribute(Element parent,
067: RuleAttribute ruleAttribute) {
068: Element attributeElement = renderer.renderElement(parent,
069: RULE_ATTRIBUTE);
070: renderer.renderTextElement(attributeElement, NAME,
071: ruleAttribute.getName());
072: renderer.renderTextElement(attributeElement, CLASS_NAME,
073: ruleAttribute.getClassName());
074: renderer.renderTextElement(attributeElement, LABEL,
075: ruleAttribute.getLabel());
076: renderer.renderTextElement(attributeElement, DESCRIPTION,
077: ruleAttribute.getDescription());
078: renderer.renderTextElement(attributeElement, TYPE,
079: ruleAttribute.getType());
080: renderer.renderTextElement(attributeElement, MESSAGE_ENTITY,
081: ruleAttribute.getMessageEntity());
082: if (!Utilities.isEmpty(ruleAttribute.getXmlConfigData())) {
083: try {
084: Document configDoc = new SAXBuilder()
085: .build(new StringReader(ruleAttribute
086: .getXmlConfigData()));
087: XmlHelper.propogateNamespace(
088: configDoc.getRootElement(),
089: RULE_ATTRIBUTE_NAMESPACE);
090: attributeElement.addContent(configDoc.getRootElement()
091: .detach());
092: } catch (Exception e) {
093: LOG.error("Error parsing attribute XML configuration.",
094: e);
095: throw new WorkflowRuntimeException(
096: "Error parsing attribute XML configuration.");
097: }
098: }
099: }
100:
101: }
|