1 25 package org.ofbiz.base.component; 26 27 import java.io.InputStream ; 28 import java.net.URL ; 29 30 import org.ofbiz.base.config.GenericConfigException; 31 import org.ofbiz.base.config.ResourceHandler; 32 import org.ofbiz.base.util.UtilXml; 33 import org.ofbiz.base.util.Debug; 34 35 import org.w3c.dom.Document ; 36 import org.w3c.dom.Element ; 37 38 45 public class ComponentResourceHandler implements ResourceHandler { 46 47 public static final String module = ComponentResourceHandler.class.getName(); 48 protected String componentName; 49 protected String loaderName; 50 protected String location; 51 52 public ComponentResourceHandler(String componentName, Element element) { 53 this.componentName = componentName; 54 this.loaderName = element.getAttribute("loader"); 55 this.location = element.getAttribute("location"); 56 } 57 58 public ComponentResourceHandler(String componentName, String loaderName, String location) { 59 this.componentName = componentName; 60 this.loaderName = loaderName; 61 this.location = location; 62 if (Debug.verboseOn()) Debug.logVerbose("Created " + this.toString(), module); 63 } 64 65 public String getLoaderName() { 66 return this.loaderName; 67 } 68 69 public String getLocation() { 70 return this.location; 71 } 72 73 public Document getDocument() throws GenericConfigException { 74 try { 75 return UtilXml.readXmlDocument(this.getStream(), this.getFullLocation()); 76 } catch (org.xml.sax.SAXException e) { 77 throw new GenericConfigException("Error reading " + this.toString(), e); 78 } catch (javax.xml.parsers.ParserConfigurationException e) { 79 throw new GenericConfigException("Error reading " + this.toString(), e); 80 } catch (java.io.IOException e) { 81 throw new GenericConfigException("Error reading " + this.toString(), e); 82 } 83 } 84 85 public InputStream getStream() throws GenericConfigException { 86 return ComponentConfig.getStream(componentName, loaderName, location); 87 } 88 89 public URL getURL() throws GenericConfigException { 90 return ComponentConfig.getURL(componentName, loaderName, location); 91 } 92 93 public boolean isFileResource() throws GenericConfigException { 94 return ComponentConfig.isFileResourceLoader(componentName, loaderName); 95 } 96 97 public String getFullLocation() throws GenericConfigException { 98 return ComponentConfig.getFullLocation(componentName, loaderName, location); 99 } 100 101 public boolean equals(Object obj) { 102 if (obj instanceof ComponentResourceHandler) { 103 ComponentResourceHandler other = (ComponentResourceHandler) obj; 104 105 if (this.loaderName.equals(other.loaderName) && 106 this.componentName.equals(other.componentName) && 107 this.location.equals(other.location)) { 108 return true; 109 } 110 } 111 return false; 112 } 113 114 public int hashCode() { 115 return (this.componentName.hashCode() + ((this.loaderName.hashCode() + this.location.hashCode()) >> 1)) >> 1; 117 } 118 119 public String toString() { 120 return "ComponentResourceHandler from XML file [" + this.componentName + "] with loaderName [" + loaderName + "] and location [" + location + "]"; 121 } 122 } 123 | Popular Tags |