1 19 20 package org.netbeans.modules.projectimport.jbuilder.parsing; 21 22 import java.io.File ; 23 import java.util.Collection ; 24 import java.util.Collections ; 25 import org.openide.filesystems.FileObject; 26 import org.openide.filesystems.FileUtil; 27 28 29 34 public abstract class ProjectBuilder { 35 private static final ProjectBuilder[] SUPPORTED_TYPES = new ProjectBuilder[] { 36 new JpxBuilder(".jpr"), new JpxBuilder(".jpx") }; 39 40 public static boolean isProjectFile(final File file) { 41 return (getProvider(file) != null); 42 } 43 44 45 public static Collection buildProjectModels(final File file) { 46 ProjectBuilder provider = null; 47 provider = getProvider(file); 48 49 return (provider != null) ? provider.buildImpl(file) : Collections.EMPTY_LIST; 50 } 51 52 static ProjectBuilder getProvider(final File file) { 53 FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(file)); 54 if (fo != null) { 55 for (int i = 0; i < SUPPORTED_TYPES.length; i++) { 56 if (SUPPORTED_TYPES[i].isProjectFileImpl(file)) { 57 return SUPPORTED_TYPES[i]; 58 } 59 } 60 } 61 62 return null; 63 } 64 65 protected abstract Collection buildImpl(File file); 66 protected abstract String getSupportedExtension(); 67 private final boolean isProjectFileImpl(File file) { 68 return file.getName().toLowerCase().endsWith(getSupportedExtension()); 69 } 70 } 71 | Popular Tags |