You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/07/10 08:03:53 UTC

[tomcat] branch 7.0.x updated: Code clean-up.

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/7.0.x by this push:
     new 2b6d105  Code clean-up.
2b6d105 is described below

commit 2b6d105f6061a0d4f3a803357486acf7b9d69191
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jul 10 09:01:44 2019 +0100

    Code clean-up.
    
    Generally, align with 8.5.x. Add i18n, enhanced for loops, reduced
    casting, use interfaces rather than concrete types.
---
 .../factory/webservices/LocalStrings.properties    | 16 ++++++
 .../factory/webservices/LocalStrings_fr.properties | 16 ++++++
 .../factory/webservices/LocalStrings_ja.properties | 16 ++++++
 .../naming/factory/webservices/ServiceProxy.java   | 15 +++--
 .../factory/webservices/ServiceRefFactory.java     | 66 +++++++---------------
 5 files changed, 75 insertions(+), 54 deletions(-)

diff --git a/java/org/apache/naming/factory/webservices/LocalStrings.properties b/java/org/apache/naming/factory/webservices/LocalStrings.properties
new file mode 100644
index 0000000..0c5d17e
--- /dev/null
+++ b/java/org/apache/naming/factory/webservices/LocalStrings.properties
@@ -0,0 +1,16 @@
+# 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.
+
+serviceProxy.portNotFound=Port-component-ref [{0}] not found
diff --git a/java/org/apache/naming/factory/webservices/LocalStrings_fr.properties b/java/org/apache/naming/factory/webservices/LocalStrings_fr.properties
new file mode 100644
index 0000000..94053ed
--- /dev/null
+++ b/java/org/apache/naming/factory/webservices/LocalStrings_fr.properties
@@ -0,0 +1,16 @@
+# 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.
+
+serviceProxy.portNotFound=Le port-component-ref [{0}] n''a pas été trouvé
diff --git a/java/org/apache/naming/factory/webservices/LocalStrings_ja.properties b/java/org/apache/naming/factory/webservices/LocalStrings_ja.properties
new file mode 100644
index 0000000..a210092
--- /dev/null
+++ b/java/org/apache/naming/factory/webservices/LocalStrings_ja.properties
@@ -0,0 +1,16 @@
+# 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.
+
+serviceProxy.portNotFound=port-component-ref [{0}] [{0}]が見つかりません
diff --git a/java/org/apache/naming/factory/webservices/ServiceProxy.java b/java/org/apache/naming/factory/webservices/ServiceProxy.java
index 4f6fee3..4539c83 100644
--- a/java/org/apache/naming/factory/webservices/ServiceProxy.java
+++ b/java/org/apache/naming/factory/webservices/ServiceProxy.java
@@ -14,8 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.naming.factory.webservices;
 
 import java.lang.reflect.InvocationHandler;
@@ -29,20 +27,22 @@ import javax.xml.namespace.QName;
 import javax.xml.rpc.Service;
 import javax.xml.rpc.ServiceException;
 
+import org.apache.naming.StringManager;
+
 /**
  * Object proxy for Web Services.
  *
  * @author Fabien Carrion
  */
+public class ServiceProxy implements InvocationHandler {
 
-public class ServiceProxy
-    implements InvocationHandler {
+    private static final StringManager sm = StringManager.getManager(ServiceProxy.class);
 
     /**
      * Service object.
      * used for delegation
      */
-    private Service service = null;
+    private final Service service;
 
     /**
      * changing behavior to method : Service.getPort(QName, Class)
@@ -101,14 +101,13 @@ public class ServiceProxy
      * @return Returns the correct Port
      * @throws ServiceException if port's QName is an unknown Port (not defined in WSDL).
      */
-    @SuppressWarnings("unchecked")
     private Object getProxyPortQNameClass(Object[] args)
     throws ServiceException {
         QName name = (QName) args[0];
         String nameString = name.getLocalPart();
         Class<?> serviceendpointClass = (Class<?>) args[1];
 
-        for (Iterator<QName> ports = service.getPorts(); ports.hasNext();) {
+        for (@SuppressWarnings("unchecked") Iterator<QName> ports = service.getPorts(); ports.hasNext();) {
             QName portName = ports.next();
             String portnameString = portName.getLocalPart();
             if (portnameString.equals(nameString)) {
@@ -117,7 +116,7 @@ public class ServiceProxy
         }
 
         // no ports have been found
-        throw new ServiceException("Port-component-ref : " + name + " not found");
+        throw new ServiceException(sm.getString("serviceProxy.portNotFound", name));
     }
 
     /**
diff --git a/java/org/apache/naming/factory/webservices/ServiceRefFactory.java b/java/org/apache/naming/factory/webservices/ServiceRefFactory.java
index b36a6af..6d9a496 100644
--- a/java/org/apache/naming/factory/webservices/ServiceRefFactory.java
+++ b/java/org/apache/naming/factory/webservices/ServiceRefFactory.java
@@ -21,6 +21,7 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -32,7 +33,6 @@ import javax.naming.Context;
 import javax.naming.Name;
 import javax.naming.NamingException;
 import javax.naming.RefAddr;
-import javax.naming.Reference;
 import javax.naming.spi.ObjectFactory;
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
@@ -56,28 +56,10 @@ import org.apache.naming.ServiceRef;
  *
  * @author Fabien Carrion
  */
-
-public class ServiceRefFactory
-    implements ObjectFactory {
-
-
-    // ----------------------------------------------------------- Constructors
-
-
-    // -------------------------------------------------------------- Constants
-
-
-    // ----------------------------------------------------- Instance Variables
-
-
-    // --------------------------------------------------------- Public Methods
-
-
-    // -------------------------------------------------- ObjectFactory Methods
-
+public class ServiceRefFactory implements ObjectFactory {
 
     /**
-     * Crete a new serviceref instance.
+     * Create a new serviceref instance.
      *
      * @param obj The reference object describing the webservice
      */
@@ -87,7 +69,7 @@ public class ServiceRefFactory
     throws Exception {
 
         if (obj instanceof ServiceRef) {
-            Reference ref = (Reference) obj;
+            ServiceRef ref = (ServiceRef) obj;
 
             // ClassLoader
             ClassLoader tcl =
@@ -110,8 +92,7 @@ public class ServiceRefFactory
                 wsdlRefAddr = (String) tmp.getContent();
 
             // PortComponent
-            Hashtable<String,QName> portComponentRef =
-                new Hashtable<String,QName>();
+            Hashtable<String,QName> portComponentRef = new Hashtable<String,QName>();
 
             // Create QName object
             QName serviceQname = null;
@@ -200,11 +181,10 @@ public class ServiceRefFactory
                     Method m = serviceInterfaceClass.getMethod("setEndpointAddress",
                             new Class[] { java.lang.String.class,
                             java.lang.String.class });
-                    for (Iterator<String> i = ports.keySet().iterator(); i.hasNext();) {
-                        String portName = i.next();
+                    for (String portName : ports.keySet()) {
                         Port port = wsdlservice.getPort(portName);
                         String endpoint = getSOAPLocation(port);
-                        m.invoke(service, new Object[] {port.getName(), endpoint });
+                        m.invoke(service, new Object[]{port.getName(), endpoint});
                         portComponentRef.put(endpoint, new QName(port.getName()));
                     }
                 } catch (Exception e) {
@@ -242,15 +222,11 @@ public class ServiceRefFactory
             proxy.setPortComponentRef(portComponentRef);
 
             // Instantiate service with proxy class
-            Class<?>[] interfaces = null;
             Class<?>[] serviceInterfaces = serviceInterfaceClass.getInterfaces();
 
-            interfaces = new Class[serviceInterfaces.length + 1];
-            for (int i = 0; i < serviceInterfaces.length; i++) {
-                interfaces[i] = serviceInterfaces[i];
-            }
-
+            Class<?>[] interfaces = Arrays.copyOf(serviceInterfaces, serviceInterfaces.length + 1);
             interfaces[interfaces.length - 1] = javax.xml.rpc.Service.class;
+
             Object proxyInstance = null;
             try {
                 proxyInstance = Proxy.newProxyInstance(tcl, interfaces, proxy);
@@ -259,13 +235,13 @@ public class ServiceRefFactory
             }
 
             // Use handler
-            if (((ServiceRef) ref).getHandlersSize() > 0) {
+            if (ref.getHandlersSize() > 0) {
 
                 HandlerRegistry handlerRegistry = service.getHandlerRegistry();
-                ArrayList<String> soaproles = new ArrayList<String>();
+                List<String> soaproles = new ArrayList<String>();
 
-                while (((ServiceRef) ref).getHandlersSize() > 0) {
-                    HandlerRef handlerRef = ((ServiceRef) ref).getHandler();
+                while (ref.getHandlersSize() > 0) {
+                    HandlerRef handlerRef = ref.getHandler();
                     HandlerInfo handlerInfo = new HandlerInfo();
 
                     // Loading handler Class
@@ -281,9 +257,9 @@ public class ServiceRefFactory
 
                     // Load all datas relative to the handler : SOAPHeaders, config init element,
                     // portNames to be set on
-                    ArrayList<QName> headers = new ArrayList<QName>();
+                    List<QName> headers = new ArrayList<QName>();
                     Hashtable<String,String> config = new Hashtable<String,String>();
-                    ArrayList<String> portNames = new ArrayList<String>();
+                    List<String> portNames = new ArrayList<String>();
                     for (int i = 0; i < handlerRef.size(); i++)
                         if (HandlerRef.HANDLER_LOCALPART.equals(handlerRef.get(i).getType())) {
                             String localpart = "";
@@ -320,10 +296,10 @@ public class ServiceRefFactory
                     handlerInfo.setHandlerConfig(config);
 
                     if (!portNames.isEmpty()) {
-                        Iterator<String> iter = portNames.iterator();
-                        while (iter.hasNext())
-                            initHandlerChain(new QName(iter.next()), handlerRegistry,
+                        for (String portName : portNames) {
+                            initHandlerChain(new QName(portName), handlerRegistry,
                                     handlerInfo, soaproles);
+                        }
                     } else {
                         Enumeration<QName> e = portComponentRef.elements();
                         while(e.hasMoreElements())
@@ -349,9 +325,7 @@ public class ServiceRefFactory
         String endpoint = null;
         @SuppressWarnings("unchecked") // Can't change the API
         List<ExtensibilityElement> extensions = port.getExtensibilityElements();
-        for (Iterator<ExtensibilityElement> i = extensions.iterator();
-                i.hasNext();) {
-            ExtensibilityElement ext = i.next();
+        for (ExtensibilityElement ext : extensions) {
             if (ext instanceof SOAPAddress) {
                 SOAPAddress addr = (SOAPAddress) ext;
                 endpoint = addr.getLocationURI();
@@ -362,7 +336,7 @@ public class ServiceRefFactory
 
 
     private void initHandlerChain(QName portName, HandlerRegistry handlerRegistry,
-            HandlerInfo handlerInfo, ArrayList<String> soaprolesToAdd) {
+            HandlerInfo handlerInfo, List<String> soaprolesToAdd) {
         HandlerChain handlerChain = (HandlerChain) handlerRegistry.getHandlerChain(portName);
         @SuppressWarnings("unchecked") // Can't change the API
         Iterator<Handler> iter = handlerChain.iterator();


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org