added isEmpty method to StringUtil.

removed dependence upon java 1.6 String.isEmpty method which doesn't exist in java 1.5.

git-svn-id: https://svn.apache.org/repos/asf/incubator/etch/branches/name-service@780705 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/services/ns/src/main/java/org/apache/etch/services/ns/support/DefaultNSLib.java b/services/ns/src/main/java/org/apache/etch/services/ns/support/DefaultNSLib.java
index 75c86e9..1ab54bd 100644
--- a/services/ns/src/main/java/org/apache/etch/services/ns/support/DefaultNSLib.java
+++ b/services/ns/src/main/java/org/apache/etch/services/ns/support/DefaultNSLib.java
@@ -31,6 +31,7 @@
 import org.apache.etch.services.ns.NameService.Entry;
 import org.apache.etch.util.AlarmListener;
 import org.apache.etch.util.AlarmManager;
+import org.apache.etch.util.StringUtil;
 import org.apache.etch.util.URL;
 import org.apache.etch.util.core.io.Session;
 
@@ -42,8 +43,10 @@
 {
 	private final static int INITIAL_ALARM_DELAY = 1;
 	
-	// Collection of <session, record> entries to keep track of all listeners connected 
-	// to this instance of NSLib
+	/**
+	 * Collection of <session, record> entries to keep track of all listeners
+	 * connected to this instance of NSLib
+	 */
 	public Map<Session, Record> recordsBySession = Collections.synchronizedMap( 
 			new HashMap<Session, Record>() );
 	
@@ -144,7 +147,7 @@
 		
 		public Record( String nsUri, String sourceUri, Map<?,?> qualities, String targetUri, int ttl )
 		{
-			this.nsUri = ( nsUri == null || nsUri.isEmpty() )? defaultNsUri : nsUri;
+			this.nsUri = StringUtil.isEmpty( nsUri ) ? defaultNsUri : nsUri;
 			this.sourceUri = sourceUri;
 			this.qualities = qualities;
 			this.targetUri = targetUri;
@@ -173,8 +176,8 @@
 		URL u = new URL( uri );
 
 		String sourceUri = u.getUri();
-		if ( sourceUri == null || sourceUri.isEmpty() )
-			throw new IllegalArgumentException( "sourceUri == null" );
+		if ( StringUtil.isEmpty( sourceUri ) )
+			throw new IllegalArgumentException( "sourceUri is empty" );
 		
 		if ( ! u.hasTerm( EtchTransportFactory.LISTENER_REGISTERED_URI ) )
 			throw new IllegalArgumentException( "listener registered uri " +
@@ -187,7 +190,7 @@
 		if ( u.hasTerm( EtchTransportFactory.NS_URI ) )
 			nsUri = u.getTerm( EtchTransportFactory.NS_URI );
 		
-		if ( nsUri == null || nsUri.isEmpty() )
+		if ( StringUtil.isEmpty( nsUri ) )
 			nsUri = defaultNsUri;
 		
 		Record record = new Record( nsUri, sourceUri, qualities, targetUri, ttl );
@@ -246,13 +249,13 @@
 		URL u = new URL( uri );
 		
 		String sourceUri = u.getUri();
-		if ( sourceUri == null || sourceUri.isEmpty() )
-			throw new IllegalArgumentException( "sourceUri == null" );
+		if ( StringUtil.isEmpty( sourceUri ) )
+			throw new IllegalArgumentException( "sourceUri is empty" );
 		
 		String nsUri = null;
 		if ( u.hasTerm( EtchTransportFactory.NS_URI ) )
 			nsUri = u.getTerm( EtchTransportFactory.NS_URI );
-		if ( nsUri == null || nsUri.isEmpty() )
+		if ( StringUtil.isEmpty( nsUri ) )
 			nsUri = getDefaultNsUri();
 		
 		// remove alarm for that session/record
@@ -296,11 +299,11 @@
 		
 		String sourceUri = u.getUri();
 		
-		if ( nsUri == null || nsUri.isEmpty() )
+		if ( StringUtil.isEmpty( nsUri ) )
 			nsUri = getDefaultNsUri();
 		
-		if ( sourceUri == null || sourceUri.isEmpty() )
-			throw new IllegalArgumentException( "sourceUri == null" );
+		if ( StringUtil.isEmpty( sourceUri ) )
+			throw new IllegalArgumentException( "sourceUri is empty" );
 		
 		Entry result = null;
 		
diff --git a/services/ns/src/main/java/org/apache/etch/services/ns/support/EtchTransportFactory.java b/services/ns/src/main/java/org/apache/etch/services/ns/support/EtchTransportFactory.java
index ff85565..106acca 100644
--- a/services/ns/src/main/java/org/apache/etch/services/ns/support/EtchTransportFactory.java
+++ b/services/ns/src/main/java/org/apache/etch/services/ns/support/EtchTransportFactory.java
@@ -32,6 +32,7 @@
 import org.apache.etch.util.AlarmListener;
 import org.apache.etch.util.AlarmManager;
 import org.apache.etch.util.Resources;
+import org.apache.etch.util.StringUtil;
 import org.apache.etch.util.URL;
 import org.apache.etch.util.core.Who;
 import org.apache.etch.util.core.io.Session;
@@ -63,10 +64,10 @@
 		URL u = new URL( uri );
 		
 		// Extract uri for the listener to listen on 
-		if ( !u.hasTerm( LISTENER_URI ) || (listenerUri = u.getTerm( LISTENER_URI )).isEmpty() )
+		if ( !u.hasTerm( LISTENER_URI ) || StringUtil.isEmpty( listenerUri = u.getTerm( LISTENER_URI ) ) )
 			throw new IllegalArgumentException( "listener uri not configured properly within the etch uri" );
 		
-		if ( !u.hasTerm( LISTENER_REGISTERED_URI ) || u.getTerm( LISTENER_REGISTERED_URI).isEmpty() )
+		if ( !u.hasTerm( LISTENER_REGISTERED_URI ) || StringUtil.isEmpty( u.getTerm( LISTENER_REGISTERED_URI) ) )
 			throw new IllegalArgumentException( "listener registered uri " +
 			"not configured properly within the etch uri" );
 		
@@ -106,7 +107,7 @@
 			
 			URL u = new URL( uri );
 
-			if ( u.getUri() == null || u.getUri().isEmpty() )
+			if ( StringUtil.isEmpty( u.getUri() ) )
 				throw new IllegalArgumentException( "source uri == null" );
 
 			if ( u.hasTerm( RECONNECT_TERM ) )
diff --git a/util/src/main/java/org/apache/etch/util/StringUtil.java b/util/src/main/java/org/apache/etch/util/StringUtil.java
index 667688a..597cc1b 100644
--- a/util/src/main/java/org/apache/etch/util/StringUtil.java
+++ b/util/src/main/java/org/apache/etch/util/StringUtil.java
@@ -209,4 +209,13 @@
 		}
 		return sb.toString();
 	}
+
+	/**
+	 * @param s
+	 * @return true if s is null or empty.
+	 */
+	public static boolean isEmpty( String s )
+	{
+		return s == null || s.length() == 0;
+	}
 }