[jboss-cvs] JBoss Messaging SVN: r7379 - in trunk: src/main/org/jboss/messaging/core/config/impl and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 17 07:52:03 EDT 2009


Author: jmesnil
Date: 2009-06-17 07:52:03 -0400 (Wed, 17 Jun 2009)
New Revision: 7379

Added:
   trunk/src/main/org/jboss/messaging/core/config/impl/Validators.java
   trunk/src/main/org/jboss/messaging/utils/XMLConfigurationUtil.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/config/impl/ValidatorsTest.java
Modified:
   trunk/src/config/common/schema/jbm-configuration.xsd
   trunk/src/config/common/schema/jbm-jms.xsd
   trunk/src/main/org/jboss/messaging/core/config/impl/FileConfiguration.java
   trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java
Log:
JBMESSAGING-1639: Validate configuration values programmatically

* removed types constraints from the XSD files and use programmatic
  Validator to check value constraints when reading them from XML files

Modified: trunk/src/config/common/schema/jbm-configuration.xsd
===================================================================
--- trunk/src/config/common/schema/jbm-configuration.xsd	2009-06-17 08:25:33 UTC (rev 7378)
+++ trunk/src/config/common/schema/jbm-configuration.xsd	2009-06-17 11:52:03 UTC (rev 7379)
@@ -23,7 +23,7 @@
 				</xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" name="security-enabled" type="xsd:boolean">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="security-invalidation-interval" type="xsd:unsignedLong">
+				<xsd:element maxOccurs="1" minOccurs="0" name="security-invalidation-interval" type="xsd:long">
 				</xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" name="wild-card-routing-enabled" type="xsd:boolean">
 				</xsd:element>
@@ -35,33 +35,33 @@
                 </xsd:element>				
                 <xsd:element maxOccurs="1" minOccurs="0" name="management-cluster-password" type="xsd:string">
                 </xsd:element>				
-                <xsd:element maxOccurs="1" minOccurs="0" name="management-request-timeout" type="xsd:unsignedLong">
+                <xsd:element maxOccurs="1" minOccurs="0" name="management-request-timeout" type="xsd:long">
                 </xsd:element>              
 				<xsd:element maxOccurs="1" minOccurs="0" name="jmx-management-enabled" type="xsd:boolean">
 				</xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" name="message-counter-enabled" type="xsd:boolean">
 				</xsd:element>
-            <xsd:element maxOccurs="1" minOccurs="0" name="message-counter-sample-period" type="xsd:unsignedLong">
+            <xsd:element maxOccurs="1" minOccurs="0" name="message-counter-sample-period" type="xsd:long">
             </xsd:element>
-            <xsd:element maxOccurs="1" minOccurs="0" name="message-counter-max-day-history" type="xsd:positiveInteger">
+            <xsd:element maxOccurs="1" minOccurs="0" name="message-counter-max-day-history" type="xsd:int">
             </xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" name="connection-ttl-override" type="xsd:long">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="transaction-timeout" type="xsd:unsignedLong">
+				<xsd:element maxOccurs="1" minOccurs="0" name="transaction-timeout" type="xsd:long">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="transaction-timeout-scan-period" type="xsd:unsignedLong">
+				<xsd:element maxOccurs="1" minOccurs="0" name="transaction-timeout-scan-period" type="xsd:long">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="message-expiry-scan-period" type="xsd:unsignedLong">
+				<xsd:element maxOccurs="1" minOccurs="0" name="message-expiry-scan-period" type="xsd:long">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="message-expiry-thread-priority" type="xsd:positiveInteger">
+				<xsd:element maxOccurs="1" minOccurs="0" name="message-expiry-thread-priority" type="xsd:int">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="id-cache-size" type="xsd:positiveInteger">
+				<xsd:element maxOccurs="1" minOccurs="0" name="id-cache-size" type="xsd:int">
 				</xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" name="persist-id-cache" type="xsd:boolean">
 				</xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" ref="remoting-interceptors">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="queue-activation-timeout" type="xsd:unsignedLong">
+				<xsd:element maxOccurs="1" minOccurs="0" name="queue-activation-timeout" type="xsd:long">
 				</xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" name="backup" type="xsd:boolean">
 				</xsd:element>				
@@ -128,9 +128,9 @@
                 </xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" name="paging-directory" type="xsd:string">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="global-page-size" type="xsd:unsignedLong">
+				<xsd:element maxOccurs="1" minOccurs="0" name="global-page-size" type="xsd:long">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="paging-max-global-size-bytes" type="xsd:unsignedLong">
+				<xsd:element maxOccurs="1" minOccurs="0" name="paging-max-global-size-bytes" type="xsd:long">
 				</xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" name="bindings-directory" type="xsd:string">
 				</xsd:element>
@@ -154,13 +154,13 @@
 				</xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" name="log-journal-write-rate" type="xsd:boolean">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="journal-file-size" type="xsd:unsignedLong">
+				<xsd:element maxOccurs="1" minOccurs="0" name="journal-file-size" type="xsd:long">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="journal-min-files" type="xsd:positiveInteger">
+				<xsd:element maxOccurs="1" minOccurs="0" name="journal-min-files" type="xsd:int">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="journal-max-aio" type="xsd:positiveInteger">
+				<xsd:element maxOccurs="1" minOccurs="0" name="journal-max-aio" type="xsd:int">
 				</xsd:element>
-				<xsd:element maxOccurs="1" minOccurs="0" name="perf-blast-pages" type="xsd:positiveInteger">
+				<xsd:element maxOccurs="1" minOccurs="0" name="perf-blast-pages" type="xsd:int">
 				</xsd:element>
 				<xsd:element maxOccurs="1" minOccurs="0" name="large-messages-directory" type="xsd:string">
 				</xsd:element>
@@ -180,13 +180,13 @@
 
 	<xsd:element name="local-bind-address" type="xsd:string"/>
 
-	<xsd:element name="local-bind-port" type="portRange"/>
+	<xsd:element name="local-bind-port" type="xsd:int"/>
 
 	<xsd:element name="group-address" type="xsd:string"/>
 
-	<xsd:element name="group-port" type="portRange"/>
+	<xsd:element name="group-port" type="xsd:int"/>
 
-	<xsd:element name="broadcast-period" type="xsd:unsignedLong"/>
+	<xsd:element name="broadcast-period" type="xsd:long"/>
 
 	<xsd:element name="connector-ref" type="connector-refType">
 	</xsd:element>
@@ -211,7 +211,7 @@
 		</xsd:complexType>
 	</xsd:element>
 
-	<xsd:element name="refresh-timeout" type="xsd:unsignedLong"/>
+	<xsd:element name="refresh-timeout" type="xsd:int"/>
 
 	<xsd:element name="discovery-group">
 		<xsd:complexType>
@@ -300,11 +300,11 @@
             </xsd:element>
 			<xsd:element maxOccurs="1" minOccurs="0" name="transformer-class-name" type="xsd:string">
 			</xsd:element>
-			<xsd:element maxOccurs="1" minOccurs="0" name="retry-interval" type="xsd:unsignedLong">
+			<xsd:element maxOccurs="1" minOccurs="0" name="retry-interval" type="xsd:long">
 			</xsd:element>
 			<xsd:element maxOccurs="1" minOccurs="0" name="retry-interval-multiplier" type="xsd:double">
 			</xsd:element>
-			<xsd:element maxOccurs="1" minOccurs="0" name="reconnect-attempts" type="minusOneOrMoreInteger">
+			<xsd:element maxOccurs="1" minOccurs="0" name="reconnect-attempts" type="xsd:int">
 			</xsd:element>
 			<xsd:element maxOccurs="1" minOccurs="0" name="failover-on-server-shutdown" type="xsd:boolean">
 			</xsd:element>
@@ -328,13 +328,13 @@
 		<xsd:sequence>
 			<xsd:element maxOccurs="1" minOccurs="1" name="address" type="xsd:string">
 			</xsd:element>
-			<xsd:element maxOccurs="1" minOccurs="0" name="retry-interval" type="xsd:unsignedLong">
+			<xsd:element maxOccurs="1" minOccurs="0" name="retry-interval" type="xsd:long">
 			</xsd:element>			
 			<xsd:element maxOccurs="1" minOccurs="0" name="use-duplicate-detection" type="xsd:boolean">
 			</xsd:element>
 			<xsd:element maxOccurs="1" minOccurs="0" name="forward-when-no-consumers" type="xsd:boolean">
 			</xsd:element>
-			<xsd:element maxOccurs="1" minOccurs="0" name="max-hops" type="xsd:positiveInteger">
+			<xsd:element maxOccurs="1" minOccurs="0" name="max-hops" type="xsd:int">
 			</xsd:element>
 			
 			<xsd:choice>
@@ -420,23 +420,23 @@
         </xsd:element>
         <xsd:element maxOccurs="1" minOccurs="0" name="expiry-address" type="xsd:string">
         </xsd:element>
-        <xsd:element maxOccurs="1" minOccurs="0" name="redelivery-delay" type="xsd:unsignedLong">
+        <xsd:element maxOccurs="1" minOccurs="0" name="redelivery-delay" type="xsd:long">
         </xsd:element>
-        <xsd:element maxOccurs="1" minOccurs="0" name="max-delivery-attempts" type="xsd:unsignedInt">
+        <xsd:element maxOccurs="1" minOccurs="0" name="max-delivery-attempts" type="xsd:int">
         </xsd:element>
         <xsd:element maxOccurs="1" minOccurs="0" name="max-size-bytes" type="xsd:long">
         </xsd:element>
-        <xsd:element maxOccurs="1" minOccurs="0" name="page-size-bytes" type="xsd:unsignedLong">
+        <xsd:element maxOccurs="1" minOccurs="0" name="page-size-bytes" type="xsd:int">
         </xsd:element>
         <xsd:element maxOccurs="1" minOccurs="0" name="drop-messages-when-full" type="xsd:boolean">
         </xsd:element>
         <xsd:element maxOccurs="1" minOccurs="0" name="distribution-policy-class" type="xsd:string">
         </xsd:element>
-        <xsd:element maxOccurs="1" minOccurs="0" name="message-counter-history-day-limit" type="xsd:positiveInteger">
+        <xsd:element maxOccurs="1" minOccurs="0" name="message-counter-history-day-limit" type="xsd:int">
         </xsd:element>
         <xsd:element maxOccurs="1" minOccurs="0" name="last-value-queue" type="xsd:boolean">
         </xsd:element>
-        <xsd:element maxOccurs="1" minOccurs="0" name="redistribution-delay" type="xsd:unsignedLong">
+        <xsd:element maxOccurs="1" minOccurs="0" name="redistribution-delay" type="xsd:long">
         </xsd:element>
       </xsd:all>
     <xsd:attribute name="match" type="xsd:string" use="required"/>
@@ -473,17 +473,4 @@
 		<xsd:attribute name="connector-name" type="xsd:IDREF" use="required">
 		</xsd:attribute>
 	</xsd:complexType>
-
-	<xsd:simpleType name="portRange">
-		<xsd:restriction base="xsd:int">
-		      <xsd:minExclusive value="1024"/>
-		</xsd:restriction>
-	</xsd:simpleType>
-	
-   <xsd:simpleType name="minusOneOrMoreInteger">
-      <xsd:restriction base="xsd:int">
-         <xsd:minInclusive value="-1"/>
-      </xsd:restriction>
-   </xsd:simpleType>	
-
 </xsd:schema>

Modified: trunk/src/config/common/schema/jbm-jms.xsd
===================================================================
--- trunk/src/config/common/schema/jbm-jms.xsd	2009-06-17 08:25:33 UTC (rev 7378)
+++ trunk/src/config/common/schema/jbm-jms.xsd	2009-06-17 11:52:03 UTC (rev 7379)
@@ -28,7 +28,7 @@
    		<xsd:all>
            	<xsd:element name="connector-ref" type="connector-refType" maxOccurs="1" minOccurs="0"></xsd:element>
            	<xsd:element name="discovery-group-ref" type="discovery-group-refType" maxOccurs="1" minOccurs="0"></xsd:element>
-           	<xsd:element name="discovery-initial-wait-timeout" type="xsd:unsignedLong" maxOccurs="1" minOccurs="0"></xsd:element>
+           	<xsd:element name="discovery-initial-wait-timeout" type="xsd:long" maxOccurs="1" minOccurs="0"></xsd:element>
            	
            	<xsd:element name="entries" maxOccurs="1" minOccurs="0">
                 <xsd:complexType>
@@ -39,37 +39,37 @@
 		            </xsd:sequence>
 	            </xsd:complexType>
             </xsd:element>
-   			<xsd:element name="client-failure-check-period" type="xsd:unsignedLong"
+   			<xsd:element name="client-failure-check-period" type="xsd:long"
    				maxOccurs="1" minOccurs="0">
    			</xsd:element>
-   			<xsd:element name="connection-ttl" type="xsd:unsignedLong"
+   			<xsd:element name="connection-ttl" type="xsd:long"
    				maxOccurs="1" minOccurs="0">
    			</xsd:element>
-   			 <xsd:element name="call-timeout" type="xsd:unsignedLong"
+   			 <xsd:element name="call-timeout" type="xsd:long"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
-            <xsd:element name="consumer-window-size" type="minusOneOrMoreInteger"
+            <xsd:element name="consumer-window-size" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
-            <xsd:element name="consumer-max-rate" type="xsd:positiveInteger"
+            <xsd:element name="consumer-max-rate" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
-            <xsd:element name="producer-window-size" type="minusOneOrMoreInteger"
+            <xsd:element name="producer-window-size" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
-            <xsd:element name="producer-max-rate" type="xsd:positiveInteger"
+            <xsd:element name="producer-max-rate" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>            
-   			<xsd:element name="min-large-message-size" type="xsd:unsignedLong"
+   			<xsd:element name="min-large-message-size" type="xsd:long"
    				maxOccurs="1" minOccurs="0">
    			</xsd:element>   			          
             <xsd:element name="client-id" type="xsd:string"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>            
-            <xsd:element name="dups-ok-batch-size" type="xsd:positiveInteger"
+            <xsd:element name="dups-ok-batch-size" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
-            <xsd:element name="transaction-batch-size" type="xsd:positiveInteger"
+            <xsd:element name="transaction-batch-size" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
             <xsd:element name="block-on-acknowledge" type="xsd:boolean"
@@ -84,19 +84,19 @@
             <xsd:element name="auto-group-id" type="xsd:boolean"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
-            <xsd:element name="max-connections" type="xsd:positiveInteger"
+            <xsd:element name="max-connections" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
             <xsd:element name="pre-acknowledge" type="xsd:boolean"
    				maxOccurs="1" minOccurs="0">
    			</xsd:element>
-            <xsd:element name="retry-interval" type="xsd:unsignedLong"
+            <xsd:element name="retry-interval" type="xsd:long"
    				maxOccurs="1" minOccurs="0">
    			</xsd:element>
    			<xsd:element name="retry-interval-multiplier" type="xsd:float"
    				maxOccurs="1" minOccurs="0">
    			</xsd:element>            
-            <xsd:element name="reconnect-attempts" type="minusOneOrMoreInteger"
+            <xsd:element name="reconnect-attempts" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
             <xsd:element name="failover-on-server-shutdown" type="xsd:boolean"
@@ -108,10 +108,10 @@
             <xsd:element name="use-global-pools" type="xsd:boolean"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
-            <xsd:element name="scheduled-thread-pool-max-size" type="xsd:positiveInteger"
+            <xsd:element name="scheduled-thread-pool-max-size" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
-            <xsd:element name="thread-pool-max-size" type="xsd:positiveInteger"
+            <xsd:element name="thread-pool-max-size" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
    		</xsd:all>
@@ -155,12 +155,4 @@
     	</xsd:sequence>
     	<xsd:attribute name="name" type="xsd:ID" use="required"></xsd:attribute>
     </xsd:complexType>
-
-    
-    <xsd:simpleType name="minusOneOrMoreInteger">
-      <xsd:restriction base="xsd:int">
-         <xsd:minInclusive value="-1"></xsd:minInclusive>
-      </xsd:restriction>
-   </xsd:simpleType>	
-    
 </xsd:schema>

Modified: trunk/src/main/org/jboss/messaging/core/config/impl/FileConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/config/impl/FileConfiguration.java	2009-06-17 08:25:33 UTC (rev 7378)
+++ trunk/src/main/org/jboss/messaging/core/config/impl/FileConfiguration.java	2009-06-17 11:52:03 UTC (rev 7379)
@@ -24,6 +24,18 @@
 
 import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL;
 import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL_MULTIPLIER;
+import static org.jboss.messaging.core.config.impl.Validators.GE_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.GT_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.MINUS_ONE_OR_GE_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.MINUS_ONE_OR_GT_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.NOT_NULL_OR_EMPTY;
+import static org.jboss.messaging.core.config.impl.Validators.NO_CHECK;
+import static org.jboss.messaging.core.config.impl.Validators.THREAD_PRIORITY_RANGE;
+import static org.jboss.messaging.utils.XMLConfigurationUtil.getBoolean;
+import static org.jboss.messaging.utils.XMLConfigurationUtil.getDouble;
+import static org.jboss.messaging.utils.XMLConfigurationUtil.getInteger;
+import static org.jboss.messaging.utils.XMLConfigurationUtil.getLong;
+import static org.jboss.messaging.utils.XMLConfigurationUtil.getString;
 
 import java.io.InputStreamReader;
 import java.io.Reader;
@@ -105,45 +117,45 @@
 
       persistDeliveryCountBeforeDelivery = getBoolean(e, "persist-delivery-count-before-delivery", persistDeliveryCountBeforeDelivery);
       
-      queueActivationTimeout = getLong(e, "queue-activation-timeout", queueActivationTimeout);
+      queueActivationTimeout = getLong(e, "queue-activation-timeout", queueActivationTimeout, GE_ZERO);
 
       // NOTE! All the defaults come from the super class
 
-      scheduledThreadPoolMaxSize = getInteger(e, "scheduled-thread-pool-max-size", scheduledThreadPoolMaxSize);
+      scheduledThreadPoolMaxSize = getInteger(e, "scheduled-thread-pool-max-size", scheduledThreadPoolMaxSize, GT_ZERO);
       
-      threadPoolMaxSize = getInteger(e, "thread-pool-max-size", threadPoolMaxSize);
+      threadPoolMaxSize = getInteger(e, "thread-pool-max-size", threadPoolMaxSize, MINUS_ONE_OR_GT_ZERO);
 
       securityEnabled = getBoolean(e, "security-enabled", securityEnabled);
 
       jmxManagementEnabled = getBoolean(e, "jmx-management-enabled", jmxManagementEnabled);
 
-      securityInvalidationInterval = getLong(e, "security-invalidation-interval", securityInvalidationInterval);
+      securityInvalidationInterval = getLong(e, "security-invalidation-interval", securityInvalidationInterval, GT_ZERO);
 
-      connectionTTLOverride = getLong(e, "connection-ttl-override", connectionTTLOverride);
+      connectionTTLOverride = getLong(e, "connection-ttl-override", connectionTTLOverride, MINUS_ONE_OR_GT_ZERO);
 
-      transactionTimeout = getLong(e, "transaction-timeout", transactionTimeout);
+      transactionTimeout = getLong(e, "transaction-timeout", transactionTimeout, GT_ZERO);
 
-      transactionTimeoutScanPeriod = getLong(e, "transaction-timeout-scan-period", transactionTimeoutScanPeriod);
+      transactionTimeoutScanPeriod = getLong(e, "transaction-timeout-scan-period", transactionTimeoutScanPeriod, GT_ZERO);
 
-      messageExpiryScanPeriod = getLong(e, "message-expiry-scan-period", messageExpiryScanPeriod);
+      messageExpiryScanPeriod = getLong(e, "message-expiry-scan-period", messageExpiryScanPeriod, GT_ZERO);
 
-      messageExpiryThreadPriority = getInteger(e, "message-expiry-thread-priority", messageExpiryThreadPriority);
+      messageExpiryThreadPriority = getInteger(e, "message-expiry-thread-priority", messageExpiryThreadPriority, THREAD_PRIORITY_RANGE);
 
-      idCacheSize = getInteger(e, "id-cache-size", idCacheSize);
+      idCacheSize = getInteger(e, "id-cache-size", idCacheSize, GT_ZERO);
 
       persistIDCache = getBoolean(e, "persist-id-cache", persistIDCache);
 
-      managementAddress = new SimpleString(getString(e, "management-address", managementAddress.toString()));
+      managementAddress = new SimpleString(getString(e, "management-address", managementAddress.toString(), NOT_NULL_OR_EMPTY));
 
       managementNotificationAddress = new SimpleString(getString(e,
                                                                  "management-notification-address",
-                                                                 managementNotificationAddress.toString()));
+                                                                 managementNotificationAddress.toString(), NOT_NULL_OR_EMPTY));
 
-      managementClusterPassword = getString(e, "management-cluster-password", managementClusterPassword);
+      managementClusterPassword = getString(e, "management-cluster-password", managementClusterPassword, NOT_NULL_OR_EMPTY);
 
-      managementClusterUser = getString(e, "management-cluster-user", managementClusterUser);
+      managementClusterUser = getString(e, "management-cluster-user", managementClusterUser, NOT_NULL_OR_EMPTY);
 
-      managementRequestTimeout = getLong(e, "management-request-timeout", managementRequestTimeout);
+      managementRequestTimeout = getLong(e, "management-request-timeout", managementRequestTimeout, GT_ZERO);
 
       NodeList interceptorNodes = e.getElementsByTagName("remoting-interceptors");
 
@@ -181,7 +193,7 @@
 
       for (int i = 0; i < connectorNodes.getLength(); i++)
       {
-         Node connectorNode = connectorNodes.item(i);
+         Element connectorNode = (Element)connectorNodes.item(i);
 
          TransportConfiguration connectorConfig = parseTransportConfiguration(connectorNode);
 
@@ -207,7 +219,7 @@
 
       for (int i = 0; i < acceptorNodes.getLength(); i++)
       {
-         Node acceptorNode = acceptorNodes.item(i);
+         Element acceptorNode = (Element)acceptorNodes.item(i);
 
          TransportConfiguration acceptorConfig = parseTransportConfiguration(acceptorNode);
 
@@ -261,29 +273,24 @@
 
       // Persistence config
 
-      largeMessagesDirectory = getString(e, "large-messages-directory", largeMessagesDirectory);
+      largeMessagesDirectory = getString(e, "large-messages-directory", largeMessagesDirectory, NOT_NULL_OR_EMPTY);
 
-      bindingsDirectory = getString(e, "bindings-directory", bindingsDirectory);
+      bindingsDirectory = getString(e, "bindings-directory", bindingsDirectory, NOT_NULL_OR_EMPTY);
 
       createBindingsDir = getBoolean(e, "create-bindings-dir", createBindingsDir);
 
-      journalDirectory = getString(e, "journal-directory", journalDirectory);
+      journalDirectory = getString(e, "journal-directory", journalDirectory, NOT_NULL_OR_EMPTY);
 
-      pagingDirectory = getString(e, "paging-directory", pagingDirectory);
+      pagingDirectory = getString(e, "paging-directory", pagingDirectory, NOT_NULL_OR_EMPTY);
 
-      pagingMaxGlobalSize = getLong(e, "paging-max-global-size-bytes", pagingMaxGlobalSize);
+      pagingMaxGlobalSize = getLong(e, "paging-max-global-size-bytes", pagingMaxGlobalSize, MINUS_ONE_OR_GT_ZERO);
 
-      globalPageSize = getInteger(e, "global-page-size", globalPageSize);
+      globalPageSize = getInteger(e, "global-page-size", globalPageSize, GT_ZERO);
       
       createJournalDir = getBoolean(e, "create-journal-dir", createJournalDir);
 
-      String s = getString(e, "journal-type", journalType.toString());
+      String s = getString(e, "journal-type", journalType.toString(), Validators.JOURNAL_TYPE);
 
-      if (s == null || !s.equals(JournalType.NIO.toString()) && !s.equals(JournalType.ASYNCIO.toString()))
-      {
-         throw new IllegalArgumentException("Invalid journal type " + s);
-      }
-
       if (s.equals(JournalType.NIO.toString()))
       {
          journalType = JournalType.NIO;
@@ -297,29 +304,29 @@
 
       journalSyncNonTransactional = getBoolean(e, "journal-sync-non-transactional", journalSyncNonTransactional);
 
-      journalFileSize = getInteger(e, "journal-file-size", journalFileSize);
+      journalFileSize = getInteger(e, "journal-file-size", journalFileSize, GT_ZERO);
       
       journalAIOFlushSync = getBoolean(e, "journal-aio-flush-on-sync", DEFAULT_JOURNAL_AIO_FLUSH_SYNC);
       
-      journalAIOBufferTimeout = getInteger(e, "journal-aio-buffer-timeout", DEFAULT_JOURNAL_AIO_BUFFER_TIMEOUT);
+      journalAIOBufferTimeout = getInteger(e, "journal-aio-buffer-timeout", DEFAULT_JOURNAL_AIO_BUFFER_TIMEOUT, GT_ZERO);
       
-      journalAIOBufferSize = getInteger(e, "journal-aio-buffer-size", DEFAULT_JOURNAL_AIO_BUFFER_SIZE);
+      journalAIOBufferSize = getInteger(e, "journal-aio-buffer-size", DEFAULT_JOURNAL_AIO_BUFFER_SIZE, GT_ZERO);
 
-      journalMinFiles = getInteger(e, "journal-min-files", journalMinFiles);
+      journalMinFiles = getInteger(e, "journal-min-files", journalMinFiles, GT_ZERO);
 
-      journalMaxAIO = getInteger(e, "journal-max-aio", journalMaxAIO);
+      journalMaxAIO = getInteger(e, "journal-max-aio", journalMaxAIO, GT_ZERO);
       
       logJournalWriteRate = getBoolean(e, "log-journal-write-rate", DEFAULT_JOURNAL_LOG_WRITE_RATE);
       
-      journalPerfBlastPages = getInteger(e, "perf-blast-pages", DEFAULT_JOURNAL_PERF_BLAST_PAGES);
+      journalPerfBlastPages = getInteger(e, "perf-blast-pages", DEFAULT_JOURNAL_PERF_BLAST_PAGES, MINUS_ONE_OR_GT_ZERO);
 
       wildcardRoutingEnabled = getBoolean(e, "wild-card-routing-enabled", wildcardRoutingEnabled);
 
       messageCounterEnabled = getBoolean(e, "message-counter-enabled", messageCounterEnabled);
 
-      messageCounterSamplePeriod = getLong(e, "message-counter-sample-period", messageCounterSamplePeriod);
+      messageCounterSamplePeriod = getLong(e, "message-counter-sample-period", messageCounterSamplePeriod, GT_ZERO);
 
-      messageCounterMaxDayHistory = getInteger(e, "message-counter-max-day-history", messageCounterMaxDayHistory);
+      messageCounterMaxDayHistory = getInteger(e, "message-counter-max-day-history", messageCounterMaxDayHistory, GT_ZERO);
       
       started = true;
    }
@@ -343,127 +350,79 @@
 
    // Private -------------------------------------------------------------------------
 
-   private Boolean getBoolean(final Element e, final String name, final Boolean def)
+   private TransportConfiguration parseTransportConfiguration(final Element e)
    {
-      NodeList nl = e.getElementsByTagName(name);
-      if (nl.getLength() > 0)
-      {
-         return org.jboss.messaging.utils.XMLUtil.parseBoolean(nl.item(0));
-      }
-      return def;
-   }
+      Node nameNode = e.getAttributes().getNamedItem("name");
 
-   private Integer getInteger(final Element e, final String name, final Integer def)
-   {
-      NodeList nl = e.getElementsByTagName(name);
-      if (nl.getLength() > 0)
-      {
-         return XMLUtil.parseInt(nl.item(0));
-      }
-      return def;
-   }
-
-   private Long getLong(final Element e, final String name, final Long def)
-   {
-      NodeList nl = e.getElementsByTagName(name);
-      if (nl.getLength() > 0)
-      {
-         return org.jboss.messaging.utils.XMLUtil.parseLong(nl.item(0));
-      }
-      return def;
-   }
-
-   private String getString(final Element e, final String name, final String def)
-   {
-      NodeList nl = e.getElementsByTagName(name);
-      if (nl.getLength() > 0)
-      {
-         return nl.item(0).getTextContent().trim();
-      }
-      return def;
-   }
-
-   private TransportConfiguration parseTransportConfiguration(final Node node)
-   {
-      Node nameNode = node.getAttributes().getNamedItem("name");
-
       String name = nameNode != null ? nameNode.getNodeValue() : null;
 
-      NodeList children = node.getChildNodes();
+      String clazz = getString(e, "factory-class", null, NOT_NULL_OR_EMPTY);
 
-      String clazz = null;
-
       Map<String, Object> params = new HashMap<String, Object>();
 
-      for (int i = 0; i < children.getLength(); i++)
+      NodeList paramsNodes = e.getElementsByTagName("param");
+
+      for (int i = 0; i < paramsNodes.getLength(); i++)
       {
-         String nodeName = children.item(i).getNodeName();
+         Node paramNode = paramsNodes.item(i);
+         NamedNodeMap attributes =paramNode.getAttributes();
 
-         if ("factory-class".equalsIgnoreCase(nodeName))
-         {
-            clazz = children.item(i).getTextContent();
-         }
-         else if ("param".equalsIgnoreCase(nodeName))
-         {
-            NamedNodeMap attributes = children.item(i).getAttributes();
+         Node nkey = attributes.getNamedItem("key");
 
-            Node nkey = attributes.getNamedItem("key");
+         String key = nkey.getTextContent();
 
-            String key = nkey.getTextContent();
+         Node nValue = attributes.getNamedItem("value");
 
-            Node nValue = attributes.getNamedItem("value");
+         Node nType = attributes.getNamedItem("type");
 
-            Node nType = attributes.getNamedItem("type");
+         String type = nType.getTextContent();
 
-            String type = nType.getTextContent();
+         if (type.equalsIgnoreCase("Integer"))
+         {
+            int iVal = org.jboss.messaging.utils.XMLUtil.parseInt(nValue);
 
-            if (type.equalsIgnoreCase("Integer"))
-            {
-               int iVal = org.jboss.messaging.utils.XMLUtil.parseInt(nValue);
+            params.put(key, iVal);
+         }
+         else if (type.equalsIgnoreCase("Long"))
+         {
+            long lVal = org.jboss.messaging.utils.XMLUtil.parseLong(nValue);
 
-               params.put(key, iVal);
-            }
-            else if (type.equalsIgnoreCase("Long"))
-            {
-               long lVal = org.jboss.messaging.utils.XMLUtil.parseLong(nValue);
+            params.put(key, lVal);
+         }
+         else if (type.equalsIgnoreCase("String"))
+         {
+            params.put(key, nValue.getTextContent().trim());
+         }
+         else if (type.equalsIgnoreCase("Boolean"))
+         {
+            boolean bVal = org.jboss.messaging.utils.XMLUtil.parseBoolean(nValue);
 
-               params.put(key, lVal);
-            }
-            else if (type.equalsIgnoreCase("String"))
-            {
-               params.put(key, nValue.getTextContent().trim());
-            }
-            else if (type.equalsIgnoreCase("Boolean"))
-            {
-               boolean bVal = org.jboss.messaging.utils.XMLUtil.parseBoolean(nValue);
-
-               params.put(key, bVal);
-            }
-            else
-            {
-               throw new IllegalArgumentException("Invalid parameter type " + type);
-            }
+            params.put(key, bVal);
          }
+         else
+         {
+            throw new IllegalArgumentException("Invalid parameter type " + type);
+         }
       }
 
       return new TransportConfiguration(clazz, params, name);
    }
 
-   private void parseBroadcastGroupConfiguration(final Element bgNode)
+   private void parseBroadcastGroupConfiguration(final Element e)
    {
-      String name = bgNode.getAttribute("name");
+      String name = e.getAttribute("name");
 
-      String localAddress = null;
+      String localAddress = getString(e, "local-bind-address", null, NO_CHECK);
       
-      int localBindPort = -1;
+      int localBindPort = getInteger(e, "local-bind-port", -1, MINUS_ONE_OR_GT_ZERO);
 
-      String groupAddress = null;
+      String groupAddress = getString(e, "group-address", null, NOT_NULL_OR_EMPTY);
 
-      int groupPort = -1;
+      int groupPort = getInteger(e, "group-port", -1, GT_ZERO);
 
-      long broadcastPeriod = ConfigurationImpl.DEFAULT_BROADCAST_PERIOD;
+      long broadcastPeriod = getLong(e, "broadcast-period", DEFAULT_BROADCAST_PERIOD, GT_ZERO);
 
-      NodeList children = bgNode.getChildNodes();
+      NodeList children = e.getChildNodes();
 
       List<Pair<String, String>> connectorNames = new ArrayList<Pair<String, String>>();
 
@@ -471,28 +430,8 @@
       {
          Node child = children.item(j);
 
-         if (child.getNodeName().equals("local-bind-address"))
+         if (child.getNodeName().equals("connector-ref"))
          {
-            localAddress = child.getTextContent().trim();
-         }
-         else if (child.getNodeName().equals("local-bind-port"))
-         {
-            localBindPort = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-         }
-         else if (child.getNodeName().equals("group-address"))
-         {
-            groupAddress = child.getTextContent().trim();
-         }
-         else if (child.getNodeName().equals("group-port"))
-         {
-            groupPort = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-         }
-         else if (child.getNodeName().equals("broadcast-period"))
-         {
-            broadcastPeriod = org.jboss.messaging.utils.XMLUtil.parseLong(child);
-         }
-         else if (child.getNodeName().equals("connector-ref"))
-         {
             String connectorName = child.getAttributes().getNamedItem("connector-name").getNodeValue();
 
             Node backupConnectorNode = child.getAttributes().getNamedItem("backup-connector-name");
@@ -521,36 +460,16 @@
       broadcastGroupConfigurations.add(config);
    }
 
-   private void parseDiscoveryGroupConfiguration(final Element bgNode)
+   private void parseDiscoveryGroupConfiguration(final Element e)
    {
-      String name = bgNode.getAttribute("name");
+      String name = e.getAttribute("name");
 
-      String groupAddress = null;
+      String groupAddress = getString(e, "group-address", null, NOT_NULL_OR_EMPTY);
 
-      int groupPort = -1;
+      int groupPort = getInteger(e, "group-port", -1, MINUS_ONE_OR_GT_ZERO);
 
-      long refreshTimeout = ConfigurationImpl.DEFAULT_BROADCAST_REFRESH_TIMEOUT;
+      long refreshTimeout = getLong(e, "refresh-timeout", DEFAULT_BROADCAST_REFRESH_TIMEOUT, GT_ZERO);
 
-      NodeList children = bgNode.getChildNodes();
-
-      for (int j = 0; j < children.getLength(); j++)
-      {
-         Node child = children.item(j);
-
-         if (child.getNodeName().equals("group-address"))
-         {
-            groupAddress = child.getTextContent().trim();
-         }
-         else if (child.getNodeName().equals("group-port"))
-         {
-            groupPort = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-         }
-         else if (child.getNodeName().equals("refresh-timeout"))
-         {
-            refreshTimeout = org.jboss.messaging.utils.XMLUtil.parseLong(child);
-         }
-      }
-
       DiscoveryGroupConfiguration config = new DiscoveryGroupConfiguration(name,
                                                                            groupAddress,
                                                                            groupPort,
@@ -568,54 +487,32 @@
       }
    }
 
-   private void parseClusterConnectionConfiguration(final Element brNode)
+   private void parseClusterConnectionConfiguration(final Element e)
    {
-      String name = null;
+      String name = e.getAttribute("name");
 
-      String address = null;
+      String address = getString(e, "address", null, NOT_NULL_OR_EMPTY);
 
-      boolean duplicateDetection = DEFAULT_CLUSTER_DUPLICATE_DETECTION;
+      boolean duplicateDetection = getBoolean(e, "use-duplicate-detection", DEFAULT_CLUSTER_DUPLICATE_DETECTION);
 
-      boolean forwardWhenNoConsumers = DEFAULT_CLUSTER_FORWARD_WHEN_NO_CONSUMERS;
+      boolean forwardWhenNoConsumers = getBoolean(e, "forward-when-no-consumers", DEFAULT_CLUSTER_FORWARD_WHEN_NO_CONSUMERS);
 
-      String discoveryGroupName = null;
+      int maxHops = getInteger(e, "max-hops", DEFAULT_CLUSTER_MAX_HOPS, GE_ZERO);
 
-      int maxHops = DEFAULT_CLUSTER_MAX_HOPS;
+      long retryInterval = getLong(e, "retry-interval", (long)DEFAULT_CLUSTER_RETRY_INTERVAL, GT_ZERO);
 
-      long retryInterval = DEFAULT_CLUSTER_RETRY_INTERVAL;
+      String discoveryGroupName = null;
 
       List<Pair<String, String>> connectorPairs = new ArrayList<Pair<String, String>>();
 
-      name = brNode.getAttribute("name");
+      NodeList children = e.getChildNodes();
 
-      NodeList children = brNode.getChildNodes();
-
       for (int j = 0; j < children.getLength(); j++)
       {
          Node child = children.item(j);
 
-         if (child.getNodeName().equals("address"))
+         if (child.getNodeName().equals("discovery-group-ref"))
          {
-            address = child.getTextContent().trim();
-         }  
-         else if (child.getNodeName().equals("retry-interval"))
-         {
-            retryInterval = XMLUtil.parseLong(child);
-         }        
-         else if (child.getNodeName().equals("max-hops"))
-         {
-            maxHops = XMLUtil.parseInt(child);
-         }        
-         else if (child.getNodeName().equals("use-duplicate-detection"))
-         {
-            duplicateDetection = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-         }
-         else if (child.getNodeName().equals("forward-when-no-consumers"))
-         {
-            forwardWhenNoConsumers = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-         }
-         else if (child.getNodeName().equals("discovery-group-ref"))
-         {
             discoveryGroupName = child.getAttributes().getNamedItem("discovery-group-name").getNodeValue();
          }
          else if (child.getNodeName().equals("connector-ref"))
@@ -665,74 +562,40 @@
 
    private void parseBridgeConfiguration(final Element brNode)
    {
-      String name = null;
+      String name = brNode.getAttribute("name");
 
-      String queueName = null;
+      String queueName = getString(brNode, "queue-name", null, NOT_NULL_OR_EMPTY);
 
-      String forwardingAddress = null;
+      String forwardingAddress = getString(brNode, "forwarding-address", null, NOT_NULL_OR_EMPTY);
 
-      String filterString = null;
+      String transformerClassName = getString(brNode, "transformer-class-name", null, NO_CHECK);
 
-      Pair<String, String> connectorPair = null;
+      long retryInterval = getLong(brNode, "retry-interval", DEFAULT_RETRY_INTERVAL, GT_ZERO);
 
-      String discoveryGroupName = null;
+      double retryIntervalMultiplier = getDouble(brNode, "retry-interval-multiplier", DEFAULT_RETRY_INTERVAL_MULTIPLIER, GT_ZERO);
+      
+      int reconnectAttempts = getInteger(brNode, "reconnect-attempts", DEFAULT_BRIDGE_RECONNECT_ATTEMPTS, MINUS_ONE_OR_GE_ZERO);
 
-      String transformerClassName = null;
+      boolean failoverOnServerShutdown = getBoolean(brNode, "failover-on-server-shutdown", ClientSessionFactoryImpl.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN);
 
-      long retryInterval = DEFAULT_RETRY_INTERVAL;
+      boolean useDuplicateDetection = getBoolean(brNode, "use-duplicate-detection", DEFAULT_BRIDGE_DUPLICATE_DETECTION);
 
-      double retryIntervalMultiplier = DEFAULT_RETRY_INTERVAL_MULTIPLIER;
+      String filterString = null;
+      
+      Pair<String, String> connectorPair = null;
 
-      int reconnectAttempts = ConfigurationImpl.DEFAULT_BRIDGE_RECONNECT_ATTEMPTS;
+      String discoveryGroupName = null;
 
-      boolean failoverOnServerShutdown = ClientSessionFactoryImpl.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN;
-
-      boolean useDuplicateDetection = DEFAULT_BRIDGE_DUPLICATE_DETECTION;
-
-      name = brNode.getAttribute("name");
-
       NodeList children = brNode.getChildNodes();
 
       for (int j = 0; j < children.getLength(); j++)
       {
          Node child = children.item(j);
 
-         if (child.getNodeName().equals("queue-name"))
+         if (child.getNodeName().equals("filter"))
          {
-            queueName = child.getTextContent().trim();
-         }
-         else if (child.getNodeName().equals("forwarding-address"))
-         {
-            forwardingAddress = child.getTextContent().trim();
-         }
-         else if (child.getNodeName().equals("filter"))
-         {
             filterString = child.getAttributes().getNamedItem("string").getNodeValue();
          }
-         else if (child.getNodeName().equals("transformer-class-name"))
-         {
-            transformerClassName = child.getTextContent().trim();
-         }
-         else if (child.getNodeName().equals("retry-interval"))
-         {
-            retryInterval = org.jboss.messaging.utils.XMLUtil.parseLong(child);
-         }
-         else if (child.getNodeName().equals("retry-interval-multiplier"))
-         {
-            retryIntervalMultiplier = XMLUtil.parseDouble(child);
-         }
-         else if (child.getNodeName().equals("reconnect-attempts"))
-         {
-            reconnectAttempts = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-         }
-         else if (child.getNodeName().equals("failover-on-server-shutdown"))
-         {
-            failoverOnServerShutdown = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-         }
-         else if (child.getNodeName().equals("use-duplicate-detection"))
-         {
-            useDuplicateDetection = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-         }
          else if (child.getNodeName().equals("discovery-group-ref"))
          {
             discoveryGroupName = child.getAttributes().getNamedItem("discovery-group-name").getNodeValue();
@@ -788,54 +651,32 @@
       bridgeConfigurations.add(config);
    }
 
-   private void parseDivertConfiguration(final Element dvNode)
+   private void parseDivertConfiguration(final Element e)
    {
-      String name = null;
+      String name = e.getAttribute("name");
 
-      String routingName = null;
+      String routingName = getString(e, "routing-name", null, NOT_NULL_OR_EMPTY);
 
-      String address = null;
+      String address = getString(e, "address", null, NOT_NULL_OR_EMPTY);
 
-      String forwardingAddress = null;
+      String forwardingAddress = getString(e, "forwarding-address", null, NOT_NULL_OR_EMPTY);
 
-      boolean exclusive = DEFAULT_DIVERT_EXCLUSIVE;
+      boolean exclusive = getBoolean(e, "exclusive", DEFAULT_DIVERT_EXCLUSIVE);
 
+      String transformerClassName = getString(e, "transformer-class-name", null, NO_CHECK);
+
       String filterString = null;
 
-      String transformerClassName = null;
+      NodeList children = e.getChildNodes();
 
-      NodeList children = dvNode.getChildNodes();
-
-      name = dvNode.getAttribute("name");
-      
       for (int j = 0; j < children.getLength(); j++)
       {
          Node child = children.item(j);
 
-         if (child.getNodeName().equals("routing-name"))
+         if (child.getNodeName().equals("filter"))
          {
-            routingName = child.getTextContent().trim();
-         }
-         else if (child.getNodeName().equals("address"))
-         {
-            address = child.getTextContent().trim();
-         }
-         else if (child.getNodeName().equals("forwarding-address"))
-         {
-            forwardingAddress = child.getTextContent().trim();
-         }
-         else if (child.getNodeName().equals("exclusive"))
-         {
-            exclusive = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-         }
-         else if (child.getNodeName().equals("filter"))
-         {
             filterString = child.getAttributes().getNamedItem("string").getNodeValue();
          }
-         else if (child.getNodeName().equals("transformer-class-name"))
-         {
-            transformerClassName = child.getTextContent().trim();
-         }
       }
 
       DivertConfiguration config = new DivertConfiguration(name,

Added: trunk/src/main/org/jboss/messaging/core/config/impl/Validators.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/config/impl/Validators.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/config/impl/Validators.java	2009-06-17 11:52:03 UTC (rev 7379)
@@ -0,0 +1,184 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.core.config.impl;
+
+import static java.lang.String.format;
+
+import org.jboss.messaging.core.server.JournalType;
+
+/**
+ * A Validators
+ *
+ * @author jmesnil
+ *
+ *
+ */
+public class Validators
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+   
+   public static interface Validator
+   {
+      void validate(String name, Object value);
+   }
+   
+   public static Validator NO_CHECK = new Validator()
+   {
+      public void validate(String name, Object value)
+      {
+         return;
+      }
+   };
+   
+   public static Validator NOT_NULL_OR_EMPTY = new Validator()
+   {
+      public void validate(String name, Object value)
+      {
+         String str = (String)value;
+         if (str == null || str.length() == 0)
+         {
+            throw new IllegalArgumentException(format("%s must neither be null nor empty", name));
+         }
+      }
+   };
+
+   public static Validator GT_ZERO = new Validator()
+   {
+      public void validate(String name, Object value)
+      {
+         Number val = (Number)value;
+         if (val.doubleValue() > 0)
+         {
+            // OK
+         }
+         else
+         {
+            throw new IllegalArgumentException(format("%s  must be greater than 0 (actual value: %s", name, val));
+         }
+      }
+   };
+
+   public static Validator GE_ZERO = new Validator()
+   {
+      public void validate(String name, Object value)
+      {
+         Number val = (Number)value;
+         if (val.doubleValue() >= 0)
+         {
+            // OK
+         }
+         else
+         {
+            throw new IllegalArgumentException(format("%s  must be greater or equals than 0 (actual value: %s",
+                                                      name,
+                                                      val));
+         }
+      }
+   };
+
+   public static Validator MINUS_ONE_OR_GT_ZERO = new Validator()
+   {
+      public void validate(String name, Object value)
+      {
+         Number val = (Number)value;
+         if (val.doubleValue() == -1 || val.doubleValue() > 0)
+         {
+            // OK
+         }
+         else
+         {
+            throw new IllegalArgumentException(format("%s  must be equals to -1 or greater than 0 (actual value: %s)",
+                                                      name,
+                                                      val));
+         }
+      }
+   };
+
+   public static Validator MINUS_ONE_OR_GE_ZERO = new Validator()
+   {
+      public void validate(String name, Object value)
+      {
+         Number val = (Number)value;
+         if (val.doubleValue() == -1 || val.doubleValue() >= 0)
+         {
+            // OK
+         }
+         else
+         {
+            throw new IllegalArgumentException(format("%s  must be equals to -1 or greater or equals to 0 (actual value: %s)",
+                                                      name,
+                                                      val));
+         }
+      }
+   };
+
+   public static final Validator THREAD_PRIORITY_RANGE = new Validator()
+   {
+      public void validate(String name, Object value)
+      {
+         Number val = (Number)value;
+         if (val.intValue() >= Thread.MIN_PRIORITY && val.intValue() <= Thread.MAX_PRIORITY)
+         {
+            // OK
+         }
+         else
+         {
+            throw new IllegalArgumentException(format("%s must be betwen %s and %s inclusive (actual value: %s)",
+                                                      name,
+                                                      Thread.MIN_PRIORITY,
+                                                      Thread.MAX_PRIORITY,
+                                                      value));
+         }
+      }
+   };
+
+   public static final Validator JOURNAL_TYPE = new Validator()
+   {
+      public void validate(String name, Object value)
+      {
+         String val = (String)value;
+         if (val == null || !val.equals(JournalType.NIO.toString()) && !val.equals(JournalType.ASYNCIO.toString()))
+         {
+            throw new IllegalArgumentException("Invalid journal type " + val);
+         }
+      }
+   };
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java	2009-06-17 08:25:33 UTC (rev 7378)
+++ trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java	2009-06-17 11:52:03 UTC (rev 7379)
@@ -12,6 +12,16 @@
 
 package org.jboss.messaging.jms.server.impl;
 
+import static org.jboss.messaging.core.config.impl.Validators.GE_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.GT_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.MINUS_ONE_OR_GE_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.MINUS_ONE_OR_GT_ZERO;
+import static org.jboss.messaging.utils.XMLConfigurationUtil.getBoolean;
+import static org.jboss.messaging.utils.XMLConfigurationUtil.getDouble;
+import static org.jboss.messaging.utils.XMLConfigurationUtil.getInteger;
+import static org.jboss.messaging.utils.XMLConfigurationUtil.getLong;
+import static org.jboss.messaging.utils.XMLConfigurationUtil.getString;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -19,11 +29,13 @@
 import org.jboss.messaging.core.config.Configuration;
 import org.jboss.messaging.core.config.TransportConfiguration;
 import org.jboss.messaging.core.config.cluster.DiscoveryGroupConfiguration;
+import org.jboss.messaging.core.config.impl.Validators;
 import org.jboss.messaging.core.deployers.DeploymentManager;
 import org.jboss.messaging.core.deployers.impl.XmlDeployer;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.jms.server.JMSServerManager;
 import org.jboss.messaging.utils.Pair;
+import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -31,6 +43,7 @@
 /**
  * @author <a href="ataylor at redhat.com">Andy Taylor</a>
  * @author <a href="tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
  */
 public class JMSServerDeployer extends XmlDeployer
 {
@@ -40,54 +53,6 @@
 
    private JMSServerManager jmsServerControl;
 
-   private static final String CLIENTID_ELEMENT = "client-id";
-
-   private static final String CLIENT_FAILURE_CHECK_PERIOD = "client-failure-check-period";
-
-   private static final String CONNECTION_TTL_ELEMENT = "connection-ttl";
-
-   private static final String CALL_TIMEOUT_ELEMENT = "call-timeout";
-
-   private static final String DUPS_OK_BATCH_SIZE_ELEMENT = "dups-ok-batch-size";
-
-   private static final String TRANSACTION_BATCH_SIZE_ELEMENT = "transaction-batch-size";
-
-   private static final String CONSUMER_WINDOW_SIZE_ELEMENT = "consumer-window-size";
-
-   private static final String CONSUMER_MAX_RATE_ELEMENT = "consumer-max-rate";
-
-   private static final String PRODUCER_WINDOW_SIZE = "producer-window-size";
-
-   private static final String PRODUCER_MAX_RATE_ELEMENT = "producer-max-rate";
-
-   private static final String MIN_LARGE_MESSAGE_SIZE = "min-large-message-size";
-
-   private static final String BLOCK_ON_ACKNOWLEDGE_ELEMENT = "block-on-acknowledge";
-
-   private static final String BLOCK_ON_NON_PERSISTENT_SEND_ELEMENT = "block-on-non-persistent-send";
-
-   private static final String BLOCK_ON_PERSISTENT_SEND_ELEMENT = "block-on-persistent-send";
-
-   private static final String AUTO_GROUP_ELEMENT = "auto-group";
-
-   private static final String MAX_CONNECTIONS_ELEMENT = "max-connections";
-
-   private static final String PRE_ACKNOWLEDGE_ELEMENT = "pre-acknowledge";
-
-   private static final String RETRY_INTERVAL = "retry-interval";
-
-   private static final String RETRY_INTERVAL_MULTIPLIER = "retry-interval-multiplier";
-
-   private static final String RECONNECT_ATTEMPTS = "reconnect-attempts";
-
-   private static final String FAILOVER_ON_SERVER_SHUTDOWN = "failover-on-server-shutdown";
-
-   private static final String USE_GLOBAL_POOLS = "use-global-pools";
-
-   private static final String SCHEDULED_THREAD_POOL_MAX_SIZE = "scheduled-thread-pool-max-size";
-
-   private static final String THREAD_POOL_MAX_SIZE = "thread-pool-max-size";
-
    private static final String CONNECTOR_REF_ELEMENT = "connector-ref";
 
    private static final String DISCOVERY_GROUP_ELEMENT = "discovery-group-ref";
@@ -102,14 +67,8 @@
 
    private static final String QUEUE_SELECTOR_NODE_NAME = "selector";
 
-   private static final String QUEUE_DURABLE_NODE_NAME = "durable";
-
    private static final String TOPIC_NODE_NAME = "topic";
 
-   private static final String CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME_ELEMENT = "connection-load-balancing-policy-class-name";
-
-   private static final String DISCOVERY_INITIAL_WAIT_TIMEOUT_ELEMENT = "discovery-initial-wait-timeout";
-
    private static final boolean DEFAULT_QUEUE_DURABILITY = true;
 
    public JMSServerDeployer(final JMSServerManager jmsServerManager,
@@ -162,141 +121,47 @@
    {
       if (node.getNodeName().equals(CONNECTION_FACTORY_NODE_NAME))
       {
-         NodeList children = node.getChildNodes();
+         Element e = (Element)node;
 
-         long clientFailureCheckPeriod = ClientSessionFactoryImpl.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD;
-         long connectionTTL = ClientSessionFactoryImpl.DEFAULT_CONNECTION_TTL;
-         long callTimeout = ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT;
-         String clientID = null;
-         int dupsOKBatchSize = ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE;
-         int transactionBatchSize = ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE;
-         int consumerWindowSize = ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE;
-         int consumerMaxRate = ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE;
-         int producerWindowSize = ClientSessionFactoryImpl.DEFAULT_PRODUCER_WINDOW_SIZE;
-         int producerMaxRate = ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE;
-         int minLargeMessageSize = ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
-         boolean blockOnAcknowledge = ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE;
-         boolean blockOnNonPersistentSend = ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND;
-         boolean blockOnPersistentSend = ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_PERSISTENT_SEND;
-         boolean autoGroup = ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP;
-         int maxConnections = ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS;
-         boolean preAcknowledge = ClientSessionFactoryImpl.DEFAULT_PRE_ACKNOWLEDGE;
-         long retryInterval = ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL;
-         double retryIntervalMultiplier = ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL_MULTIPLIER;
-         int reconnectAttempts = ClientSessionFactoryImpl.DEFAULT_RECONNECT_ATTEMPTS;
-         boolean failoverOnServerShutdown = ClientSessionFactoryImpl.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN;
-         boolean useGlobalPools = ClientSessionFactoryImpl.DEFAULT_USE_GLOBAL_POOLS;
-         int scheduledThreadPoolMaxSize = ClientSessionFactoryImpl.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE;
-         int threadPoolMaxSize = ClientSessionFactoryImpl.DEFAULT_THREAD_POOL_MAX_SIZE;
+         long clientFailureCheckPeriod = getLong(e, "client-failure-check-period", ClientSessionFactoryImpl.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, GT_ZERO);
+         long connectionTTL = getLong(e, "connection-ttl", ClientSessionFactoryImpl.DEFAULT_CONNECTION_TTL, GE_ZERO);
+         long callTimeout = getLong(e, "call-timeout", ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT, GE_ZERO);
+         String clientID = getString(e, "client-id", null, Validators.NO_CHECK);
+         int dupsOKBatchSize = getInteger(e, "dups-ok-batch-size", ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE, GT_ZERO);
+         int transactionBatchSize = getInteger(e, "transaction-batch-size", ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE, GT_ZERO);
+         int consumerWindowSize = getInteger(e, "consumer-window-size", ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE, GT_ZERO);
+         int consumerMaxRate = getInteger(e, "consumer-max-rate", ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE, MINUS_ONE_OR_GT_ZERO);
+         int producerWindowSize = getInteger(e, "producer-window-size", ClientSessionFactoryImpl.DEFAULT_PRODUCER_WINDOW_SIZE, GT_ZERO);
+         int producerMaxRate = getInteger(e, "producer-max-rate", ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE, MINUS_ONE_OR_GT_ZERO);
+         int minLargeMessageSize = getInteger(e, "min-large-message-size", ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE, GT_ZERO);
+         boolean blockOnAcknowledge = getBoolean(e, "block-on-acknowledge", ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE);
+         boolean blockOnNonPersistentSend = getBoolean(e, "block-on-non-persistent-send", ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND);
+         boolean blockOnPersistentSend = getBoolean(e, "block-on-persistent-send", ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_PERSISTENT_SEND);
+         boolean autoGroup = getBoolean(e, "auto-group", ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP);
+         int maxConnections = getInteger(e, "max-connections", ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS, GT_ZERO);
+         boolean preAcknowledge = getBoolean(e, "pre-acknowledge", ClientSessionFactoryImpl.DEFAULT_PRE_ACKNOWLEDGE);
+         long retryInterval = getLong(e, "retry-interval", ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL, GT_ZERO);
+         double retryIntervalMultiplier = getDouble(e, "retry-interval-multiplier", ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL_MULTIPLIER, GT_ZERO);
+         int reconnectAttempts = getInteger(e, "reconnect-attempts", ClientSessionFactoryImpl.DEFAULT_RECONNECT_ATTEMPTS, MINUS_ONE_OR_GE_ZERO);
+         boolean failoverOnServerShutdown = getBoolean(e, "failover-on-server-shutdown", ClientSessionFactoryImpl.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN);
+         boolean useGlobalPools = getBoolean(e, "use-global-pools", ClientSessionFactoryImpl.DEFAULT_USE_GLOBAL_POOLS);
+         int scheduledThreadPoolMaxSize = getInteger(e, "scheduled-thread-pool-max-size", ClientSessionFactoryImpl.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, MINUS_ONE_OR_GT_ZERO);
+         int threadPoolMaxSize = getInteger(e, "thread-pool-max-size", ClientSessionFactoryImpl.DEFAULT_THREAD_POOL_MAX_SIZE, MINUS_ONE_OR_GT_ZERO);
+         String connectionLoadBalancingPolicyClassName = getString(e, "connection-load-balancing-policy-class-name", ClientSessionFactoryImpl.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, Validators.NOT_NULL_OR_EMPTY);
+         long discoveryInitialWaitTimeout = getLong(e, "discovery-initial-wait-timeout", ClientSessionFactoryImpl.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, GT_ZERO);
 
          List<String> jndiBindings = new ArrayList<String>();
          List<Pair<TransportConfiguration, TransportConfiguration>> connectorConfigs = new ArrayList<Pair<TransportConfiguration, TransportConfiguration>>();
          DiscoveryGroupConfiguration discoveryGroupConfiguration = null;
-         String connectionLoadBalancingPolicyClassName = ClientSessionFactoryImpl.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME;
-         long discoveryInitialWaitTimeout = ClientSessionFactoryImpl.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT;
 
+         NodeList children = node.getChildNodes();
+
          for (int j = 0; j < children.getLength(); j++)
          {
             Node child = children.item(j);
 
-            if (CLIENT_FAILURE_CHECK_PERIOD.equals(child.getNodeName()))
+            if (ENTRIES_NODE_NAME.equals(child.getNodeName()))
             {
-               clientFailureCheckPeriod = org.jboss.messaging.utils.XMLUtil.parseLong(child);
-            }
-            else if (CONNECTION_TTL_ELEMENT.equals(child.getNodeName()))
-            {
-               connectionTTL = org.jboss.messaging.utils.XMLUtil.parseLong(child);
-            }
-            else if (CALL_TIMEOUT_ELEMENT.equals(child.getNodeName()))
-            {
-               callTimeout = org.jboss.messaging.utils.XMLUtil.parseLong(child);
-            }
-            else if (CONSUMER_WINDOW_SIZE_ELEMENT.equals(child.getNodeName()))
-            {
-               consumerWindowSize = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (CONSUMER_MAX_RATE_ELEMENT.equals(child.getNodeName()))
-            {
-               consumerMaxRate = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (PRODUCER_WINDOW_SIZE.equals(child.getNodeName()))
-            {
-               producerWindowSize = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (PRODUCER_MAX_RATE_ELEMENT.equals(child.getNodeName()))
-            {
-               producerMaxRate = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (MIN_LARGE_MESSAGE_SIZE.equals(child.getNodeName()))
-            {
-               minLargeMessageSize = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (CLIENTID_ELEMENT.equals(child.getNodeName()))
-            {
-               clientID = child.getTextContent().trim();
-            }
-            else if (DUPS_OK_BATCH_SIZE_ELEMENT.equals(child.getNodeName()))
-            {
-               dupsOKBatchSize = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (TRANSACTION_BATCH_SIZE_ELEMENT.equals(child.getNodeName()))
-            {
-               transactionBatchSize = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (BLOCK_ON_ACKNOWLEDGE_ELEMENT.equals(child.getNodeName()))
-            {
-               blockOnAcknowledge = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-            }
-            else if (BLOCK_ON_NON_PERSISTENT_SEND_ELEMENT.equals(child.getNodeName()))
-            {
-               blockOnNonPersistentSend = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-            }
-            else if (BLOCK_ON_PERSISTENT_SEND_ELEMENT.equals(child.getNodeName()))
-            {
-               blockOnPersistentSend = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-            }
-            else if (AUTO_GROUP_ELEMENT.equals(child.getNodeName()))
-            {
-               autoGroup = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-            }
-            else if (MAX_CONNECTIONS_ELEMENT.equals(child.getNodeName()))
-            {
-               maxConnections = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (PRE_ACKNOWLEDGE_ELEMENT.equals(child.getNodeName()))
-            {
-               preAcknowledge = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-            }
-            else if (RETRY_INTERVAL.equals(child.getNodeName()))
-            {
-               retryInterval = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (RETRY_INTERVAL_MULTIPLIER.equals(child.getNodeName()))
-            {
-               retryIntervalMultiplier = org.jboss.messaging.utils.XMLUtil.parseDouble(child);
-            }
-            else if (RECONNECT_ATTEMPTS.equals(child.getNodeName()))
-            {
-               reconnectAttempts = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (FAILOVER_ON_SERVER_SHUTDOWN.equals(child.getNodeName()))
-            {
-               failoverOnServerShutdown = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-            }
-            else if (USE_GLOBAL_POOLS.equals(child.getNodeName()))
-            {
-               useGlobalPools = org.jboss.messaging.utils.XMLUtil.parseBoolean(child);
-            }
-            else if (SCHEDULED_THREAD_POOL_MAX_SIZE.equals(child.getNodeName()))
-            {
-               scheduledThreadPoolMaxSize = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (THREAD_POOL_MAX_SIZE.equals(child.getNodeName()))
-            {
-               threadPoolMaxSize = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
-            else if (ENTRIES_NODE_NAME.equals(child.getNodeName()))
-            {
                NodeList entries = child.getChildNodes();
                for (int i = 0; i < entries.getLength(); i++)
                {
@@ -309,14 +174,6 @@
                   }
                }
             }
-            else if (CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME_ELEMENT.equals(child.getNodeName()))
-            {
-               connectionLoadBalancingPolicyClassName = child.getTextContent().trim();
-            }
-            else if (DISCOVERY_INITIAL_WAIT_TIMEOUT_ELEMENT.equals(child.getNodeName()))
-            {
-               discoveryInitialWaitTimeout = org.jboss.messaging.utils.XMLUtil.parseInt(child);
-            }
             else if (CONNECTOR_REF_ELEMENT.equals(child.getNodeName()))
             {
                String connectorName = child.getAttributes().getNamedItem("connector-name").getNodeValue();
@@ -435,10 +292,11 @@
       }
       else if (node.getNodeName().equals(QUEUE_NODE_NAME))
       {
+         Element e = (Element)node;
          NamedNodeMap atts = node.getAttributes();
          String queueName = atts.getNamedItem(getKeyAttribute()).getNodeValue();
          String selectorString = null;
-         boolean durable = DEFAULT_QUEUE_DURABILITY;
+         boolean durable = getBoolean(e, "durable", DEFAULT_QUEUE_DURABILITY);
          NodeList children = node.getChildNodes();
          ArrayList<String> jndiNames = new ArrayList<String>();
          for (int i = 0; i < children.getLength(); i++)
@@ -450,13 +308,6 @@
                String jndiName = child.getAttributes().getNamedItem("name").getNodeValue();
                jndiNames.add(jndiName);
             }
-            else if (QUEUE_DURABLE_NODE_NAME.equals(children.item(i).getNodeName()))
-            {
-               Node durableNode = children.item(i);
-               durable = durableNode.getNodeValue() == null ? DEFAULT_QUEUE_DURABILITY
-                                                           : durableNode.getNodeValue()
-                                                                        .equalsIgnoreCase(Boolean.FALSE.toString());
-            }
             else if (QUEUE_SELECTOR_NODE_NAME.equals(children.item(i).getNodeName()))
             {
                Node selectorNode = children.item(i);

Added: trunk/src/main/org/jboss/messaging/utils/XMLConfigurationUtil.java
===================================================================
--- trunk/src/main/org/jboss/messaging/utils/XMLConfigurationUtil.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/utils/XMLConfigurationUtil.java	2009-06-17 11:52:03 UTC (rev 7379)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.messaging.utils;
+
+import org.jboss.messaging.core.config.impl.Validators;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * A XMLConfigurationUtil
+ *
+ * @author jmesnil
+ *
+ *
+ */
+public class XMLConfigurationUtil
+{
+
+   public static Double getDouble(final Element e, final String name, final double def, final Validators.Validator validator)
+   {
+      NodeList nl = e.getElementsByTagName(name);
+      if (nl.getLength() > 0)
+      {
+         double val = XMLUtil.parseDouble(nl.item(0));
+         validator.validate(name, val);
+         return val;
+      }
+      else
+      {
+         validator.validate(name, def);
+         return def;
+      }
+   }
+
+   public static String getString(final Element e, final String name, final String def, final Validators.Validator validator)
+   {
+      NodeList nl = e.getElementsByTagName(name);
+      if (nl.getLength() > 0)
+      {
+         String val =  nl.item(0).getTextContent().trim();
+         validator.validate(name, val);
+         return val;
+      }
+      else
+      {
+         validator.validate(name, def);
+         return def;
+      }
+   }
+
+   public static Long getLong(final Element e, final String name, final long def, final Validators.Validator validator)
+   {
+      NodeList nl = e.getElementsByTagName(name);
+      if (nl.getLength() > 0)
+      {
+         long val = XMLUtil.parseLong(nl.item(0));
+         validator.validate(name, val);
+         return val;
+      }
+      else
+      {
+         validator.validate(name, def);
+         return def;
+      }
+   }
+
+   public static Integer getInteger(final Element e, final String name, final int def, final Validators.Validator validator)
+   {
+      NodeList nl = e.getElementsByTagName(name);
+      if (nl.getLength() > 0)
+      {
+         int val = XMLUtil.parseInt(nl.item(0));
+         validator.validate(name, val);
+         return val;
+      }
+      else
+      {
+         validator.validate(name, def);
+         return def;
+      }
+   }
+
+   public static Boolean getBoolean(final Element e, final String name, final boolean def)
+   {
+      NodeList nl = e.getElementsByTagName(name);
+      if (nl.getLength() > 0)
+      {
+         return org.jboss.messaging.utils.XMLUtil.parseBoolean(nl.item(0));
+      }
+      else
+      {
+         return def;
+      }
+   }
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/config/impl/ValidatorsTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/config/impl/ValidatorsTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/config/impl/ValidatorsTest.java	2009-06-17 11:52:03 UTC (rev 7379)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.core.config.impl;
+
+import static org.jboss.messaging.core.config.impl.Validators.GE_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.GT_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.JOURNAL_TYPE;
+import static org.jboss.messaging.core.config.impl.Validators.MINUS_ONE_OR_GE_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.MINUS_ONE_OR_GT_ZERO;
+import static org.jboss.messaging.core.config.impl.Validators.NOT_NULL_OR_EMPTY;
+import static org.jboss.messaging.core.config.impl.Validators.NO_CHECK;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.config.impl.Validators;
+import org.jboss.messaging.core.server.JournalType;
+
+/**
+ * A ValidatorsTest
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ *
+ */
+public class ValidatorsTest extends TestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   private static void success(Validators.Validator validator, Object value)
+   {
+      validator.validate(randomString(), value);
+   }
+
+   private static void failure(Validators.Validator validator, Object value)
+   {
+      try
+      {
+         validator.validate(randomString(), value);
+         fail(validator + " must not validate " + value);
+      }
+      catch (IllegalArgumentException e)
+      {
+
+      }
+   }
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testGE_ZERO() throws Exception
+   {
+      failure(GE_ZERO, -1);
+      success(GE_ZERO, 0);
+      success(GE_ZERO, 0.1);
+      success(GE_ZERO, 1);
+   }
+
+   public void testGT_ZERO() throws Exception
+   {
+      failure(GT_ZERO, -1);
+      failure(GT_ZERO, 0);
+      success(GT_ZERO, 0.1);
+      success(GT_ZERO, 1);
+   }
+
+   public void testMINUS_ONE_OR_GE_ZERO() throws Exception
+   {
+      failure(MINUS_ONE_OR_GE_ZERO, -2);
+      success(MINUS_ONE_OR_GE_ZERO, -1);
+      success(MINUS_ONE_OR_GE_ZERO, 0);
+      success(MINUS_ONE_OR_GE_ZERO, 0.1);
+      success(MINUS_ONE_OR_GE_ZERO, 1);
+   }
+
+   public void testMINUS_ONE_OR_GT_ZERO() throws Exception
+   {
+      failure(MINUS_ONE_OR_GT_ZERO, -2);
+      success(MINUS_ONE_OR_GT_ZERO, -1);
+      failure(MINUS_ONE_OR_GT_ZERO, 0);
+      success(MINUS_ONE_OR_GT_ZERO, 0.1);
+      success(MINUS_ONE_OR_GT_ZERO, 1);
+   }
+
+   public void testNO_CHECK() throws Exception
+   {
+      success(NO_CHECK, -1);
+      success(NO_CHECK, null);
+      success(NO_CHECK, "");
+      success(NO_CHECK, true);
+      success(NO_CHECK, false);
+   }
+
+   public void testNOT_NULL_OR_EMPTY() throws Exception
+   {
+      failure(NOT_NULL_OR_EMPTY, null);
+      failure(NOT_NULL_OR_EMPTY, "");
+      success(NOT_NULL_OR_EMPTY, randomString());
+   }
+   
+   public void testJOURNAL_TYPE() throws Exception
+   {
+      for(JournalType type: JournalType.values())
+      {
+         success(JOURNAL_TYPE, type.toString());
+      }
+      failure(JOURNAL_TYPE, null);
+      failure(JOURNAL_TYPE, "");
+      failure(JOURNAL_TYPE, randomString());
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}




More information about the jboss-cvs-commits mailing list