001: /*
002: * Copyright 2006 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.io.File;
031: import java.util.*;
032: import java.util.concurrent.*;
033:
034: /**
035: * Standard locations of file objects.
036: *
037: * @author Peter von der Ahé
038: * @since 1.6
039: */
040: public enum StandardLocation implements Location {
041:
042: /**
043: * Location of new class files.
044: */
045: CLASS_OUTPUT,
046:
047: /**
048: * Location of new source files.
049: */
050: SOURCE_OUTPUT,
051:
052: /**
053: * Location to search for user class files.
054: */
055: CLASS_PATH,
056:
057: /**
058: * Location to search for existing source files.
059: */
060: SOURCE_PATH,
061:
062: /**
063: * Location to search for annotation processors.
064: */
065: ANNOTATION_PROCESSOR_PATH,
066:
067: /**
068: * Location to search for platform classes. Sometimes called
069: * the boot class path.
070: */
071: PLATFORM_CLASS_PATH;
072:
073: /**
074: * Gets a location object with the given name. The following
075: * property must hold: {@code locationFor(x) ==
076: * locationFor(y)} if and only if {@code x.equals(y)}.
077: * The returned location will be an output location if and only if
078: * name ends with {@code "_OUTPUT"}.
079: *
080: * @param name a name
081: * @return a location
082: */
083: public static Location locationFor(final String name) {
084: if (locations.isEmpty()) {
085: // can't use valueOf which throws IllegalArgumentException
086: for (Location location : values())
087: locations.putIfAbsent(location.getName(), location);
088: }
089: locations.putIfAbsent(name.toString(/* null-check */),
090: new Location() {
091: public String getName() {
092: return name;
093: }
094:
095: public boolean isOutputLocation() {
096: return name.endsWith("_OUTPUT");
097: }
098: });
099: return locations.get(name);
100: }
101:
102: //where
103: private static ConcurrentMap<String, Location> locations = new ConcurrentHashMap<String, Location>();
104:
105: public String getName() {
106: return name();
107: }
108:
109: public boolean isOutputLocation() {
110: return this == CLASS_OUTPUT || this == SOURCE_OUTPUT;
111: }
112: }
|