Coverage Report - org.kuali.rice.kew.batch.XmlDigesterServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlDigesterServiceImpl
0%
0/30
0%
0/10
5.5
 
 1  
 /*
 2  
  * Copyright 2005-2007 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.batch;
 18  
 
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.kew.util.Utilities;
 21  
 import org.kuali.rice.kew.xml.XmlLoader;
 22  
 
 23  
 import java.io.BufferedInputStream;
 24  
 import java.io.IOException;
 25  
 import java.io.InputStream;
 26  
 
 27  
 
 28  
 /**
 29  
  * XmlDigesterService implementation.  This class simply loads the specified xml doc
 30  
  * with the specified XmlLoader.
 31  
  * @see org.kuali.rice.kew.batch.XmlDigesterService
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  0
 public class XmlDigesterServiceImpl implements XmlDigesterService {
 35  0
     private static final Logger LOG = Logger.getLogger(XmlDigesterServiceImpl.class);
 36  
 
 37  
     private static void addProcessingException(XmlDoc xmlDoc, String message, Throwable t) {
 38  0
         String msg = xmlDoc.getProcessingMessage();
 39  0
         if (msg == null) {
 40  0
             msg = "";
 41  
         }
 42  0
         msg += message + "\n" + Utilities.collectStackTrace(t);
 43  0
         xmlDoc.setProcessingMessage(msg);
 44  0
     }
 45  
 
 46  
     public void digest(XmlLoader xmlLoader, XmlDocCollection xmlDocCollection, String principalId) throws IOException {
 47  0
         for (XmlDoc xmlDoc : xmlDocCollection.getXmlDocs())
 48  
         {
 49  0
             InputStream inputStream = null;
 50  
             try
 51  
             {
 52  0
                 inputStream = new BufferedInputStream(xmlDoc.getStream());
 53  
                 // NOTE: do we need XmlLoader to return a boolean to indicate
 54  
                 // whether the document was handled at all, now that we are handing
 55  
                 // all docs to all services?
 56  
                 // e.g. if (xmlLoader.loadXml(inputstream)) xmlDoc.setProcessed(true);
 57  
                 // it's ok if the xml doc is processed multiple times however
 58  
                 // because it could have multiple types of content
 59  
                 // but we need to know if it was not processed ANY times
 60  
                 // (so just don't setProcessed to false)
 61  0
                 xmlLoader.loadXml(inputStream, principalId);
 62  
                 // it would be nice to know if the xmlLoader actually handled the doc
 63  
                 // so we could print out a log entry ONLY if the doc was handled, not
 64  
                 // if it was just (successfully) ignored
 65  
 
 66  
                 // should only be set on successful loading
 67  0
                 xmlDoc.setProcessed(true);
 68  0
             } catch (Exception e)
 69  
             {
 70  0
                 xmlDoc.setProcessed(false);
 71  0
                 addProcessingException(xmlDoc, "Caught Exception loading xml data from " + xmlDoc + ".  Will move associated file to problem dir.", e);
 72  0
                 LOG.error("Caught Exception loading xml data from " + xmlDoc + ".  Will move associated file to problem dir.", e);
 73  0
                 if (e instanceof RuntimeException)
 74  
                 {
 75  0
                     throw (RuntimeException) e;
 76  0
                 } else if (e instanceof IOException)
 77  
                 {
 78  0
                     throw (IOException) e;
 79  
                 }
 80  0
             } finally
 81  
             {
 82  0
                 if (inputStream != null) try
 83  
                 {
 84  0
                     inputStream.close();
 85  0
                 } catch (IOException ioe)
 86  
                 {
 87  0
                     LOG.warn("Error closing stream for xml doc: " + xmlDoc, ioe);
 88  0
                 }
 89  0
             }
 90  0
         }
 91  0
     }
 92  
 }