directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r782980 [6/8] - in /directory/sandbox/slp/src/main/java/org/apache/directory/slp: ./ codec/ extensions/ impl/ impl/da/ impl/filter/ messages/
Date Tue, 09 Jun 2009 12:50:47 GMT
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPUtils.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPUtils.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPUtils.java Tue Jun
 9 12:50:45 2009
@@ -32,7 +32,6 @@
 
 import org.apache.directory.slp.OpaqueValue;
 
-
 /**
  * Utility class.
  * 
@@ -41,33 +40,33 @@
 public final class SLPUtils {
 
 	public static final String KEYWORD_STRING = "jslpkeyword";
-	
-	
+
 	/**
 	 * hidden constructor.
 	 */
-	private  SLPUtils() {
+	private SLPUtils() {
 
 	}
 
 	/**
-	 * get a <code>List</code> of attribute/value pairs in String
-	 * representation from a <code>Dictionary</code>.
+	 * get a <code>List</code> of attribute/value pairs in String representation
+	 * from a <code>Dictionary</code>.
 	 * 
 	 * @param attributes
 	 *            the <code>Dictionary</code>
 	 * @return the <code>List</code>.
 	 */
 	public static List<String> dictToAttrList(final Dictionary attributes) {
-		List<String> attList = new ArrayList<String>();
+		final List<String> attList = new ArrayList<String>();
 		if (attributes != null) {
-			for (Enumeration keys = attributes.keys(); keys.hasMoreElements();) {
-				Object key = keys.nextElement();
-				if (attributes.get(key).equals(KEYWORD_STRING)){
+			for (final Enumeration keys = attributes.keys(); keys
+					.hasMoreElements();) {
+				final Object key = keys.nextElement();
+				if (attributes.get(key).equals(KEYWORD_STRING)) {
 					attList.add(key.toString());
 					continue;
 				}
-				StringBuffer buffer = new StringBuffer();
+				final StringBuffer buffer = new StringBuffer();
 				buffer.append("(");
 				buffer.append(key);
 				buffer.append("=");
@@ -78,9 +77,9 @@
 		}
 		return attList;
 	}
-	
-	
-	public static String dictToString(final Dictionary<String,String> attributes){
+
+	public static String dictToString(
+			final Dictionary<String, String> attributes) {
 		return listToString(dictToAttrList(attributes), ",");
 	}
 
@@ -93,16 +92,16 @@
 	 *            the attribute list.
 	 * @return the <code>Dictionary</code>.
 	 */
-	static Dictionary<String,Object> attrListToDict(final List<String> attrList)
{
-		Dictionary<String,Object> dict = new Hashtable<String,Object>();
+	static Dictionary<String, Object> attrListToDict(final List<String> attrList)
{
+		final Dictionary<String, Object> dict = new Hashtable<String, Object>();
 
-		for (Iterator iter = attrList.iterator(); iter.hasNext();) {
+		for (final Iterator iter = attrList.iterator(); iter.hasNext();) {
 			String attrStr = (String) iter.next();
 			attrStr = attrStr.substring(1, attrStr.length() - 1);
-			int pos = attrStr.indexOf("=");
+			final int pos = attrStr.indexOf("=");
 			if (pos > -1) {
-				String key = attrStr.substring(0, pos).trim();
-				String value = attrStr.substring(pos + 1).trim();
+				final String key = attrStr.substring(0, pos).trim();
+				final String value = attrStr.substring(pos + 1).trim();
 				dict.put(key, value);
 			}
 		}
@@ -111,94 +110,99 @@
 	}
 
 	/**
-	 * This is the most important method of the class. It is used to parse the 
-	 * attribute lists from their string form as received in messages to their typed
-	 * form in the Service object.
+	 * This is the most important method of the class. It is used to parse the
+	 * attribute lists from their string form as received in messages to their
+	 * typed form in the Service object.
 	 * 
 	 * @param arr
-	 * 		The attributes as an array of string representations
+	 *            The attributes as an array of string representations
 	 * @return
 	 */
-	public static Dictionary<String,Object> stringArrayToDict(final String[] arr){
-		Dictionary<String,Object> dict = new Hashtable<String,Object>();
-		for (int i=0;i<arr.length;i++){
+	public static Dictionary<String, Object> stringArrayToDict(
+			final String[] arr) {
+		final Dictionary<String, Object> dict = new Hashtable<String, Object>();
+		for (int i = 0; i < arr.length; i++) {
 			String attrStr = arr[i];
-			attrStr = attrStr.substring(1,attrStr.length()-1);
-			int pos = attrStr.indexOf("=");
-			if (pos>-1){
-				String key = attrStr.substring(0, pos).trim();
-				String value = attrStr.substring(pos+1).trim();
-				//added by Lorenz to support multivalued attributes
-				String valueRep = value.replace("\\,", "SLP_ESCAPED_COMMA");
-				String[] valuesRep = valueRep.split(",");
-				String[] valuesFixed = new String[valuesRep.length];
+			attrStr = attrStr.substring(1, attrStr.length() - 1);
+			final int pos = attrStr.indexOf("=");
+			if (pos > -1) {
+				final String key = attrStr.substring(0, pos).trim();
+				final String value = attrStr.substring(pos + 1).trim();
+				// added by Lorenz to support multivalued attributes
+				final String valueRep = value.replace("\\,",
+						"SLP_ESCAPED_COMMA");
+				final String[] valuesRep = valueRep.split(",");
+				final String[] valuesFixed = new String[valuesRep.length];
 				int k = 0;
-				for (String s: valuesRep){
-					valuesFixed[k++] = s.replace("SLP_ESCAPED_COMMA", "\\,").trim();
+				for (final String s : valuesRep) {
+					valuesFixed[k++] = s.replace("SLP_ESCAPED_COMMA", "\\,")
+							.trim();
 				}
-				
-				if (valuesFixed.length==1){
-					if (value.toLowerCase().equals("true") || value.toLowerCase().equals("false")) {
-						dict.put(key, new Boolean(value) );
+
+				if (valuesFixed.length == 1) {
+					if (value.toLowerCase().equals("true")
+							|| value.toLowerCase().equals("false")) {
+						dict.put(key, new Boolean(value));
 					} else if (value.startsWith("\\FF")) {
-						dict.put(key, new OpaqueValue(value) );
+						dict.put(key, new OpaqueValue(value));
 					} else {
 						try {
-							int v = Integer.parseInt(value);
+							final int v = Integer.parseInt(value);
 							dict.put(key, v);
-						} catch (NumberFormatException e){
+						} catch (final NumberFormatException e) {
 							dict.put(key, value);
-						} 
+						}
 					}
 
 					continue;
 				}
-				
+
 				Object[] values;
 				String type;
-				String value1 = valuesFixed[0];
-				if (value1.startsWith("\\FF")){
+				final String value1 = valuesFixed[0];
+				if (value1.startsWith("\\FF")) {
 					values = new OpaqueValue[valuesFixed.length];
-					values[0]=new OpaqueValue(value1);
-					type="opaque";
-				} else if (value1.toLowerCase().equals("true") || value1.toLowerCase().equals("false")){
+					values[0] = new OpaqueValue(value1);
+					type = "opaque";
+				} else if (value1.toLowerCase().equals("true")
+						|| value1.toLowerCase().equals("false")) {
 					values = new Boolean[valuesFixed.length];
-					values[0]= Boolean.valueOf(value1);
-					type="boolean";
+					values[0] = Boolean.valueOf(value1);
+					type = "boolean";
 				} else {
 					try {
-						int v = Integer.parseInt(value1);
+						final int v = Integer.parseInt(value1);
 						values = new Number[valuesFixed.length];
 						values[0] = v;
-						type="integer";
-					} catch (NumberFormatException e){
+						type = "integer";
+					} catch (final NumberFormatException e) {
 						values = new String[valuesFixed.length];
-						values[0]=value1;
-						type="string";
+						values[0] = value1;
+						type = "string";
 					}
 				}
-				for (int j=1;j<values.length;j++){
-					if (type.equals("opaque")){
+				for (int j = 1; j < values.length; j++) {
+					if (type.equals("opaque")) {
 						values[j] = new OpaqueValue(valuesFixed[j]);
-					} else if (type.equals("string")){
-						values[j]=valuesFixed[j];
-					} else if (type.equals("boolean")){
-						values[j]=Boolean.valueOf(valuesFixed[j]);
+					} else if (type.equals("string")) {
+						values[j] = valuesFixed[j];
+					} else if (type.equals("boolean")) {
+						values[j] = Boolean.valueOf(valuesFixed[j]);
 					} else {
-						values[j]=Integer.parseInt(valuesFixed[j]);
+						values[j] = Integer.parseInt(valuesFixed[j]);
 					}
 
 				}
 				dict.put(key, values);
 			} else {
-				// this is a keyword attribute, Lorenz decided to handle it as a string
-				dict.put(attrStr,KEYWORD_STRING);
+				// this is a keyword attribute, Lorenz decided to handle it as a
+				// string
+				dict.put(attrStr, KEYWORD_STRING);
 			}
 		}
 		return dict;
 	}
-	
-	
+
 	/**
 	 * transforms a Java list to string list.
 	 * 
@@ -224,7 +228,7 @@
 			return buffer.toString();
 		}
 	}
-	
+
 	/**
 	 * transforms a String-array to a string list.
 	 * 
@@ -260,54 +264,51 @@
 	 * @return the List.
 	 */
 	public static List<String> stringToList(final String str, final String delim) {
-		List<String> result = new ArrayList<String>();
-		String strFixed = str.replace("\\"+delim, "SLP_ESCAPED_DELIM");
-		StringTokenizer tokenizer = new StringTokenizer(strFixed, delim);
+		final List<String> result = new ArrayList<String>();
+		final String strFixed = str.replace("\\" + delim, "SLP_ESCAPED_DELIM");
+		final StringTokenizer tokenizer = new StringTokenizer(strFixed, delim);
 		while (tokenizer.hasMoreTokens()) {
-			result.add(tokenizer.nextToken().replace("SLP_ESCAPED_DELIM", "\\"+delim));
+			result.add(tokenizer.nextToken().replace("SLP_ESCAPED_DELIM",
+					"\\" + delim));
 		}
 		return result;
 	}
-	
-	public static List<String> arrayToList(final String[] arr){
-		List<String> result = new ArrayList<String>();
-		for (int i=0;i< arr.length;i++){
+
+	public static List<String> arrayToList(final String[] arr) {
+		final List<String> result = new ArrayList<String>();
+		for (int i = 0; i < arr.length; i++) {
 			result.add(arr[i]);
 		}
-			
+
 		return result;
 	}
-	
-	public static String[] listToStringArray(final List list){
-		if (list==null){
-			return new String[]{};
-		}
-		if (list.isEmpty()){
-			return new String[]{};
-		}
-		String[] result = new String[list.size()];
-		for (int i = 0;i<result.length;i++){
-			result[i]=(String) list.get(i);
+
+	public static String[] listToStringArray(final List list) {
+		if (list == null) {
+			return new String[] {};
+		}
+		if (list.isEmpty()) {
+			return new String[] {};
+		}
+		final String[] result = new String[list.size()];
+		for (int i = 0; i < result.length; i++) {
+			result[i] = (String) list.get(i);
 		}
 		return result;
 	}
-	
-	
-	
-	
-	
-	public static String[] stringToStringArray(String string, String delim){
-		List<String> result = new ArrayList<String>();
-		String strFixed = string.replace("\\"+delim, "SLP_ESCAPED_DELIM");
-		StringTokenizer tokenizer = new StringTokenizer(strFixed, delim);
+
+	public static String[] stringToStringArray(final String string,
+			final String delim) {
+		final List<String> result = new ArrayList<String>();
+		final String strFixed = string.replace("\\" + delim,
+				"SLP_ESCAPED_DELIM");
+		final StringTokenizer tokenizer = new StringTokenizer(strFixed, delim);
 		while (tokenizer.hasMoreTokens()) {
-			result.add(tokenizer.nextToken().replace("SLP_ESCAPED_DELIM","\\"+delim));
+			result.add(tokenizer.nextToken().replace("SLP_ESCAPED_DELIM",
+					"\\" + delim));
 		}
-		return result.toArray(new String[]{});
+		return result.toArray(new String[] {});
 	}
-	
-	
-
 
 	/**
 	 * add a value to a value list in a Map.
@@ -366,7 +367,7 @@
 	static void removeValueFromAll(final Map map, final Object value) {
 		final Object[] keys = map.keySet().toArray();
 		for (int i = 0; i < keys.length; i++) {
-			List list = (List) map.get(keys[i]);
+			final List list = (List) map.get(keys[i]);
 			list.remove(value);
 			if (list.isEmpty()) {
 				map.remove(keys[i]);
@@ -395,13 +396,14 @@
 	 *            the attribute Dictionary.
 	 * @return a List of matches.
 	 */
-	public static List<String> findMatches(final List keyList, final Dictionary<String,String>
attributes) {
-		List<String> results = new ArrayList<String>();
-		Set<String> caseInsensitiveKeyList = new HashSet<String>();
-		List<String> wildcards = new ArrayList<String>();
+	public static List<String> findMatches(final List keyList,
+			final Dictionary<String, String> attributes) {
+		final List<String> results = new ArrayList<String>();
+		final Set<String> caseInsensitiveKeyList = new HashSet<String>();
+		final List<String> wildcards = new ArrayList<String>();
 		if (!keyList.isEmpty()) {
-			for (Iterator keys = keyList.iterator(); keys.hasNext();) {
-				String key = (String) keys.next();
+			for (final Iterator keys = keyList.iterator(); keys.hasNext();) {
+				final String key = (String) keys.next();
 				if (key.indexOf("*") == -1) {
 					caseInsensitiveKeyList.add(key.toLowerCase());
 				} else {
@@ -410,16 +412,16 @@
 			}
 		}
 
-		for (Enumeration keys = attributes.keys(); keys.hasMoreElements();) {
-			String key = (String) keys.nextElement();
+		for (final Enumeration keys = attributes.keys(); keys.hasMoreElements();) {
+			final String key = (String) keys.nextElement();
 			if (keyList.isEmpty()
 					|| caseInsensitiveKeyList.contains(key.toLowerCase())) {
 				results.add("(" + key + "=" + attributes.get(key).toString()
 						+ ")");
 				continue;
 			}
-			for (Iterator iter = wildcards.iterator(); iter.hasNext();) {
-				String wildcard = (String) iter.next();
+			for (final Iterator iter = wildcards.iterator(); iter.hasNext();) {
+				final String wildcard = (String) iter.next();
 				if (equalsWithWildcard(wildcard.toCharArray(), 0, key
 						.toCharArray(), 0)) {
 					results.add("(" + key + "="
@@ -445,8 +447,8 @@
 	 *            the current position within the attribute.
 	 * @return true if equals.
 	 */
-	private static boolean equalsWithWildcard(char[] val, int valIndex,
-			char[] attr, int attrIndex) {
+	private static boolean equalsWithWildcard(final char[] val, int valIndex,
+			final char[] attr, int attrIndex) {
 		if (val.length == valIndex) {
 			return attr.length == attrIndex;
 		}
@@ -460,108 +462,113 @@
 			} while (attr.length - attrIndex > -1);
 			return false;
 		} else {
-			return (attr.length == attrIndex || attr[attrIndex] != val[valIndex]) ? false
+			return attr.length == attrIndex || attr[attrIndex] != val[valIndex] ? false
 					: equalsWithWildcard(val, ++valIndex, attr, ++attrIndex);
 		}
 	}
 
-
 	/**
-	 * Merges the SLP attribute-list by merging multiple attributes with the same name and type
into one
+	 * Merges the SLP attribute-list by merging multiple attributes with the
+	 * same name and type into one
 	 * 
 	 * @param atts
-	 * 			The atttribute list as a a list of SLP atribute strings (name=value)
-	 * @return
-	 * 			The merged attributes as an array
-	 */
-	public static String[] mergeAttributes(List<String> atts){
-		Map<String,List<String>> ad = new Hashtable<String, List<String>>();
-		List<String> keywords = new ArrayList<String>();
-		
-		for (String s : atts){
-			String[] fields = s.split("=");
+	 *            The atttribute list as a a list of SLP atribute strings
+	 *            (name=value)
+	 * @return The merged attributes as an array
+	 */
+	public static String[] mergeAttributes(final List<String> atts) {
+		final Map<String, List<String>> ad = new Hashtable<String, List<String>>();
+		final List<String> keywords = new ArrayList<String>();
+
+		for (final String s : atts) {
+			final String[] fields = s.split("=");
 			String at_name = fields[0];
-			if (at_name.startsWith("(")){
-				at_name=at_name.substring(1);
+			if (at_name.startsWith("(")) {
+				at_name = at_name.substring(1);
 			}
-			if (at_name.endsWith(")")){
-				at_name=at_name.substring(0, at_name.length()-1);
+			if (at_name.endsWith(")")) {
+				at_name = at_name.substring(0, at_name.length() - 1);
 			}
-			if (fields.length==1 && !keywords.contains(at_name)){
+			if (fields.length == 1 && !keywords.contains(at_name)) {
 				keywords.add(at_name);
 				continue;
 			}
-			if (ad.keySet().contains(at_name)){
-				for (String s2:stringToList(fields[1].substring(0, fields[1].length()-1), ",")){
-					List<String> current = ad.get(at_name);
-					if (!current.contains(s2)){
+			if (ad.keySet().contains(at_name)) {
+				for (final String s2 : stringToList(fields[1].substring(0,
+						fields[1].length() - 1), ",")) {
+					final List<String> current = ad.get(at_name);
+					if (!current.contains(s2)) {
 						current.add(s2);
 					}
 				}
 				continue;
 			}
-			ad.put(at_name, stringToList(fields[1].substring(0, fields[1].length()-1), ","));
+			ad.put(at_name, stringToList(fields[1].substring(0, fields[1]
+					.length() - 1), ","));
 		}
-		
-		List<String> result = new ArrayList<String>();
-		Set<String> keys = ad.keySet();
-		for (String k:keys){
-			result.add("("+k+"="+listToString(ad.get(k), ",")+")");
+
+		final List<String> result = new ArrayList<String>();
+		final Set<String> keys = ad.keySet();
+		for (final String k : keys) {
+			result.add("(" + k + "=" + listToString(ad.get(k), ",") + ")");
 		}
-		for (String kw:keywords){
+		for (final String kw : keywords) {
 			result.add(kw);
 		}
 		return listToStringArray(result);
-		
+
 	}
-	
+
 	/**
-	 * Merges the SLP attribute-list by merging multiple attributes with the same name and type
into one
+	 * Merges the SLP attribute-list by merging multiple attributes with the
+	 * same name and type into one
 	 * 
 	 * @param atts
-	 * 			The atttribute list as a an array of SLP atribute strings (name=value)
-	 * @return
-	 * 			The merged attributes as an array
-	 */
-	public static String[] mergeAttributes(String[] atts){
-		Map<String,List<String>> ad = new Hashtable<String, List<String>>();
-		List<String> keywords = new ArrayList<String>();
-		
-		for (String s : atts){
-			String[] fields = s.split("=");
+	 *            The atttribute list as a an array of SLP atribute strings
+	 *            (name=value)
+	 * @return The merged attributes as an array
+	 */
+	public static String[] mergeAttributes(final String[] atts) {
+		final Map<String, List<String>> ad = new Hashtable<String, List<String>>();
+		final List<String> keywords = new ArrayList<String>();
+
+		for (final String s : atts) {
+			final String[] fields = s.split("=");
 			String at_name = fields[0];
-			if (at_name.startsWith("(")){
-				at_name=at_name.substring(1);
+			if (at_name.startsWith("(")) {
+				at_name = at_name.substring(1);
 			}
-			if (at_name.endsWith(")")){
-				at_name=at_name.substring(0, at_name.length()-1);
+			if (at_name.endsWith(")")) {
+				at_name = at_name.substring(0, at_name.length() - 1);
 			}
-			if (fields.length==1 && !keywords.contains(at_name)){
+			if (fields.length == 1 && !keywords.contains(at_name)) {
 				keywords.add(at_name);
 				continue;
 			}
-			if (ad.keySet().contains(at_name)){
-				for (String s2:stringToList(fields[1].substring(0, fields[1].length()-1), ",")){
-					List<String> current = ad.get(at_name);
-					if (!current.contains(s2)){
+			if (ad.keySet().contains(at_name)) {
+				for (final String s2 : stringToList(fields[1].substring(0,
+						fields[1].length() - 1), ",")) {
+					final List<String> current = ad.get(at_name);
+					if (!current.contains(s2)) {
 						current.add(s2);
 					}
 				}
 				continue;
 			}
-			ad.put(at_name, stringToList(fields[1].substring(0, fields[1].length()-1), ","));
+			ad.put(at_name, stringToList(fields[1].substring(0, fields[1]
+					.length() - 1), ","));
 		}
-		
-		List<String> result = new ArrayList<String>();
-		Set<String> keys = ad.keySet();
-		for (String k:keys){
-			result.add("("+k+"="+listToString(ad.get(k), ",")+")");
+
+		final List<String> result = new ArrayList<String>();
+		final Set<String> keys = ad.keySet();
+		for (final String k : keys) {
+			result.add("(" + k + "=" + listToString(ad.get(k), ",") + ")");
 		}
-		for (String kw:keywords){
+		for (final String kw : keywords) {
 			result.add(kw);
 		}
 		return listToStringArray(result);
-		
+
 	}
 
 }

Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ServiceLocationEnumerationImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ServiceLocationEnumerationImpl.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ServiceLocationEnumerationImpl.java
(original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ServiceLocationEnumerationImpl.java
Tue Jun  9 12:50:45 2009
@@ -26,7 +26,6 @@
 import org.apache.directory.slp.ServiceLocationEnumeration;
 import org.apache.directory.slp.ServiceLocationException;
 
-
 /**
  * the implementation of a ServiceLocationEnumeration.
  * 
@@ -37,12 +36,12 @@
 	/**
 	 * a list of results.
 	 */
-	private List<String> list;
+	private final List<String> list;
 
 	/**
 	 * internal Iterator over the elements of the list.
 	 */
-	private Iterator iterator;
+	private final Iterator iterator;
 
 	/**
 	 * creates a new ServiceLocationEnumerationImpl.
@@ -52,7 +51,7 @@
 	 */
 	ServiceLocationEnumerationImpl(final List<String> resultList) {
 		list = resultList != null ? resultList : new ArrayList<String>();
-		this.iterator = list.iterator();
+		iterator = list.iterator();
 	}
 
 	/**
@@ -66,7 +65,7 @@
 	public synchronized Object next() throws ServiceLocationException {
 		try {
 			return iterator.next();
-		} catch (Exception e) {
+		} catch (final Exception e) {
 			throw new ServiceLocationException(
 					ServiceLocationException.INTERNAL_SYSTEM_ERROR, e
 							.getMessage());
@@ -90,7 +89,7 @@
 	public synchronized Object nextElement() {
 		try {
 			return next();
-		} catch (ServiceLocationException sle) {
+		} catch (final ServiceLocationException sle) {
 			return null;
 		}
 	}

Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ServiceReplyFutureImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ServiceReplyFutureImpl.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ServiceReplyFutureImpl.java
(original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ServiceReplyFutureImpl.java
Tue Jun  9 12:50:45 2009
@@ -59,7 +59,7 @@
 	 * @param lifetime
 	 *            The time until the ReplyFuture is considered done in ms
 	 */
-	public ServiceReplyFutureImpl(long lifetime) {
+	public ServiceReplyFutureImpl(final long lifetime) {
 		super(lifetime);
 	}
 
@@ -73,12 +73,12 @@
 	 *            The scopes for which replies are expected. used for completion
 	 *            checks
 	 */
-	public ServiceReplyFutureImpl(long lifetime, List<String> scopes) {
+	public ServiceReplyFutureImpl(final long lifetime, final List<String> scopes) {
 		super(lifetime, scopes);
 	}
 
 	@Override
-	public void add(AbstractSLPReplyMessage reply) {
+	public void add(final AbstractSLPReplyMessage reply) {
 
 		if (reply == null || reply.getErrorCode() != 0) {
 			return;
@@ -97,14 +97,14 @@
 		}
 
 		if (reply instanceof ServiceReplyMessage) {
-			for (String s : reply.getResult()) {
+			for (final String s : reply.getResult()) {
 				try {
-					Service srv = new Service(new ServiceURL(s, 0));
+					final Service srv = new Service(new ServiceURL(s, 0));
 					synchronized (services) {
 						services.add(srv);
 					}
 
-				} catch (ServiceLocationException sle) {
+				} catch (final ServiceLocationException sle) {
 					continue;
 				}
 			}
@@ -114,10 +114,10 @@
 
 		// stick to the basic behaviour...
 		synchronized (responses) {
-			List<String> res = reply.getResultAsList();
+			final List<String> res = reply.getResultAsList();
 			if (res != null && res.size() > 0) {
-				List<String> resp = reply.getResultAsList();
-				for (String s : resp) {
+				final List<String> resp = reply.getResultAsList();
+				for (final String s : resp) {
 					if (!responses.contains(s)) {
 						responses.add(s);
 					}
@@ -135,21 +135,21 @@
 	 *            The reply message possibly containing extensions
 	 * 
 	 */
-	private void processExtensions(AbstractSLPReplyMessage reply) {
-		for (AbstractExtension ae : reply.getExtensions()) {
+	private void processExtensions(final AbstractSLPReplyMessage reply) {
+		for (final AbstractExtension ae : reply.getExtensions()) {
 			if (ae instanceof UnsupportedExtension) {
 				return;
 			}
 			switch (ae.getId()) {
 			case AbstractExtension.ATTRIBUTE_LIST_EXTENSION:
-				AttributeListExtension ale = (AttributeListExtension) ae;
+				final AttributeListExtension ale = (AttributeListExtension) ae;
 				if (SLPCore.CONFIG.getSecurityEnabled()) {
 					if (!ale.verify()) {
 						return;
 					}
 				}
 				synchronized (services) {
-					for (Service srv : services) {
+					for (final Service srv : services) {
 						if (srv.toString().toLowerCase().equals(
 								ale.getUrl().toLowerCase())) {
 							srv.setAttributes(SLPUtils
@@ -176,7 +176,7 @@
 				}
 				try {
 					services.wait(timeout - System.currentTimeMillis() + 1000);
-				} catch (InterruptedException e) {
+				} catch (final InterruptedException e) {
 
 				}
 			}
@@ -197,7 +197,7 @@
 			synchronized (donelock) {
 				try {
 					donelock.wait();
-				} catch (InterruptedException ie) {
+				} catch (final InterruptedException ie) {
 
 				}
 			}

Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ThreadedReplyFuture.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ThreadedReplyFuture.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ThreadedReplyFuture.java
(original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/ThreadedReplyFuture.java
Tue Jun  9 12:50:45 2009
@@ -26,241 +26,252 @@
 import org.apache.directory.slp.messages.AbstractSLPReplyMessage;
 
 /**
- * The future returned when performing SLP lookups. It can be accessed while results still
come in using next(),
- * or after all results have arrived using getResult().
+ * The future returned when performing SLP lookups. It can be accessed while
+ * results still come in using next(), or after all results have arrived using
+ * getResult().
  * 
  * @author Lorenz Breu
- *
+ * 
  */
 public class ThreadedReplyFuture implements ReplyFuture {
 
 	// used to wait for done status
 	protected final Object donelock = new Object();
-	
-	//List of responses (i.e. message results)
+
+	// List of responses (i.e. message results)
 	protected final List<String> responses = new ArrayList<String>();
-	
-	// List of responders, used to build initial list of previous responders for multicast convergence
+
+	// List of responders, used to build initial list of previous responders for
+	// multicast convergence
 	protected final List<String> responders = new ArrayList<String>();
-	
+
 	// point when reply future is closed automatically
 	protected long timeout;
-	
+
 	// set to true when all operations producing results have completed
 	protected boolean done = false;
-	
+
 	// the next position to be returned using the next() method.
 	// currently a future object is read by only one consumer.
 	private int nextPosition = 0;
-	
-	// the list of scopes this future has to cover, used to control correct closure.
+
+	// the list of scopes this future has to cover, used to control correct
+	// closure.
 	private List<String> unhandledScopes = new ArrayList<String>();
-	
+
 	// used to close the future when lifetime expires
-	private Thread timeoutThread;
-	
+	private final Thread timeoutThread;
+
 	/**
-	 * Basic constructor, sets a default timeout value and uses all scopes definied in CONFIG
+	 * Basic constructor, sets a default timeout value and uses all scopes
+	 * definied in CONFIG
 	 */
-	public ThreadedReplyFuture(){
-		//TODO: which wait time should we use here? has to be larger than the time it takes to
start and end the multicast convergence
-		this(SLPCore.CONFIG.getWaitTime()*5);
-	}
-	
-	
-	
-	
+	public ThreadedReplyFuture() {
+		// TODO: which wait time should we use here? has to be larger than the
+		// time it takes to start and end the multicast convergence
+		this(SLPCore.CONFIG.getWaitTime() * 5);
+	}
+
 	/**
-	 * Constructor with a specific lifetime. The future expects to handle all scopes defined
in CONFIG
+	 * Constructor with a specific lifetime. The future expects to handle all
+	 * scopes defined in CONFIG
 	 * 
 	 * @param lifetime
-	 * 				Number of milliseconds this future should remain open to receive results.
+	 *            Number of milliseconds this future should remain open to
+	 *            receive results.
 	 */
-	public ThreadedReplyFuture(long lifetime){
-		unhandledScopes = SLPUtils.stringToList(SLPCore.CONFIG.getScopes().toLowerCase(), ",");
-		timeout = System.currentTimeMillis()+lifetime;
+	public ThreadedReplyFuture(final long lifetime) {
+		unhandledScopes = SLPUtils.stringToList(SLPCore.CONFIG.getScopes()
+				.toLowerCase(), ",");
+		timeout = System.currentTimeMillis() + lifetime;
 		timeoutThread = new TimeoutThread();
 	}
-	
-	
+
 	/**
 	 * Detailed constructor.
 	 * 
 	 * @param lifetime
-	 * 			Number of milliseconds this future should remain open to receive results.
+	 *            Number of milliseconds this future should remain open to
+	 *            receive results.
 	 * @param scopes
-	 * 			List of scopes to be handled.
+	 *            List of scopes to be handled.
 	 */
-	public ThreadedReplyFuture(long lifetime,List<String> scopes){
-		for (String s : scopes){
+	public ThreadedReplyFuture(final long lifetime, final List<String> scopes) {
+		for (final String s : scopes) {
 			unhandledScopes.add(s.toLowerCase());
 		}
-		timeout = System.currentTimeMillis()+lifetime;
+		timeout = System.currentTimeMillis() + lifetime;
 		timeoutThread = new TimeoutThread();
 	}
-	
-	
-	
+
 	/**
-	 * Adds the result of an SLP reply message to the list of responses and the sender of the

-	 * reply to the list of responders, if the error code is 0. 
+	 * Adds the result of an SLP reply message to the list of responses and the
+	 * sender of the reply to the list of responders, if the error code is 0.
 	 * 
 	 * @param reply
-	 * 			An AbstractSLPReplyMessage obtained through unicast or multicast
+	 *            An AbstractSLPReplyMessage obtained through unicast or
+	 *            multicast
 	 */
-	public void add(AbstractSLPReplyMessage reply){
+	public void add(final AbstractSLPReplyMessage reply) {
 
-		if (reply==null || reply.getErrorCode()!=0){
+		if (reply == null || reply.getErrorCode() != 0) {
 			return;
 		}
-		if (done){
+		if (done) {
 			// this reply is coming in too late...
 			return;
 		}
-		
-		synchronized (responders){
+
+		synchronized (responders) {
 			if (!responders.contains(reply.getSource())) {
 				responders.add(reply.getSource());
 			} else {
 				return;
 			}
 		}
-		
-		synchronized(responses){
-			List<String> res = reply.getResultAsList();
-			if (res!=null && res.size()>0){
-				List<String> resp = reply.getResultAsList();
-				for (String s: resp){
-					if (!responses.contains(s)){
+
+		synchronized (responses) {
+			final List<String> res = reply.getResultAsList();
+			if (res != null && res.size() > 0) {
+				final List<String> resp = reply.getResultAsList();
+				for (final String s : resp) {
+					if (!responses.contains(s)) {
 						responses.add(s);
 					}
 				}
 				responses.notifyAll();
 			}
 		}
-		
+
 	}
-	
+
 	/**
-	 * Close the future.
-	 * If the override flag is set, the future will be closed directly.
-	 * If override is false, then the defined scopes will be removed from the list of unhandled
scopes
-	 * and the future will be closed only if no scopes remain unhandled. Else it will remain
open.
+	 * Close the future. If the override flag is set, the future will be closed
+	 * directly. If override is false, then the defined scopes will be removed
+	 * from the list of unhandled scopes and the future will be closed only if
+	 * no scopes remain unhandled. Else it will remain open.
 	 * 
 	 * @param scopes
-	 * 			The scopes to mark as done.
+	 *            The scopes to mark as done.
 	 * @param override
-	 * 			Set to true if the future should be closed even if scopes remain unhandled (e.g. timeout)
+	 *            Set to true if the future should be closed even if scopes
+	 *            remain unhandled (e.g. timeout)
 	 */
-	public synchronized void setDone(String[] scopes, boolean override){
-		synchronized (unhandledScopes){
-			for (String s: scopes){
+	public synchronized void setDone(final String[] scopes,
+			final boolean override) {
+		synchronized (unhandledScopes) {
+			for (final String s : scopes) {
 				unhandledScopes.remove(s.toLowerCase());
 			}
 		}
-		
-		if (!unhandledScopes.isEmpty() && !override){
-			//oops, not all scopes that were expected to be handled actually were handled, so keep
waiting
+
+		if (!unhandledScopes.isEmpty() && !override) {
+			// oops, not all scopes that were expected to be handled actually
+			// were handled, so keep waiting
 			return;
 		}
-		if (!done){
-			done=true;
-			synchronized(donelock){
+		if (!done) {
+			done = true;
+			synchronized (donelock) {
 				donelock.notifyAll();
 			}
-			synchronized(responses){
+			synchronized (responses) {
 				responses.notifyAll();
 			}
 		}
 		try {
 			timeoutThread.interrupt();
-		} catch (Exception e){
+		} catch (final Exception e) {
 			System.out.println("oops");
 		}
 	}
-	
-	/* (non-Javadoc)
+
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see ch.ethz.iks.slp.ServiceLocationEnumeration#next()
 	 */
-	public String next(){
-		// NOTE: a future is currently only read by one consumer (i.e. LocatorImpl) and therefor
a single
-		// position marker is sufficient. Also the data containers holding responses must add new
elements to the end.
-		synchronized(responses){
-			while (!done){
-				if (responses.size()>nextPosition){
+	public String next() {
+		// NOTE: a future is currently only read by one consumer (i.e.
+		// LocatorImpl) and therefor a single
+		// position marker is sufficient. Also the data containers holding
+		// responses must add new elements to the end.
+		synchronized (responses) {
+			while (!done) {
+				if (responses.size() > nextPosition) {
 					return responses.get(nextPosition++);
 				}
-				try{
-					responses.wait(timeout-System.currentTimeMillis()+1000);
-				} catch (InterruptedException e){
-					
+				try {
+					responses.wait(timeout - System.currentTimeMillis() + 1000);
+				} catch (final InterruptedException e) {
+
 				}
 			}
-			if (responses.size()>nextPosition){
+			if (responses.size() > nextPosition) {
 				return responses.get(nextPosition++);
 			}
 			return null;
 		}
 	}
-	
-	
+
 	/**
 	 * Returns the status of the future.
 	 * 
-	 * @return
-	 * 		True if done, false if results can still be added.
+	 * @return True if done, false if results can still be added.
 	 */
-	public synchronized boolean isDone(){
+	public synchronized boolean isDone() {
 		return done;
 	}
-	
-	
+
 	/**
-	 * Blocking call that waits until the future is marked as "done" before returning all available
responses.
+	 * Blocking call that waits until the future is marked as "done" before
+	 * returning all available responses.
 	 * 
-	 * @return
-	 * 		A list of all results obtained during the unicast or multicast SLP operation in the
form of Strings.
+	 * @return A list of all results obtained during the unicast or multicast
+	 *         SLP operation in the form of Strings.
 	 */
-	public List<String> getResult(){
-		while (!done){
-			synchronized (donelock){
+	public List<String> getResult() {
+		while (!done) {
+			synchronized (donelock) {
 				try {
 					donelock.wait();
-				} catch (InterruptedException ie){
-					
+				} catch (final InterruptedException ie) {
+
 				}
 			}
 		}
 		return responses;
 	}
-	
-	
+
 	/**
-	 * Returns the sources of all reply messages with error code 0 passed on to this future.

+	 * Returns the sources of all reply messages with error code 0 passed on to
+	 * this future.
 	 * 
-	 * @return
-	 * 		Array of IP addresses as Strings in dot notation of the sources of reply messages.
+	 * @return Array of IP addresses as Strings in dot notation of the sources
+	 *         of reply messages.
 	 */
-	public synchronized String[] getResponders(){
+	public synchronized String[] getResponders() {
 		return SLPUtils.listToStringArray(responders);
 	}
-	
-	/* (non-Javadoc)
+
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see java.util.Enumeration#hasMoreElements()
 	 */
 	public synchronized boolean hasMoreElements() {
-		return (responses.size()>nextPosition);
+		return responses.size() > nextPosition;
 	}
 
-	/* (non-Javadoc)
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see java.util.Enumeration#nextElement()
 	 */
 	public String nextElement() {
 		return next();
 	}
-	
-	
-	
+
 	/**
 	 * setup a new thread to close this future when it times out.
 	 * 
@@ -268,34 +279,26 @@
 	private class TimeoutThread extends Thread {
 
 		public TimeoutThread() {
-			this.start();
+			start();
 		}
 
+		@Override
 		public void run() {
 
 			long remain;
 
 			// while lifetime is not expired
-			while (((remain=timeout-System.currentTimeMillis())>0) && !isDone()){
+			while ((remain = timeout - System.currentTimeMillis()) > 0
+					&& !isDone()) {
 				try {
 					Thread.sleep(remain);
-				} catch (InterruptedException ie){
+				} catch (final InterruptedException ie) {
 					continue;
 				}
 			}
 			// close the future, even if scopes remain unhandled
-			setDone(new String[]{},true);
+			setDone(new String[] {}, true);
 		}
 	}
 
-
 }
-
-	
-	
-	
-	
-	
-	
-	
-

Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/da/DirectoryAgentDaemon.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/da/DirectoryAgentDaemon.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/da/DirectoryAgentDaemon.java
(original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/da/DirectoryAgentDaemon.java
Tue Jun  9 12:50:45 2009
@@ -31,143 +31,147 @@
 import org.apache.directory.slp.messages.ServiceDeregistrationMessage;
 import org.apache.directory.slp.messages.ServiceRegistrationMessage;
 
-
 /**
- * Internal interface of the jSLP Directory Agent. This interface is to the "daemon" that
does message handling
- * and reads services from and writes them to the store. This should only be used by the
jSLP machinery, not fro the outside.
- * To access the DA from a client application, or to start a standalone DA, use the DirectoryAgent
interface.
+ * Internal interface of the jSLP Directory Agent. This interface is to the
+ * "daemon" that does message handling and reads services from and writes them
+ * to the store. This should only be used by the jSLP machinery, not fro the
+ * outside. To access the DA from a client application, or to start a standalone
+ * DA, use the DirectoryAgent interface.
  * 
  * @author Lorenz Breu
  */
 public interface DirectoryAgentDaemon {
 
 	/**
-	 * This does the actual message handling and controlling. Called by the SLPHandler if it
receives a message
-	 * of interest.
+	 * This does the actual message handling and controlling. Called by the
+	 * SLPHandler if it receives a message of interest.
 	 * 
 	 * @param msg
-	 * 		The received AbstractSLPMessage
-	 * @return
-	 * 		The reply if the received message triggers such, null else.
+	 *            The received AbstractSLPMessage
+	 * @return The reply if the received message triggers such, null else.
 	 * @throws ServiceLocationException
 	 */
-	public AbstractSLPReplyMessage handleMessage(AbstractSLPMessage msg) throws ServiceLocationException;
-	
+	public AbstractSLPReplyMessage handleMessage(AbstractSLPMessage msg)
+			throws ServiceLocationException;
+
 	/**
 	 * Checks if the DA is set to handle requests in this specific scope.
 	 * 
 	 * @param scope
-	 * 		The scope to be checked
-	 * @return
-	 * 		True if the DA supports that scope, false otherwise
+	 *            The scope to be checked
+	 * @return True if the DA supports that scope, false otherwise
 	 */
 	public boolean isInScope(String scope);
-	
+
 	/**
 	 * Builds the DAAdvertisementMessage.
 	 * 
-	 * @return
-	 * 		A DAAdvertisementMessage
+	 * @return A DAAdvertisementMessage
 	 * @throws ServiceLocationException
 	 */
 	public DAAdvertisementMessage buildAdvert() throws ServiceLocationException;
-	
+
 	/**
 	 * Gets the statelessBootTimestamp of the DA
 	 * 
-	 * @return
-	 * 		statelessBootTimestamp
-	 * 		
+	 * @return statelessBootTimestamp
+	 * 
 	 */
 	public int getStatelessBootTimestamp();
-	
+
 	/**
 	 * Sets the store that contains the registered services
 	 * 
 	 * @param store
-	 * 		An object that implements the ServiceStore interface
+	 *            An object that implements the ServiceStore interface
 	 */
 	public void setStore(ServiceStore store);
-	
+
 	/**
 	 * Checks if a service with the given url has been registered with this DA
 	 * 
 	 * @param service
-	 * 		The service to be checked
-	 * @return
-	 * 		True if a service with that url has been found in the store
+	 *            The service to be checked
+	 * @return True if a service with that url has been found in the store
 	 */
 	public boolean isKnownService(Service service);
-	
+
 	/**
 	 * Updates a registered service entry with new attributes.
 	 * 
 	 * @param reg
-	 * 			A ServiceRegistrationMessage which doesn't have the FRESH flag set.
+	 *            A ServiceRegistrationMessage which doesn't have the FRESH flag
+	 *            set.
 	 * @throws ServiceLocationException
 	 */
-	public void updateServiceEntry(ServiceRegistrationMessage reg) throws ServiceLocationException;
-	
+	public void updateServiceEntry(ServiceRegistrationMessage reg)
+			throws ServiceLocationException;
+
 	/**
 	 * Register the service (if all checks pass) with the DA.
 	 * 
 	 * @param reg
-	 * 			A FRESH service registration message
+	 *            A FRESH service registration message
 	 * @throws ServiceLocationException
 	 */
-	public void registerService(ServiceRegistrationMessage reg) throws ServiceLocationException;
-	
+	public void registerService(ServiceRegistrationMessage reg)
+			throws ServiceLocationException;
+
 	/**
-	 * Register the service (if all checks pass) with the DA. This method does not have to perform
any
-	 * checks, it just registers the service.
+	 * Register the service (if all checks pass) with the DA. This method does
+	 * not have to perform any checks, it just registers the service.
+	 * 
 	 * @param reg
-	 * 			The service to be registered
+	 *            The service to be registered
 	 * @throws ServiceLocationException
 	 */
-	public void registerService(Service service) throws ServiceLocationException;
-	
+	public void registerService(Service service)
+			throws ServiceLocationException;
+
 	/**
 	 * Deregisters a service from the DA.
 	 * 
 	 * @param dereg
-	 * 			The ServiceDeregistrationMessage asking for the deregistration.
+	 *            The ServiceDeregistrationMessage asking for the
+	 *            deregistration.
 	 * @throws ServiceLocationException
 	 */
-	public void deregisterService(ServiceDeregistrationMessage dereg) throws ServiceLocationException;
-	
+	public void deregisterService(ServiceDeregistrationMessage dereg)
+			throws ServiceLocationException;
+
 	/**
 	 * Deregisters a service from the DA.
 	 * 
 	 * @param dereg
-	 * 			The Service to be deregistered.
+	 *            The Service to be deregistered.
 	 * @throws ServiceLocationException
 	 */
-	public void deregisterService(Service service) throws ServiceLocationException;
-	
+	public void deregisterService(Service service)
+			throws ServiceLocationException;
+
 	/**
 	 * Lists all services currently registered with the DA.
 	 * 
-	 * @return
-	 * 		A List of the service urls of all registered services.
+	 * @return A List of the service urls of all registered services.
 	 */
 	public List<Service> listServices();
-	
+
 	/**
-	 * Shuts the DA down and sends a DAAdvert informing other SLP agents of this fact.
-	 * All registered services are lost on shutdown.
+	 * Shuts the DA down and sends a DAAdvert informing other SLP agents of this
+	 * fact. All registered services are lost on shutdown.
 	 */
 	public void shutdown();
-	
-	
+
 	/**
-	 * Returns the mappings of attributes of specific abstract SLP service types to their type
(string, integer, boolean, opaquevalue or array thereof)
-	 * The method returns a copy of the actual type registry, changes made to the returned object
are not
-	 * reflected in the actual type registry
+	 * Returns the mappings of attributes of specific abstract SLP service types
+	 * to their type (string, integer, boolean, opaquevalue or array thereof)
+	 * The method returns a copy of the actual type registry, changes made to
+	 * the returned object are not reflected in the actual type registry
 	 * 
-	 * @return
-	 * 		A copy of the attribute type registry
+	 * @return A copy of the attribute type registry
 	 * @throws ServiceLocationException
-	 * 		If not implemented
+	 *             If not implemented
 	 */
-	public Map<String, Integer> getAttributeTypes() throws ServiceLocationException;
+	public Map<String, Integer> getAttributeTypes()
+			throws ServiceLocationException;
 }



Mime
View raw message