KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import org.netbeans.api.java.queries.JavadocForBinaryQuery;
30 import org.netbeans.modules.apisupport.project.NbModuleProject;
31 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
32 import org.netbeans.modules.apisupport.project.Util;
33 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
34 import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
35 import org.openide.filesystems.URLMapper;
36
37 /**
38  * Defines Javadoc locations for built modules.
39  * @author Jesse Glick
40  */

41 public final class JavadocForBinaryImpl implements JavadocForBinaryQueryImplementation {
42     
43     private static final String JavaDoc NB_ALL_INFIX = "nbbuild" + File.separatorChar + "build" + File.separatorChar + "javadoc" + File.separatorChar; // NOI18N
44
private static final String JavaDoc EXT_INFIX = "build" + File.separatorChar + "javadoc" + File.separatorChar; // NOI18N
45

46     /** Configurable for the unit test, since it is too cumbersome to create fake Javadoc in all the right places. */
47     static boolean ignoreNonexistentRoots = true;
48     
49     private final NbModuleProject project;
50     
51     public JavadocForBinaryImpl(NbModuleProject project) {
52         this.project = project;
53     }
54
55     public JavadocForBinaryQuery.Result findJavadoc(URL JavaDoc binaryRoot) {
56         if (!binaryRoot.equals(Util.urlForJar(project.getModuleJarLocation()))) {
57             return null;
58         }
59         String JavaDoc cnbdashes = project.getCodeNameBase().replace('.', '-');
60         try {
61             final List JavaDoc<URL JavaDoc> candidates = new ArrayList JavaDoc();
62             NbPlatform platform = project.getPlatform(false);
63             if (platform == null) {
64                 return null;
65             }
66             URL JavaDoc[] roots = platform.getJavadocRoots();
67             for (int i = 0; i < roots.length; i++) {
68                 candidates.add(new URL JavaDoc(roots[i], cnbdashes + "/")); // NOI18N
69
}
70             File JavaDoc dir;
71             NbModuleProvider.NbModuleType type = Util.getModuleType(project);
72             if (type == NbModuleProvider.NETBEANS_ORG) {
73                 dir = project.getNbrootFile(NB_ALL_INFIX + cnbdashes);
74             } else {
75                 dir = new File JavaDoc(project.getProjectDirectoryFile(), EXT_INFIX + cnbdashes);
76             }
77             candidates.add(Util.urlForDir(dir));
78             if (ignoreNonexistentRoots) {
79                 Iterator JavaDoc it = candidates.iterator();
80                 while (it.hasNext()) {
81                     URL JavaDoc u = (URL JavaDoc) it.next();
82                     if (URLMapper.findFileObject(u) == null) {
83                         it.remove();
84                     }
85                 }
86             }
87             return new JavadocForBinaryQuery.Result() {
88                 public URL JavaDoc[] getRoots() {
89                     return (URL JavaDoc[]) candidates.toArray(new URL JavaDoc[candidates.size()]);
90                 }
91                 public void addChangeListener(ChangeListener JavaDoc l) {}
92                 public void removeChangeListener(ChangeListener JavaDoc l) {}
93             };
94         } catch (MalformedURLException JavaDoc e) {
95             throw new AssertionError JavaDoc(e);
96         }
97     }
98     
99 }
100
Popular Tags