1 23 24 29 30 package com.sun.enterprise.deployment.backend; 31 32 import java.io.*; 33 import java.util.*; 34 import java.util.logging.*; 35 36 import javax.enterprise.deploy.shared.ModuleType ; 37 38 import com.sun.enterprise.deployment.Application; 39 import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile; 40 import com.sun.enterprise.deployment.io.runtime.ApplicationRuntimeDDFile; 41 import com.sun.enterprise.deployment.util.ModuleDescriptor; 42 43 import org.xml.sax.SAXParseException ; 44 import com.sun.enterprise.util.i18n.StringManager; 45 import com.sun.enterprise.deployment.util.LogDomains; 46 47 48 53 54 public class AppDD 55 { 56 public AppDD(File f) throws IASDeploymentException, IOException, SAXParseException 57 { 58 this(f, false); 59 } 60 61 63 public AppDD(File f, boolean validateXML) throws IASDeploymentException, IOException, SAXParseException 64 { 65 if(f == null || !f.exists()) { 66 String msg = localStrings.getString( 67 "enterprise.deployment.backend.bad_file_parameter", f ); 68 throw new IllegalArgumentException ( msg ); 69 } 70 71 File f2 = null; 72 if(f.isDirectory()) 73 { 74 File f1 = new File(f, "META-INF"); 75 f = new File(f1, "application.xml"); f2 = new File(f1, "sun-application.xml"); } 78 79 if(!f.exists() || f.isDirectory()) { 81 String msg = localStrings.getString( 82 "enterprise.deployment.backend.no_application_xml", 83 f.getPath() ); 84 throw new IASDeploymentException( msg ); 85 } 86 87 file = f; 88 89 if(f2 != null && f2.exists() && f2.isFile()) { 90 file2 = f2; 91 } 92 93 try 94 { 95 parse(validateXML); 96 } 97 catch(Throwable t) 98 { 99 100 t.printStackTrace(); 101 if(t instanceof IASDeploymentException) 102 throw (IASDeploymentException) t; 103 else { 104 String msg = localStrings.getString( 105 "enterprise.deployment.backend.error_parsing_application_xml", 106 file.getPath(), t ); 107 throw new IASDeploymentException( msg, t ); 108 } 109 } 110 } 111 112 114 public Application getApplication() 115 { 116 117 return app; 118 } 119 120 public String [] getEjbModules() 121 { 122 String [] ss = new String [ejbModules.size()]; 123 124 return (String [])ejbModules.toArray(ss); 125 } 126 127 129 public String [] getWarModules() 130 { 131 String [] ss = new String [warModules.size()]; 132 133 return (String [])warModules.toArray(ss); 134 } 135 136 138 public String [] getRarModules() 139 { 140 String [] ss = new String [rarModules.size()]; 141 142 return (String [])rarModules.toArray(ss); 143 } 144 145 147 public String [] getClientModules() 148 { 149 String [] ss = new String [clientModules.size()]; 150 151 return (String [])clientModules.toArray(ss); 152 } 153 154 156 public String [] getContextRoots() 157 { 158 String [] ss = new String [contextRoots.size()]; 159 160 return (String [])contextRoots.toArray(ss); 161 } 162 163 165 public File getFile() 166 { 167 return file; 168 } 169 170 172 private void parse(boolean validateXML) throws IASDeploymentException, IOException, SAXParseException 173 { 174 FileInputStream fis = null; 175 try { 176 fis = new FileInputStream(file); 177 ApplicationDeploymentDescriptorFile addf = new ApplicationDeploymentDescriptorFile(); 178 addf.setXMLValidation(validateXML); 179 if (validateXML) { 180 addf.setXMLValidationLevel(addf.PARSING_VALIDATION); 181 } 182 183 app = (Application) addf.read(fis); 184 185 if (file2 != null) { 187 FileInputStream fis2 = new FileInputStream(file2); 188 ApplicationRuntimeDDFile arddf = 189 new ApplicationRuntimeDDFile(); 190 arddf.setXMLValidation(validateXML); 191 if (validateXML) { 192 arddf.setXMLValidationLevel(arddf.PARSING_VALIDATION); 193 } 194 app = (Application)arddf.read(app, fis2); 195 if (fis2 != null) { 196 fis2.close(); 197 } 198 199 } 200 201 206 for (Iterator modules = app.getModules(); modules.hasNext();) { 207 ModuleDescriptor md = (ModuleDescriptor) modules.next(); 208 if (md.getModuleType().equals(ModuleType.EJB)) { 209 ejbModules.add(md.getArchiveUri()); 210 } else 211 if (md.getModuleType().equals(ModuleType.WAR)) { 212 warModules.add(md.getArchiveUri()); 213 } else 214 if (md.getModuleType().equals(ModuleType.CAR)) { 215 clientModules.add(md.getArchiveUri()); 216 } else 217 if (md.getModuleType().equals(ModuleType.RAR)) { 218 rarModules.add(md.getArchiveUri()); 219 } 220 } 221 222 setContextRoots(app); 223 } finally { 224 if (fis != null) { 225 fis.close(); 226 } 227 } 228 } 229 230 232 private void setContextRoots(Application app) throws IASDeploymentException 233 { 234 assert app != null; 235 assert warModules != null; 236 assert contextRoots == null; 238 contextRoots = new HashSet(); 239 240 for(Iterator it = warModules.iterator(); it.hasNext(); ) { 241 242 ModuleDescriptor md = app.getModuleDescriptorByUri((String ) it.next()); 243 String cr = md.getContextRoot(); 244 245 if(contextRoots.add(cr) == false) { 246 249 String msg = localStrings.getString( 250 "enterprise.deployment.backend.duplicate_context_root", 251 cr ); 252 throw new IASDeploymentException( msg ); 253 } 254 } 255 } 256 257 259 private String trim(String s) 260 { 261 263 int index = s.indexOf(">"); 264 String ret = s.substring(index + 1); 265 ret = ret.substring(0, ret.indexOf("<")); 266 267 return ret; 268 } 269 270 272 private File file = null; 273 private File file2 = null; 274 private Set ejbModules = new HashSet(); 275 private Set warModules = new HashSet(); 276 private Set rarModules = new HashSet(); 277 private Set clientModules = new HashSet(); 278 private Application app = null; 279 private Set contextRoots = null; 280 private final Logger logger = LogDomains.getLogger(LogDomains.DPL_LOGGER); 281 private static StringManager localStrings = 282 StringManager.getManager( AppDD.class ); 283 } 284 | Popular Tags |