1 21 22 package com.sun.enterprise.tools.admingui.util; 23 24 import com.sun.enterprise.tools.guiframework.view.ViewDescriptorManager; 25 import com.sun.enterprise.tools.admingui.AdminGUIConstants; 26 import com.sun.enterprise.tools.guiframework.view.ViewXMLEntityResolver; 27 28 import java.io.FileInputStream ; 29 import java.io.FileOutputStream ; 30 import java.io.ObjectInputStream ; 31 import java.io.ObjectOutputStream ; 32 import java.net.URL ; 33 import javax.servlet.ServletConfig ; 34 35 36 public class PreloadXML extends Thread { 37 38 45 public PreloadXML(String name, String xmlFileName, ServletConfig config) { 46 super(name); 47 setXMLFileName(xmlFileName); 48 _config = config; 49 } 50 51 58 public PreloadXML(ServletConfig config) { 59 this("PreloadXML", null, config); 61 62 String xmlFile = "xml/eeViewDescriptor.xml"; 64 URL xmlURL = null; 65 try { 66 xmlURL = getClass().getClassLoader().getResource(xmlFile); 67 if (xmlURL == null) { 68 xmlURL = new URL ("file:///" + _config.getServletContext().getRealPath(xmlFile)); 70 xmlURL.openConnection().connect(); } 72 } catch (Exception ex) { 73 xmlFile = "xml/viewDescriptor.xml"; 75 } 76 77 setXMLFileName(xmlFile); 79 } 80 81 85 public static boolean isAlreadyLoaded() { 86 ViewDescriptorManager vdm = ViewDescriptorManager.getInstance(); 87 return (vdm.getViewDescriptorURL() != null); 88 } 89 90 93 public void deserialize() { 94 ViewDescriptorManager vdm = ViewDescriptorManager.getInstance(); 95 try { 96 vdm.deserialize( 97 new ObjectInputStream (getClass().getClassLoader(). 98 getResourceAsStream("viewXML.ser"))); 99 } catch (Exception ex) { 100 ex.printStackTrace(); 102 return; 103 } 104 } 105 106 109 public void run() { 110 init(); 111 deserialize(); 112 } 113 114 117 protected void init() { 118 URL xmlURL = null; 120 try { 121 xmlURL = getClass().getClassLoader().getResource(_xmlFileName); 122 } catch (Exception ex) { 123 } 125 try { 126 ViewDescriptorManager vdm = ViewDescriptorManager.getInstance(); 127 if (PreloadXML.isAlreadyLoaded()) { 128 return; 135 } 136 if (xmlURL == null) { 137 xmlURL = new URL ("file:///" + _config.getServletContext().getRealPath(_xmlFileName)); 138 } 139 vdm.setViewDescriptorURL(xmlURL); 140 vdm.setDTDURLBase("/xml/"); vdm.setJSPRoot(AdminGUIConstants.DEFAULT_DISPLAY_URL_DIR); 142 vdm.setViewXMLEntityResolver(new ViewXMLEntityResolver()); 143 } catch (Exception ex) { 144 ex.printStackTrace(); 145 } 146 } 147 148 152 public static void printUsage() { 153 System.out.println("You must specify the xml file name:\n"); 154 System.out.println("Usage:\n"); 155 System.out.println("java " + PreloadXML.class.getName() 156 + " <xml file name>\n"); 157 } 158 159 165 public static void main(String args[]) { 166 if (args.length < 1) { 167 printUsage(); 168 return; 169 } 170 171 PreloadXML pre = new PreloadXML("na", args[0], (ServletConfig ) null); 173 pre.init(); 174 175 ViewDescriptorManager vdm = ViewDescriptorManager.getInstance(); 177 vdm.getViewDescriptor("TopFrameset"); 178 179 try { 181 vdm.serialize( 182 new ObjectOutputStream (new FileOutputStream ("viewXML.ser"))); 183 } catch (Exception ex) { 184 ex.printStackTrace(); 185 return; 186 } 187 188 System.out.println("Success!"); 190 } 191 192 public String getXMLFileName() { 193 return _xmlFileName; 194 } 195 196 public void setXMLFileName(String name) { 197 _xmlFileName = name; 198 } 199 200 private String _xmlFileName = null; 201 private ServletConfig _config = null; 202 } 203 | Popular Tags |