1 19 20 package org.netbeans.modules.apisupport.project.queries; 21 22 import java.util.Iterator ; 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 ; 31 32 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 isPubliclyAccessible(FileObject pkg) { 45 FileObject srcdir = project.getSourceDirectory(); 46 if (srcdir != null) { 47 String path = FileUtil.getRelativePath(srcdir, pkg); 48 if (path != null) { 49 String name = path.replace('/', '.'); 50 Element config = project.getPrimaryConfigurationData(); 51 Element pubPkgs = Util.findElement(config, "public-packages", NbModuleProjectType.NAMESPACE_SHARED); if (pubPkgs == null) { 53 pubPkgs = Util.findElement(config, "friend-packages", NbModuleProjectType.NAMESPACE_SHARED); } 56 if (pubPkgs != null) { 57 Iterator it = Util.findSubElements(pubPkgs).iterator(); 58 while (it.hasNext()) { 59 Element pubPkg = (Element ) it.next(); 60 boolean sub = "subpackages".equals(pubPkg.getLocalName()); String 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 |