1 /*
2 * ApplicationCfgImpl.java
3 * Created on July 28, 2003
4 *
5 * The Blues Framework - A lightweight application framework
6 * Copyright (C) 2003 Lonnie Pryor
7 * http://blues.lonniepryor.com
8 *
9 * This library is free software; you can redistribute it and/or modify it under the
10 * terms of the GNU Lesser General Public License as published by the Free Software
11 * Foundation; either version 2.1 of the License, or (at your option) any later
12 * version.
13 *
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License along
19 * with this library; if not, write to:
20 *
21 * The Free Software Foundation, Inc.
22 * 59 Temple Place, Suite 330
23 * Boston, MA 02111-1307 USA
24 *
25 */
26 package com.lonniepryor.blues.cfg;
27
28 import java.util.HashSet;
29 import java.util.LinkedList;
30 import java.util.List;
31 import java.util.Set;
32
33 /***
34 * Generic implementation of {@link ApplicationCfg}.
35 *
36 * @author Lonnie Pryor
37 * @version $Revision: 1.1 $
38 */
39 public class ApplicationCfgImpl implements ApplicationCfg {
40 /*** All of the singleton types declared in this application. */
41 private final Set singeltonClasses = new HashSet();
42 /*** The singletons declared in this application. */
43 private final List singeltonCfgs = new LinkedList();
44 /*** The root module of this application. */
45 private ModuleCfg rootModule = null;
46
47 /***
48 * Creates a new ApplicationCfgImpl object.
49 */
50 public ApplicationCfgImpl () {
51 }
52
53 /***
54 * Decalres a singleton in this application.
55 *
56 * @param singleton The singleton to declare.
57 */
58 public void declareSingleton (SingletonCfgImpl singleton) {
59 declare(singleton);
60 }
61
62 /***
63 * Decalres the root module of this application.
64 *
65 * @param rootModule The root module of this application.
66 */
67 public void declareServices (ModuleCfgImpl rootModule) {
68 if (rootModule == null)
69 throw new NullPointerException("Root module config cannot be null");
70 if (this.rootModule != null)
71 throw new IllegalStateException("Root module already declared");
72 this.rootModule = rootModule;
73 }
74
75 /***
76 * Decalres a singleton config in this application.
77 *
78 * @param singleton The singleton to declare.
79 */
80 public void declare (SingletonCfg singleton) {
81 if (singleton == null)
82 throw new NullPointerException("singleton");
83 if (!singeltonClasses.add(singleton.getSingeltonType()))
84 throw new IllegalArgumentException(
85 "Cannot declare more than one singleton of class '"
86 + singleton.getSingeltonType() + "'");
87 singeltonCfgs.add(singleton);
88 }
89
90 /* (non-Javadoc)
91 * @see com.lonniepryor.blues.cfg.ApplicationCfg#getDeclaredSingletons()
92 */
93 public SingletonCfg[] getSingletons () {
94 return (SingletonCfg[])singeltonCfgs.toArray(
95 new SingletonCfg[singeltonCfgs.size()]);
96 }
97
98 /* (non-Javadoc)
99 * @see com.lonniepryor.blues.cfg.ApplicationCfg#getRootModule()
100 */
101 public ModuleCfg getRootModule () {
102 return rootModule;
103 }
104 }
This page was automatically generated by Maven