Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5e0f98b358450fd246de690823dea67e4c753814 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package org.eclipse.jst.server.tomcat.core.internal;
/**********************************************************************
 * Copyright (c) 2003 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 *
 * Contributors:
 *    IBM - Initial API and implementation
 **********************************************************************/
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
/**
 * Helper class to load and save Tomcat server and identify configurations.
 */
public class TomcatServerUtil {
	/**
	 * TomcatServerSerializer constructor comment.
	 */
	protected TomcatServerUtil() {
		super();
	}
	
	/**
	 * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form.
	 */
	protected static int getClasspathKindFromString(String kindStr) {
		//if (kindStr.equalsIgnoreCase("prj"))
		//	return IClasspathEntry.CPE_PROJECT;
		if (kindStr.equalsIgnoreCase("var"))
			return IClasspathEntry.CPE_VARIABLE;
		//if (kindStr.equalsIgnoreCase("src"))
		//	return IClasspathEntry.CPE_SOURCE;
		if (kindStr.equalsIgnoreCase("lib"))
			return IClasspathEntry.CPE_LIBRARY;
		return -1;
	}

	/**
	 * Returns a <code>String</code> for the kind of a class path entry.
	 */
	protected static String getClasspathKindToString(int kind) {
		switch (kind) {
			//case IClasspathEntry.CPE_PROJECT :
			//	return "prj";
			//case IClasspathEntry.CPE_SOURCE :
			//	return "src";
			case IClasspathEntry.CPE_LIBRARY :
				return "lib";
			case IClasspathEntry.CPE_VARIABLE :
				return "var";
			default :
				return "unknown";
		}
	}
	
	/**
	 * Create's a classpath entry of the specified kind.
	 *
	 * Returns null if unable to create a valid entry.
	 */
	protected static IClasspathEntry createClasspathEntry(IPath path, int kind, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath) {
		switch (kind) {
			/*case IClasspathEntry.CPE_PROJECT:
				if (!path.isAbsolute())
					return null;
				else
					return JavaCore.newProjectEntry(path);*/
	
			case IClasspathEntry.CPE_LIBRARY:
				if (!path.isAbsolute())
					return null;
				
				return JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath);
	
			case IClasspathEntry.CPE_VARIABLE:
				return JavaCore.newVariableEntry(path, sourceAttachmentPath, sourceAttachmentRootPath);
	
			default:
				return null;
		}
	}
}

Back to the top