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.getter.impl;
15  
16  import javax.xml.xpath.XPathExpressionException;
17  
18  import olg.csv.bean.getter.AbstractGetter;
19  import olg.csv.bean.loader.CustomLoader;
20  import olg.csv.bean.loader.LoadException;
21  import olg.csv.bean.loader.getter.AbstractGetterLoader;
22  
23  import org.w3c.dom.Element;
24  
25  /**
26   * The loader used to load a user getter described in XML node. This node must
27   * to be conformed to CustomType as defined in our XML schema.
28   * 
29   * @see CustomLoader
30   * 
31   */
32  public final class CustomGetterLoader extends AbstractGetterLoader {
33  
34  	/**
35  	 * Constructs a loader bound with the custom node.
36  	 * 
37  	 * @param successor
38  	 *            the next getter loader in the loader chain.
39  	 */
40  	public CustomGetterLoader(AbstractGetterLoader successor) {
41  		super("custom", successor);
42  
43  	}
44  
45  	@Override
46  	protected AbstractGetter getConcreteGetter(Element node, String defaultValue) throws XPathExpressionException,
47  			LoadException {
48  		Object object = CustomLoader.getBean(node);
49  		if (!(object instanceof AbstractGetter)) {
50  			throw new LoadException(object.getClass() + " must extend " + AbstractGetter.class);
51  		}
52  		AbstractGetter getter = (AbstractGetter) object;
53  		getter.setDefaultValue(defaultValue);
54  		return getter;
55  	}
56  
57  }