jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/HandlerAnnotationProcessor.java
changeset 36523 116e5d5cdade
parent 25871 b80b84e87032
child 44560 7ecd9d2e2a6e
equal deleted inserted replaced
36522:0017f3cf1657 36523:116e5d5cdade
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   195             return clazz;
   195             return clazz;
   196         }
   196         }
   197         return null;
   197         return null;
   198     }
   198     }
   199 
   199 
   200    static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
   200     static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
   201         URL url = clazz.getResource(chain.file());
   201         Package pkg = clazz.getPackage();
   202         if (url == null) {
   202         String filename = chain.file();
   203             url = Thread.currentThread().getContextClassLoader().
   203         String fullpath = addPackagePath(filename, pkg);
   204                 getResource(chain.file());
   204         InputStream is;
   205         }
   205 
   206         if (url == null) {
   206         is = moduleResource(clazz, filename);
   207             String tmp = clazz.getPackage().getName();
   207         if (is != null) return is;
   208             tmp = tmp.replace('.', '/');
   208 
   209             tmp += "/" + chain.file();
   209         is = moduleResource(clazz, fullpath);
   210             url =
   210         if (is != null) return is;
   211                 Thread.currentThread().getContextClassLoader().getResource(tmp);
   211 
   212         }
   212         URL url = cpResource(clazz, filename);
       
   213         if (url == null) url = cpResource(clazz, fullpath);
       
   214 
   213         if (url == null) {
   215         if (url == null) {
   214             throw new UtilException("util.failed.to.find.handlerchain.file",
   216             throw new UtilException("util.failed.to.find.handlerchain.file",
   215                 clazz.getName(), chain.file());
   217                     clazz.getName(), filename);
   216         }
   218         }
   217         try {
   219         try {
   218             return url.openStream();
   220             return url.openStream();
   219         } catch (IOException e) {
   221         } catch (IOException e) {
   220             throw new UtilException("util.failed.to.parse.handlerchain.file",
   222             throw new UtilException("util.failed.to.parse.handlerchain.file",
   221                 clazz.getName(), chain.file());
   223                     clazz.getName(), filename);
   222         }
   224         }
       
   225     }
       
   226 
       
   227     private static URL cpResource(Class clazz, String name) {
       
   228         URL url = clazz.getResource(name);
       
   229         if (url == null) {
       
   230             ClassLoader tccl = Thread.currentThread().getContextClassLoader();
       
   231             url = tccl.getResource(name);
       
   232         }
       
   233         return url;
       
   234     }
       
   235 
       
   236     private static InputStream moduleResource(Class resolvingClass, String name) {
       
   237         java.lang.reflect.Module module = resolvingClass.getModule();
       
   238         if (module != null) {
       
   239             try {
       
   240                 InputStream stream = module.getResourceAsStream(name);
       
   241                 if (stream != null) {
       
   242                     return stream;
       
   243                 }
       
   244             } catch(IOException e) {
       
   245                 throw new UtilException("util.failed.to.find.handlerchain.file",
       
   246                         resolvingClass.getName(), name);
       
   247             }
       
   248         }
       
   249         return null;
       
   250     }
       
   251 
       
   252     private static String addPackagePath(String file, Package pkg) {
       
   253         String tmp = pkg.getName();
       
   254         tmp = tmp.replace('.', '/');
       
   255         tmp += "/" + file;
       
   256         return tmp;
   223     }
   257     }
   224 }
   258 }