src/share/jaxws_classes/javax/xml/ws/spi/FactoryFinder.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
     1.1 --- a/src/share/jaxws_classes/javax/xml/ws/spi/FactoryFinder.java	Thu Apr 04 19:05:24 2013 -0700
     1.2 +++ b/src/share/jaxws_classes/javax/xml/ws/spi/FactoryFinder.java	Tue Apr 09 14:51:13 2013 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -25,13 +25,9 @@
    1.11  
    1.12  package javax.xml.ws.spi;
    1.13  
    1.14 -import java.io.InputStream;
    1.15 -import java.io.File;
    1.16 -import java.io.FileInputStream;
    1.17 +import java.io.*;
    1.18  
    1.19  import java.util.Properties;
    1.20 -import java.io.BufferedReader;
    1.21 -import java.io.InputStreamReader;
    1.22  import javax.xml.ws.WebServiceException;
    1.23  
    1.24  class FactoryFinder {
    1.25 @@ -93,8 +89,9 @@
    1.26  
    1.27          String serviceId = "META-INF/services/" + factoryId;
    1.28          // try to find services in CLASSPATH
    1.29 +        BufferedReader rd = null;
    1.30          try {
    1.31 -            InputStream is=null;
    1.32 +            InputStream is;
    1.33              if (classLoader == null) {
    1.34                  is=ClassLoader.getSystemResourceAsStream(serviceId);
    1.35              } else {
    1.36 @@ -102,22 +99,23 @@
    1.37              }
    1.38  
    1.39              if( is!=null ) {
    1.40 -                BufferedReader rd =
    1.41 -                    new BufferedReader(new InputStreamReader(is, "UTF-8"));
    1.42 +                rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
    1.43  
    1.44                  String factoryClassName = rd.readLine();
    1.45 -                rd.close();
    1.46  
    1.47                  if (factoryClassName != null &&
    1.48                      ! "".equals(factoryClassName)) {
    1.49                      return newInstance(factoryClassName, classLoader);
    1.50                  }
    1.51              }
    1.52 -        } catch( Exception ex ) {
    1.53 +        } catch( Exception ignored) {
    1.54 +        } finally {
    1.55 +            close(rd);
    1.56          }
    1.57  
    1.58  
    1.59          // try to read from $java.home/lib/jaxws.properties
    1.60 +        FileInputStream inStream = null;
    1.61          try {
    1.62              String javah=System.getProperty( "java.home" );
    1.63              String configFile = javah + File.separator +
    1.64 @@ -125,14 +123,16 @@
    1.65              File f=new File( configFile );
    1.66              if( f.exists()) {
    1.67                  Properties props=new Properties();
    1.68 -                props.load( new FileInputStream(f));
    1.69 +                inStream = new FileInputStream(f);
    1.70 +                props.load(inStream);
    1.71                  String factoryClassName = props.getProperty(factoryId);
    1.72                  return newInstance(factoryClassName, classLoader);
    1.73              }
    1.74 -        } catch(Exception ex ) {
    1.75 +        } catch(Exception ignored) {
    1.76 +        } finally {
    1.77 +            close(inStream);
    1.78          }
    1.79  
    1.80 -
    1.81          // Use the system property
    1.82          try {
    1.83              String systemProp =
    1.84 @@ -140,7 +140,7 @@
    1.85              if( systemProp!=null) {
    1.86                  return newInstance(systemProp, classLoader);
    1.87              }
    1.88 -        } catch (SecurityException se) {
    1.89 +        } catch (SecurityException ignored) {
    1.90          }
    1.91  
    1.92          if (fallbackClassName == null) {
    1.93 @@ -151,6 +151,15 @@
    1.94          return newInstance(fallbackClassName, classLoader);
    1.95      }
    1.96  
    1.97 +    private static void close(Closeable closeable) {
    1.98 +        if (closeable != null) {
    1.99 +            try {
   1.100 +                closeable.close();
   1.101 +            } catch (IOException ignored) {
   1.102 +            }
   1.103 +        }
   1.104 +    }
   1.105 +
   1.106  
   1.107      /**
   1.108       * Loads the class, provided that the calling thread has an access to the class being loaded.
   1.109 @@ -184,7 +193,7 @@
   1.110          try {
   1.111              Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME);
   1.112              return true;
   1.113 -        } catch (ClassNotFoundException cnfe) {
   1.114 +        } catch (ClassNotFoundException ignored) {
   1.115          }
   1.116          return false;
   1.117      }
   1.118 @@ -196,9 +205,9 @@
   1.119              Class[] args = new Class[]{serviceClass};
   1.120              Class target = Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME);
   1.121              java.lang.reflect.Method m = target.getMethod("lookupProviderInstances", Class.class);
   1.122 -            java.util.Iterator iter = ((Iterable) m.invoke(null, args)).iterator();
   1.123 +            java.util.Iterator iter = ((Iterable) m.invoke(null, (Object[]) args)).iterator();
   1.124              return iter.hasNext() ? iter.next() : null;
   1.125 -        } catch (Exception e) {
   1.126 +        } catch (Exception ignored) {
   1.127              // log and continue
   1.128              return null;
   1.129          }

mercurial