[or-cvs] r11431: added method for replacing existing configuration strings (in puppetor/trunk/src/de/uniba/wiai/lspi/puppetor: . impl)

kloesing at seul.org kloesing at seul.org
Wed Sep 12 09:08:54 UTC 2007


Author: kloesing
Date: 2007-09-12 05:08:54 -0400 (Wed, 12 Sep 2007)
New Revision: 11431

Modified:
   puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/ProxyNode.java
   puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java
Log:
added method for replacing existing configuration strings

Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/ProxyNode.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/ProxyNode.java	2007-09-11 20:17:28 UTC (rev 11430)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/ProxyNode.java	2007-09-12 09:08:54 UTC (rev 11431)
@@ -63,13 +63,15 @@
 			Set<String> authorizedDirServerStrings);
 
 	/**
-	 * Adds the given configuration string to the configuration of this node.
+	 * Adds the given configuration string, consisting of "<configuration key>
+	 * <configuration value>", to the configuration of this node.
 	 * 
 	 * @param configurationString
 	 *            The configuration string to be added.
 	 * @throws IllegalArgumentException
 	 *             Thrown if the given configurationString is either
-	 *             <code>null</code> or a zero-length string.
+	 *             <code>null</code>, a zero-length string, or does not
+	 *             consist of configuration key and value.
 	 * @throws IllegalStateException
 	 *             Thrown if not invoked in state
 	 *             <code>NodeState.CONFIGURING</code>.
@@ -77,6 +79,26 @@
 	public abstract void addConfiguration(String configurationString);
 
 	/**
+	 * Replaces the first configuration string, consisting of "<configuration
+	 * key> <configuration value>", that contains the same configuration key as
+	 * <code>configurationString</code> by this new configuration string; if
+	 * multiple occurrences of the given configuration key are found, only the
+	 * first occurrence is replaced; if no configuration can be found, the
+	 * configuration string is added.
+	 * 
+	 * @param configurationString
+	 *            The replacing configuration string.
+	 * @throws IllegalArgumentException
+	 *             Thrown if the given configurationString is either
+	 *             <code>null</code>, a zero-length string, or does not
+	 *             consist of configuration key and value.
+	 * @throws IllegalStateException
+	 *             Thrown if not invoked in state
+	 *             <code>NodeState.CONFIGURING</code>.
+	 */
+	public abstract void replaceConfiguration(String configurationString);
+
+	/**
 	 * Returns the name of this node.
 	 * 
 	 * @return The name of this node.

Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java	2007-09-11 20:17:28 UTC (rev 11430)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java	2007-09-12 09:08:54 UTC (rev 11431)
@@ -9,6 +9,7 @@
 import java.io.InputStreamReader;
 import java.net.Socket;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.logging.Level;
@@ -207,7 +208,8 @@
 	public void addConfiguration(String configurationString) {
 
 		// log entering
-		this.logger.entering(this.getClass().getName(), "addConfiguration");
+		this.logger.entering(this.getClass().getName(), "addConfiguration",
+				configurationString);
 
 		// check state
 		if (this.nodeState != NodeState.CONFIGURING) {
@@ -218,7 +220,8 @@
 		}
 
 		// check parameter
-		if (configurationString == null || configurationString.length() < 1) {
+		if (configurationString == null || configurationString.length() < 1
+				|| !configurationString.contains(" ")) {
 			IllegalArgumentException e = new IllegalArgumentException();
 			this.logger.throwing(this.getClass().getName(), "addConfiguration",
 					e);
@@ -232,6 +235,56 @@
 		this.logger.exiting(this.getClass().getName(), "addConfiguration");
 	}
 
+	public void replaceConfiguration(String configurationString) {
+
+		// log entering
+		this.logger.entering(this.getClass().getName(), "replaceConfiguration",
+				configurationString);
+
+		// check state
+		if (this.nodeState != NodeState.CONFIGURING) {
+			IllegalStateException e = new IllegalStateException();
+			this.logger.throwing(this.getClass().getName(),
+					"replaceConfiguration", e);
+			throw e;
+		}
+
+		// check parameter
+		if (configurationString == null || configurationString.length() < 1
+				|| !configurationString.contains(" ")) {
+			IllegalArgumentException e = new IllegalArgumentException();
+			this.logger.throwing(this.getClass().getName(),
+					"replaceConfiguration", e);
+			throw e;
+		}
+
+		// extract configuration key
+		String configurationKey = configurationString.substring(0,
+				configurationString.indexOf(" "));
+
+		// iterate over existing configuration strings and replace first
+		// occurrence of configuration key with new configuration string
+		Iterator<String> it = this.configuration.listIterator();
+		boolean replaced = false;
+		for (int counter = 0; !replaced && it.hasNext(); counter++) {
+			String currentConfigurationString = it.next();
+			String currentConfigurationKey = currentConfigurationString
+					.substring(0, currentConfigurationString.indexOf(" "));
+			if (currentConfigurationKey.equals(configurationKey)) {
+				this.configuration.set(counter, configurationString);
+				replaced = true;
+			}
+		}
+		
+		// if no such configuration key was found, append the configuration string
+		if (!replaced) {
+			this.configuration.add(configurationString);
+		}
+
+		// log exiting
+		this.logger.exiting(this.getClass().getName(), "replaceConfiguration");
+	}
+
 	public synchronized void addHiddenService(String serviceName,
 			int servicePort, int virtualPort) {
 



More information about the tor-commits mailing list