Author: manik.surtani(a)jboss.com
Date: 2008-08-21 13:33:17 -0400 (Thu, 21 Aug 2008)
New Revision: 6594
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/CustomInterceptorsElementParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java
Log:
Null chks
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-08-21
15:02:58 UTC (rev 6593)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-08-21
17:33:17 UTC (rev 6594)
@@ -259,7 +259,7 @@
{
if (element == null) return; //this element is optional
String asyncPoolSizeStr = getAttributeValue(element, "asyncPoolSize");
- if (asyncPoolSizeStr != null &&
!asyncPoolSizeStr.trim().equals(""))
+ if (existsAttribute(asyncPoolSizeStr))
{
try
{
@@ -306,21 +306,21 @@
{
if (element == null) return; //might not be specified
String enabled = getAttributeValue(element, "enabled");
- if (enabled != null) config.setExposeManagementStatistics(getBoolean(enabled));
+ config.setExposeManagementStatistics(getBoolean(enabled));
}
private void configureShutdown(Element element)
{
if (element == null) return;
String hookBehavior = getAttributeValue(element, "hookBehavior");
- if (hookBehavior != null) config.setShutdownHookBehavior(hookBehavior);
+ if (existsAttribute(hookBehavior)) config.setShutdownHookBehavior(hookBehavior);
}
private void configureTransport(Element element)
{
if (element == null) return; //transport might be missing
String clusterName = getAttributeValue(element, "clusterName");
- config.setClusterName(clusterName);
+ if (existsAttribute(clusterName)) config.setClusterName(clusterName);
String multiplexerStack = getAttributeValue(element,
"multiplexerStack");
if (existsAttribute(multiplexerStack))
config.setMultiplexerStack(multiplexerStack);
Element clusterConfig = getSingleElementInCoreNS("jgroupsConfig",
element);
@@ -378,7 +378,7 @@
private void configureSyncMode(Element element)
{
String replTimeout = getAttributeValue(element, "replTimeout");
- if (replTimeout != null) config.setSyncReplTimeout(getLong(replTimeout));
+ if (existsAttribute(replTimeout)) config.setSyncReplTimeout(getLong(replTimeout));
}
private void configureAsyncMode(Element element)
Modified: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java 2008-08-21
15:02:58 UTC (rev 6593)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java 2008-08-21
17:33:17 UTC (rev 6594)
@@ -21,9 +21,9 @@
*/
package org.jboss.cache.config.parsing;
+import org.jboss.util.StringPropertyReplacer;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-import org.jboss.util.StringPropertyReplacer;
/**
* Contains utility methods that might be useful to most of the parsers.
@@ -56,15 +56,15 @@
*/
protected boolean getBoolean(String str)
{
- return Boolean.valueOf(str);
+ return str == null ? false : Boolean.valueOf(str);
}
/**
- * Retunrs true if the given value is not empty.
+ * @return true if the given value is not empty.
*/
protected boolean existsAttribute(String attrValue)
{
- return attrValue.length() > 0;
+ return attrValue != null && attrValue.length() > 0;
}
/**
@@ -91,10 +91,12 @@
/**
* Beside querying the element for it's attribute value, it will look into the
value, if any, and replace the
* jboss properties(e.g. ${someValue:defaultValue}.
+ *
* @see StringPropertyReplacer#replaceProperties(value);
*/
protected String getAttributeValue(Element element, String attrName)
{
+ if (element == null || attrName == null) return null;
String value = element.getAttribute(attrName);
return value == null ? null : StringPropertyReplacer.replaceProperties(value);
}
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java 2008-08-21
15:02:58 UTC (rev 6593)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java 2008-08-21
17:33:17 UTC (rev 6594)
@@ -1,9 +1,9 @@
package org.jboss.cache.config.parsing.element;
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.parsing.XmlParserBase;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
import org.w3c.dom.Element;
import java.util.Properties;
@@ -24,7 +24,7 @@
{
BuddyReplicationConfig brc = new BuddyReplicationConfig();
String enabled = getAttributeValue(element, "enabled");
- if (existsAttribute(enabled)) brc.setEnabled(getBoolean(enabled));
+ brc.setEnabled(getBoolean(enabled));
String buddyPoolName = getAttributeValue(element, "poolName");
if (existsAttribute(buddyPoolName)) brc.setBuddyPoolName(buddyPoolName);
String buddyCommunicationTimeout = getAttributeValue(element,
"communicationTimeout");
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/CustomInterceptorsElementParser.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/CustomInterceptorsElementParser.java 2008-08-21
15:02:58 UTC (rev 6593)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/CustomInterceptorsElementParser.java 2008-08-21
17:33:17 UTC (rev 6594)
@@ -21,11 +21,11 @@
*/
package org.jboss.cache.config.parsing.element;
+import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.CustomInterceptorConfig;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.XmlParserBase;
import org.jboss.cache.config.parsing.ParsedAttributes;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.XmlParserBase;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.util.Util;
import org.w3c.dom.Element;
@@ -63,7 +63,7 @@
int index = -1;
String after = null;
String before = null;
-
+
Element interceptorElement = (Element) interceptorNodes.item(i);
String position = getAttributeValue(interceptorElement, "position");
if (existsAttribute(position) &&
"first".equalsIgnoreCase(position))
@@ -83,7 +83,7 @@
if (!existsAttribute(after)) after = null;
CommandInterceptor interceptor = buildCommandInterceptor(interceptorElement);
-
+
CustomInterceptorConfig customInterceptorConfig = new
CustomInterceptorConfig(interceptor, first, last, index, after, before);
interceptorConfigs.add(customInterceptorConfig);
}
@@ -96,6 +96,7 @@
private CommandInterceptor buildCommandInterceptor(Element element)
{
String interceptorClass = getAttributeValue(element, "class");
+ if (!existsAttribute(interceptorClass)) throw new
ConfigurationException("Interceptor class cannot be empty!");
CommandInterceptor result;
try
{
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java 2008-08-21
15:02:58 UTC (rev 6593)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java 2008-08-21
17:33:17 UTC (rev 6594)
@@ -76,7 +76,7 @@
Element node = (Element) nodesToPreload.item(i);
String fqn2preload = getAttributeValue(node, "fqn");
if (!existsAttribute(fqn2preload))
- throw new ConfigurationException("Missing 'fqn' attribute in
'preload\\norde' tag");
+ throw new ConfigurationException("Missing 'fqn' attribute in
'preload' element");
if (i > 0) result.append(",");
result.append(fqn2preload);
}