Author: doogie
Date: Wed Oct 17 14:56:36 2007 New Revision: 585720 URL: http://svn.apache.org/viewvc?rev=585720&view=rev Log: Java 1.5 markup for config and containers. Closes https://issues.apache.org/jira/browse/OFBIZ-1335 Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/JNDIConfigUtil.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/ResourceLoader.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/SecurityConfigUtil.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ContainerConfig.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ContainerLoader.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/JunitContainer.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/JNDIConfigUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/JNDIConfigUtil.java?rev=585720&r1=585719&r2=585720&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/JNDIConfigUtil.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/JNDIConfigUtil.java Wed Oct 17 14:56:36 2007 @@ -33,7 +33,7 @@ public static final String module = JNDIConfigUtil.class.getName(); public static final String JNDI_CONFIG_XML_FILENAME = "jndiservers.xml"; - protected static Map jndiServerInfos = FastMap.newInstance(); + protected static Map<String, JndiServerInfo> jndiServerInfos = FastMap.newInstance(); protected static Element getXmlRootElement() throws GenericConfigException { try { @@ -59,14 +59,8 @@ } } public static void initialize(Element rootElement) throws GenericConfigException { - List childElements = null; - Iterator elementIter = null; - // jndi-server - jndiServerInfos - childElements = UtilXml.childElementList(rootElement, "jndi-server"); - elementIter = childElements.iterator(); - while (elementIter.hasNext()) { - Element curElement = (Element) elementIter.next(); + for (Element curElement: UtilXml.childElementList(rootElement, "jndi-server")) { JNDIConfigUtil.JndiServerInfo jndiServerInfo = new JNDIConfigUtil.JndiServerInfo(curElement); JNDIConfigUtil.jndiServerInfos.put(jndiServerInfo.name, jndiServerInfo); @@ -74,7 +68,7 @@ } public static JNDIConfigUtil.JndiServerInfo getJndiServerInfo(String name) { - return (JNDIConfigUtil.JndiServerInfo) jndiServerInfos.get(name); + return jndiServerInfos.get(name); } public static final class JndiServerInfo { Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/ResourceLoader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/ResourceLoader.java?rev=585720&r1=585719&r2=585720&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/ResourceLoader.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/ResourceLoader.java Wed Oct 17 14:56:36 2007 @@ -35,7 +35,7 @@ public abstract class ResourceLoader { public static final String module = ResourceLoader.class.getName(); - protected static UtilCache loaderCache = new UtilCache("resource.ResourceLoaders", 0, 0); + protected static UtilCache<String, Object> loaderCache = new UtilCache<String, Object>("resource.ResourceLoaders", 0, 0); protected String name; protected String prefix; Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/SecurityConfigUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/SecurityConfigUtil.java?rev=585720&r1=585719&r2=585720&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/SecurityConfigUtil.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/config/SecurityConfigUtil.java Wed Oct 17 14:56:36 2007 @@ -40,7 +40,7 @@ /** The security config filename */ public static final String SECURITY_CONFIG_XML_FILENAME = "security.xml"; - protected static Map securityInfos = FastMap.newInstance(); + protected static Map<String, SecurityInfo> securityInfos = FastMap.newInstance(); /** * Returns the XmlRootElement for the security config @@ -77,14 +77,8 @@ * @throws GenericConfigException */ public static void initialize(Element rootElement) throws GenericConfigException { - List childElements = null; - Iterator elementIter = null; - // security-config - securityInfos - childElements = UtilXml.childElementList(rootElement, "security"); - elementIter = childElements.iterator(); - while (elementIter.hasNext()) { - Element curElement = (Element) elementIter.next(); + for (Element curElement: UtilXml.childElementList(rootElement, "security")) { SecurityConfigUtil.SecurityInfo securityInfo = new SecurityConfigUtil.SecurityInfo(curElement); if (Debug.verboseOn()) Debug.logVerbose("LOADED SECURITY CONFIG FROM XML - NAME: " + securityInfo.name + " ClassName: " + securityInfo.className, module); @@ -99,7 +93,7 @@ * @return */ public static SecurityConfigUtil.SecurityInfo getSecurityInfo(String name) { - return (SecurityConfigUtil.SecurityInfo) securityInfos.get(name); + return securityInfos.get(name); } /** Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java?rev=585720&r1=585719&r2=585720&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java Wed Oct 17 14:56:36 2007 @@ -99,7 +99,7 @@ } // get the components to load - List components = ComponentLoaderConfig.getRootComponents(loaderConfig); + List<ComponentLoaderConfig.ComponentDef> components = ComponentLoaderConfig.getRootComponents(loaderConfig); String parentPath; try { @@ -111,9 +111,7 @@ } // load each component if (components != null) { - Iterator ci = components.iterator(); - while (ci.hasNext()) { - ComponentLoaderConfig.ComponentDef def = (ComponentLoaderConfig.ComponentDef) ci.next(); + for (ComponentLoaderConfig.ComponentDef def: components) { this.loadComponentFromConfig(parentPath, def); } } @@ -166,11 +164,9 @@ URL configUrl = null; try { configUrl = componentLoadConfig.toURI().toURL(); - List componentsToLoad = ComponentLoaderConfig.getComponentsFromConfig(configUrl); + List<ComponentLoaderConfig.ComponentDef> componentsToLoad = ComponentLoaderConfig.getComponentsFromConfig(configUrl); if (componentsToLoad != null) { - Iterator i = componentsToLoad.iterator(); - while (i.hasNext()) { - ComponentLoaderConfig.ComponentDef def = (ComponentLoaderConfig.ComponentDef) i.next(); + for (ComponentLoaderConfig.ComponentDef def: componentsToLoad) { this.loadComponentFromConfig(parentPath.toString(), def); } } @@ -180,11 +176,10 @@ Debug.logError(e, "Unable to load components from URL: " + configUrl.toExternalForm(), module); } } else { - String subs[] = parentPath.list(); - for (int i = 0; i < subs.length; i++) { + for (String sub: parentPath.list()) { try { - File componentPath = new File(parentPath.getCanonicalPath() + "/" + subs[i]); - if (componentPath.isDirectory() && !subs[i].equals("CVS")) { + File componentPath = new File(parentPath.getCanonicalPath() + "/" + sub); + if (componentPath.isDirectory() && !sub.equals("CVS")) { // make sure we have a component configuraton file String componentLocation = componentPath.getCanonicalPath(); File configFile = new File(componentLocation + "/ofbiz-component.xml"); @@ -219,7 +214,7 @@ } Debug.logInfo("Loading component : [" + config.getComponentName() + "]", module); - List classpathInfos = config.getClasspathInfos(); + List<ComponentConfig.ClasspathInfo> classpathInfos = config.getClasspathInfos(); String configRoot = config.getRootLocation(); configRoot = configRoot.replace('\\', '/'); // set the root to have a trailing slash @@ -227,9 +222,7 @@ configRoot = configRoot + "/"; } if (classpathInfos != null) { - Iterator cpi = classpathInfos.iterator(); - while (cpi.hasNext()) { - ComponentConfig.ClasspathInfo cp = (ComponentConfig.ClasspathInfo) cpi.next(); + for (ComponentConfig.ClasspathInfo cp: classpathInfos) { String location = cp.location.replace('\\', '/'); // set the location to not have a leading slash if (location.startsWith("/")) { @@ -248,10 +241,10 @@ if (path.isDirectory()) { // load all .jar and .zip files in this directory File files[] = path.listFiles(); - for (int i = 0; i < files.length; i++) { - String file = files[i].getName(); - if (file.endsWith(".jar") || file.endsWith(".zip")) { - classPath.addComponent(files[i]); + for (File file: path.listFiles()) { + String fileName = file.getName(); + if (fileName.endsWith(".jar") || fileName.endsWith(".zip")) { + classPath.addComponent(file); } } } else { Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ContainerConfig.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ContainerConfig.java?rev=585720&r1=585719&r2=585720&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ContainerConfig.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ContainerConfig.java Wed Oct 17 14:56:36 2007 @@ -44,13 +44,13 @@ public static final String module = ContainerConfig.class.getName(); - protected static Map containers = new LinkedHashMap(); + protected static Map<String, Container> containers = new LinkedHashMap<String, Container>(); public static Container getContainer(String containerName, String configFile) throws ContainerException { - Container container = (Container) containers.get(containerName); + Container container = containers.get(containerName); if (container == null) { synchronized (ContainerConfig.class) { - container = (Container) containers.get(containerName); + container = containers.get(containerName); if (container == null) { if (configFile == null) { throw new ContainerException("Container config file cannot be null"); @@ -66,7 +66,7 @@ return container; } - public static Collection getContainers(String configFile) throws ContainerException { + public static Collection<Container> getContainers(String configFile) throws ContainerException { if (containers.size() == 0) { synchronized (ContainerConfig.class) { if (containers.size() == 0) { @@ -174,9 +174,7 @@ Element root = containerDocument.getDocumentElement(); // containers - Iterator elementIter = UtilXml.childElementList(root, "container").iterator(); - while (elementIter.hasNext()) { - Element curElement = (Element) elementIter.next(); + for (Element curElement: UtilXml.childElementList(root, "container")) { Container container = new Container(curElement); containers.put(container.name, container); } @@ -185,32 +183,27 @@ public static class Container { public String name; public String className; - public Map properties; + public Map<String, Property> properties; public Container(Element element) { this.name = element.getAttribute("name"); this.className = element.getAttribute("class"); - properties = new LinkedHashMap(); - Iterator elementIter = UtilXml.childElementList(element, "property").iterator(); - while (elementIter.hasNext()) { - Element curElement = (Element) elementIter.next(); + properties = new LinkedHashMap<String, Property>(); + for (Element curElement: UtilXml.childElementList(element, "property")) { Property property = new Property(curElement); properties.put(property.name, property); } } public Property getProperty(String name) { - return (Property) properties.get(name); + return properties.get(name); } - public List getPropertiesWithValue(String value) { - List props = new LinkedList(); + public List<Property> getPropertiesWithValue(String value) { + List<Property> props = new LinkedList<Property>(); if (properties != null && properties.size() > 0) { - Iterator i = properties.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry e = (Map.Entry) i.next(); - Property p = (Property) e.getValue(); + for (Property p: properties.values()) { if (p != null && value.equals(p.value)) { props.add(p); } @@ -222,7 +215,7 @@ public static class Property { public String name; public String value; - public Map properties; + public Map<String, Property> properties; public Property(Element element) { this.name = element.getAttribute("name"); @@ -231,26 +224,21 @@ this.value = UtilXml.childElementValue(element, "property-value"); } - properties = new LinkedHashMap(); - Iterator elementIter = UtilXml.childElementList(element, "property").iterator(); - while (elementIter.hasNext()) { - Element curElement = (Element) elementIter.next(); + properties = new LinkedHashMap<String, Property>(); + for (Element curElement: UtilXml.childElementList(element, "property")) { Property property = new Property(curElement); properties.put(property.name, property); } } public Property getProperty(String name) { - return (Property) properties.get(name); + return properties.get(name); } - public List getPropertiesWithValue(String value) { - List props = new LinkedList(); + public List<Property> getPropertiesWithValue(String value) { + List<Property> props = new LinkedList<Property>(); if (properties != null && properties.size() > 0) { - Iterator i = properties.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry e = (Map.Entry) i.next(); - Property p = (Property) e.getValue(); + for (Property p: properties.values()) { if (p != null && value.equals(p.value)) { props.add(p); } Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ContainerLoader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ContainerLoader.java?rev=585720&r1=585719&r2=585720&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ContainerLoader.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ContainerLoader.java Wed Oct 17 14:56:36 2007 @@ -40,7 +40,7 @@ public static final String CONTAINER_CONFIG = "ofbiz-containers.xml"; private static boolean loaded = false; - protected List loadedContainers = new LinkedList(); + protected List<Container> loadedContainers = new LinkedList<Container>(); protected String configFile = null; /** @@ -53,7 +53,7 @@ // get the master container configuration file this.configFile = config.containerConfig; - Collection containers = null; + Collection<ContainerConfig.Container> containers = null; try { containers = ContainerConfig.getContainers(configFile); } catch (ContainerException e) { @@ -61,9 +61,7 @@ } if (containers != null) { - Iterator i = containers.iterator(); - while (i.hasNext()) { - ContainerConfig.Container containerCfg = (ContainerConfig.Container) i.next(); + for (ContainerConfig.Container containerCfg: containers) { loadedContainers.add(loadContainer(containerCfg, args)); } } @@ -76,8 +74,7 @@ Debug.logInfo("[Startup] Starting containers...", module); // start each container object - for (int i = 0; i < loadedContainers.size(); i++) { - Container container = (Container) loadedContainers.get(i); + for (Container container: loadedContainers) { try { container.start(); } catch (ContainerException e) { @@ -98,7 +95,7 @@ // shutting down in reverse order for (int i = loadedContainers.size(); i > 0; i--) { - Container container = (Container) loadedContainers.get(i-1); + Container container = loadedContainers.get(i-1); try { container.stop(); } catch (ContainerException e) { @@ -119,14 +116,14 @@ StringWriter writer = new StringWriter(); PrintWriter out = new PrintWriter(writer); out.println("Thread dump:"); - for (int i = 0; i < threadArr.length; i++) { - if (threadArr[i] != null) { - ThreadGroup g = threadArr[i].getThreadGroup(); - out.println("Thread: " + threadArr[i].getName() + " [" + threadArr[i].getId() + "] @ " + (g != null ? g.getName() : "[none]") + " : " + threadArr[i].getPriority() + " [" + threadArr[i].getState().name() + "]"); - out.println("--- Alive: " + threadArr[i].isAlive() + " Daemon: " + threadArr[i].isDaemon()); - StackTraceElement[] stacks = threadArr[i].getStackTrace(); - for (int x = 0; x < stacks.length; x++) { - out.println("### " + stacks[x].toString()); + for (Thread t: threadArr) { + if (t != null) { + ThreadGroup g = t.getThreadGroup(); + out.println("Thread: " + t.getName() + " [" + t.getId() + "] @ " + (g != null ? g.getName() : "[none]") + " : " + t.getPriority() + " [" + t.getState().name() + "]"); + out.println("--- Alive: " + t.isAlive() + " Daemon: " + t.isDaemon()); + StackTraceElement[] stacks = t.getStackTrace(); + for (StackTraceElement stack: t.getStackTrace()) { + out.println("### " + stack.toString()); } } } Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/JunitContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/JunitContainer.java?rev=585720&r1=585719&r2=585720&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/JunitContainer.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/JunitContainer.java Wed Oct 17 14:56:36 2007 @@ -44,7 +44,7 @@ ContainerConfig.Container jc = ContainerConfig.getContainer("junit-container", configFile); // get the tests to run - Iterator ti = jc.properties.values().iterator(); + Iterator<ContainerConfig.Container.Property> ti = jc.properties.values().iterator(); if (ti == null) { Debug.log("No tests to load", module); return true; @@ -53,7 +53,7 @@ // load the tests into the suite TestSuite suite = new TestSuite(); while (ti.hasNext()) { - ContainerConfig.Container.Property prop = (ContainerConfig.Container.Property) ti.next(); + ContainerConfig.Container.Property prop = ti.next(); Class clz = null; try { clz = ObjectType.loadClass(prop.value); |
Free forum by Nabble | Edit this page |