You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/05/05 18:54:48 UTC
svn commit: r1099869 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/net/Service.java
test/org/apache/commons/runtime/TestAddress.java
Author: mturk
Date: Thu May 5 16:54:48 2011
New Revision: 1099869
URL: http://svn.apache.org/viewvc?rev=1099869&view=rev
Log:
Implement Service aliases method
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestAddress.java
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java?rev=1099869&r1=1099868&r2=1099869&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java Thu May 5 16:54:48 2011
@@ -16,11 +16,17 @@
package org.apache.commons.runtime.net;
+import java.util.List;
+import java.util.ArrayList;
import org.apache.commons.runtime.InvalidArgumentException;
import org.apache.commons.runtime.Status;
/**
- * Represents tje Internet network service.
+ * Represents the Internet network service.
+ * <p>
+ * Retreives service information corresponding to a service
+ * name and protocol.
+ * </p>
*/
public final class Service
{
@@ -43,6 +49,16 @@ public final class Service
// No instance
}
+ /**
+ * Constructs a new Service object.
+ *
+ * @param name the service name to match.
+ *
+ * @throws NullPointerException
+ * if the argument {@code name} is {@code null}.
+ * @throws ServiceNotFoundException
+ * if the service is unknown.
+ */
public Service(String name)
throws NullPointerException,
ServiceNotFoundException
@@ -54,6 +70,18 @@ public final class Service
throw new ServiceNotFoundException(Status.describe(rc));
}
+ /**
+ * Constructs a new Service object.
+ *
+ * @param name the service name to match.
+ * @param protocol the service protocol to match.
+ *
+ * @throws NullPointerException
+ * if the argument {@code name} is {@code null}.
+ * @throws ServiceNotFoundException
+ * if the service is unknown or does not exsit for the
+ * specified {@code protocol}.
+ */
public Service(String name, String protocol)
throws NullPointerException,
ServiceNotFoundException
@@ -65,6 +93,16 @@ public final class Service
throw new ServiceNotFoundException(Status.describe(rc));
}
+ /**
+ * Constructs a new Service object.
+ *
+ * @param port the service port to match.
+ *
+ * @throws InvalidArgumentException
+ * if the argument {@code port} is invalid.
+ * @throws ServiceNotFoundException
+ * if the service is unknown.
+ */
public Service(int port)
throws InvalidArgumentException,
ServiceNotFoundException
@@ -76,6 +114,18 @@ public final class Service
throw new ServiceNotFoundException(Status.describe(rc));
}
+ /**
+ * Constructs a new Service object.
+ *
+ * @param port the service port to match.
+ * @param protocol the service protocol to match.
+ *
+ * @throws InvalidArgumentException
+ * if the argument {@code port} is invalid.
+ * @throws ServiceNotFoundException
+ * if the service is unknown or does not exsit for the
+ * specified {@code protocol}.
+ */
public Service(int port, String protocol)
throws NullPointerException,
InvalidArgumentException,
@@ -114,4 +164,19 @@ public final class Service
return port;
}
+ /**
+ * Gets the service alternate names.
+ *
+ * @return list of alternate service names or {@code null} if the service
+ * does not have alternate name(s).
+ */
+ public List<String> getAliases()
+ {
+ if (aliases == null)
+ return null;
+ ArrayList<String> a = new ArrayList<String>(aliases.length);
+ for (int i = 0; i < aliases.length; i++)
+ a.add(aliases[i]);
+ return a;
+ }
}
Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestAddress.java?rev=1099869&r1=1099868&r2=1099869&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestAddress.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestAddress.java Thu May 5 16:54:48 2011
@@ -53,8 +53,12 @@ public class TestAddress extends Assert
public void serviceName()
throws IOException
{
+ // XXX: It works only for lowercase names.
+ // Eg. "Http" will fail with EAGAIN.
+ //
Service s1 = new Service("http", "tcp");
assertEquals(s1.getPort(), 80);
+ assertNotNull(s1.getAliases());
Service s2 = new Service(21);
assertEquals(s2.getName(), "ftp");
}