1 23 24 29 30 package com.sun.enterprise.tools.launcher; 31 import java.io.FileWriter ; 32 import java.io.File ; 33 import java.io.FilenameFilter ; 34 import java.io.IOException ; 35 import java.util.Properties ; 36 import java.util.logging.Logger ; 37 import java.util.logging.Level ; 38 39 import javax.xml.parsers.DocumentBuilder ; 40 import javax.xml.parsers.DocumentBuilderFactory ; 41 import org.w3c.dom.Document ; 42 import org.w3c.dom.Node ; 43 import org.w3c.dom.Element ; 44 import org.w3c.dom.NodeList ; 45 import org.xml.sax.SAXException ; 46 import javax.xml.parsers.ParserConfigurationException ; 47 import com.sun.logging.LogDomains; 48 import com.sun.enterprise.config.ConfigException; 49 import com.sun.enterprise.util.RelativePathResolver; 50 import com.sun.enterprise.util.i18n.StringManager; 51 52 53 114 public class ProcessLauncherConfig { 115 116 private String _process=""; 117 private String _configFile=""; 118 private String _classpathExcludes=""; 119 private String _classpathIncludes=""; 120 private String _classpathLibDir=""; 121 private String _classpathPrefix=""; 122 private String _classpathJ2se14Prefix=""; 123 private String _classpathJ2se15OrLaterPrefix=""; 124 private String _mainClass=""; 125 private StringManager _strMgr=null; 126 private Properties _sysProperties=null; 127 private static boolean bDebug=false; 128 129 private static final String PROCESS="process"; 130 private static final String SYSTEM_PROPERTY="sysproperty"; 131 private static final String MAIN_CLASS="main_class"; 132 private static final String MAIN_CLASS_CLASSNAME="classname"; 133 private static final String CLASSPATH="classpath"; 134 private static final String CLASSPATH_INCLUDES="includes"; 135 private static final String CLASSPATH_EXCLUDES="excludes"; 136 private static final String CLASSPATH_PREFIX="prefix"; 137 private static final String CLASSPATH_J2SE1_4_PREFIX="j2se1_4_prefix"; 138 private static final String CLASSPATH_J2SE1_5_OR_LATER_PREFIX="j2se1_5_or_later_prefix"; 139 private static final String CLASSPATH_DIR="dir"; 140 141 142 protected ProcessLauncherConfig() { 143 } 144 145 149 protected ProcessLauncherConfig(String configFile, String process) throws ConfigException { 150 initializeConfig(configFile, process); 151 } 152 153 157 protected void initializeConfig(String configFile, String process) throws ConfigException { 158 _configFile=configFile; 160 _process=process; 161 _sysProperties=new Properties (); 162 _strMgr=StringManager.getManager(ProcessLauncherConfig.class); 163 164 try { 165 boolean bFoundProcess=false; 167 String key=null; 168 Document doc=readDOM(configFile); 169 Element element=null; 170 NodeList nl=doc.getElementsByTagName(PROCESS); 171 172 for(int ii=0;ii < nl.getLength(); ii++) { 173 element=(Element )nl.item(ii); 175 key=element.getAttribute("name"); 176 if(key.equals(process)) { 177 bFoundProcess=true; 179 loadProcess(element); 180 } 181 } 182 183 if(!bFoundProcess) { 184 throw new ConfigException(_strMgr.getString("launcher.process_launcher_config_not_found", 186 new String []{process, configFile})); 187 } 188 } catch (ConfigException ce) { 189 throw ce; 190 } catch (Exception e) { 191 throw new ConfigException(_strMgr.getString("launcher.process_launcher_config_exception", _configFile), e); 192 } 193 } 194 195 198 protected void loadProcess(Element process) { 199 String key=null, value=null, ifx=null; 201 Element element=null; 202 203 NodeList nl=process.getChildNodes(); 205 for(int ii=0;ii < nl.getLength(); ii++) { 206 207 if(nl.item(ii) instanceof Element ) { 208 element=(Element )nl.item(ii); 209 210 if(element.getTagName().equals(SYSTEM_PROPERTY)) { 211 key=element.getAttribute("key"); 213 value=element.getAttribute("value"); 214 ifx=element.getAttribute("if"); 215 216 if(!key.equals("")) { 218 if(ifx.equals("") || System.getProperty(ifx) != null) { 220 _sysProperties.setProperty(key, RelativePathResolver.resolvePath(value)); 222 } 223 } 224 225 } else if(element.getTagName().equals(MAIN_CLASS)) { 226 _mainClass=element.getAttribute(MAIN_CLASS_CLASSNAME); 228 229 } else if(element.getTagName().equals(CLASSPATH)) { 230 _classpathLibDir=element.getAttribute(CLASSPATH_DIR); 232 _classpathIncludes=element.getAttribute(CLASSPATH_INCLUDES); 233 _classpathExcludes=element.getAttribute(CLASSPATH_EXCLUDES); 234 _classpathPrefix=element.getAttribute(CLASSPATH_PREFIX); 235 _classpathJ2se14Prefix=element.getAttribute(CLASSPATH_J2SE1_4_PREFIX); 236 _classpathJ2se15OrLaterPrefix=element.getAttribute(CLASSPATH_J2SE1_5_OR_LATER_PREFIX); 237 } 238 } 239 } 240 } 241 242 243 protected String getConfigFile() { 244 return _configFile; 245 } 246 protected String getClasspathLibDir() { 247 return _classpathLibDir; 248 } 249 protected String getClasspathIncludes() { 250 return _classpathIncludes; 251 } 252 protected String getClasspathExcludes() { 253 return _classpathExcludes; 254 } 255 protected String getClasspathPrefix() { 256 return _classpathPrefix; 257 } 258 protected String getClasspathJ2se14Prefix() { 259 return _classpathJ2se14Prefix; 260 } 261 protected String getClasspathJ2se15OrLaterPrefix() { 262 return _classpathJ2se15OrLaterPrefix; 263 } 264 265 266 267 protected String getMainClass() { 268 return _mainClass; 269 } 270 protected Properties getSystemProperties() { 271 return _sysProperties; 272 } 273 274 281 protected Document readDOM(String file) throws SAXException , ParserConfigurationException , IOException { 282 DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance(); 283 DocumentBuilder db=dbf.newDocumentBuilder(); 284 return db.parse(new File (file)); 285 } 286 } 287 | Popular Tags |