Coverage Report - org.kuali.rice.kew.xml.export.RuleAttributeXmlExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleAttributeXmlExporter
0%
0/28
0%
0/6
4
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.xml.export;
 18  
 
 19  
 import java.io.StringReader;
 20  
 import java.util.Iterator;
 21  
 
 22  
 import org.jdom.Document;
 23  
 import org.jdom.Element;
 24  
 import org.jdom.input.SAXBuilder;
 25  
 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
 26  
 import org.kuali.rice.kew.export.ExportDataSet;
 27  
 import org.kuali.rice.kew.rule.bo.RuleAttribute;
 28  
 import org.kuali.rice.kew.util.Utilities;
 29  
 import org.kuali.rice.kew.util.XmlHelper;
 30  
 import org.kuali.rice.kew.xml.XmlConstants;
 31  
 import org.kuali.rice.kew.xml.XmlRenderer;
 32  
 
 33  
 
 34  
 /**
 35  
  * Exports {@link RuleAttribute}s to XML.
 36  
  * 
 37  
  * @see RuleAttribute
 38  
  *
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  */
 41  0
 public class RuleAttributeXmlExporter implements XmlExporter, XmlConstants {
 42  
 
 43  0
     protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass());
 44  
     
 45  0
     private XmlRenderer renderer = new XmlRenderer(RULE_ATTRIBUTE_NAMESPACE);
 46  
     
 47  
     public Element export(ExportDataSet dataSet) {
 48  0
         if (!dataSet.getRuleAttributes().isEmpty()) {
 49  0
             Element rootElement = renderer.renderElement(null, RULE_ATTRIBUTES);
 50  0
             rootElement.setAttribute(SCHEMA_LOCATION_ATTR, RULE_ATTRIBUTE_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
 51  0
             for (Iterator iterator = dataSet.getRuleAttributes().iterator(); iterator.hasNext();) {
 52  0
                 RuleAttribute template = (RuleAttribute)iterator.next();
 53  0
                 exportRuleAttribute(rootElement, template);
 54  0
             }
 55  0
             return rootElement;
 56  
         }
 57  0
         return null;
 58  
     }
 59  
     
 60  
     private void exportRuleAttribute(Element parent, RuleAttribute ruleAttribute) {
 61  0
         Element attributeElement = renderer.renderElement(parent, RULE_ATTRIBUTE);
 62  0
         renderer.renderTextElement(attributeElement, NAME, ruleAttribute.getName());
 63  0
         renderer.renderTextElement(attributeElement, CLASS_NAME, ruleAttribute.getClassName());
 64  0
         renderer.renderTextElement(attributeElement, LABEL, ruleAttribute.getLabel());
 65  0
         renderer.renderTextElement(attributeElement, DESCRIPTION, ruleAttribute.getDescription());
 66  0
         renderer.renderTextElement(attributeElement, TYPE, ruleAttribute.getType());
 67  0
         renderer.renderTextElement(attributeElement, SERVICE_NAMESPACE, ruleAttribute.getServiceNamespace());
 68  0
         if (!Utilities.isEmpty(ruleAttribute.getXmlConfigData())) {
 69  
             try {
 70  0
                 Document configDoc = new SAXBuilder().build(new StringReader(ruleAttribute.getXmlConfigData()));
 71  0
                 XmlHelper.propogateNamespace(configDoc.getRootElement(), RULE_ATTRIBUTE_NAMESPACE);
 72  0
                 attributeElement.addContent(configDoc.getRootElement().detach());
 73  0
             } catch (Exception e) {
 74  0
                     LOG.error("Error parsing attribute XML configuration.", e);
 75  0
                 throw new WorkflowRuntimeException("Error parsing attribute XML configuration.");
 76  0
             }
 77  
         }
 78  0
     }
 79  
     
 80  
 }