1 package net.sf.mmapps.modules.config.dumper;
2
3 import java.util.*;
4
5 import org.mmbase.bridge.*;
6 import net.sf.mmapps.modules.config.*;
7
8 import org.apache.commons.logging.*;
9
10
11
12 public class Dumper {
13
14 private static Log log = LogFactory.getLog(Dumper.class);
15 /***
16 * method to read the configuration of mmbase
17 * (does <B>NOT</B> required a gui to be running)
18 * and should be moved... to a util class
19 * @param cloud the cloud where the application must come from
20 **/
21 public static Configuration getConfiguration(Cloud cloud){
22 Configuration config = new Configuration();
23 ApplicationConfiguration appConfig = config.createApplicationConfiguration();
24 appConfig.setName("LiveMMBase");
25 log.debug("getting list of node managers");
26 NodeManagerList nodeManagers = cloud.getNodeManagers();
27 log.debug("the list contains " + nodeManagers.size() + " nodemanagers");
28 for (int x = 0 ; x < nodeManagers.size() ; x ++){
29 NodeManager nm = nodeManagers.getNodeManager(x);
30 String stringConfiguration = nm.getStringValue("config");
31 log.debug("START INPUT CONFIGURATION DUMP for nodemanager" + nm.getName());
32 log.debug(stringConfiguration);
33 log.debug("END INPUT CONFIGURATION DUMP for nodemanager" + nm.getName());
34 NodeManagerConfiguration conf = ConfigurationXMLReader.createNodeManagerConfiguration(config,stringConfiguration);
35 conf.setName(nm.getName());
36 appConfig.addNodeManagerConfiguration(conf);
37 appConfig.addRequiredNodeManager(conf.getName());
38 }
39
40
41 RelationManagerList relationManagers = cloud.getRelationManagers();
42 for (int x = 0 ; x < relationManagers.size(); x++){
43 RelationManager relationManager = relationManagers.getRelationManager(x);
44 String sname = relationManager.getStringValue("sname");
45 String sguiname = relationManager.getStringValue("sguiname");
46 String dguiname = relationManager.getStringValue("dguiname");
47 String dir = (relationManager.getIntValue("dir") ==2)?"BIDIRECTIONAL":"UNIDIRECTIONAL";
48
49 String builder = relationManager.getNodeManager().getName();
50
51 RelationType reltype = new RelationType(sname,sguiname,dguiname,dir,builder);
52
53 appConfig.addRelationType(reltype);
54 }
55
56 NodeManager typerel = cloud.getNodeManager("typerel");
57 NodeIterator nodeIterator = typerel.getList(null,null,null).nodeIterator();
58 while(nodeIterator.hasNext()){
59 Node node = nodeIterator.nextNode();
60 RelationManagerConfiguration conf = config.createRelationManagerConfiguration();
61 if(! cloud.hasNode(node.getIntValue("snumber")) ){
62 continue;
63 }
64 if(! cloud.hasNode(node.getIntValue("dnumber")) ){
65 continue;
66 }
67 if(! cloud.hasNode(node.getIntValue("rnumber")) ){
68 continue;
69 }
70 try {
71 conf.setSourceNodeManagerName(cloud.getNodeManager(node.getIntValue("snumber")).getStringValue("name"));
72 conf.setDestinationNodeManagerName(cloud.getNodeManager(node.getIntValue("dnumber")).getStringValue("name"));
73 conf.setRelationTypeName(node.getNodeValue("rnumber").getStringValue("sname"));
74 appConfig.addRelationManagerConfiguration(conf);
75 } catch (NotFoundException nnfe){};
76
77 }
78 config.addApplicationConfiguration(appConfig);
79 return config;
80 }
81 }