View Javadoc

1   /*
2    * $Id: DefinitionsFactory.java 537196 2007-05-11 14:07:35Z 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 org.apache.tiles.context.TilesRequestContext;
25  import org.apache.tiles.Definition;
26  import org.apache.tiles.TilesException;
27  
28  import java.util.Map;
29  
30  /***
31   * Interface for creating a {@link org.apache.tiles.definition.Definitions} object and managing
32   * its contents.
33   * <p/>
34   * <p>DefinitionsFactory implementations are responsible for maintaining the data
35   * sources of Tiles configuration data and using the data to create
36   * Definitions sets.  Implementations also know how to append
37   * locale-specific configuration data to an existing Definitions set.</p>
38   *
39   * @version $Rev: 537196 $ $Date: 2007-05-11 16:07:35 +0200 (Fri, 11 May 2007) $
40   */
41  public interface DefinitionsFactory {
42  
43      /***
44       * Property name that specifies the implementation of the DefinitionsReader.
45       */
46      String READER_IMPL_PROPERTY =
47          "org.apache.tiles.definition.DefinitionsReader";
48  
49      /***
50       * Property name that specifies the implementation of
51       * {@link org.apache.tiles.locale.LocaleResolver}.
52       */
53      String LOCALE_RESOLVER_IMPL_PROPERTY =
54          "org.apache.tiles.locale.LocaleResolver";
55  
56      /***
57       * Initializes the DefinitionsFactory and its subcomponents. <p/>
58       * Implementations may support configuration properties to be passed in via
59       * the params Map.
60       *
61       * @param params The Map of configuration properties.
62       * @throws TilesException If a Tiles exception, such as an initialization
63       * error, occurs.
64       */
65      void init(Map<String, String> params) throws TilesException;
66  
67      /***
68       * Returns a Definition object that matches the given name and
69       * Tiles context.
70       *
71       * @param name         The name of the Definition to return.
72       * @param tilesContext The Tiles context to use to resolve the definition.
73       * @return the Definition matching the given name or null if none
74       *         is found.
75       * @throws DefinitionsFactoryException if an error occurs reading definitions.
76       */
77      Definition getDefinition(String name, TilesRequestContext tilesContext)
78              throws DefinitionsFactoryException;
79  
80      /***
81       * Adds a source where Definition objects are stored.
82       * <p/>
83       * Implementations should publish what type of source object they expect.
84       * The source should contain enough information to resolve a configuration
85       * source containing definitions.  The source should be a "base" source for
86       * configurations.  Internationalization and Localization properties will be
87       * applied by implementations to discriminate the correct data sources based
88       * on locale.
89       *
90       * @param source The configuration source for definitions.
91       * @throws DefinitionsFactoryException if an invalid source is passed in or
92       *                                     an error occurs resolving the source to an actual data store.
93       */
94      void addSource(Object source) throws DefinitionsFactoryException;
95  
96      /***
97       * Creates and returns a {@link Definitions} set by reading
98       * configuration data from the applied sources.
99       *
100      * @return The read definitions.
101      * @throws DefinitionsFactoryException if an error occurs reading the
102      *                                     sources.
103      */
104     Definitions readDefinitions()
105         throws DefinitionsFactoryException;
106 }