KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > snmp > ExtractDomainRoots


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.snmp;
25
26 //import from DomainRegistry
27
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 // jdk imports
32
import java.lang.*;
33 import java.io.*;
34 import java.util.Vector JavaDoc;
35 import java.util.Arrays JavaDoc;
36 import java.util.Iterator JavaDoc;
37
38 public class ExtractDomainRoots {
39     
40     public String JavaDoc[] getAllDomainRoots() {
41         Vector JavaDoc vt = new Vector JavaDoc();
42         String JavaDoc[] domains = null;
43         try
44         {
45             DomainRegistry domainRegistry = DomainRegistry.newInstance();
46             Iterator JavaDoc 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 JavaDoc[vt.size()];
53             domains = (String JavaDoc[])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 JavaDoc[] domains) {
64         String JavaDoc fileName = new String JavaDoc("/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 JavaDoc 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 JavaDoc[] args) {
88         ExtractDomainRoots droot = new ExtractDomainRoots();
89         String JavaDoc[] dInfo = droot.getAllDomainRoots();
90         droot.writeDomainInfo(dInfo);
91     }
92 }
93
Popular Tags