1 19 20 package org.netbeans.modules.j2ee.deployment.impl; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import org.netbeans.modules.j2ee.deployment.common.api.SourceFileMap; 27 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeAppProvider; 28 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileUtil; 31 32 36 public class DefaultSourceMap extends SourceFileMap { 37 38 42 private J2eeModuleProvider provider; 43 private HashSet rootFiles = new HashSet (); 44 45 46 public DefaultSourceMap(J2eeModuleProvider provider) { 47 this.provider = provider; 48 FileObject[] roots = provider.getSourceRoots(); 49 for (int i=0; i<roots.length; i++) { 50 if (roots[i] != null) { 51 rootFiles.add(FileUtil.toFile(roots[i])); 52 } 53 } 54 } 55 56 public String getContextName() { 57 return provider.getDeploymentName(); 58 } 59 60 public FileObject[] getSourceRoots() { 61 return provider.getSourceRoots(); 62 } 63 64 public File getEnterpriseResourceDir() { 65 return provider.getEnterpriseResourceDirectory(); 66 } 67 68 public File [] getEnterpriseResourceDirs() { 69 ArrayList result = new ArrayList (); 70 result.add(provider.getEnterpriseResourceDirectory()); 71 if (provider instanceof J2eeAppProvider) { 72 J2eeAppProvider jap = (J2eeAppProvider) provider; 73 J2eeModuleProvider[] children = jap.getChildModuleProviders(); 74 for (int i=0; i<children.length; i++) { 75 result.add(children[i].getEnterpriseResourceDirectory()); 76 } 77 } 78 return (File []) result.toArray(new File [result.size()]); 79 } 80 81 public boolean add(String distributionPath, FileObject sourceFile) { 82 return false; 83 } 84 85 public FileObject remove(String distributionPath) { 86 return null; 87 } 88 89 public FileObject[] findSourceFile(String distributionPath) { 90 ArrayList ret = new ArrayList (); 91 FileObject[] roots = getSourceRoots(); 92 String path = distributionPath.startsWith("/") ? distributionPath.substring(1) : distributionPath; for (int i=0; i<roots.length; i++) { 94 FileObject fo = roots[i].getFileObject(path); 95 if (fo != null) 96 ret.add(fo); 97 } 98 return (FileObject[]) ret.toArray(new FileObject[ret.size()]); 99 } 100 101 public File getDistributionPath(FileObject sourceFile) { 102 for (Iterator i=rootFiles.iterator(); i.hasNext();) { 103 File rootFile = (File ) i.next(); 104 FileObject root = FileUtil.toFileObject(rootFile); 105 String relative = FileUtil.getRelativePath(root, sourceFile); 106 if (relative != null && ! relative.trim().equals("")) { return new File (relative); 108 } 109 } 110 return null; 111 } 112 } 113 114 115 | Popular Tags |