1 /* |
1 /* |
2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2016, 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 |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.doclets.internal.toolkit.util; |
26 package com.sun.tools.doclets.internal.toolkit.util; |
27 |
27 |
28 import java.util.Map; |
|
29 import java.util.WeakHashMap; |
|
30 |
|
31 import javax.tools.JavaFileManager; |
28 import javax.tools.JavaFileManager; |
32 import javax.tools.JavaFileManager.Location; |
29 import javax.tools.JavaFileManager.Location; |
33 import javax.tools.StandardJavaFileManager; |
30 import javax.tools.StandardJavaFileManager; |
34 import javax.tools.StandardLocation; |
31 import javax.tools.StandardLocation; |
35 |
32 |
43 * This code and its internal interfaces are subject to change or |
40 * This code and its internal interfaces are subject to change or |
44 * deletion without notice.</b> |
41 * deletion without notice.</b> |
45 * |
42 * |
46 * @since 1.8 |
43 * @since 1.8 |
47 */ |
44 */ |
48 abstract class DocFileFactory { |
45 public abstract class DocFileFactory { |
49 private static final Map<Configuration, DocFileFactory> factories = new WeakHashMap<>(); |
|
50 |
|
51 /** |
46 /** |
52 * Get the appropriate factory, based on the file manager given in the |
47 * Get the appropriate factory, based on the file manager given in the |
53 * configuration. |
48 * configuration. |
54 */ |
49 */ |
55 static synchronized DocFileFactory getFactory(Configuration configuration) { |
50 static synchronized DocFileFactory getFactory(Configuration configuration) { |
56 DocFileFactory f = factories.get(configuration); |
51 DocFileFactory f = configuration.docFileFactory; |
57 if (f == null) { |
52 if (f == null) { |
58 JavaFileManager fm = configuration.getFileManager(); |
53 JavaFileManager fm = configuration.getFileManager(); |
59 if (fm instanceof StandardJavaFileManager) { |
54 if (fm instanceof StandardJavaFileManager) { |
60 f = new StandardDocFileFactory(configuration); |
55 f = new StandardDocFileFactory(configuration); |
61 } else { |
56 } else { |
62 throw new IllegalStateException(); |
57 throw new IllegalStateException(); |
63 } |
58 } |
64 factories.put(configuration, f); |
59 configuration.docFileFactory = f; |
65 } |
60 } |
66 return f; |
61 return f; |
67 } |
62 } |
68 |
63 |
69 protected Configuration configuration; |
64 protected Configuration configuration; |