%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.validator.FormSetFactory |
|
|
1 | /* |
|
2 | * $Id: FormSetFactory.java 366933 2006-01-07 22:51:01Z niallp $ |
|
3 | * $Rev: 366933 $ |
|
4 | * $Date: 2006-01-07 22:51:01 +0000 (Sat, 07 Jan 2006) $ |
|
5 | * |
|
6 | * ==================================================================== |
|
7 | * Copyright 2005-2006 The Apache Software Foundation |
|
8 | * |
|
9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
10 | * you may not use this file except in compliance with the License. |
|
11 | * You may obtain a copy of the License at |
|
12 | * |
|
13 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
14 | * |
|
15 | * Unless required by applicable law or agreed to in writing, software |
|
16 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 | * See the License for the specific language governing permissions and |
|
19 | * limitations under the License. |
|
20 | */ |
|
21 | package org.apache.commons.validator; |
|
22 | ||
23 | import org.xml.sax.Attributes; |
|
24 | import org.apache.commons.digester.AbstractObjectCreationFactory; |
|
25 | import org.apache.commons.logging.Log; |
|
26 | import org.apache.commons.logging.LogFactory; |
|
27 | ||
28 | /** |
|
29 | * Factory class used by Digester to create FormSet's. |
|
30 | * |
|
31 | * @since Validator 1.2 |
|
32 | */ |
|
33 | 207 | public class FormSetFactory extends AbstractObjectCreationFactory { |
34 | ||
35 | /** Logging */ |
|
36 | 94 | private transient Log log = LogFactory.getLog(FormSetFactory.class); |
37 | ||
38 | /** |
|
39 | * <p>Create or retrieve a <code>FormSet</code> for the specified |
|
40 | * attributes.</p> |
|
41 | * |
|
42 | * @param attributes The sax attributes for the formset element. |
|
43 | * @return The FormSet for a locale. |
|
44 | * @throws Exception If an error occurs creating the FormSet. |
|
45 | */ |
|
46 | public Object createObject(Attributes attributes) throws Exception { |
|
47 | ||
48 | 144 | ValidatorResources resources = (ValidatorResources)digester.peek(0); |
49 | ||
50 | 144 | String language = attributes.getValue("language"); |
51 | 144 | String country = attributes.getValue("country"); |
52 | 144 | String variant = attributes.getValue("variant"); |
53 | ||
54 | 144 | return createFormSet(resources, language, country, variant); |
55 | ||
56 | } |
|
57 | ||
58 | /** |
|
59 | * <p>Create or retrieve a <code>FormSet</code> based on the language, country |
|
60 | * and variant.</p> |
|
61 | * |
|
62 | * @param resources The validator resources. |
|
63 | * @param language The locale's language. |
|
64 | * @param country The locale's country. |
|
65 | * @param variant The locale's language variant. |
|
66 | * @return The FormSet for a locale. |
|
67 | * @since Validator 1.2 |
|
68 | */ |
|
69 | private FormSet createFormSet(ValidatorResources resources, |
|
70 | String language, |
|
71 | String country, |
|
72 | String variant) throws Exception { |
|
73 | ||
74 | // Retrieve existing FormSet for the language/country/variant |
|
75 | 144 | FormSet formSet = resources.getFormSet(language, country, variant); |
76 | 144 | if (formSet != null) { |
77 | 10 | if (getLog().isDebugEnabled()) { |
78 | 0 | getLog().debug("FormSet[" + formSet.displayKey() + "] found - merging."); |
79 | } |
|
80 | 10 | return formSet; |
81 | } |
|
82 | ||
83 | // Create a new FormSet for the language/country/variant |
|
84 | 134 | formSet = new FormSet(); |
85 | 134 | formSet.setLanguage(language); |
86 | 134 | formSet.setCountry(country); |
87 | 134 | formSet.setVariant(variant); |
88 | ||
89 | // Add the FormSet to the validator resources |
|
90 | 134 | resources.addFormSet(formSet); |
91 | ||
92 | 134 | if (getLog().isDebugEnabled()) { |
93 | 0 | getLog().debug("FormSet[" + formSet.displayKey() + "] created."); |
94 | } |
|
95 | ||
96 | 134 | return formSet; |
97 | ||
98 | } |
|
99 | ||
100 | /** |
|
101 | * Accessor method for Log instance. |
|
102 | * |
|
103 | * The Log instance variable is transient and |
|
104 | * accessing it through this method ensures it |
|
105 | * is re-initialized when this instance is |
|
106 | * de-serialized. |
|
107 | * |
|
108 | * @return The Log instance. |
|
109 | */ |
|
110 | private Log getLog() { |
|
111 | 144 | if (log == null) { |
112 | 0 | log = LogFactory.getLog(FormSetFactory.class); |
113 | } |
|
114 | 144 | return log; |
115 | } |
|
116 | ||
117 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |