DocFileFactory.java revision 3233:b5d08bc0d224
1/*
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.
4 *
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
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package jdk.javadoc.internal.doclets.toolkit.util;
27
28import javax.tools.JavaFileManager;
29import javax.tools.JavaFileManager.Location;
30import javax.tools.StandardJavaFileManager;
31import javax.tools.StandardLocation;
32
33import jdk.javadoc.internal.doclets.toolkit.Configuration;
34
35/**
36 * Factory for DocFile objects.
37 *
38 *  <p><b>This is NOT part of any supported API.
39 *  If you write code that depends on this, you do so at your own risk.
40 *  This code and its internal interfaces are subject to change or
41 *  deletion without notice.</b>
42 *
43 */
44public abstract class DocFileFactory {
45    /**
46     * Get the appropriate factory, based on the file manager given in the
47     * configuration.
48     */
49    static synchronized DocFileFactory getFactory(Configuration configuration) {
50        DocFileFactory f = configuration.docFileFactory;
51        if (f == null) {
52            JavaFileManager fm = configuration.getFileManager();
53            if (fm instanceof StandardJavaFileManager) {
54                f = new StandardDocFileFactory(configuration);
55            } else {
56                throw new IllegalStateException();
57            }
58            configuration.docFileFactory = f;
59        }
60        return f;
61    }
62
63    protected Configuration configuration;
64
65    protected DocFileFactory(Configuration configuration) {
66        this.configuration = configuration;
67    }
68
69    /** Create a DocFile for a directory. */
70    abstract DocFile createFileForDirectory(String file);
71
72    /** Create a DocFile for a file that will be opened for reading. */
73    abstract DocFile createFileForInput(String file);
74
75    /** Create a DocFile for a file that will be opened for writing. */
76    abstract DocFile createFileForOutput(DocPath path);
77
78    /**
79     * List the directories and files found in subdirectories along the
80     * elements of the given location.
81     * @param location currently, only {@link StandardLocation#SOURCE_PATH} is supported.
82     * @param path the subdirectory of the directories of the location for which to
83     *  list files
84     */
85    abstract Iterable<DocFile> list(Location location, DocPath path);
86}
87