View Javadoc
1   /*
2    * Copyright 2012 Olivier Godineau
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at http://www.apache.org/licenses/LICENSE-2.0
7    * 
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11   * License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package olg.csv.bean.loader.parser.impl;
15  
16  import javax.xml.xpath.XPathExpressionException;
17  
18  import olg.csv.bean.loader.CustomLoader;
19  import olg.csv.bean.loader.LoadException;
20  import olg.csv.bean.loader.parser.AbstractParserLoader;
21  import olg.csv.bean.parser.AbstractParser;
22  
23  import org.w3c.dom.Element;
24  
25  /**
26   * Loader used to load user custom parser described in XML node. This node must
27   * to be conformed to CustomType as defined in our XML schema.
28   * 
29   * @see CustomLoader
30   * @see AbstractParser
31   */
32  public final class CustomParserLoader extends AbstractParserLoader {
33  	/**
34  	 * Constructor.
35  	 * 
36  	 * @param successor
37  	 *            the next parser loader in the loader chain.
38  	 */
39  	public CustomParserLoader(AbstractParserLoader successor) {
40  		super("custom", successor);
41  
42  	}
43  
44  	@SuppressWarnings("unchecked")
45  	@Override
46  	protected <T> AbstractParser<T> getConcreteParser(Class<T> clazz, Element node) throws XPathExpressionException,
47  			LoadException {
48  		Object object = CustomLoader.getBean(node);
49  		if (!(object instanceof AbstractParser)) {
50  			throw new LoadException(object.getClass() + " doit étendre la classe " + AbstractParser.class);
51  		}
52  		return (AbstractParser<T>) object;
53  	}
54  }