}
}
@RemoteMethod
public static Tree getTrees(HttpSession session) {
Tree dependencyTree = new Tree(null, "name");
TreeEntry treeEAR = new TreeEntry("Enterprise Applications", NOT_LEAF_TYPE);
dependencyTree.addItem(treeEAR);
TreeEntry treeEJB = new TreeEntry("EJBModule", NOT_LEAF_TYPE);
dependencyTree.addItem(treeEJB);
TreeEntry treeWeb = new TreeEntry("WebModule", NOT_LEAF_TYPE);
dependencyTree.addItem(treeWeb);
TreeEntry treeRAR = new TreeEntry("ResourceAdapterModule", NOT_LEAF_TYPE);
dependencyTree.addItem(treeRAR);
TreeEntry treeCLI = new TreeEntry("AppClientModule", NOT_LEAF_TYPE);
dependencyTree.addItem(treeCLI);
TreeEntry treeSys = new TreeEntry("System Module", NOT_LEAF_TYPE);
dependencyTree.addItem(treeSys);
org.apache.geronimo.kernel.Kernel kernel = org.apache.geronimo.kernel.KernelRegistry.getSingleKernel();
ConfigurationManager configManager = null;
try {
configManager = ConfigurationUtil.getConfigurationManager(kernel);
} catch (GBeanNotFoundException e) {
// Ignore
}
List infos = configManager.listConfigurations();
for (Iterator infoIterator = infos.iterator(); infoIterator.hasNext();) {
ConfigurationInfo info = (ConfigurationInfo) infoIterator.next();
Configuration conf = configManager.getConfiguration(info.getConfigID());
if (conf != null) {
TreeEntry curr = new TreeEntry(info.getConfigID().toString(), NORMAL_TYPE);
switch (info.getType().getValue()) {
case 0:// EAR
{
treeEAR.addChild(curr);
break;
}
case 1:// EJB
{
treeEJB.addChild(curr);
break;
}
case 2:// CAR
{
treeCLI.addChild(curr);
break;
}
case 3:// RAR
{
treeRAR.addChild(curr);
break;
}
case 4:// WAR
{
treeWeb.addChild(curr);
break;
}
case 5:// SERVICE
{
treeSys.addChild(curr);
break;
}
}
addDependencies(curr, conf);
if (info.getType().getValue() == ConfigurationModuleType.EAR.getValue()) {
TreeEntry nodeEJB = new TreeEntry("EJBModule", NOT_LEAF_TYPE);
curr.addChild(nodeEJB);
TreeEntry nodeWeb = new TreeEntry("WebModule", NOT_LEAF_TYPE);
curr.addChild(nodeWeb);
TreeEntry nodeRAR = new TreeEntry("ResourceAdapterModule", NOT_LEAF_TYPE);
curr.addChild(nodeRAR);
TreeEntry nodeCLI = new TreeEntry("AppClientModule", NOT_LEAF_TYPE);
curr.addChild(nodeCLI);
Map<String, String> query = new HashMap<String, String>();
query.put("j2eeType", "EJBModule");
query.put("J2EEApplication", info.getConfigID().toString());
Set<AbstractName> setEnt = kernel.listGBeans(new AbstractNameQuery(null, query));
for (AbstractName gb : setEnt) {
TreeEntry subCurr = new TreeEntry(info.getConfigID().getGroupId() + "/"
+ info.getConfigID().getArtifactId() + "_" + gb.getNameProperty("name") + "/"
+ info.getConfigID().getVersion() + "/" + info.getConfigID().getType(), NORMAL_TYPE);
nodeEJB.addChild(subCurr);
addDependencies(subCurr, configManager.getConfiguration(gb.getArtifact()));
}
Map<String, String> query1 = new HashMap<String, String>();
query1.put("j2eeType", "ResourceAdapterModule");
query1.put("J2EEApplication", info.getConfigID().toString());
Set<AbstractName> setEnt1 = kernel.listGBeans(new AbstractNameQuery(null, query1));
for (AbstractName gb : setEnt1) {
TreeEntry subCurr = new TreeEntry(info.getConfigID().getGroupId() + "/"
+ info.getConfigID().getArtifactId() + "_" + gb.getNameProperty("name") + "/"
+ info.getConfigID().getVersion() + "/" + info.getConfigID().getType(), NORMAL_TYPE);
nodeRAR.addChild(subCurr);
addDependencies(subCurr, configManager.getConfiguration(gb.getArtifact()));
}
for (Configuration config : conf.getChildren()) {
TreeEntry subCurr = new TreeEntry(config.getAbstractName().toString(), NORMAL_TYPE);
nodeWeb.addChild(subCurr);
addDependencies(subCurr, config);
}
for (Artifact name : conf.getOwnedConfigurations()) {
TreeEntry subCurr = new TreeEntry(name.toString(), NORMAL_TYPE);
nodeCLI.addChild(subCurr);
addDependencies(subCurr, configManager.getConfiguration(name));
}
}
}
}
TreeEntry treeRepo = new TreeEntry("Repository", NORMAL_TYPE);
dependencyTree.addItem(treeRepo);
J2EEServer server = (J2EEServer) session.getAttribute(DependencyViewPortlet.Server_Key);
if (null == server) {
logger.error("can not find expected J2EEServer object");
treeRepo.addChild(new TreeEntry("Not found the content of repository", NORMAL_TYPE));// Ignore the error at client
return dependencyTree;
}
session.removeAttribute(DependencyViewPortlet.Server_Key);
ListableRepository[] repos = server.getRepositories();
for (int i = 0; i < repos.length; i++) {
ListableRepository repo = repos[i];
final SortedSet artifacts = repo.list();
for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) {
String fileName = iterator.next().toString();
treeRepo.addChild(new TreeEntry(fileName, NORMAL_TYPE));
}
}
check_no_child(dependencyTree.getItems());
return dependencyTree;
}