KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > queries > ModuleProjectClassPathExtender


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.apisupport.project.queries;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.net.URI JavaDoc;
25 import org.netbeans.api.project.ProjectManager;
26 import org.netbeans.api.project.ant.AntArtifact;
27 import org.netbeans.api.project.libraries.Library;
28 import org.netbeans.modules.apisupport.project.NbModuleProject;
29 import org.netbeans.modules.apisupport.project.Util;
30 import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
31 import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender;
32 import org.openide.filesystems.FileObject;
33 import org.openide.filesystems.FileUtil;
34 import org.openide.util.NbBundle;
35
36 /**
37  * Makes sure you can safely use natural layout in forms you develop for your module.
38  * @author Jesse Glick
39  * @see "#62942"
40  */

41 public final class ModuleProjectClassPathExtender implements ProjectClassPathExtender {
42     
43     private static final String JavaDoc LIBRARY_NAME = "swing-layout"; // NOI18N
44
private static final String JavaDoc MODULE_NAME = "org.jdesktop.layout"; // NOI18N
45

46     private final NbModuleProject project;
47     
48     public ModuleProjectClassPathExtender(NbModuleProject project) {
49         this.project = project;
50     }
51     
52     public boolean addLibrary(Library library) throws IOException JavaDoc {
53         boolean cpChanged = false;
54         if (library.getName().equals(LIBRARY_NAME)) {
55             ModuleEntry entry = project.getModuleList().getEntry(MODULE_NAME);
56             if (entry != null) {
57                 cpChanged = Util.addDependency(project, MODULE_NAME);
58             } else {
59                 IOException JavaDoc e = new IOException JavaDoc("no module " + MODULE_NAME); // NOI18N
60
Util.err.annotate(e, NbBundle.getMessage(ModuleProjectClassPathExtender.class, "ERR_could_not_find_module", MODULE_NAME));
61                 throw e;
62             }
63         } else {
64             IOException JavaDoc e = new IOException JavaDoc("unknown lib " + library.getName()); // NOI18N
65
Util.err.annotate(e, NbBundle.getMessage(ModuleProjectClassPathExtender.class, "ERR_unsupported_library", library.getDisplayName()));
66             throw e;
67         }
68         if (cpChanged) {
69             ProjectManager.getDefault().saveProject(project);
70         }
71         return cpChanged;
72     }
73     
74     public boolean addArchiveFile(FileObject archiveFile) throws IOException JavaDoc {
75         IOException JavaDoc e = new IOException JavaDoc("not implemented: " + archiveFile); // NOI18N
76
Util.err.annotate(e, NbBundle.getMessage(ModuleProjectClassPathExtender.class, "ERR_jar", FileUtil.getFileDisplayName(archiveFile)));
77         throw e;
78     }
79     
80     public boolean addAntArtifact(AntArtifact artifact, URI JavaDoc artifactElement) throws IOException JavaDoc {
81         // XXX ideally would check to see if it was owned by a NBM project in this universe...
82
IOException JavaDoc e = new IOException JavaDoc("not implemented: " + artifactElement); // NOI18N
83
String JavaDoc displayName;
84         if ("file".equals(artifactElement.getScheme())) { // NOI18N
85
displayName = new File JavaDoc(artifactElement).getAbsolutePath();
86         } else {
87             displayName = artifactElement.toString();
88         }
89         Util.err.annotate(e, NbBundle.getMessage(ModuleProjectClassPathExtender.class, "ERR_jar", displayName));
90         throw e;
91     }
92     
93 }
94
Popular Tags