View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2006 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.services.xmlmerge.config;
18  
19  import java.io.InputStream;
20  
21  import org.w3c.dom.Document;
22  
23  import ch.elca.el4j.services.xmlmerge.AbstractXmlMergeException;
24  import ch.elca.el4j.services.xmlmerge.ConfigurationException;
25  import ch.elca.el4j.services.xmlmerge.Configurer;
26  import ch.elca.el4j.services.xmlmerge.Mapper;
27  import ch.elca.el4j.services.xmlmerge.MergeAction;
28  import ch.elca.el4j.services.xmlmerge.XmlMerge;
29  import ch.elca.el4j.services.xmlmerge.merge.DefaultXmlMerge;
30  
31  /**
32   * XmlMerge wrapper applying a configurer on the wrapped instance.
33   *
34   * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/xml_merge/common/src/main/java/ch/elca/el4j/services/xmlmerge/config/ConfigurableXmlMerge.java $
35   *
36   * @author Laurent Bovet (LBO)
37   * @author Alex Mathey (AMA)
38   */
39  public class ConfigurableXmlMerge implements XmlMerge {
40  
41  	/**
42  	 * Wrapped XmlMerge instance.
43  	 */
44  	XmlMerge m_wrappedXmlMerge;
45  	
46  	/**
47  	 * Creates a default XmlMerge instance and configures it with the given
48  	 * configurer.
49  	 *
50  	 * @param configurer
51  	 *            The configurer used to configure the XmlMerge instance
52  	 * @throws ConfigurationException
53  	 *             If an error occurred during configuration
54  	 */
55  	public ConfigurableXmlMerge(Configurer configurer)
56  		throws ConfigurationException {
57  		this(new DefaultXmlMerge(), configurer);
58  	}
59  	
60  	/**
61  	 * Applies a configurer on a wrapped XmlMerge instance.
62  	 *
63  	 * @param wrappedXmlMerge
64  	 *            The wrapped XmlMerge instance to configure
65  	 * @param configurer
66  	 *            The configurer to apply
67  	 * @throws ConfigurationException
68  	 *             If an error occurred during configuration
69  	 */
70  	public ConfigurableXmlMerge(XmlMerge wrappedXmlMerge, Configurer configurer)
71  		throws ConfigurationException {
72  		this.m_wrappedXmlMerge = wrappedXmlMerge;
73  		configurer.configure(wrappedXmlMerge);
74  	}
75  
76  	/**
77  	 * {@inheritDoc}
78  	 */
79  	public InputStream merge(InputStream[] sources) throws AbstractXmlMergeException {
80  		return m_wrappedXmlMerge.merge(sources);
81  	}
82  	
83  	/**
84  	 * {@inheritDoc}
85  	 */
86  	public Document merge(Document[] sources) throws AbstractXmlMergeException {
87  		return m_wrappedXmlMerge.merge(sources);
88  	}
89  
90  	/**
91  	 * {@inheritDoc}
92  	 */
93  	public String merge(String[] sources) throws AbstractXmlMergeException {
94  		return m_wrappedXmlMerge.merge(sources);
95  	}
96  
97  	/**
98  	 * {@inheritDoc}
99  	 */
100 	public void setRootMapper(Mapper rootMapper) {
101 		m_wrappedXmlMerge.setRootMapper(rootMapper);
102 	}
103 
104 	/**
105 	 * {@inheritDoc}
106 	 */
107 	public void setRootMergeAction(MergeAction rootMergeAction) {
108 		m_wrappedXmlMerge.setRootMergeAction(rootMergeAction);
109 	}
110 	
111 }