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.factory;
18  
19  import org.jdom.Element;
20  
21  import ch.elca.el4j.services.xmlmerge.AbstractXmlMergeException;
22  import ch.elca.el4j.services.xmlmerge.Operation;
23  import ch.elca.el4j.services.xmlmerge.OperationFactory;
24  
25  /**
26   * An operation factory delegating to other operation factories according to the
27   * existence of the original and patch element.
28   *
29   * @svnLink $Revision: 3874 $;$Date: 2009-08-04 14:25:40 +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/factory/DiffOperationFactory.java $
30   *
31   * @author Laurent Bovet (LBO)
32   * @author Alex Mathey (AMA)
33   */
34  public class DiffOperationFactory implements OperationFactory {
35  
36  	/**
37  	 * OperationFactory this factory delegates to if only the original element
38  	 * exists.
39  	 */
40  	OperationFactory m_onlyInOriginalOperationFactory;
41  
42  	/**
43  	 * OperationFactory this factory delegates to if only the patch element
44  	 * exists.
45  	 */
46  	OperationFactory m_onlyInPatchOperationFactory;
47  
48  	/**
49  	 * OperationFactory this factory delegates to if the original and patch
50  	 * elements exist.
51  	 */
52  	OperationFactory m_inBothOperationFactory;
53  
54  	/**
55  	 * Sets the operation factory this factory delegates to if the original and
56  	 * patch elements exist.
57  	 *
58  	 * @param inBothOperationFactory
59  	 *            the operation factory this factory delegates to if the
60  	 *            original and patch elements exist.
61  	 */
62  	public void setInBothOperationFactory(
63  		OperationFactory inBothOperationFactory) {
64  		this.m_inBothOperationFactory = inBothOperationFactory;
65  	}
66  
67  	/**
68  	 * Sets the operation factory this factory delegates to if only the original
69  	 * element exists.
70  	 *
71  	 * @param onlyInOriginalOperationFactory
72  	 *            factory this factory delegates to if only the original element
73  	 *            exists
74  	 */
75  	public void setOnlyInOriginalOperationFactory(
76  		OperationFactory onlyInOriginalOperationFactory) {
77  		this.m_onlyInOriginalOperationFactory = onlyInOriginalOperationFactory;
78  	}
79  
80  	/**
81  	 * Sets the operation factory this factory delegates to if only the patch
82  	 * element exists.
83  	 *
84  	 * @param onlyInPatchOperationFactory
85  	 *            factory this factory delegates to if only the patch element
86  	 *            exists
87  	 */
88  	public void setOnlyInPatchOperationFactory(
89  		OperationFactory onlyInPatchOperationFactory) {
90  		this.m_onlyInPatchOperationFactory = onlyInPatchOperationFactory;
91  	}
92  
93  	/**
94  	 * {@inheritDoc}
95  	 */
96  	public Operation getOperation(Element originalElement, Element patchElement)
97  		throws AbstractXmlMergeException {
98  
99  		if (originalElement != null && patchElement == null) {
100 			return m_onlyInOriginalOperationFactory.getOperation(
101 				originalElement, null);
102 		}
103 
104 		if (originalElement == null && patchElement != null) {
105 			return m_onlyInPatchOperationFactory.getOperation(null,
106 				patchElement);
107 		}
108 
109 		if (originalElement != null && patchElement != null) {
110 			return m_inBothOperationFactory.getOperation(originalElement,
111 				patchElement);
112 		}
113 
114 		throw new IllegalArgumentException();
115 	}
116 
117 }