KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Iterator JavaDoc;
23 import org.netbeans.modules.apisupport.project.NbModuleProject;
24 import org.netbeans.modules.apisupport.project.NbModuleProjectType;
25 import org.netbeans.modules.apisupport.project.Util;
26 import org.netbeans.spi.java.queries.AccessibilityQueryImplementation;
27 import org.openide.ErrorManager;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30 import org.w3c.dom.Element JavaDoc;
31
32 /**
33  * Says which module packages are accessible.
34  * @author Jesse Glick
35  */

36 public final class AccessibilityQueryImpl implements AccessibilityQueryImplementation {
37     
38     private final NbModuleProject project;
39     
40     public AccessibilityQueryImpl(NbModuleProject project) {
41         this.project = project;
42     }
43     
44     public Boolean JavaDoc isPubliclyAccessible(FileObject pkg) {
45         FileObject srcdir = project.getSourceDirectory();
46         if (srcdir != null) {
47             String JavaDoc path = FileUtil.getRelativePath(srcdir, pkg);
48             if (path != null) {
49                 String JavaDoc name = path.replace('/', '.');
50                 Element JavaDoc config = project.getPrimaryConfigurationData();
51                 Element JavaDoc pubPkgs = Util.findElement(config, "public-packages", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
52
if (pubPkgs == null) {
53                     // Try <friend-packages> too.
54
pubPkgs = Util.findElement(config, "friend-packages", NbModuleProjectType.NAMESPACE_SHARED); // NOI18N
55
}
56                 if (pubPkgs != null) {
57                     Iterator JavaDoc it = Util.findSubElements(pubPkgs).iterator();
58                     while (it.hasNext()) {
59                         Element JavaDoc pubPkg = (Element JavaDoc) it.next();
60                         boolean sub = "subpackages".equals(pubPkg.getLocalName()); // NOI18N
61
String JavaDoc pubPkgS = Util.findText(pubPkg);
62                         if (name.equals(pubPkgS) || (sub && name.startsWith(pubPkgS + '.'))) {
63                             return Boolean.TRUE;
64                         }
65                     }
66                     return Boolean.FALSE;
67                 } else {
68                     Util.err.log(ErrorManager.WARNING, "Invalid project.xml for " + project);
69                     return null;
70                 }
71             }
72         }
73         return null;
74     }
75     
76 }
77
Popular Tags