KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > eclipse > ClassPathEntry


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.projectimport.eclipse;
21
22 import java.io.File JavaDoc;
23 import org.openide.ErrorManager;
24
25 /**
26  * Represents one classpath entry of an Eclipse project's .classpath file.
27  *
28  * @author mkrauskopf
29  */

30 public final class ClassPathEntry {
31
32     /** Serves for type-safe enumeration of types */
33     static class Type {
34         String JavaDoc desc;
35         private Type(String JavaDoc desc) {
36             this.desc = desc;
37         }
38         public String JavaDoc toString() {
39             return desc;
40         }
41     }
42
43     static final Type TYPE_OUTPUT = new Type("output"); // NOI18N
44
static final Type TYPE_LIBRARY = new Type("lib"); // NOI18N
45
static final Type TYPE_EXTERNAL_LIBRARY = new Type("lib-ext"); // NOI18N
46
static final Type TYPE_CONTAINER = new Type("con"); // NOI18N
47
static final Type TYPE_VARIABLE= new Type("var"); // NOI18N
48
static final Type TYPE_SOURCE = new Type("src"); // NOI18N
49
static final Type TYPE_PROJECT = new Type("src-prj"); // NOI18N
50
static final Type TYPE_LINK = new Type("src-link"); // NOI18N
51
static final Type TYPE_UNKNOWN = new Type("unkown"); // NOI18N
52

53     private Type type;
54     private String JavaDoc rawPath;
55     private String JavaDoc absolutePath;
56     
57     ClassPathEntry(String JavaDoc type, String JavaDoc rawPath) {
58         this.rawPath = rawPath;
59         setTypeFromRawtype(type);
60     }
61
62     void setType(ClassPathEntry.Type type) {
63         this.type = type;
64     }
65     
66     private void setTypeFromRawtype(String JavaDoc rawType) {
67         if ("output".equals(rawType)) { // NOI18N
68
this.type = TYPE_OUTPUT;
69         } else if ("src".equals(rawType)) { // NOI18N
70
// raw path for project entries starts with slash (on all platforms)
71
if (rawPath.startsWith("/")) { // NOI18N
72
this.type = TYPE_PROJECT;
73             } else {
74                 this.type = TYPE_SOURCE;
75             }
76         } else if ("lib".equals(rawType)) { // NOI18N
77
if (isRawPathRelative()) {
78                 this.type = TYPE_LIBRARY;
79             } else {
80                 this.type = TYPE_EXTERNAL_LIBRARY;
81             }
82         } else if ("con".equals(rawType)) { // NOI18N
83
this.type = TYPE_CONTAINER;
84         } else if ("var".equals(rawType)) { // NOI18N
85
this.type = TYPE_VARIABLE;
86         } else {
87             ErrorManager.getDefault().log(ErrorManager.WARNING,
88                     "Unkown type encountered in " + // NOI18N
89
"ClassPathEntry.setTypeFromRawtype(): " + rawType); // NOI18N
90
this.type = TYPE_UNKNOWN;
91         }
92     }
93     
94     Type getType() {
95         return type;
96     }
97     
98     public String JavaDoc getRawPath() {
99         return rawPath;
100     }
101     
102     public String JavaDoc getAbsolutePath() {
103         return absolutePath;
104     }
105     
106     void setAbsolutePath(String JavaDoc absolutePath) {
107         this.absolutePath = absolutePath;
108     }
109     
110     boolean isRawPathRelative() {
111         return !(new File JavaDoc(rawPath).isAbsolute());
112     }
113     
114     public String JavaDoc toString() {
115         return type + " = \"" + rawPath + "\"" + // NOI18N
116
" (absolutePath: " + absolutePath + ")"; // NOI18N
117
}
118 }
119
120
Popular Tags