1 23 package com.sun.enterprise.deployment.backend; 24 25 import com.sun.enterprise.deployment.Application; 26 import com.sun.enterprise.deployment.ApplicationClientDescriptor; 27 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 28 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 29 import com.sun.enterprise.deployment.deploy.shared.OutputJarArchive; 30 import com.sun.enterprise.deployment.interfaces.ClientJarMaker; 31 import com.sun.enterprise.deployment.interfaces.DeploymentImplConstants; 32 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 33 import com.sun.enterprise.deployment.util.ModuleDescriptor; 34 import com.sun.enterprise.util.i18n.StringManager; 35 import com.sun.enterprise.util.io.FileUtils; 36 import com.sun.enterprise.util.zip.ZipItem; 37 38 import java.io.File ; 39 import java.util.Collection ; 40 import java.util.Iterator ; 41 import java.util.logging.Level ; 42 import java.util.Properties ; 43 import java.util.Set ; 44 45 51 public class ClientJarMakerThread extends Thread { 52 53 private DeploymentRequest request; 54 private File clientJar; 55 private ZipItem[] clientStubs; 56 private String clientJarChoice = null; 57 58 private static StringManager localStrings = StringManager.getManager( Deployer.class ); 59 60 61 public ClientJarMakerThread(DeploymentRequest request, File clientJar, 62 ZipItem[] clientStubs, 63 String clientJarChoice) { 64 this.request = request; 65 this.clientJar = clientJar; 66 this.clientStubs = clientStubs; 67 this.clientJarChoice = clientJarChoice; 68 } 69 70 public void run() { 71 ClientJarMakerRegistry registry = ClientJarMakerRegistry.getInstance(); 74 75 String moduleID = request.getName(); 76 registry.register(moduleID, this); 77 78 try { 80 createClientJar(request, clientJar, clientStubs, clientJarChoice); 81 } catch(IASDeploymentException e) { 82 DeploymentLogger.get().log(Level.SEVERE, 85 localStrings.getString("enterprise.deployment.error_creating_client_jar", 86 e.getLocalizedMessage()) ,e); 87 88 } finally { 89 90 registry.unregister(moduleID); 92 } 93 94 DeploymentLogger.get().fine("Created client jar file for " + moduleID + " at " + clientJar.getAbsolutePath()); 96 97 } 98 99 103 public static final void createClientJar( 104 DeploymentRequest request, File clientJar, ZipItem[] clientStubs, 105 String clientJarChoice) throws IASDeploymentException { 106 try { 107 OutputJarArchive target = new OutputJarArchive(); 109 target.create(clientJar.getAbsolutePath()); 110 111 RootDeploymentDescriptor descriptor; 112 if (request.getDescriptor().isVirtual()) { 113 descriptor = request.getDescriptor().getStandaloneBundleDescriptor(); 114 } else { 115 descriptor = request.getDescriptor(); 116 } 117 118 AbstractArchive source = new FileArchive(); 119 ((FileArchive) source).open(request.getDeployedDirectory().getAbsolutePath()); 120 PEDeploymentFactoryImpl pe = new PEDeploymentFactoryImpl(); 121 Properties props = getPropertiesForClientJarMaker( 122 CLIENT_JAR_CHOICES.getClientJarChoice(clientJarChoice), 123 request, descriptor); 124 ClientJarMaker jarMaker = pe.getClientJarMaker(props); 125 126 if (FileUtils.safeIsDirectory( 130 request.getGeneratedXMLDirectory())) { 131 AbstractArchive source2 = new FileArchive(); 132 ((FileArchive) source2).open( 133 request.getGeneratedXMLDirectory().getAbsolutePath()); 134 jarMaker.create(descriptor, source, source2, target, clientStubs, 135 null); 136 source2.close(); 137 } else { 138 jarMaker.create(descriptor, source, target, clientStubs,null); 139 } 140 source.close(); 141 target.close(); 142 } catch(Exception e) { 143 IASDeploymentException newE = new IASDeploymentException(); 144 newE.initCause(e); 145 throw newE; 146 } 147 } 148 149 private static Properties getPropertiesForClientJarMaker( 150 CLIENT_JAR_CHOICES choice, 151 DeploymentRequest request, RootDeploymentDescriptor descriptor) { 152 153 boolean qualify = qualifyModuleClientFormat(request,descriptor); 154 155 Properties props = null; 156 Boolean propertySetting = choice.useModuleClientJarMaker(qualify); 157 158 if (propertySetting != null) { 159 props = new Properties (); 160 props.setProperty( 161 DeploymentImplConstants.USE_MODULE_CLIENT_JAR_MAKER, 162 propertySetting.toString()); 163 } 164 return props; 165 } 166 167 175 private static boolean qualifyModuleClientFormat 176 (DeploymentRequest request, RootDeploymentDescriptor descriptor) { 177 178 if (request.getDescriptor().isVirtual()) { 180 return true; 181 } 182 183 Application app = Application.class.cast(descriptor); 184 Set appClients = app.getApplicationClientDescriptors(); 185 if (appClients != null) { 186 187 if (appClients.size() > 1) { 190 return false; 191 } 192 193 if (!appClients.isEmpty()) { 194 ApplicationClientDescriptor ac = 195 ApplicationClientDescriptor.class.cast(appClients.iterator().next()); 196 197 Set msgDestRefs = ac.getMessageDestinationReferenceDescriptors(); 200 if (msgDestRefs != null && !msgDestRefs.isEmpty()) { 201 return false; 202 } 203 204 Set entityMgrFacRefs = ac.getEntityManagerFactoryReferenceDescriptors(); 207 if (entityMgrFacRefs != null && !entityMgrFacRefs.isEmpty()) { 208 return false; 209 } 210 } 211 } 212 213 for (Iterator modules = app.getModules(); modules.hasNext();) { 214 ModuleDescriptor md = ModuleDescriptor.class.cast(modules.next()); 215 216 if (md.getAlternateDescriptor() != null) { 222 return false; 223 } 224 } 225 226 return true; 227 } 228 229 private static enum CLIENT_JAR_CHOICES { 230 231 USE_ORIGINAL_MAKER { 233 public Boolean useModuleClientJarMaker(boolean qualify) { 234 return null;}}, 235 236 USE_TRANSITION_MAKER { 239 public Boolean useModuleClientJarMaker(boolean qualify) { 240 return qualify == true ? Boolean.TRUE : null;}}, 241 242 USE_COMBO_MAKER { 245 public Boolean useModuleClientJarMaker(boolean qualify) { 246 return new Boolean (qualify);}}, 247 248 USE_EAR_MAKER { 251 public Boolean useModuleClientJarMaker(boolean qualify) { 252 return Boolean.FALSE;}}; 253 254 public abstract Boolean useModuleClientJarMaker(boolean qualify); 255 256 public static CLIENT_JAR_CHOICES DEFAULT_CHOICE = USE_EAR_MAKER; 257 258 public static CLIENT_JAR_CHOICES getClientJarChoice(String choice) { 259 try { 260 if (choice == null) { 261 return DEFAULT_CHOICE; 262 } 263 return valueOf(choice); 264 } catch (IllegalArgumentException iae) { 265 return DEFAULT_CHOICE; 266 } 267 } 268 } 269 } 270 | Popular Tags |