1 19 20 package org.netbeans.modules.j2ee.sun.share.config; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.HashMap ; 25 26 import org.openide.filesystems.FileObject; 27 import org.openide.filesystems.FileUtil; 28 import org.openide.util.Lookup; 29 import org.openide.loaders.DataObjectExistsException; 30 import org.openide.loaders.MultiDataObject; 31 import org.openide.loaders.UniFileLoader; 32 import org.openide.util.NbBundle; 33 34 import org.netbeans.api.project.FileOwnerQuery; 35 import org.netbeans.api.project.Project; 36 37 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 38 39 40 44 public class ConfigDataLoader extends UniFileLoader { 45 46 47 49 private static final String GENERIC_EXTENSION = "dpf"; private static final String PRIMARY = "primary"; private static final String SECONDARY = "secondary"; 54 private static HashMap primaryByName; 55 private static HashMap secondaryByName; 56 57 58 public ConfigDataLoader () { 59 super("org.netbeans.modules.j2ee.sun.share.config.ConfigDataObject"); 61 initMaps(); 62 } 63 64 65 protected void initialize () { 66 super.initialize(); 67 } 68 69 private void initMaps() { 70 primaryByName = new HashMap (); 71 secondaryByName = new HashMap (); 72 73 primaryByName.put("sun-web.xml", "WEB-INF/sun-web.xml"); 75 primaryByName.put("sun-ejb-jar.xml", "META-INF/sun-ejb-jar.xml"); 76 secondaryByName.put("sun-cmp-mappings.xml", "META-INF/sun-cmp-mappings.xml"); 77 primaryByName.put("sun-application.xml", "META-INF/sun-application.xml"); 78 primaryByName.put("sun-application-client.xml", "META-INF/sun-application-client.xml"); 79 } 80 81 82 protected String defaultDisplayName() { 83 return NbBundle.getMessage (ConfigDataLoader.class, "LBL_LoaderName"); 84 } 85 86 89 protected String actionsContext() { 90 return "Loaders/xml/sun-dd/Actions/"; } 92 93 95 protected MultiDataObject createMultiObject (FileObject fo) 96 throws DataObjectExistsException, IOException { 97 if (isPrimaryDescriptor(fo)) { 98 return new ConfigDataObject(fo, this); 99 } else { 100 return new SecondaryConfigDataObject(fo, this); 101 } 102 } 103 104 private boolean isPrimaryDescriptor(FileObject fo) { 105 String filename = fo.getNameExt(); 106 return getPrimaryByName(filename) != null; 107 } 108 109 protected FileObject findPrimaryFile (FileObject fo) { 110 if (fo.isFolder()) { 112 return null; 113 } 114 115 String ext = fo.getExt(); 116 String filename = fo.getNameExt (); 117 FileObject primaryFO = null; 118 String secondaryName = null; 119 if (getPrimaryByName(filename) != null || ext.equals(GENERIC_EXTENSION)) { 120 primaryFO = fo; 121 } else if (getPrimaryBySecondaryName (filename) != null) { secondaryName = filename; 123 } 124 125 if (primaryFO == null && secondaryName == null) { 126 return null; 127 } 128 129 Project owner = FileOwnerQuery.getOwner(fo); 130 if (owner != null) { 131 Lookup l = owner.getLookup(); 132 J2eeModuleProvider projectModule = (J2eeModuleProvider) l.lookup(J2eeModuleProvider.class); 133 if (projectModule != null) { 134 if (primaryFO != null) { 135 primaryFO = projectModule.findDeploymentConfigurationFile(filename); 136 if (primaryFO != null) { 137 File primary = FileUtil.toFile(primaryFO); 138 if (primary != null && primary.equals(FileUtil.toFile(fo))) { 139 return fo; 140 } 141 } 142 } else { FileObject secondaryFO = projectModule.findDeploymentConfigurationFile(secondaryName); 144 if(secondaryFO != null) { 145 File secondary = FileUtil.toFile(secondaryFO); 146 if (secondary != null && secondary.equals(FileUtil.toFile(fo))) { 147 return fo; 148 } 149 } 150 } 151 } 152 } 153 return null; 154 } 155 156 private String getPrimaryByName (String name) { 157 return (String ) primaryByName.get(name); 158 } 159 160 private String getPrimaryBySecondaryName (String name) { 161 return (String ) secondaryByName.get(name); 162 } 163 } 164 | Popular Tags |