KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > script > xml > XStreamComponentInstanceFactory


1 /*****************************************************************************
2  * Copyright (C) NanoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  *****************************************************************************/

9 package org.nanocontainer.script.xml;
10
11 import org.picocontainer.PicoContainer;
12 import org.w3c.dom.Element JavaDoc;
13
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.io.xml.DomDriver;
16 import com.thoughtworks.xstream.io.xml.DomReader;
17
18 /**
19  * Implementation of XMLComponentInstanceFactory that uses
20  * XStream to unmarshal DOM elements.
21  *
22  * @author Paul Hammant
23  * @author Marcos Tarruella
24  * @author Mauro Talevi
25  */

26 public class XStreamComponentInstanceFactory implements XMLComponentInstanceFactory {
27     /** The XStream used to unmarshal the DOM element */
28     private XStream xstream;
29
30     /**
31      * Creates an XStreamComponentInstanceFactory with the default instance
32      * of XStream
33      */

34     public XStreamComponentInstanceFactory(){
35         this(new XStream(new DomDriver()));
36     }
37     
38     /**
39      * Creates an XStreamComponentInstanceFactory for a given instance
40      * of XStream
41      * @param xstream the XStream instance
42      */

43     public XStreamComponentInstanceFactory(XStream xstream){
44         this.xstream = xstream;
45     }
46     
47     /**
48      * {@inheritDoc}
49      *
50      * @see XMLComponentInstanceFactory#makeInstance(org.picocontainer.PicoContainer,org.w3c.dom.Element,ClassLoader)
51      */

52     public Object JavaDoc makeInstance(PicoContainer pico, Element JavaDoc element, ClassLoader JavaDoc classLoader) throws ClassNotFoundException JavaDoc {
53         return xstream.unmarshal(new DomReader(element));
54     }
55 }
56
Popular Tags