KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > java > project > classpath > ProjectClassPathModifierImplementation


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.spi.java.project.classpath;
21
22 import java.io.IOException JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.net.URL JavaDoc;
25 import org.netbeans.api.project.SourceGroup;
26 import org.netbeans.api.project.ant.AntArtifact;
27 import org.netbeans.api.project.libraries.Library;
28 import org.netbeans.modules.java.project.classpath.ProjectClassPathModifierAccessor;
29 import org.openide.filesystems.FileObject;
30
31 /**
32  * An SPI for project's classpaths modification.
33  * A project can provide subclass of this class in its {@link org.netbeans.api.project.Project#getLookup lookup} to
34  * allow clients to add or remove new classpath elements (JAR, folder, dependent project, or library) to its
35  * classpaths.
36  * @since org.netbeans.modules.java.project/1 1.10
37  */

38 public abstract class ProjectClassPathModifierImplementation {
39     
40     static {
41         ProjectClassPathModifierAccessor.INSTANCE = new Accessor ();
42     }
43     
44     protected ProjectClassPathModifierImplementation () {
45     }
46     
47     
48     /**
49      * Returns the {@link SourceGroup}s providing classpath(s)
50      * which may be modified.
51      * @return (possibly empty) array of {@link SourceGroup}, never returns null
52      */

53     protected abstract SourceGroup [] getExtensibleSourceGroups ();
54     
55     
56     /**
57      * Returns the types of classpaths for given {@link SourceGroup} which may be modified.
58      * @param sourceGroup for which the classpath types should be returned
59      * @return (possibly empty) array of classpath types, never returns null
60      */

61     protected abstract String JavaDoc[] getExtensibleClassPathTypes (SourceGroup sourceGroup);
62             
63     /**
64      * Adds libraries into the project's classpath if the
65      * libraries are not already included.
66      * @param libraries to be added
67      * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
68      * identifying the compilation unit to change
69      * @param type the type of the classpath the library should be added to,
70      * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
71      * @return true in case the classpath was changed (at least one library was added to the classpath),
72      * the value false is returned when all the libraries are already included on the classpath.
73      * @exception IOException in case the project metadata cannot be changed
74      * @exception UnsupportedOperationException is thrown when the project does not support
75      * adding of a library to the classpath of the given type.
76      */

77     protected abstract boolean addLibraries (Library[] libraries, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc;
78     
79     
80     /**
81      * Removes libraries from the project's classpath if the
82      * libraries are included on it.
83      * @param libraries to be removed
84      * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
85      * identifying the compilation unit to change
86      * @param type the type of the classpath the library should be removed from,
87      * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
88      * @return true in case the classpath was changed, (at least one library was removed from the classpath),
89      * the value false is returned when none of the libraries was included on the classpath.
90      * @exception IOException in case the project metadata cannot be changed
91      * @exception UnsupportedOperationException is thrown when the project does not support
92      * removing of a library from the classpath of the given type.
93      */

94     protected abstract boolean removeLibraries (Library[] libraries, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc;
95     
96     /**
97      * Adds archive files or folders into the project's classpath if the
98      * entries are not already there.
99      * @param classPathRoots roots to be added, each root has to be either a root of an archive or a folder
100      * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
101      * identifying the compilation unit to change
102      * @param type the type of the classpath the root should be added to,
103      * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
104      * @return true in case the classpath was changed, (at least one classpath root was added to the classpath),
105      * the value false is returned when all the classpath roots are already included on the classpath.
106      * @exception IOException in case the project metadata cannot be changed
107      * @exception UnsupportedOperationException is thrown when the project does not support
108      * adding of a root to the classpath of the given type.
109      */

110     protected abstract boolean addRoots (URL JavaDoc[] classPathRoots, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc;
111     
112     /**
113      * Removes archive files or folders from the project's classpath if the
114      * entries are included on it.
115      * @param classPathRoots roots to be removed, each root has to be either a root of an archive or a folder
116      * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
117      * identifying the compilation unit to change
118      * @param type the type of the classpath the root should be removed from,
119      * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
120      * @return true in case the classpath was changed, (at least one classpath root was removed from the classpath),
121      * the value false is returned when none of the classpath roots was included on the classpath.
122      * @exception IOException in case the project metadata cannot be changed
123      * @exception UnsupportedOperationException is thrown when the project does not support
124      * removing of a root from the classpath of the given type.
125      */

126     protected abstract boolean removeRoots (URL JavaDoc[] classPathRoots, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc;
127     
128     /**
129      * Adds artifacts (e.g. subprojects) into project's classpath if the
130      * artifacts are not already on it.
131      * @param artifacts to be added
132      * @param artifactElements the URIs of the build output, the artifactElements has to have the same length
133      * as artifacts.
134      * (must be owned by the artifact and be relative to it)
135      * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
136      * identifying the compilation unit to change
137      * @param type the type of the classpath the artifact should be added to,
138      * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
139      * @return true in case the classpath was changed, (at least one artifact was added to the classpath),
140      * the value false is returned when all the artifacts are already included on the classpath.
141      * @exception IOException in case the project metadata cannot be changed
142      * @exception UnsupportedOperationException is thrown when the project does not support
143      * adding of an artifact to the classpath of the given type.
144      */

145     protected abstract boolean addAntArtifacts (AntArtifact[] artifacts, URI JavaDoc[] artifactElements, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc;
146     
147     /**
148      * Removes artifacts (e.g. subprojects) from project's classpath if the
149      * artifacts are included on it.
150      * @param artifacts to be added
151      * @param artifactElements the URIs of the build output, the artifactElements has to have the same length
152      * as artifacts.
153      * (must be owned by the artifact and be relative to it)
154      * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
155      * identifying the compilation unit to change
156      * @param type the type of the classpath the artifact should be removed from,
157      * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
158      * @return true in case the classpath was changed, (at least one artifact was removed from the classpath),
159      * the value false is returned when none of the artifacts was included on the classpath.
160      * @exception IOException in case the project metadata cannot be changed
161      * @exception UnsupportedOperationException is thrown when the project does not support
162      * removing of an artifact from the classpath of the given type.
163      */

164     protected abstract boolean removeAntArtifacts (AntArtifact[] artifacts, URI JavaDoc[] artifactElements, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc;
165
166     
167     private static class Accessor extends ProjectClassPathModifierAccessor {
168         
169         public SourceGroup[] getExtensibleSourceGroups(final ProjectClassPathModifierImplementation m) {
170             assert m != null;
171             return m.getExtensibleSourceGroups();
172         }
173         
174         public String JavaDoc[] getExtensibleClassPathTypes (final ProjectClassPathModifierImplementation m, SourceGroup sg) {
175             assert m != null;
176             assert sg != null;
177             return m.getExtensibleClassPathTypes(sg);
178         }
179         
180         public boolean removeLibraries(Library[] libraries, ProjectClassPathModifierImplementation m, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc {
181             assert m!= null;
182             return m.removeLibraries(libraries, sourceGroup, type);
183         }
184
185         public boolean removeAntArtifacts(AntArtifact[] artifacts, URI JavaDoc[] artifactElements, ProjectClassPathModifierImplementation m, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc {
186             assert m!= null;
187             return m.removeAntArtifacts(artifacts, artifactElements, sourceGroup, type);
188         }
189
190         public boolean addLibraries (Library[] libraries, ProjectClassPathModifierImplementation m, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc {
191             assert m!= null;
192             return m.addLibraries(libraries, sourceGroup, type);
193         }
194
195         public boolean addAntArtifacts (AntArtifact[] artifacts, URI JavaDoc[] artifactElements, ProjectClassPathModifierImplementation m, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc {
196             assert m!= null;
197             return m.addAntArtifacts (artifacts, artifactElements, sourceGroup, type);
198         }
199
200         public boolean removeRoots (URL JavaDoc[] classPathRoots, ProjectClassPathModifierImplementation m, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc {
201             assert m!= null;
202             return m.removeRoots(classPathRoots, sourceGroup, type);
203         }
204
205         public boolean addRoots (URL JavaDoc[] classPathRoots, ProjectClassPathModifierImplementation m, SourceGroup sourceGroup, String JavaDoc type) throws IOException JavaDoc, UnsupportedOperationException JavaDoc {
206             assert m!= null;
207             return m.addRoots (classPathRoots, sourceGroup, type);
208         }
209                         
210     }
211 }
212
Popular Tags