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 16:03:08 UTC

svn commit: r1099811 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/Service.java java/org/apache/commons/runtime/net/ServiceNotFoundException.java native/shared/netaddr.c native/shared/netserv.c

Author: mturk
Date: Thu May  5 14:03:07 2011
New Revision: 1099811

URL: http://svn.apache.org/viewvc?rev=1099811&view=rev
Log:
Add service not found exception

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServiceNotFoundException.java   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Service.java
    commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
    commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c

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=1099811&r1=1099810&r2=1099811&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 14:03:07 2011
@@ -16,6 +16,9 @@
 
 package org.apache.commons.runtime.net;
 
+import org.apache.commons.runtime.InvalidArgumentException;
+import org.apache.commons.runtime.Status;
+
 /**
  * Represents tje Internet network service.
  */
@@ -26,44 +29,65 @@ public final class Service
     private int         port;
     private String[]    aliases;
 
-    private static native void   init0();
+    private static native void init0();
 
     private native int  getservbyname(String name, String proto);
-    private native int  getservbyport(int port, String proto);
+    private native int  getservbyport(char port, String proto);
 
     static {
         init0();
     }
-    
+
     private Service()
     {
         // No instance
     }
 
     public Service(String name)
+        throws NullPointerException,
+               ServiceNotFoundException
     {
         if (name == null)
             throw new NullPointerException();
         int rc = getservbyname(name, null);
+        if (rc != 0)
+            throw new ServiceNotFoundException(Status.describe(rc));
     }
-    
+
     public Service(String name, String protocol)
+        throws NullPointerException,
+               ServiceNotFoundException
     {
         if (name == null || protocol == null)
             throw new NullPointerException();
         int rc = getservbyname(name, protocol);
+        if (rc != 0)
+            throw new ServiceNotFoundException(Status.describe(rc));
     }
 
     public Service(int port)
+        throws InvalidArgumentException,
+               ServiceNotFoundException
     {
-        int rc = getservbyport(port, null);
+        if (port < 0 || port > 65535)
+            throw new InvalidArgumentException();
+        int rc = getservbyport((char)port, null);
+        if (rc != 0)
+            throw new ServiceNotFoundException(Status.describe(rc));
     }
 
     public Service(int port, String protocol)
+        throws NullPointerException,
+               InvalidArgumentException,
+               ServiceNotFoundException
     {
         if (protocol == null)
             throw new NullPointerException();
-        int rc = getservbyport(port, protocol);
+        if (port < 0 || port > 65535)
+            throw new InvalidArgumentException();
+        int rc = getservbyport((char)port, protocol);
+        if (rc != 0)
+            throw new ServiceNotFoundException(Status.describe(rc));
     }
 
     /**

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServiceNotFoundException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServiceNotFoundException.java?rev=1099811&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServiceNotFoundException.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServiceNotFoundException.java Thu May  5 14:03:07 2011
@@ -0,0 +1,40 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.net;
+
+import org.apache.commons.runtime.NoSuchObjectException;
+
+/**
+ * ServiceNotFoundException is thrown when an attempt is made to
+ * create unexisting network Service {@code object}.
+ *
+ * @since Runtime 1.0
+ */
+
+public class ServiceNotFoundException extends NoSuchObjectException
+{
+
+    public ServiceNotFoundException()
+    {
+        super();
+    }
+
+    public ServiceNotFoundException(String msg)
+    {
+        super(msg);
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ServiceNotFoundException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c?rev=1099811&r1=1099810&r2=1099811&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c Thu May  5 14:03:07 2011
@@ -410,7 +410,7 @@ AcrGetSockaddrIp(char *buf, int buflen, 
     if (sockaddr->family == AF_INET6 &&
         IN6_IS_ADDR_V4MAPPED((struct in6_addr *)sockaddr->ipaddr) &&
         buflen > 7) {
-        /* Number 7 here is strlen("::ffff:") */    
+        /* Number 7 here is strlen("::ffff:") */
         /* This is an IPv4-mapped IPv6 address; drop the leading
          * part of the address string so we're left with the familiar
          * IPv4 format.
@@ -885,7 +885,7 @@ ACR_NET_EXPORT(jint, SocketAddress, sock
     switch (family) {
         case 1:
             ffamily = AF_INET;
-        break;    
+        break;
         case 2:
             ffamily = AF_INET6;
         break;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c?rev=1099811&r1=1099810&r2=1099811&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/netserv.c Thu May  5 14:03:07 2011
@@ -98,7 +98,7 @@ ACR_NET_EXPORT(jint, Service, getservbyn
     return rc;
 }
 
-ACR_NET_EXPORT(jint, Service, getservbyport)(JNI_STDARGS, jint port, jstring proto)
+ACR_NET_EXPORT(jint, Service, getservbyport)(JNI_STDARGS, jchar port, jstring proto)
 {
     int rc = 0;
     struct servent *se;