KickJava   Java API By Example, From Geeks To Geeks.

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


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.netbeans.modules.projectimport.ProjectImporterException;
24 import org.openide.filesystems.FileUtil;
25
26 /**
27  * Able to load and fill up an <code>EclipseWorkspace</code> from an Eclipse
28  * workspace directory using a .workspace and .classpath file and eventually
29  * passed workspace. It is also able to load a basic information from workspace.
30  *
31  * @author mkrauskopf
32  */

33 public final class WorkspaceFactory {
34
35     /** singleton */
36     private static WorkspaceFactory instance = new WorkspaceFactory();
37     
38     private WorkspaceFactory() {/*empty constructor*/}
39     
40     public static WorkspaceFactory getInstance() {
41         return instance;
42     }
43     
44     /**
45      * Loads a workspace contained in the given <code>workspaceDir</code>.
46      *
47      * @throws InvalidWorkspaceException if workspace in the given
48      * <code>workspaceDir</code> is not a valid Eclipse workspace.
49      */

50     public Workspace load(String JavaDoc workspaceDir) throws ProjectImporterException {
51         if (workspaceDir != null) {
52             return load(FileUtil.normalizeFile(new File JavaDoc(workspaceDir)));
53         }
54         return null;
55     }
56     
57     /**
58      * Loads a workspace contained in the given <code>workspaceDir</code>.
59      *
60      * @throws InvalidWorkspaceException if workspace in the given
61      * <code>workspaceDir</code> is not a valid Eclipse workspace.
62      */

63     public Workspace load(File JavaDoc workspaceDir) throws ProjectImporterException {
64         Workspace workspace = Workspace.createWorkspace(workspaceDir);
65         if (workspace != null) {
66             WorkspaceParser parser = new WorkspaceParser(workspace);
67             parser.parse();
68         }
69         return workspace;
70     }
71 }
72
Popular Tags