001    /*
002     * Copyright 2006-2008 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package javax.tools;
027    
028    import javax.tools.JavaFileManager.Location;
029    
030    import java.util.concurrent.*;
031    
032    /**
033     * Standard locations of file objects.
034     *
035     * @author Peter von der Ahé
036     * @since 1.6
037     */
038    public enum StandardLocation implements Location {
039    
040        /**
041         * Location of new class files.
042         */
043        CLASS_OUTPUT,
044    
045        /**
046         * Location of new source files.
047         */
048        SOURCE_OUTPUT,
049    
050        /**
051         * Location to search for user class files.
052         */
053        CLASS_PATH,
054    
055        /**
056         * Location to search for existing source files.
057         */
058        SOURCE_PATH,
059    
060        /**
061         * Location to search for annotation processors.
062         */
063        ANNOTATION_PROCESSOR_PATH,
064    
065        /**
066         * Location to search for platform classes.  Sometimes called
067         * the boot class path.
068         */
069        PLATFORM_CLASS_PATH;
070    
071        /**
072         * Gets a location object with the given name.  The following
073         * property must hold: {@code locationFor(x) ==
074         * locationFor(y)} if and only if {@code x.equals(y)}.
075         * The returned location will be an output location if and only if
076         * name ends with {@code "_OUTPUT"}.
077         *
078         * @param name a name
079         * @return a location
080         */
081        public static Location locationFor(final String name) {
082            if (locations.isEmpty()) {
083                // can't use valueOf which throws IllegalArgumentException
084                for (Location location : values())
085                    locations.putIfAbsent(location.getName(), location);
086            }
087            locations.putIfAbsent(name.toString(/* null-check */), new Location() {
088                    public String getName() { return name; }
089                    public boolean isOutputLocation() { return name.endsWith("_OUTPUT"); }
090                });
091            return locations.get(name);
092        }
093        //where
094            private static ConcurrentMap<String,Location> locations
095                = new ConcurrentHashMap<String,Location>();
096    
097        public String getName() { return name(); }
098    
099        public boolean isOutputLocation() {
100            return this == CLASS_OUTPUT || this == SOURCE_OUTPUT;
101        }
102    }