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 ch.elca.el4j.services.xmlmerge.ConfigurationException;
20  import ch.elca.el4j.services.xmlmerge.Configurer;
21  import ch.elca.el4j.services.xmlmerge.Mapper;
22  import ch.elca.el4j.services.xmlmerge.Matcher;
23  import ch.elca.el4j.services.xmlmerge.MergeAction;
24  import ch.elca.el4j.services.xmlmerge.XmlMerge;
25  import ch.elca.el4j.services.xmlmerge.action.OrderedMergeAction;
26  import ch.elca.el4j.services.xmlmerge.action.StandardActions;
27  import ch.elca.el4j.services.xmlmerge.factory.AttributeOperationFactory;
28  import ch.elca.el4j.services.xmlmerge.factory.OperationResolver;
29  import ch.elca.el4j.services.xmlmerge.factory.StaticOperationFactory;
30  import ch.elca.el4j.services.xmlmerge.mapper.NamespaceFilterMapper;
31  import ch.elca.el4j.services.xmlmerge.matcher.StandardMatchers;
32  import ch.elca.el4j.services.xmlmerge.matcher.TagMatcher;
33  
34  /**
35   * Configure to apply actions declared as attributes in the patch DOM.
36   *
37   * @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/AttributeMergeConfigurer.java $
38   *
39   * @author Laurent Bovet (LBO)
40   * @author Alex Mathey (AMA)
41   */
42  public class AttributeMergeConfigurer implements Configurer {
43  
44  	/**
45  	 * Attribute namespace.
46  	 */
47  	public static final String ATTRIBUTE_NAMESPACE
48  		= "http://xmlmerge.el4j.elca.ch";
49  	
50  	/**
51  	 * Action attribute.
52  	 */
53  	public static final String ACTION_ATTRIBUTE = "action";
54  
55  	/**
56  	 * Matcher attribute.
57  	 */
58  	public static final String MATCHER_ATTRIBUTE = "matcher";
59  	
60  	/**
61  	 * {@inheritDoc}
62  	 */
63  	public void configure(XmlMerge xmlMerge) throws ConfigurationException {
64  
65  		MergeAction defaultMergeAction = new OrderedMergeAction();
66  
67  		Mapper mapper = new NamespaceFilterMapper(ATTRIBUTE_NAMESPACE);
68  
69  		defaultMergeAction.setMapperFactory(new StaticOperationFactory(mapper));
70  
71  		// Configure the action factory
72  		OperationResolver actionResolver = new OperationResolver(
73  			StandardActions.class);
74  
75  		defaultMergeAction.setActionFactory(new AttributeOperationFactory(
76  			defaultMergeAction, actionResolver, ACTION_ATTRIBUTE,
77  			ATTRIBUTE_NAMESPACE));
78  
79  		// Configure the matcher factory
80  		Matcher defaultMatcher = new TagMatcher();
81  
82  		OperationResolver matcherResolver = new OperationResolver(
83  			StandardMatchers.class);
84  
85  		defaultMergeAction.setMatcherFactory(new AttributeOperationFactory(
86  			defaultMatcher, matcherResolver, MATCHER_ATTRIBUTE,
87  			ATTRIBUTE_NAMESPACE));
88  
89  		xmlMerge.setRootMapper(mapper);
90  		xmlMerge.setRootMergeAction(defaultMergeAction);
91  	}
92  
93  }