KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > transformers > xml > AbstractXStreamTransformer


1 /*
2  * $Id: AbstractXStreamTransformer.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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 com.thoughtworks.xstream.XStream;
14 import org.mule.config.i18n.Message;
15 import org.mule.transformers.AbstractEventAwareTransformer;
16 import org.mule.umo.transformer.TransformerException;
17
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20
21 /**
22  * <code>AbstractXStreamTransformer</code> is a base class for all XStream based
23  * transformers. It takes care of creating and configuring the XStream parser.
24  */

25
26 public abstract class AbstractXStreamTransformer extends AbstractEventAwareTransformer
27 {
28     private String JavaDoc driverClassName = XStreamFactory.XSTREAM_XPP_DRIVER;
29     private XStream xstream;
30     private Map JavaDoc aliases;
31     private List JavaDoc converters;
32
33     public synchronized final XStream getXStream() throws TransformerException
34     {
35         if (xstream == null)
36         {
37             try
38             {
39                 xstream = new XStreamFactory(driverClassName, aliases, converters).getInstance();
40             }
41             catch (Exception JavaDoc e)
42             {
43                 throw new TransformerException(Message.createStaticMessage("Unable to initialize XStream"), e);
44             }
45         }
46
47         return xstream;
48     }
49
50     public synchronized String JavaDoc getDriverClassName()
51     {
52         return driverClassName;
53     }
54
55     public synchronized void setDriverClassName(String JavaDoc driverClassName)
56     {
57         this.driverClassName = driverClassName;
58     }
59
60     public synchronized Map JavaDoc getAliases()
61     {
62         return aliases;
63     }
64
65     public synchronized void setAliases(Map JavaDoc aliases)
66     {
67         this.aliases = aliases;
68     }
69
70     public synchronized List JavaDoc getConverters()
71     {
72         return converters;
73     }
74
75     public synchronized void setConverters(List JavaDoc converters)
76     {
77         this.converters = converters;
78     }
79
80     protected boolean requiresCurrentEvent()
81     {
82         return false;
83     }
84
85 }
86
Popular Tags