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 java.util.Locale;
17
18 import olg.csv.bean.loader.LoadException;
19 import olg.csv.bean.loader.Util;
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 * Characteristic loader of Date parser described in XML node. This node must to
27 * be conformed to DateParserType as defined in our XML schema.
28 *
29 * @see AbstractParser#getDateParser(String, Class, Locale)
30 * @see AbstractParser
31 *
32 */
33 public final class DateParserLoader extends AbstractParserLoader {
34 /**
35 * Constructor.
36 *
37 * @param successor
38 * the next parser loader in the loader chain.
39 */
40 public DateParserLoader(AbstractParserLoader successor) {
41 super("date", successor);
42
43 }
44
45 @SuppressWarnings({"unchecked", "rawtypes"})
46 @Override
47 protected AbstractParser getConcreteParser(Class clazz, Element node) throws LoadException {
48 String loc = node.getAttribute("locale");
49 Locale locale = Util.getLocale(loc);
50
51 if (!"".equals(loc) && locale == null) {
52 throw new LoadException("Locale based on expression[" + loc + "] is not available ");
53 }
54 return AbstractParser.getDateParser(node.getAttribute("format"), clazz, locale);
55 }
56
57 }