Author: adrianc
Date: Sun Oct 20 18:42:07 2013
New Revision: 1533946

URL: http://svn.apache.org/r1533946
Log:
Reformatted ComponentConfig.java - no functional change. This is in preparation 
for some refactoring.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/component/ComponentConfig.java

Modified: 
ofbiz/trunk/framework/base/src/org/ofbiz/base/component/ComponentConfig.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/component/ComponentConfig.java?rev=1533946&r1=1533945&r2=1533946&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/base/src/org/ofbiz/base/component/ComponentConfig.java 
(original)
+++ 
ofbiz/trunk/framework/base/src/org/ofbiz/base/component/ComponentConfig.java 
Sun Oct 20 18:42:07 2013
@@ -22,12 +22,13 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.security.KeyStore;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
-import java.security.KeyStore;
+
 import javax.xml.parsers.ParserConfigurationException;
 
 import javolution.util.FastList;
@@ -53,44 +54,10 @@ public class ComponentConfig {
 
     public static final String module = ComponentConfig.class.getName();
     public static final String OFBIZ_COMPONENT_XML_FILENAME = 
"ofbiz-component.xml";
-
     // this is not a UtilCache because reloading may cause problems
     protected static Map<String, ComponentConfig> componentConfigs = 
FastMap.newInstance();
     protected static Map<String, List<WebappInfo>> serverWebApps = 
FastMap.newInstance();
 
-    public static ComponentConfig getComponentConfig(String globalName) throws 
ComponentException {
-        // TODO: we need to look up the rootLocation from the container 
config, or this will blow up
-        return getComponentConfig(globalName, null);
-    }
-
-    public static ComponentConfig getComponentConfig(String globalName, String 
rootLocation) throws ComponentException {
-        ComponentConfig componentConfig = null;
-        if (UtilValidate.isNotEmpty(globalName)) {
-            componentConfig = componentConfigs.get(globalName);
-        }
-        if (componentConfig == null) {
-            if (rootLocation != null) {
-                synchronized (ComponentConfig.class) {
-                    if (UtilValidate.isNotEmpty(globalName)) {
-                        componentConfig = componentConfigs.get(globalName);
-                    }
-                    if (componentConfig == null) {
-                        componentConfig = new ComponentConfig(globalName, 
rootLocation);
-                        if 
(componentConfigs.containsKey(componentConfig.getGlobalName())) {
-                            Debug.logWarning("WARNING: Loading ofbiz-component 
using a global name that already exists, will over-write: " + 
componentConfig.getGlobalName(), module);
-                        }
-                        if (componentConfig.enabled()) {
-                            
componentConfigs.put(componentConfig.getGlobalName(), componentConfig);
-                        }
-                    }
-                }
-            } else {
-                throw new ComponentException("No component found named : " + 
globalName);
-            }
-        }
-        return componentConfig;
-    }
-
     public static Boolean componentExists(String componentName) {
         ComponentConfig componentConfig = componentConfigs.get(componentName);
         if (componentConfig == null) {
@@ -100,6 +67,20 @@ public class ComponentConfig {
         }
     }
 
+    public static List<ClasspathInfo> getAllClasspathInfos() {
+        return getAllClasspathInfos(null);
+    }
+
+    public static List<ClasspathInfo> getAllClasspathInfos(String 
componentName) {
+        List<ClasspathInfo> classpaths = FastList.newInstance();
+        for (ComponentConfig cc : getAllComponents()) {
+            if (componentName == null || 
componentName.equals(cc.getComponentName())) {
+                classpaths.addAll(cc.getClasspathInfos());
+            }
+        }
+        return classpaths;
+    }
+
     public static Collection<ComponentConfig> getAllComponents() {
         Collection<ComponentConfig> values = componentConfigs.values();
         if (values != null) {
@@ -110,18 +91,18 @@ public class ComponentConfig {
         }
     }
 
-    public static List<ClasspathInfo> getAllClasspathInfos() {
-        return getAllClasspathInfos(null);
+    public static List<ContainerConfig.Container> getAllContainers() {
+        return getAllContainers(null);
     }
 
-    public static List<ClasspathInfo> getAllClasspathInfos(String 
componentName) {
-        List<ClasspathInfo> classpaths = FastList.newInstance();
-        for (ComponentConfig cc: getAllComponents()) {
+    public static List<ContainerConfig.Container> getAllContainers(String 
componentName) {
+        List<ContainerConfig.Container> containers = FastList.newInstance();
+        for (ComponentConfig cc : getAllComponents()) {
             if (componentName == null || 
componentName.equals(cc.getComponentName())) {
-                classpaths.addAll(cc.getClasspathInfos());
+                containers.addAll(cc.getContainers());
             }
         }
-        return classpaths;
+        return containers;
     }
 
     public static List<EntityResourceInfo> getAllEntityResourceInfos(String 
type) {
@@ -130,13 +111,13 @@ public class ComponentConfig {
 
     public static List<EntityResourceInfo> getAllEntityResourceInfos(String 
type, String componentName) {
         List<EntityResourceInfo> entityInfos = FastList.newInstance();
-        for (ComponentConfig cc: getAllComponents()) {
+        for (ComponentConfig cc : getAllComponents()) {
             if (componentName == null || 
componentName.equals(cc.getComponentName())) {
                 List<EntityResourceInfo> ccEntityInfoList = 
cc.getEntityResourceInfos();
                 if (UtilValidate.isEmpty(type)) {
                     entityInfos.addAll(ccEntityInfoList);
                 } else {
-                    for (EntityResourceInfo entityResourceInfo: 
ccEntityInfoList) {
+                    for (EntityResourceInfo entityResourceInfo : 
ccEntityInfoList) {
                         if (type.equals(entityResourceInfo.type)) {
                             entityInfos.add(entityResourceInfo);
                         }
@@ -147,19 +128,33 @@ public class ComponentConfig {
         return entityInfos;
     }
 
+    public static List<KeystoreInfo> getAllKeystoreInfos() {
+        return getAllKeystoreInfos(null);
+    }
+
+    public static List<KeystoreInfo> getAllKeystoreInfos(String componentName) 
{
+        List<KeystoreInfo> keystoreInfos = FastList.newInstance();
+        for (ComponentConfig cc : getAllComponents()) {
+            if (componentName == null || 
componentName.equals(cc.getComponentName())) {
+                keystoreInfos.addAll(cc.getKeystoreInfos());
+            }
+        }
+        return keystoreInfos;
+    }
+
     public static List<ServiceResourceInfo> getAllServiceResourceInfos(String 
type) {
         return getAllServiceResourceInfos(type, null);
     }
 
     public static List<ServiceResourceInfo> getAllServiceResourceInfos(String 
type, String componentName) {
         List<ServiceResourceInfo> serviceInfos = FastList.newInstance();
-        for (ComponentConfig cc: getAllComponents()) {
+        for (ComponentConfig cc : getAllComponents()) {
             if (componentName == null || 
componentName.equals(cc.getComponentName())) {
                 List<ServiceResourceInfo> ccServiceInfoList = 
cc.getServiceResourceInfos();
                 if (UtilValidate.isEmpty(type)) {
                     serviceInfos.addAll(ccServiceInfoList);
                 } else {
-                    for (ServiceResourceInfo serviceResourceInfo: 
ccServiceInfoList) {
+                    for (ServiceResourceInfo serviceResourceInfo : 
ccServiceInfoList) {
                         if (type.equals(serviceResourceInfo.type)) {
                             serviceInfos.add(serviceResourceInfo);
                         }
@@ -176,7 +171,7 @@ public class ComponentConfig {
 
     public static List<TestSuiteInfo> getAllTestSuiteInfos(String 
componentName) {
         List<TestSuiteInfo> testSuiteInfos = FastList.newInstance();
-        for (ComponentConfig cc: getAllComponents()) {
+        for (ComponentConfig cc : getAllComponents()) {
             if (componentName == null || 
componentName.equals(cc.getComponentName())) {
                 testSuiteInfos.addAll(cc.getTestSuiteInfos());
             }
@@ -184,41 +179,13 @@ public class ComponentConfig {
         return testSuiteInfos;
     }
 
-    public static List<KeystoreInfo> getAllKeystoreInfos() {
-        return getAllKeystoreInfos(null);
-    }
-
-    public static List<KeystoreInfo> getAllKeystoreInfos(String componentName) 
{
-        List<KeystoreInfo> keystoreInfos = FastList.newInstance();
-        for (ComponentConfig cc: getAllComponents()) {
-            if (componentName == null || 
componentName.equals(cc.getComponentName())) {
-                keystoreInfos.addAll(cc.getKeystoreInfos());
-            }
-        }
-        return keystoreInfos;
-    }
-
-    public static KeystoreInfo getKeystoreInfo(String componentName, String 
keystoreName) {
-        for (ComponentConfig cc: getAllComponents()) {
-            if (componentName != null && 
componentName.equals(cc.getComponentName())) {
-                for (KeystoreInfo ks: cc.getKeystoreInfos()) {
-                    if (keystoreName != null && 
keystoreName.equals(ks.getName())) {
-                        return ks;
-                    }
-                }
-            }
-        }
-
-        return null;
-    }
-
     public static List<WebappInfo> getAllWebappResourceInfos() {
         return getAllWebappResourceInfos(null);
     }
 
     public static List<WebappInfo> getAllWebappResourceInfos(String 
componentName) {
         List<WebappInfo> webappInfos = FastList.newInstance();
-        for (ComponentConfig cc: getAllComponents()) {
+        for (ComponentConfig cc : getAllComponents()) {
             if (componentName == null || 
componentName.equals(cc.getComponentName())) {
                 webappInfos.addAll(cc.getWebappInfos());
             }
@@ -226,68 +193,10 @@ public class ComponentConfig {
         return webappInfos;
     }
 
-    public static List<ContainerConfig.Container> getAllContainers() {
-        return getAllContainers(null);
-    }
-
-    public static List<ContainerConfig.Container> getAllContainers(String 
componentName) {
-        List<ContainerConfig.Container> containers = FastList.newInstance();
-        for (ComponentConfig cc: getAllComponents()) {
-            if (componentName == null || 
componentName.equals(cc.getComponentName())) {
-                containers.addAll(cc.getContainers());
-            }
-        }
-        return containers;
-    }
-
-    public static boolean isFileResourceLoader(String componentName, String 
resourceLoaderName) throws ComponentException {
-        ComponentConfig cc = ComponentConfig.getComponentConfig(componentName);
-        if (cc == null) {
-            throw new ComponentException("Could not find component with name: 
" + componentName);
-        }
-        return cc.isFileResourceLoader(resourceLoaderName);
-    }
-
-    public static InputStream getStream(String componentName, String 
resourceLoaderName, String location) throws ComponentException {
-        ComponentConfig cc = ComponentConfig.getComponentConfig(componentName);
-        if (cc == null) {
-            throw new ComponentException("Could not find component with name: 
" + componentName);
-        }
-        return cc.getStream(resourceLoaderName, location);
-    }
-
-    public static URL getURL(String componentName, String resourceLoaderName, 
String location) throws ComponentException {
-        ComponentConfig cc = ComponentConfig.getComponentConfig(componentName);
-        if (cc == null) {
-            throw new ComponentException("Could not find component with name: 
" + componentName);
-        }
-        return cc.getURL(resourceLoaderName, location);
-    }
-
-    public static String getFullLocation(String componentName, String 
resourceLoaderName, String location) throws ComponentException {
-        ComponentConfig cc = ComponentConfig.getComponentConfig(componentName);
-        if (cc == null) {
-            throw new ComponentException("Could not find component with name: 
" + componentName);
-        }
-        return cc.getFullLocation(resourceLoaderName, location);
-    }
-
-    public static String getRootLocation(String componentName) throws 
ComponentException {
-        ComponentConfig cc = ComponentConfig.getComponentConfig(componentName);
-        if (cc == null) {
-            throw new ComponentException("Could not find component with name: 
" + componentName);
-        }
-        return cc.getRootLocation();
-    }
-
     public static List<WebappInfo> getAppBarWebInfos(String serverName) {
         return ComponentConfig.getAppBarWebInfos(serverName, null, null);
     }
 
-    public static List<WebappInfo> getAppBarWebInfos(String serverName, String 
menuName) {
-        return ComponentConfig.getAppBarWebInfos(serverName, null, menuName);
-    }
-
     public static List<WebappInfo> getAppBarWebInfos(String serverName, 
Comparator<? super String> comp, String menuName) {
         List<WebappInfo> webInfos = serverWebApps.get(serverName + menuName);
         if (webInfos == null) {
@@ -302,9 +211,9 @@ public class ComponentConfig {
                         tm = new TreeMap<String, WebappInfo>();
                     }
 
-                    for (ComponentConfig cc: getAllComponents()) {
-                        for (WebappInfo wInfo: cc.getWebappInfos()) {
-                            String key = 
UtilValidate.isNotEmpty(wInfo.position)? wInfo.position: wInfo.title;
+                    for (ComponentConfig cc : getAllComponents()) {
+                        for (WebappInfo wInfo : cc.getWebappInfos()) {
+                            String key = 
UtilValidate.isNotEmpty(wInfo.position) ? wInfo.position : wInfo.title;
                             if (serverName.equals(wInfo.server) && 
wInfo.appBarDisplay) {
                                 if (UtilValidate.isNotEmpty(menuName)) {
                                     if (menuName.equals(wInfo.menuName)) {
@@ -326,14 +235,97 @@ public class ComponentConfig {
         return webInfos;
     }
 
+    public static List<WebappInfo> getAppBarWebInfos(String serverName, String 
menuName) {
+        return ComponentConfig.getAppBarWebInfos(serverName, null, menuName);
+    }
+
+    public static ComponentConfig getComponentConfig(String globalName) throws 
ComponentException {
+        // TODO: we need to look up the rootLocation from the container 
config, or this will blow up
+        return getComponentConfig(globalName, null);
+    }
+
+    public static ComponentConfig getComponentConfig(String globalName, String 
rootLocation) throws ComponentException {
+        ComponentConfig componentConfig = null;
+        if (UtilValidate.isNotEmpty(globalName)) {
+            componentConfig = componentConfigs.get(globalName);
+        }
+        if (componentConfig == null) {
+            if (rootLocation != null) {
+                synchronized (ComponentConfig.class) {
+                    if (UtilValidate.isNotEmpty(globalName)) {
+                        componentConfig = componentConfigs.get(globalName);
+                    }
+                    if (componentConfig == null) {
+                        componentConfig = new ComponentConfig(globalName, 
rootLocation);
+                        if 
(componentConfigs.containsKey(componentConfig.getGlobalName())) {
+                            Debug.logWarning("WARNING: Loading ofbiz-component 
using a global name that already exists, will over-write: " + 
componentConfig.getGlobalName(), module);
+                        }
+                        if (componentConfig.enabled()) {
+                            
componentConfigs.put(componentConfig.getGlobalName(), componentConfig);
+                        }
+                    }
+                }
+            } else {
+                throw new ComponentException("No component found named : " + 
globalName);
+            }
+        }
+        return componentConfig;
+    }
+
+    public static String getFullLocation(String componentName, String 
resourceLoaderName, String location) throws ComponentException {
+        ComponentConfig cc = ComponentConfig.getComponentConfig(componentName);
+        if (cc == null) {
+            throw new ComponentException("Could not find component with name: 
" + componentName);
+        }
+        return cc.getFullLocation(resourceLoaderName, location);
+    }
+
+    public static KeystoreInfo getKeystoreInfo(String componentName, String 
keystoreName) {
+        for (ComponentConfig cc : getAllComponents()) {
+            if (componentName != null && 
componentName.equals(cc.getComponentName())) {
+                for (KeystoreInfo ks : cc.getKeystoreInfos()) {
+                    if (keystoreName != null && 
keystoreName.equals(ks.getName())) {
+                        return ks;
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+    public static String getRootLocation(String componentName) throws 
ComponentException {
+        ComponentConfig cc = ComponentConfig.getComponentConfig(componentName);
+        if (cc == null) {
+            throw new ComponentException("Could not find component with name: 
" + componentName);
+        }
+        return cc.getRootLocation();
+    }
+
+    public static InputStream getStream(String componentName, String 
resourceLoaderName, String location) throws ComponentException {
+        ComponentConfig cc = ComponentConfig.getComponentConfig(componentName);
+        if (cc == null) {
+            throw new ComponentException("Could not find component with name: 
" + componentName);
+        }
+        return cc.getStream(resourceLoaderName, location);
+    }
+
+    public static URL getURL(String componentName, String resourceLoaderName, 
String location) throws ComponentException {
+        ComponentConfig cc = ComponentConfig.getComponentConfig(componentName);
+        if (cc == null) {
+            throw new ComponentException("Could not find component with name: 
" + componentName);
+        }
+        return cc.getURL(resourceLoaderName, location);
+    }
+
     public static WebappInfo getWebAppInfo(String serverName, String 
contextRoot) {
         ComponentConfig.WebappInfo info = null;
         if (serverName == null || contextRoot == null) {
             return info;
         }
 
-        for (ComponentConfig cc: getAllComponents()) {
-            for (WebappInfo wInfo: cc.getWebappInfos()) {
+        for (ComponentConfig cc : getAllComponents()) {
+            for (WebappInfo wInfo : cc.getWebappInfos()) {
                 if (serverName.equals(wInfo.server) && 
contextRoot.equals(wInfo.getContextRoot())) {
                     info = wInfo;
                 }
@@ -342,6 +334,14 @@ public class ComponentConfig {
         return info;
     }
 
+    public static boolean isFileResourceLoader(String componentName, String 
resourceLoaderName) throws ComponentException {
+        ComponentConfig cc = ComponentConfig.getComponentConfig(componentName);
+        if (cc == null) {
+            throw new ComponentException("Could not find component with name: 
" + componentName);
+        }
+        return cc.isFileResourceLoader(resourceLoaderName);
+    }
+
     // ========== component info fields ==========
     protected String globalName = null;
     protected String rootLocation = null;
@@ -357,7 +357,8 @@ public class ComponentConfig {
     protected List<WebappInfo> webappInfos = FastList.newInstance();
     protected List<ContainerConfig.Container> containers = 
FastList.newInstance();
 
-    protected ComponentConfig() {}
+    protected ComponentConfig() {
+    }
 
     protected ComponentConfig(String globalName, String rootLocation) throws 
ComponentException {
         this.globalName = globalName;
@@ -365,7 +366,6 @@ public class ComponentConfig {
             rootLocation = rootLocation + "/";
         }
         this.rootLocation = rootLocation.replace('\\', '/');
-
         File rootLocationDir = new File(rootLocation);
         if (!rootLocationDir.exists()) {
             throw new ComponentException("The component root location does not 
exist: " + rootLocation);
@@ -373,13 +373,11 @@ public class ComponentConfig {
         if (!rootLocationDir.isDirectory()) {
             throw new ComponentException("The component root location is not a 
directory: " + rootLocation);
         }
-
         String xmlFilename = rootLocation + "/" + OFBIZ_COMPONENT_XML_FILENAME;
         URL xmlUrl = UtilURL.fromFilename(xmlFilename);
         if (xmlUrl == null) {
             throw new ComponentException("Could not find the " + 
OFBIZ_COMPONENT_XML_FILENAME + " configuration file in the component root 
location: " + rootLocation);
         }
-
         Document ofbizComponentDocument = null;
         try {
             ofbizComponentDocument = UtilXml.readXmlDocument(xmlUrl, true);
@@ -390,121 +388,75 @@ public class ComponentConfig {
         } catch (IOException e) {
             throw new ComponentException("Error reading the component config 
file: " + xmlUrl, e);
         }
-
         Element ofbizComponentElement = 
ofbizComponentDocument.getDocumentElement();
         this.componentName = ofbizComponentElement.getAttribute("name");
         this.enabled = 
"true".equalsIgnoreCase(ofbizComponentElement.getAttribute("enabled"));
         if (UtilValidate.isEmpty(this.globalName)) {
             this.globalName = this.componentName;
         }
-
         // resource-loader - resourceLoaderInfos
-        for (Element curElement: 
UtilXml.childElementList(ofbizComponentElement, "resource-loader")) {
+        for (Element curElement : 
UtilXml.childElementList(ofbizComponentElement, "resource-loader")) {
             ResourceLoaderInfo resourceLoaderInfo = new 
ResourceLoaderInfo(curElement);
             this.resourceLoaderInfos.put(resourceLoaderInfo.name, 
resourceLoaderInfo);
         }
-
         // classpath - classpathInfos
-        for (Element curElement: 
UtilXml.childElementList(ofbizComponentElement, "classpath")) {
+        for (Element curElement : 
UtilXml.childElementList(ofbizComponentElement, "classpath")) {
             ClasspathInfo classpathInfo = new ClasspathInfo(this, curElement);
             this.classpathInfos.add(classpathInfo);
         }
-
         // entity-resource - entityResourceInfos
-        for (Element curElement: 
UtilXml.childElementList(ofbizComponentElement, "entity-resource")) {
+        for (Element curElement : 
UtilXml.childElementList(ofbizComponentElement, "entity-resource")) {
             EntityResourceInfo entityResourceInfo = new 
EntityResourceInfo(this, curElement);
             this.entityResourceInfos.add(entityResourceInfo);
         }
-
         // service-resource - serviceResourceInfos
-        for (Element curElement: 
UtilXml.childElementList(ofbizComponentElement, "service-resource")) {
+        for (Element curElement : 
UtilXml.childElementList(ofbizComponentElement, "service-resource")) {
             ServiceResourceInfo serviceResourceInfo = new 
ServiceResourceInfo(this, curElement);
             this.serviceResourceInfos.add(serviceResourceInfo);
         }
-
         // test-suite - serviceResourceInfos
-        for (Element curElement: 
UtilXml.childElementList(ofbizComponentElement, "test-suite")) {
+        for (Element curElement : 
UtilXml.childElementList(ofbizComponentElement, "test-suite")) {
             TestSuiteInfo testSuiteInfo = new TestSuiteInfo(this, curElement);
             this.testSuiteInfos.add(testSuiteInfo);
         }
-
         // keystore - (cert/trust store infos)
-        for (Element curElement: 
UtilXml.childElementList(ofbizComponentElement, "keystore")) {
+        for (Element curElement : 
UtilXml.childElementList(ofbizComponentElement, "keystore")) {
             KeystoreInfo keystoreInfo = new KeystoreInfo(this, curElement);
             this.keystoreInfos.add(keystoreInfo);
         }
-
         // webapp - webappInfos
-        for (Element curElement: 
UtilXml.childElementList(ofbizComponentElement, "webapp")) {
+        for (Element curElement : 
UtilXml.childElementList(ofbizComponentElement, "webapp")) {
             WebappInfo webappInfo = new WebappInfo(this, curElement);
             this.webappInfos.add(webappInfo);
         }
-
         // containers
         try {
             this.containers.addAll(ContainerConfig.getContainers(xmlUrl));
-        } catch(ContainerException ce) {
+        } catch (ContainerException ce) {
             throw new ComponentException("Error reading containers for 
component: " + this.globalName, ce);
         }
-
-        if (Debug.verboseOn()) Debug.logVerbose("Read component config : [" + 
rootLocation + "]", module);
+        if (Debug.verboseOn())
+            Debug.logVerbose("Read component config : [" + rootLocation + "]", 
module);
     }
 
-    public boolean isFileResource(ResourceInfo resourceInfo) throws 
ComponentException {
-        return isFileResourceLoader(resourceInfo.loader);
+    public boolean enabled() {
+        return this.enabled;
     }
-    public boolean isFileResourceLoader(String resourceLoaderName) throws 
ComponentException {
-        ResourceLoaderInfo resourceLoaderInfo = 
resourceLoaderInfos.get(resourceLoaderName);
-        if (resourceLoaderInfo == null) {
-            throw new ComponentException("Could not find resource-loader 
named: " + resourceLoaderName);
-        }
-        return "file".equals(resourceLoaderInfo.type) || 
"component".equals(resourceLoaderInfo.type);
+
+    public List<ClasspathInfo> getClasspathInfos() {
+        return this.classpathInfos;
     }
 
-    public InputStream getStream(String resourceLoaderName, String location) 
throws ComponentException {
-        URL url = getURL(resourceLoaderName, location);
-        try {
-            return url.openStream();
-        } catch (java.io.IOException e) {
-            throw new ComponentException("Error opening resource at location 
[" + url.toExternalForm() + "]", e);
-        }
+    public String getComponentName() {
+        return this.componentName;
     }
 
-    public URL getURL(String resourceLoaderName, String location) throws 
ComponentException {
-        ResourceLoaderInfo resourceLoaderInfo = 
resourceLoaderInfos.get(resourceLoaderName);
-        if (resourceLoaderInfo == null) {
-            throw new ComponentException("Could not find resource-loader 
named: " + resourceLoaderName);
-        }
+    public List<ContainerConfig.Container> getContainers() {
+        return this.containers;
+    }
 
-        if ("component".equals(resourceLoaderInfo.type) || 
"file".equals(resourceLoaderInfo.type)) {
-            String fullLocation = getFullLocation(resourceLoaderName, 
location);
-            URL fileUrl = UtilURL.fromFilename(fullLocation);
-            if (fileUrl == null) {
-                throw new ComponentException("File Resource not found: " + 
fullLocation);
-            }
-            return fileUrl;
-        } else if ("classpath".equals(resourceLoaderInfo.type)) {
-            String fullLocation = getFullLocation(resourceLoaderName, 
location);
-            URL url = UtilURL.fromResource(fullLocation);
-            if (url == null) {
-                throw new ComponentException("Classpath Resource not found: " 
+ fullLocation);
-            }
-            return url;
-        } else if ("url".equals(resourceLoaderInfo.type)) {
-            String fullLocation = getFullLocation(resourceLoaderName, 
location);
-            URL url = null;
-            try {
-                url = FlexibleLocation.resolveLocation(location);
-            } catch (java.net.MalformedURLException e) {
-                throw new ComponentException("Error with malformed URL while 
trying to load URL resource at location [" + fullLocation + "]", e);
-            }
-            if (url == null) {
-                throw new ComponentException("URL Resource not found: " + 
fullLocation);
-            }
-            return url;
-        } else {
-            throw new ComponentException("The resource-loader type is not 
recognized: " + resourceLoaderInfo.type);
-        }
+    public List<EntityResourceInfo> getEntityResourceInfos() {
+        return this.entityResourceInfos;
     }
 
     public String getFullLocation(String resourceLoaderName, String location) 
throws ComponentException {
@@ -512,9 +464,7 @@ public class ComponentConfig {
         if (resourceLoaderInfo == null) {
             throw new ComponentException("Could not find resource-loader 
named: " + resourceLoaderName);
         }
-
         StringBuilder buf = new StringBuilder();
-
         // pre-pend component root location if this is a type component 
resource-loader
         if ("component".equals(resourceLoaderInfo.type)) {
             buf.append(rootLocation);
@@ -536,22 +486,14 @@ public class ComponentConfig {
         return buf.toString();
     }
 
-    public List<ClasspathInfo> getClasspathInfos() {
-        return this.classpathInfos;
-    }
-
-    public String getComponentName() {
-        return this.componentName;
-    }
-
-    public List<EntityResourceInfo> getEntityResourceInfos() {
-        return this.entityResourceInfos;
-    }
-
     public String getGlobalName() {
         return this.globalName;
     }
 
+    public List<KeystoreInfo> getKeystoreInfos() {
+        return this.keystoreInfos;
+    }
+
     public Map<String, ResourceLoaderInfo> getResourceLoaderInfos() {
         return this.resourceLoaderInfos;
     }
@@ -564,58 +506,69 @@ public class ComponentConfig {
         return this.serviceResourceInfos;
     }
 
+    public InputStream getStream(String resourceLoaderName, String location) 
throws ComponentException {
+        URL url = getURL(resourceLoaderName, location);
+        try {
+            return url.openStream();
+        } catch (java.io.IOException e) {
+            throw new ComponentException("Error opening resource at location 
[" + url.toExternalForm() + "]", e);
+        }
+    }
+
     public List<TestSuiteInfo> getTestSuiteInfos() {
         return this.testSuiteInfos;
     }
 
-    public List<KeystoreInfo> getKeystoreInfos() {
-        return this.keystoreInfos;
+    public URL getURL(String resourceLoaderName, String location) throws 
ComponentException {
+        ResourceLoaderInfo resourceLoaderInfo = 
resourceLoaderInfos.get(resourceLoaderName);
+        if (resourceLoaderInfo == null) {
+            throw new ComponentException("Could not find resource-loader 
named: " + resourceLoaderName);
+        }
+        if ("component".equals(resourceLoaderInfo.type) || 
"file".equals(resourceLoaderInfo.type)) {
+            String fullLocation = getFullLocation(resourceLoaderName, 
location);
+            URL fileUrl = UtilURL.fromFilename(fullLocation);
+            if (fileUrl == null) {
+                throw new ComponentException("File Resource not found: " + 
fullLocation);
+            }
+            return fileUrl;
+        } else if ("classpath".equals(resourceLoaderInfo.type)) {
+            String fullLocation = getFullLocation(resourceLoaderName, 
location);
+            URL url = UtilURL.fromResource(fullLocation);
+            if (url == null) {
+                throw new ComponentException("Classpath Resource not found: " 
+ fullLocation);
+            }
+            return url;
+        } else if ("url".equals(resourceLoaderInfo.type)) {
+            String fullLocation = getFullLocation(resourceLoaderName, 
location);
+            URL url = null;
+            try {
+                url = FlexibleLocation.resolveLocation(location);
+            } catch (java.net.MalformedURLException e) {
+                throw new ComponentException("Error with malformed URL while 
trying to load URL resource at location [" + fullLocation + "]", e);
+            }
+            if (url == null) {
+                throw new ComponentException("URL Resource not found: " + 
fullLocation);
+            }
+            return url;
+        } else {
+            throw new ComponentException("The resource-loader type is not 
recognized: " + resourceLoaderInfo.type);
+        }
     }
 
     public List<WebappInfo> getWebappInfos() {
         return this.webappInfos;
     }
 
-    public List<ContainerConfig.Container> getContainers() {
-        return this.containers;
-    }
-
-    public boolean enabled() {
-        return this.enabled;
-    }
-
-    public static class ResourceLoaderInfo {
-        public String name;
-        public String type;
-        public String prependEnv;
-        public String prefix;
-
-        public ResourceLoaderInfo(Element element) {
-            this.name = element.getAttribute("name");
-            this.type = element.getAttribute("type");
-            this.prependEnv = element.getAttribute("prepend-env");
-            this.prefix = element.getAttribute("prefix");
-        }
+    public boolean isFileResource(ResourceInfo resourceInfo) throws 
ComponentException {
+        return isFileResourceLoader(resourceInfo.loader);
     }
 
-    public static class ResourceInfo {
-        public ComponentConfig componentConfig;
-        public String loader;
-        public String location;
-
-        public ResourceInfo(ComponentConfig componentConfig, Element element) {
-            this.componentConfig = componentConfig;
-            this.loader = element.getAttribute("loader");
-            this.location = element.getAttribute("location");
-        }
-
-        public ComponentResourceHandler createResourceHandler() {
-            return new 
ComponentResourceHandler(componentConfig.getGlobalName(), loader, location);
-        }
-
-        public String getLocation() {
-            return location;
+    public boolean isFileResourceLoader(String resourceLoaderName) throws 
ComponentException {
+        ResourceLoaderInfo resourceLoaderInfo = 
resourceLoaderInfos.get(resourceLoaderName);
+        if (resourceLoaderInfo == null) {
+            throw new ComponentException("Could not find resource-loader 
named: " + resourceLoaderName);
         }
+        return "file".equals(resourceLoaderInfo.type) || 
"component".equals(resourceLoaderInfo.type);
     }
 
     public static class ClasspathInfo {
@@ -641,21 +594,6 @@ public class ComponentConfig {
         }
     }
 
-    public static class ServiceResourceInfo extends ResourceInfo {
-        public String type;
-
-        public ServiceResourceInfo(ComponentConfig componentConfig, Element 
element) {
-            super(componentConfig, element);
-            this.type = element.getAttribute("type");
-        }
-    }
-
-    public static class TestSuiteInfo extends ResourceInfo {
-        public TestSuiteInfo(ComponentConfig componentConfig, Element element) 
{
-            super(componentConfig, element);
-        }
-    }
-
     public static class KeystoreInfo extends ResourceInfo {
         public String name;
         public String type;
@@ -688,14 +626,14 @@ public class ComponentConfig {
             return name;
         }
 
-        public String getType() {
-            return type;
-        }
-
         public String getPassword() {
             return password;
         }
 
+        public String getType() {
+            return type;
+        }
+
         public boolean isCertStore() {
             return isCertStore;
         }
@@ -705,6 +643,55 @@ public class ComponentConfig {
         }
     }
 
+    public static class ResourceInfo {
+        public ComponentConfig componentConfig;
+        public String loader;
+        public String location;
+
+        public ResourceInfo(ComponentConfig componentConfig, Element element) {
+            this.componentConfig = componentConfig;
+            this.loader = element.getAttribute("loader");
+            this.location = element.getAttribute("location");
+        }
+
+        public ComponentResourceHandler createResourceHandler() {
+            return new 
ComponentResourceHandler(componentConfig.getGlobalName(), loader, location);
+        }
+
+        public String getLocation() {
+            return location;
+        }
+    }
+
+    public static class ResourceLoaderInfo {
+        public String name;
+        public String type;
+        public String prependEnv;
+        public String prefix;
+
+        public ResourceLoaderInfo(Element element) {
+            this.name = element.getAttribute("name");
+            this.type = element.getAttribute("type");
+            this.prependEnv = element.getAttribute("prepend-env");
+            this.prefix = element.getAttribute("prefix");
+        }
+    }
+
+    public static class ServiceResourceInfo extends ResourceInfo {
+        public String type;
+
+        public ServiceResourceInfo(ComponentConfig componentConfig, Element 
element) {
+            super(componentConfig, element);
+            this.type = element.getAttribute("type");
+        }
+    }
+
+    public static class TestSuiteInfo extends ResourceInfo {
+        public TestSuiteInfo(ComponentConfig componentConfig, Element element) 
{
+            super(componentConfig, element);
+        }
+    }
+
     public static class WebappInfo {
         public ComponentConfig componentConfig;
         public List<String> virtualHosts;
@@ -742,7 +729,6 @@ public class ComponentConfig {
                 // default base permission is NONE
                 this.basePermission = new String[] { "NONE" };
             }
-
             // trim the permissions (remove spaces)
             for (int i = 0; i < this.basePermission.length; i++) {
                 this.basePermission[i] = this.basePermission[i].trim();
@@ -750,30 +736,24 @@ public class ComponentConfig {
                     this.basePermission[i] = 
this.basePermission[i].substring(0, this.basePermission[i].indexOf('_'));
                 }
             }
-
             // default title is name w/ upper-cased first letter
             if (UtilValidate.isEmpty(this.title)) {
                 this.title = Character.toUpperCase(name.charAt(0)) + 
name.substring(1).toLowerCase();
             }
-
             if (UtilValidate.isEmpty(this.description)) {
                 this.description = this.title;
             }
-
             String menuNameStr = element.getAttribute("menu-name");
             if (UtilValidate.isNotEmpty(menuNameStr)) {
                 this.menuName = menuNameStr;
             } else {
                 this.menuName = "main";
             }
-
             this.position = element.getAttribute("position");
-
             // default mount point is name if none specified
             if (UtilValidate.isEmpty(this.mountPoint)) {
                 this.mountPoint = this.name;
             }
-
             // check the mount point and make sure it is properly formatted
             if (!"/".equals(this.mountPoint)) {
                 if (!this.mountPoint.startsWith("/")) {
@@ -786,24 +766,26 @@ public class ComponentConfig {
                     this.mountPoint = this.mountPoint + "*";
                 }
             }
-
             // load the virtual hosts
             List<? extends Element> virtHostList = 
UtilXml.childElementList(element, "virtual-host");
             if (UtilValidate.isNotEmpty(virtHostList)) {
-                for (Element e: virtHostList) {
+                for (Element e : virtHostList) {
                     virtualHosts.add(e.getAttribute("host-name"));
                 }
             }
-
             // load the init parameters
             List<? extends Element> initParamList = 
UtilXml.childElementList(element, "init-param");
             if (UtilValidate.isNotEmpty(initParamList)) {
-                for (Element e: initParamList) {
+                for (Element e : initParamList) {
                     this.initParameters.put(e.getAttribute("name"), 
e.getAttribute("value"));
                 }
             }
         }
 
+        public String[] getBasePermission() {
+            return this.basePermission;
+        }
+
         public String getContextRoot() {
             if (mountPoint.endsWith("/*")) {
                 return mountPoint.substring(0, mountPoint.length() - 2);
@@ -811,34 +793,30 @@ public class ComponentConfig {
             return mountPoint;
         }
 
-        public String[] getBasePermission() {
-            return this.basePermission;
+        public String getDescription() {
+            return description;
         }
 
-        public String getName() {
-            return name;
+        public Map<String, String> getInitParameters() {
+            return initParameters;
         }
 
         public String getLocation() {
             return componentConfig.getRootLocation() + location;
         }
 
-        public String getTitle() {
-            return title;
+        public String getName() {
+            return name;
         }
 
-        public String getDescription() {
-            return description;
+        public String getTitle() {
+            return title;
         }
 
         public List<String> getVirtualHosts() {
             return virtualHosts;
         }
 
-        public Map<String, String> getInitParameters() {
-            return initParameters;
-        }
-
         public boolean isSessionCookieAccepted() {
             return sessionCookieAccepted;
         }


Reply via email to