1 19 20 package org.netbeans.modules.tomcat5; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import org.openide.ErrorManager; 25 import org.netbeans.modules.tomcat5.config.gen.Engine; 26 import org.netbeans.modules.tomcat5.config.gen.Host; 27 import org.netbeans.modules.tomcat5.config.gen.SContext; 28 import org.netbeans.modules.tomcat5.config.gen.Server; 29 import org.netbeans.modules.tomcat5.config.gen.Service; 30 31 36 public class TomcatManagerConfig { 37 private File serverXml; 38 private long timestamp; 39 40 private boolean hasLogger; 42 private String loggerClassName; 43 private String loggerDir; 44 private String loggerPrefix; 45 private String loggerSuffix; 46 private boolean loggerTimestamp; 47 48 53 public TomcatManagerConfig(File serverXml) { 54 this.serverXml = serverXml; 55 refresh(); 56 } 57 58 61 public void refresh() { 62 long newTimestamp = serverXml.lastModified(); 63 if (newTimestamp > timestamp) { 64 timestamp = newTimestamp; 65 Host host = getHostElement(); 66 if (host != null && host.isLogger()) { 67 hasLogger = true; 68 loggerClassName = host.getAttributeValue(SContext.LOGGER, "className"); loggerDir = host.getAttributeValue(SContext.LOGGER, "directory"); loggerPrefix = host.getAttributeValue(SContext.LOGGER, "prefix"); loggerSuffix = host.getAttributeValue(SContext.LOGGER, "suffix"); String timestamp = host.getAttributeValue(SContext.LOGGER, "timestamp"); loggerTimestamp = Boolean.valueOf(timestamp).booleanValue(); 74 } else { 75 Engine engine = getEngineElement(); 76 if (engine != null && engine.isLogger()) { 77 hasLogger = true; 78 loggerClassName = engine.getAttributeValue(SContext.LOGGER, "className"); loggerDir = engine.getAttributeValue(SContext.LOGGER, "directory"); loggerPrefix = engine.getAttributeValue(SContext.LOGGER, "prefix"); loggerSuffix = engine.getAttributeValue(SContext.LOGGER, "suffix"); String timestamp = engine.getAttributeValue(SContext.LOGGER, "timestamp"); loggerTimestamp = Boolean.valueOf(timestamp).booleanValue(); 84 } else { 85 hasLogger = false; 86 } 87 } 88 } 89 } 90 91 96 public String serverXmlPath() { 97 return serverXml.getAbsolutePath(); 98 } 99 100 106 public Server getServerElement() { 107 try { 108 return Server.createGraph(serverXml); 109 } catch (IOException ioe) { 110 ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, ioe); 111 } catch (RuntimeException e) { 112 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 113 } 114 return null; 115 } 116 117 122 public Engine getEngineElement() { 123 Server server = getServerElement(); 124 if (server == null) return null; 125 Service[] service = server.getService(); 126 if (service.length > 0) { 127 return service[0].getEngine(); 128 } 129 return null; 130 } 131 132 137 public Host getHostElement() { 138 Engine engine = getEngineElement(); 139 if (engine != null) { 140 Host[] host = engine.getHost(); 141 if (host.length > 0) { 142 return host[0]; 143 } 144 } 145 return null; 146 } 147 148 155 public boolean hasLogger() { 156 return hasLogger; 157 } 158 159 164 public String loggerClassName() { 165 return loggerClassName; 166 } 167 168 173 public String loggerDir() { 174 return loggerDir; 175 } 176 177 182 public String loggerPrefix() { 183 return loggerPrefix; 184 } 185 186 191 public String loggerSuffix() { 192 return loggerSuffix; 193 } 194 195 202 public boolean loggerTimestamp() { 203 return loggerTimestamp; 204 } 205 } 206 | Popular Tags |