View Javadoc

1   /*
2    * $Id: DefinitionsFactoryUtil.java 527536 2007-04-11 15:44:51Z 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.util;
23  
24  import org.apache.tiles.TilesContainer;
25  import org.apache.tiles.access.TilesAccess;
26  import org.apache.tiles.definition.DefinitionsFactory;
27  import org.apache.tiles.definition.DefinitionsFactoryException;
28  import org.apache.tiles.definition.ReloadableDefinitionsFactory;
29  import org.apache.tiles.impl.BasicTilesContainer;
30  
31  /***
32   * Various {@link DefinitionsFactory} utilities.
33   *
34   * @version $Rev: 527536 $ $Date: 2007-04-11 17:44:51 +0200 (Wed, 11 Apr 2007) $
35   */
36  public final class DefinitionsFactoryUtil {
37  
38      /***
39       * Private constructor to avoid instatiation.
40       */
41      private DefinitionsFactoryUtil() {
42      }
43  
44      /***
45       * Reloads the definitions factory content, if necessary.
46       *
47       * @param context The context object to use
48       * @throws DefinitionsFactoryException If something goes wrong during
49       * reload.
50       */
51      public static void reloadDefinitionsFactory(Object context)
52              throws DefinitionsFactoryException {
53          TilesContainer container = TilesAccess.getContainer(context);
54          if (container instanceof BasicTilesContainer) {
55              BasicTilesContainer basic = (BasicTilesContainer) container;
56              DefinitionsFactory factory = basic.getDefinitionsFactory();
57              if (factory instanceof ReloadableDefinitionsFactory) {
58                  ReloadableDefinitionsFactory rFactory = (ReloadableDefinitionsFactory) factory;
59                  if (rFactory.refreshRequired()) {
60                      rFactory.refresh();
61                  }
62              }
63          }
64      }
65  }