1 23 24 package com.sun.enterprise.server; 25 26 import java.io.File ; 27 import java.io.FileFilter ; 28 import java.io.IOException ; 29 import java.util.jar.JarFile ; 30 import java.util.jar.Manifest ; 31 import java.util.jar.Attributes ; 32 33 import java.util.logging.Level ; 34 import java.util.logging.Logger ; 35 import com.sun.logging.LogDomains; 36 37 import com.sun.enterprise.server.ManagerFactory; 38 import com.sun.enterprise.server.ApplicationManager; 39 import com.sun.enterprise.server.StandAloneConnectorModulesManager; 40 import com.sun.enterprise.server.StandAloneEJBModulesManager; 41 import com.sun.enterprise.deployment.autodeploy.AutoDeployConstants; 42 import com.sun.enterprise.deployment.autodeploy.AutoDeployDirectoryScanner; 43 44 51 52 public class SystemAppScanner extends AutoDeployDirectoryScanner { 53 54 private String targetType; 55 56 public SystemAppScanner(String targetType){ 57 this.targetType = targetType; 58 } 59 60 protected File [] getListOfFiles(File dir, boolean includeSubDir) { 61 return dir.listFiles(new TargetFileFilter(targetType)); 62 } 63 64 } 65 66 class TargetFileFilter implements FileFilter { 67 private static final Logger sLogger= LogDomains.getLogger(LogDomains.CORE_LOGGER); 68 69 String targetType = null; 70 71 TargetFileFilter(String targetType){ 72 this.targetType = targetType; 73 } 74 75 76 77 85 public boolean accept(File f){ 86 boolean flag=false; 87 String name= f.getName(); 88 String fileType = null; 89 int lastIndex=-1; 90 91 if(name !=null && name.length() >0){ 92 lastIndex = name.lastIndexOf('.'); 93 try{ 94 if (lastIndex >= 0) 95 fileType = name.substring(lastIndex + 1); 96 if(!f.isDirectory() && f.canRead()) 97 { 98 name=name.substring(0,lastIndex); if(name !=null && name.length() >0) 100 flag=true; 101 } 102 }catch(SecurityException se){ 103 sLogger.log(Level.WARNING, "SecurityException occured while accessing :" +f.getName()); 104 }catch(Exception e){ 106 sLogger.log(Level.WARNING, "Exception occured while accessing :" +f.getName()); 107 } 109 } 110 if(flag && isApplicableToTarget(f) && !(isRegistered(name,fileType))) { 111 sLogger.log(Level.FINE,"Selecting file ["+ f.getAbsolutePath()+"] for autodeployment"); 112 return true; 113 }else 114 return false; 115 116 } 117 118 private boolean isApplicableToTarget(File f) { 119 JarFile j = null; 120 try{ 121 j = new JarFile (f); 122 Manifest m = j.getManifest(); 123 Attributes a = m.getMainAttributes(); 124 String appType = a.getValue(Constants.APPLICATION_TYPE); 125 if(appType == null) appType = Constants.USER; 126 if(targetType.equals(Constants.TARGET_TYPE_ADMIN)){ 127 if(appType.equals(Constants.SYSTEM_ADMIN) || appType.equals(Constants.SYSTEM_ALL)) 128 return true; 129 else 130 return false; 131 }else if(targetType.equals(Constants.TARGET_TYPE_INSTANCE)){ 132 if(appType.equals(Constants.SYSTEM_INSTANCE) || appType.equals(Constants.SYSTEM_ALL)) 133 return true; 134 else 135 return false; 136 } 137 return false; 138 }catch(Exception e) { 139 sLogger.log(Level.WARNING, "Exception occured while accessing :" +f.getName()); 140 return false; 141 } finally { 142 if (j != null) { 143 try { 144 j.close(); 145 } catch (IOException ioe) { 146 sLogger.log(Level.WARNING, "Error closing jar file after checking for autodeploy", ioe); 147 } 148 } 149 } 150 } 151 152 158 private boolean isRegistered(String name, String type) 159 { 160 try{ 161 162 if(type.equals(AutoDeployConstants.EAR_EXTENSION)) { 163 164 ApplicationManager amgr = 165 ManagerFactory.getApplicationManager(); 166 return amgr.isRegistered(name); 167 168 }else if(type.equals(AutoDeployConstants.JAR_EXTENSION)) { 169 170 StandAloneEJBModulesManager emgr = 171 ManagerFactory.getSAEJBModulesManager(); 172 return emgr.isRegistered(name); 173 174 }else if(type.equals(AutoDeployConstants.RAR_EXTENSION)) { 175 176 StandAloneConnectorModulesManager cmgr = 177 ManagerFactory.getSAConnectorModulesManager(); 178 return cmgr.isRegistered(name); 179 180 }else if(type.equals(AutoDeployConstants.WAR_EXTENSION)) { 181 } 182 183 }catch(Exception e){ 184 sLogger.log(Level.FINE, "error_occured_in_isreg",e); 185 } 186 return false; 187 } 188 189 } 190 191 | Popular Tags |