Coverage Report - org.mule.transformers.xml.AbstractXStreamTransformer
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractXStreamTransformer
88%
30/34
62%
5/8
1.667
 
 1  
 /*
 2  
  * $Id: AbstractXStreamTransformer.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transformers.xml;
 12  
 
 13  
 import org.mule.config.i18n.MessageFactory;
 14  
 import org.mule.transformers.AbstractEventAwareTransformer;
 15  
 import org.mule.umo.transformer.TransformerException;
 16  
 
 17  
 import com.thoughtworks.xstream.XStream;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.HashMap;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 
 24  
 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicReference;
 25  
 
 26  
 /**
 27  
  * <code>AbstractXStreamTransformer</code> is a base class for all XStream based
 28  
  * transformers. It takes care of creating and configuring the XStream parser.
 29  
  */
 30  
 
 31  58
 public abstract class AbstractXStreamTransformer extends AbstractEventAwareTransformer
 32  
 {
 33  58
     private final AtomicReference/* XStream */xstream = new AtomicReference();
 34  58
     private volatile String driverClassName = XStreamFactory.XSTREAM_XPP_DRIVER;
 35  58
     private volatile Map aliases = null;
 36  58
     private volatile List converters = null;
 37  
 
 38  
     public final XStream getXStream() throws TransformerException
 39  
     {
 40  38
         XStream instance = (XStream) xstream.get();
 41  
 
 42  38
         if (instance == null)
 43  
         {
 44  
             try
 45  
             {
 46  36
                 instance = new XStreamFactory(driverClassName, aliases, converters).getInstance();
 47  34
                 if (!xstream.compareAndSet(null, instance))
 48  
                 {
 49  0
                     instance = (XStream)xstream.get();
 50  
                 }
 51  
             }
 52  2
             catch (Exception e)
 53  
             {
 54  2
                 throw new TransformerException(MessageFactory.createStaticMessage("Unable to initialize XStream"), e);
 55  34
             }
 56  
         }
 57  
 
 58  36
         return instance;
 59  
     }
 60  
 
 61  
     public Object clone() throws CloneNotSupportedException
 62  
     {
 63  6
         AbstractXStreamTransformer clone = (AbstractXStreamTransformer) super.clone();
 64  6
         clone.setDriverClassName(driverClassName);
 65  
 
 66  6
         if (aliases != null)
 67  
         {
 68  0
             clone.setAliases(new HashMap(aliases));
 69  
         }
 70  
         
 71  6
         if (converters != null)
 72  
         {
 73  0
             clone.setConverters(new ArrayList(converters));
 74  
         }
 75  
 
 76  6
         return clone;
 77  
     }
 78  
 
 79  
     public String getDriverClassName()
 80  
     {
 81  12
         return driverClassName;
 82  
     }
 83  
 
 84  
     public void setDriverClassName(String driverClassName)
 85  
     {
 86  16
         this.driverClassName = driverClassName;
 87  
         // force XStream instance update
 88  16
         this.xstream.set(null);
 89  16
     }
 90  
 
 91  
     public Map getAliases()
 92  
     {
 93  12
         return aliases;
 94  
     }
 95  
 
 96  
     public void setAliases(Map aliases)
 97  
     {
 98  6
         this.aliases = aliases;
 99  
         // force XStream instance update
 100  6
         this.xstream.set(null);
 101  6
     }
 102  
 
 103  
     public List getConverters()
 104  
     {
 105  12
         return converters;
 106  
     }
 107  
 
 108  
     public void setConverters(List converters)
 109  
     {
 110  6
         this.converters = converters;
 111  
         // force XStream instance update
 112  6
         this.xstream.set(null);
 113  6
     }
 114  
 
 115  
     protected boolean requiresCurrentEvent()
 116  
     {
 117  0
         return false;
 118  
     }
 119  
 
 120  
 }