1 23 24 29 30 package com.sun.enterprise.tools.upgrade.common; 31 32 36 import java.util.*; 37 import java.io.*; 38 39 import org.w3c.dom.NodeList ; 41 import javax.xml.parsers.DocumentBuilder ; 42 import org.w3c.dom.Element ; 43 import org.w3c.dom.Document ; 44 import javax.xml.parsers.DocumentBuilderFactory ; 45 47 public class DomainInfo { 48 49 private String domainName; 50 private String domainPath; 51 private List instanceNames; 52 private Hashtable instancePathMapping; 53 54 56 public DomainInfo(String dName,String dPath) { 57 this.domainName = dName; 58 this.domainPath = dPath; 59 } 61 62 66 public java.lang.String getDomainName() { 67 return domainName; 68 } 69 70 74 public void setDomainName(java.lang.String domainName) { 75 this.domainName = domainName; 76 } 77 78 82 public java.lang.String getDomainPath() { 83 return domainPath; 84 } 85 86 90 public void setDomainPath(java.lang.String domainPath) { 91 this.domainPath = domainPath; 92 } 93 94 98 public java.util.List getInstanceNames() { 99 if(this.instanceNames == null){ 101 instanceNames = new ArrayList(); 106 instancePathMapping = new Hashtable(); 107 File domainDir = new File(this.domainPath); 108 String [] instanceDirs = domainDir.list(); 109 for (int i=0 ; i<instanceDirs.length ; i++) { 110 instanceNames.add(instanceDirs[i]); 111 String instancePath= this.domainPath + File.separator + instanceDirs[i]; 112 instancePathMapping.put(instanceDirs[i],instancePath); 113 } 114 } 119 return instanceNames; 120 } 121 122 public String getInstancePath(String instanceName) { 123 if(this.instancePathMapping == null){ 124 this.getInstanceNames(); 125 } 126 if(instanceName == null || "".equals(instanceName.trim())){ 128 return this.domainPath; 129 } 130 return (String )this.instancePathMapping.get(instanceName); 131 } 132 133 public String getDomainApplicationRoot() { 135 String configFileName = domainPath + File.separator + "config" + File.separator + "domain.xml"; 136 String applRoot = null; 137 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 138 factory.setNamespaceAware(true); 139 try { 140 DocumentBuilder builder = factory.newDocumentBuilder(); 141 builder.setEntityResolver((org.xml.sax.helpers.DefaultHandler )Class.forName("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance()); 142 Document adminServerDoc = builder.parse( new File(configFileName)); 143 NodeList domainElements = adminServerDoc.getElementsByTagName("domain"); 144 Element domainElement = (Element )domainElements.item(0); 146 if(domainElement != null) { 147 String attrValue = domainElement.getAttribute("application-root"); 148 StringTokenizer attrTokens = new StringTokenizer(attrValue, "/"); 149 attrTokens.nextToken(); 150 applRoot = attrTokens.nextToken(); 151 } 152 }catch (Exception ex){ 153 } 154 return applRoot; 155 } 156 } 158 | Popular Tags |