1 23 24 package com.sun.enterprise.admin.snmp; 25 26 import com.sun.enterprise.admin.common.domains.registry.DomainRegistry; 28 import com.sun.enterprise.admin.common.domains.registry.DomainRegistryException; 29 import com.sun.enterprise.admin.common.domains.registry.DomainEntry; 30 31 import java.lang.*; 33 import java.io.*; 34 import java.util.Vector ; 35 import java.util.Arrays ; 36 import java.util.Iterator ; 37 38 public class ExtractDomainRoots { 39 40 public String [] getAllDomainRoots() { 41 Vector vt = new Vector (); 42 String [] domains = null; 43 try 44 { 45 DomainRegistry domainRegistry = DomainRegistry.newInstance(); 46 Iterator it = domainRegistry.iterator(); 47 while (it.hasNext()) 48 { 49 DomainEntry entry = (DomainEntry)it.next(); 50 vt.addElement(entry.getRoot().getPath()); 51 } 52 domains = new String [vt.size()]; 53 domains = (String [])vt.toArray(domains); 54 } 55 catch (DomainRegistryException e) 56 { 57 System.err.println("ExtractDomainRoots: Exception caught, while parsing the domain registry"); 58 e.printStackTrace(); 59 } 60 return domains; 61 } 62 63 public void writeDomainInfo(String [] domains) { 64 String fileName = new String ("/tmp/appserv_domainInfo.txt"); 65 try { 66 File domainFile = new File(fileName); 67 FileWriter domainFileWriter = new FileWriter(domainFile); 68 for(int i = 0; i< domains.length; i++) 69 { 70 domainFileWriter.write(domains[i]); 71 domainFileWriter.write("\n"); 72 System.out.println(domains[i]); 73 } 74 domainFileWriter.flush(); 75 domainFileWriter.close(); 76 } 77 catch(IOException e) { 78 System.out.println("ExtractDomainRoots: IOException caught while writing domain information to file"); 79 e.printStackTrace(); 80 } 81 catch(Exception e) { 82 System.out.println("ExtractDomainRoots: Exception caught while writing domain information to file"); 83 e.printStackTrace(); 84 } 85 } 86 87 public static void main(String [] args) { 88 ExtractDomainRoots droot = new ExtractDomainRoots(); 89 String [] dInfo = droot.getAllDomainRoots(); 90 droot.writeDomainInfo(dInfo); 91 } 92 } 93 | Popular Tags |