1 package de.matthias_burbach.mosaique.core.model;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6
7 /***
8 * @author Matthias Burbach
9 */
10 public class DefinitionResolver {
11 /***
12 * The singleton instance of this class.
13 */
14 private static DefinitionResolver instance = new DefinitionResolver();
15
16 /***
17 * The cached objects of type {@link TilesDefinitions}.
18 */
19 private List tilesDefinitionsObjects = new ArrayList();
20
21 /***
22 * @return The singleton instance of this class.
23 */
24 public static DefinitionResolver getInstance() {
25 return instance;
26 }
27
28 /***
29 * Clears the internal list of added TilesDefinitions objects.
30 */
31 public void clear() {
32 tilesDefinitionsObjects.clear();
33 }
34
35 /***
36 * Adds a TilesDefinitions object to the internal list.
37 * @param tilesDefinitions The object to add.
38 */
39 public void addTilesDefinitions(final TilesDefinitions tilesDefinitions) {
40 tilesDefinitionsObjects.add(tilesDefinitions);
41 }
42
43 /***
44 * Resolves a definition by name from the internal list of TilesDefinitions
45 * objects.
46 *
47 * @param name The name of the definition to resolve.
48 * @return The definition resolved or <code>null</code> if none such
49 * definition exists.
50 */
51 public Definition resolve(final String name) {
52 Definition result = null;
53 for (Iterator iter = tilesDefinitionsObjects.iterator();
54 iter.hasNext();) {
55 TilesDefinitions tilesDefinitions = (TilesDefinitions) iter.next();
56 result = (Definition)
57 tilesDefinitions.getDefinitionsByName().get(name);
58 if (result != null) {
59 break;
60 }
61 }
62 return result;
63 }
64 }