View Javadoc

1   package net.sf.mmapps.modules.config;
2   import net.sf.mmapps.modules.config.implementation.*;
3   /***
4    * The configuration class reflects mmbase the mmbase configuration of node managers, relation managers and applications
5    **/
6   public class Configuration {
7   
8       //holder for the core builders
9       NodeManagerConfigurations nodeManagerConfigurations;
10  
11      //bolder for the applications
12      ApplicationConfigurations applicationConfigurations;
13      ConfigurationFactory configurationFactory = new ConfigurationFactory();
14      /***
15       * create a new Configuration 
16       **/
17      public Configuration() {
18          nodeManagerConfigurations = new NodeManagerConfigurations();
19          applicationConfigurations = new ApplicationConfigurations();
20      }
21  
22      /***
23       * Add a node manager to the "core" configuration.  
24       * Node managers that are added this way are treated as core builders and do not belong to an application.
25       * @param nodeManagerConfiguration the node manager configuration to add
26       **/
27      public void addNodeManagerConfiguration(NodeManagerConfiguration nodeManagerConfiguration) {
28          nodeManagerConfigurations.add(nodeManagerConfiguration);
29      }
30  
31      /***
32       * Add an application configuration to the configuration.
33       * an application configuration consists of node managers and relation managers
34       * @param applicationConfiguration the application configuration to add to the configuration
35       **/
36      public void addApplicationConfiguration(ApplicationConfiguration applicationConfiguration) {
37          applicationConfigurations.add(applicationConfiguration);
38      }
39  
40      /***
41       * @param name the node manager name
42       * @return the "core" node manager with name name or null of the nodemanager does not exist in den root of the configuration
43       **/
44      public NodeManagerConfiguration getNodeManagerConfigurationFromRoot(String name) {
45          return nodeManagerConfigurations.getNodeManagerConfiguration(name);
46      }
47  
48      /***
49       * @param appName the name of the application
50       * @param name the name of the builder
51       * @return the node manager configuration 
52       **/
53      public NodeManagerConfiguration getNodeManagerConfigurationFromApplication(String appName, String name) {
54          ApplicationConfiguration appConfig = applicationConfigurations.getApplicationConfiguration(name);
55          if (appConfig != null) {
56              return appConfig.getNodeManagerConfigurations().getNodeManagerConfiguration(name);
57          }
58          return null;
59      }
60  
61      /*** 
62       * @return the core node manager configuations
63       */
64      public NodeManagerConfigurations getNodeManagerConfigurations() {
65          return nodeManagerConfigurations;
66      }
67  
68      public ApplicationConfigurations getApplicationConfigurations() {
69          return applicationConfigurations;
70      }
71  
72      public NodeManagerConfiguration getNodeManagerConfiguration(String name) {
73          NodeManagerConfiguration nodeManagerConfiguration;
74          nodeManagerConfiguration = getNodeManagerConfigurationFromRoot(name);
75  
76          if (nodeManagerConfiguration == null) {
77              for (int x = 0; x < applicationConfigurations.size(); x++) {
78                  ApplicationConfiguration appConfig = applicationConfigurations.getApplicationConfiguration(x);
79                  nodeManagerConfiguration = appConfig.getNodeManagerConfigurations().getNodeManagerConfiguration(name);
80                  if (nodeManagerConfiguration != null) {
81                      break;
82                  }
83              }
84  
85          }
86          return nodeManagerConfiguration;
87      }
88      public ApplicationConfiguration createApplicationConfiguration() {
89          return configurationFactory.createApplicationConfiguration();
90      }
91  
92      public FieldConfiguration createFieldConfiguration() {
93          return configurationFactory.createFieldConfiguration();
94      }
95  
96      public NodeManagerConfiguration createNodeManagerConfiguration() {
97          return configurationFactory.createNodeManagerConfiguration();
98      }
99  
100     public RelationManagerConfiguration createRelationManagerConfiguration() {
101         return configurationFactory.createRelationManagerConfiguration();
102     }
103 }