選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

VaadinServiceClassLoaderUtil.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server;
  17. import java.security.AccessController;
  18. import java.security.PrivilegedAction;
  19. /**
  20. * Utility class used by {@link VaadinService#setDefaultClassLoader()}.
  21. *
  22. * @since 7.4
  23. * @author Vaadin Ltd
  24. */
  25. public class VaadinServiceClassLoaderUtil {
  26. private static class GetClassLoaderPrivilegedAction
  27. implements PrivilegedAction<ClassLoader> {
  28. @Override
  29. public ClassLoader run() {
  30. return Thread.currentThread().getContextClassLoader();
  31. }
  32. }
  33. /**
  34. * Called by {@link VaadinService#setDefaultClassLoader()} to acquire
  35. * appropriate class loader to load application's classes (e.g. UI). Calls
  36. * should be guarded by try/catch block to catch SecurityException and log
  37. * appropriate message. The code for this method is modeled after
  38. * recommendations laid out by JEE 5 specification sections EE.6.2.4.7 and
  39. * EE.8.2.5
  40. *
  41. * @return Instance of {@link ClassLoader} that should be used by this
  42. * instance of {@link VaadinService}
  43. * @throws SecurityException
  44. * if current security policy doesn't allow acquiring current
  45. * thread's context class loader
  46. */
  47. public static ClassLoader findDefaultClassLoader()
  48. throws SecurityException {
  49. return AccessController.doPrivileged(
  50. new VaadinServiceClassLoaderUtil.GetClassLoaderPrivilegedAction());
  51. }
  52. private VaadinServiceClassLoaderUtil() {
  53. }
  54. }