This project has retired. For details please refer to its Attic page.
UnresolvingLocaleDefinitionsFactory xref
View Javadoc

1   /*
2    * $Id: UnresolvingLocaleDefinitionsFactory.java 822631 2009-10-07 09:21:12Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.tiles.definition;
23  
24  import java.util.Locale;
25  import java.util.Map;
26  
27  import org.apache.tiles.Definition;
28  import org.apache.tiles.TilesApplicationContext;
29  import org.apache.tiles.awareness.TilesApplicationContextAware;
30  import org.apache.tiles.context.TilesRequestContext;
31  import org.apache.tiles.definition.dao.DefinitionDAO;
32  import org.apache.tiles.locale.LocaleResolver;
33  
34  /***
35   * {@link DefinitionsFactory DefinitionsFactory} implementation that manages
36   * Definitions configuration data from URLs, without resolving definition
37   * inheritance when a definition is returned.<p/>
38   * <p>
39   * The Definition objects are read from the
40   * {@link org.apache.tiles.definition.digester.DigesterDefinitionsReader DigesterDefinitionsReader}
41   * class unless another implementation is specified.
42   * </p>
43   *
44   * @version $Rev: 822631 $ $Date: 2009-10-07 11:21:12 +0200 (mer, 07 ott 2009) $
45   * @since 2.2.1
46   */
47  public class UnresolvingLocaleDefinitionsFactory implements DefinitionsFactory,
48          TilesApplicationContextAware {
49  
50      /***
51       * The definition DAO that extracts the definitions from the sources.
52       *
53       * @since 2.2.1
54       */
55      protected DefinitionDAO<Locale> definitionDao;
56  
57      /***
58       * The application context.
59       *
60       * @since 2.2.1
61       */
62      protected TilesApplicationContext applicationContext;
63  
64      /***
65       * The locale resolver object.
66       *
67       * @since 2.2.1
68       */
69      protected LocaleResolver localeResolver;
70  
71      /*** {@inheritDoc} */
72      public void setApplicationContext(TilesApplicationContext applicationContext) {
73          this.applicationContext = applicationContext;
74      }
75  
76      /***
77       * Sets the locale resolver to use.
78       *
79       * @param localeResolver The locale resolver.
80       * @since 2.2.1
81       */
82      public void setLocaleResolver(LocaleResolver localeResolver) {
83          this.localeResolver = localeResolver;
84      }
85  
86      /***
87       * Sets the definition DAO to use. It must be locale-based.
88       *
89       * @param definitionDao The definition DAO.
90       * @since 2.2.1
91       */
92      public void setDefinitionDAO(DefinitionDAO<Locale> definitionDao) {
93          this.definitionDao = definitionDao;
94      }
95  
96      /*** {@inheritDoc} */
97      public Definition getDefinition(String name,
98              TilesRequestContext tilesContext) {
99          Locale locale = null;
100 
101         if (tilesContext != null) {
102             locale = localeResolver.resolveLocale(tilesContext);
103         }
104 
105         return definitionDao.getDefinition(name, locale);
106     }
107 
108     /*** {@inheritDoc} */
109     @Deprecated
110     public void addSource(Object source) {
111         throw new UnsupportedOperationException(
112                 "The addSource method is not supported");
113     }
114 
115     /*** {@inheritDoc} */
116     @Deprecated
117     public Definitions readDefinitions() {
118         throw new UnsupportedOperationException(
119                 "The readDefinitions method is not supported");
120     }
121 
122     /*** {@inheritDoc} */
123     @Deprecated
124     public void init(Map<String, String> params) {
125         // It's here only for binary compatibility reasons.
126     }
127 }