KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > core > internal > WkspJarFactoryContainer


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * wharley@bea.com - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.apt.core.internal;
13
14 import java.io.File JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.resources.IWorkspaceRoot;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.core.runtime.IPath;
20 import org.eclipse.core.runtime.IStatus;
21
22 /**
23  * Annotation processor factory container based on a jar file
24  * within the workspace.
25  */

26 public class WkspJarFactoryContainer extends JarFactoryContainer {
27
28     private final String JavaDoc _id;
29     private final File JavaDoc _jarFile; // A java.io.File, not guaranteed to exist.
30

31     /**
32      * Construct a workspace-jar container from an IPath representing
33      * the jar file's location in the workspace. We will construct
34      * the container even if the file does not exist.
35      * @param jar an IPath representing a jar file in the workspace;
36      * the path is relative to the workspace root.
37      */

38     public WkspJarFactoryContainer(IPath jar) {
39         _id = jar.toString();
40         IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
41         IResource res = root.findMember(_id);
42         if (null == res) {
43             // The file evidently doesn't exist on disk. Do our best to
44
// construct a java.io.File for it anyway.
45
_jarFile = root.getLocation().append(jar).toFile();
46             
47         }
48         else if (res.getType() == IResource.FILE) {
49             _jarFile = res.getLocation().toFile();
50         }
51         else {
52             _jarFile = null;
53             IStatus s = AptPlugin.createWarningStatus(
54                 null, "The factorypath entry " + _id + " does not refer to a jar file"); //$NON-NLS-1$ //$NON-NLS-2$
55
AptPlugin.log(s);
56         }
57     }
58
59     @Override JavaDoc
60     public FactoryType getType() {
61         return FactoryType.WKSPJAR;
62     }
63
64     /* (non-Javadoc)
65      * @see org.eclipse.jdt.apt.core.internal.JarFactoryContainer#getJarFile()
66      */

67     @Override JavaDoc
68     public File JavaDoc getJarFile() {
69         return _jarFile;
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.jdt.apt.core.FactoryContainer#getId()
74      */

75     @Override JavaDoc
76     public String JavaDoc getId() {
77         return _id;
78     }
79 }
80
Popular Tags