KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > tools > StandardLocation


1 /*
2  * @(#)StandardLocation.java 1.2 06/06/25
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.tools;
9
10 import javax.tools.JavaFileManager.Location;
11
12 import java.io.File JavaDoc;
13 import java.util.*;
14 import java.util.concurrent.*;
15
16 /**
17  * Standard locations of file objects.
18  *
19  * @author Peter von der Ahé
20  * @since 1.6
21  */

22 public enum StandardLocation implements Location {
23
24     /**
25      * Location of new class files.
26      */

27     CLASS_OUTPUT,
28
29     /**
30      * Location of new source files.
31      */

32     SOURCE_OUTPUT,
33
34     /**
35      * Location to search for user class files.
36      */

37     CLASS_PATH,
38
39     /**
40      * Location to search for existing source files.
41      */

42     SOURCE_PATH,
43
44     /**
45      * Location to search for annotation processors.
46      */

47     ANNOTATION_PROCESSOR_PATH,
48
49     /**
50      * Location to search for platform classes. Sometimes called
51      * the boot class path.
52      */

53     PLATFORM_CLASS_PATH;
54
55     /**
56      * Gets a location object with the given name. The following
57      * property must hold: {@code locationFor(x) ==
58      * locationFor(y)} if and only if {@code x.equals(y)}.
59      * The returned location will be an output location if and only if
60      * name ends with {@code "_OUTPUT"}.
61      *
62      * @param name a name
63      * @return a location
64      */

65     public static Location locationFor(final String JavaDoc name) {
66         if (locations.isEmpty()) {
67             // can't use valueOf which throws IllegalArgumentException
68
for (Location location : values())
69                 locations.putIfAbsent(location.getName(), location);
70         }
71         locations.putIfAbsent(name.toString(/* null-check */), new Location() {
72                 public String JavaDoc getName() { return name; }
73                 public boolean isOutputLocation() { return name.endsWith("_OUTPUT"); }
74             });
75         return locations.get(name);
76     }
77     //where
78
private static ConcurrentMap<String JavaDoc,Location> locations
79             = new ConcurrentHashMap<String JavaDoc,Location>();
80
81     public String JavaDoc getName() { return name(); }
82
83     public boolean isOutputLocation() {
84         return this == CLASS_OUTPUT || this == SOURCE_OUTPUT;
85     }
86 }
87
Popular Tags