jjg@1412: /* jjg@1412: * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. jjg@1412: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@1412: * jjg@1412: * This code is free software; you can redistribute it and/or modify it jjg@1412: * under the terms of the GNU General Public License version 2 only, as jjg@1412: * published by the Free Software Foundation. Oracle designates this jjg@1412: * particular file as subject to the "Classpath" exception as provided jjg@1412: * by Oracle in the LICENSE file that accompanied this code. jjg@1412: * jjg@1412: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@1412: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@1412: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@1412: * version 2 for more details (a copy is included in the LICENSE file that jjg@1412: * accompanied this code). jjg@1412: * jjg@1412: * You should have received a copy of the GNU General Public License version jjg@1412: * 2 along with this work; if not, write to the Free Software Foundation, jjg@1412: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@1412: * jjg@1412: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@1412: * or visit www.oracle.com if you need additional information or have any jjg@1412: * questions. jjg@1412: */ jjg@1412: jjg@1412: package com.sun.tools.doclets.internal.toolkit.util; jjg@1412: jjg@1412: import java.util.Map; jjg@1412: import java.util.WeakHashMap; jjg@1412: jjg@1412: import javax.tools.JavaFileManager; jjg@1412: import javax.tools.JavaFileManager.Location; jjg@1412: import javax.tools.StandardJavaFileManager; jjg@1412: import javax.tools.StandardLocation; jjg@1412: jjg@1412: import com.sun.tools.doclets.internal.toolkit.Configuration; jjg@1412: jjg@1412: /** jjg@1412: * Factory for DocFile objects. jjg@1412: * jjg@1412: *

This is NOT part of any supported API. jjg@1412: * If you write code that depends on this, you do so at your own risk. jjg@1412: * This code and its internal interfaces are subject to change or jjg@1412: * deletion without notice. jjg@1412: * jjg@1412: * @since 1.8 jjg@1412: */ jjg@1412: abstract class DocFileFactory { vromero@1442: private static final Map factories = jjg@1412: new WeakHashMap(); jjg@1412: jjg@1412: /** jjg@1412: * Get the appropriate factory, based on the file manager given in the jjg@1412: * configuration. jjg@1412: */ jjg@1412: static synchronized DocFileFactory getFactory(Configuration configuration) { jjg@1412: DocFileFactory f = factories.get(configuration); jjg@1412: if (f == null) { jjg@1412: JavaFileManager fm = configuration.getFileManager(); jjg@1412: if (fm instanceof StandardJavaFileManager) jjg@1412: f = new StandardDocFileFactory(configuration); jjg@1412: else { jjg@1412: try { jjg@1412: Class pathFileManagerClass = jjg@1412: Class.forName("com.sun.tools.javac.nio.PathFileManager"); jjg@1412: if (pathFileManagerClass.isAssignableFrom(fm.getClass())) jjg@1412: f = new PathDocFileFactory(configuration); jjg@1412: } catch (Throwable t) { jjg@1412: throw new IllegalStateException(t); jjg@1412: } jjg@1412: } jjg@1413: factories.put(configuration, f); jjg@1412: } jjg@1412: return f; jjg@1412: } jjg@1412: jjg@1412: protected Configuration configuration; jjg@1412: jjg@1412: protected DocFileFactory(Configuration configuration) { jjg@1412: this.configuration = configuration; jjg@1412: } jjg@1412: jjg@1412: /** Create a DocFile for a directory. */ jjg@1412: abstract DocFile createFileForDirectory(String file); jjg@1412: jjg@1412: /** Create a DocFile for a file that will be opened for reading. */ jjg@1412: abstract DocFile createFileForInput(String file); jjg@1412: jjg@1412: /** Create a DocFile for a file that will be opened for writing. */ jjg@1412: abstract DocFile createFileForOutput(DocPath path); jjg@1412: jjg@1412: /** jjg@1412: * List the directories and files found in subdirectories along the jjg@1412: * elements of the given location. jjg@1412: * @param location currently, only {@link StandardLocation#SOURCE_PATH} is supported. jjg@1412: * @param path the subdirectory of the directories of the location for which to jjg@1412: * list files jjg@1412: */ jjg@1412: abstract Iterable list(Location location, DocPath path); jjg@1412: }