1 19 20 package org.efs.openreports.util; 21 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 25 import com.opensymphony.xwork.ActionContext; 26 import com.opensymphony.xwork.interceptor.component.*; 27 28 import org.apache.log4j.Logger; 29 import org.xml.sax.SAXException ; 30 31 public class ORComponentManager 32 { 33 protected static Logger log = Logger.getLogger(ORComponentManager.class); 34 35 40 public static void initializeObject(Object object) 41 { 42 ComponentManager container = (ComponentManager) ActionContext.getContext().get( 43 "com.opensymphony.xwork.interceptor.component.ComponentManager"); 44 45 if (container == null) 46 { 47 log.info("Creating ComponentManager for: " + object.getClass().getName()); 48 49 container = new DefaultComponentManager(); 50 51 ComponentConfiguration config = loadConfiguration(); 52 config.configure(container, "application"); 53 54 ActionContext.getContext().put( 55 "com.opensymphony.xwork.interceptor.component.ComponentManager", container); 56 } 57 58 container.initializeObject(object); 59 } 60 61 public static ComponentConfiguration loadConfiguration() 62 { 63 ComponentConfiguration config = new ComponentConfiguration(); 64 65 InputStream configXml = Thread.currentThread().getContextClassLoader() 66 .getResourceAsStream("components.xml"); 67 68 if (configXml == null) 69 { 70 final String message = "Unable to find the file components.xml in the classpath."; 71 log.error(message); 72 throw new RuntimeException (message); 73 } 74 75 try 76 { 77 config.loadFromXml(configXml); 78 } 79 catch (IOException ioe) 80 { 81 log.error(ioe); 82 throw new RuntimeException ("Unable to load component configuration"); 83 } 84 catch (SAXException sae) 85 { 86 log.error(sae); 87 throw new RuntimeException ("Unable to load component configuration"); 88 } 89 90 return config; 91 } 92 93 } | Popular Tags |