1 5 package com.bull.eclipse.jonas.actions.ws; 6 7 import java.io.File ; 8 import java.io.FileWriter ; 9 import java.io.IOException ; 10 11 import org.apache.velocity.VelocityContext; 12 import org.apache.velocity.app.VelocityEngine; 13 import org.apache.velocity.exception.MethodInvocationException; 14 import org.apache.velocity.exception.ParseErrorException; 15 import org.apache.velocity.exception.ResourceNotFoundException; 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IFolder; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.runtime.CoreException; 20 21 import com.bull.eclipse.jonas.JonasLauncherPlugin; 22 import com.bull.eclipse.jonas.JonasProject; 23 import com.bull.eclipse.jonas.utils.FileUtil; 24 import com.bull.eclipse.jonas.utils.TemplateDirUtil; 25 26 31 public class CreateDeployWSDD 32 { 33 private IFolder pkgfolder; private JonasProject project; 36 private VelocityEngine vEngine = null; 37 private VelocityContext vContext = null; 38 39 private static final int EXIT_SUCCESS = 0; 40 private static final int EXIT_FAILURE = 1; 41 42 43 public CreateDeployWSDD( JonasProject proj) 44 { 45 project = proj; 46 } 47 48 51 private void copyFileToWebAppDirectory( File f ) 52 { 53 IFile xmlfile = project.getProject().getFile( f.getName() ); 54 try{ FileUtil.copy( f, xmlfile.getLocation().toFile() ); } 55 catch( IOException e ) { 56 JonasLauncherPlugin.log( 57 "JOPE: exception copying file " + f.getName() 58 + " to project " + project.getProject().getName() + ": " + e ); 59 } 60 } 61 62 private boolean myDelete( File f ) 63 { 64 boolean b = f.delete(); 65 int retryCount = 5; 66 while( !b && retryCount-->0 ) { 67 try{ java.lang.Thread.sleep(1000); } catch(Exception e) {} 68 b = f.delete(); 69 } 70 return b; 71 } 72 73 public void runUpdate(String endpointName, String jndiName, String homeClass, 74 String remoteClass, String homeLocalClass, String localClass, String packName) 75 { 76 vContext = new VelocityContext(); 77 78 String jonasRoot = JonasLauncherPlugin.getDefault().getJonasDir(); 79 80 vContext.put("endpoint",endpointName); 81 82 vContext.put("jndiName", jndiName); 83 vContext.put("localHomeClassName", homeLocalClass); 84 vContext.put("localClassName", localClass); 85 vContext.put("homeClassName", homeClass); 86 vContext.put("remoteClassName", remoteClass); 87 JonasLauncherPlugin.log("Deploy = " + project.getProject().getLocation().append(project.getSrcEJBDir() + File.separator + packName )); 88 File outputDir = new File (project.getProject().getLocation().append(project.getSrcEJBDir() + File.separator + packName ).toOSString()); 89 90 91 try { 93 vEngine = new VelocityEngine(); 94 vEngine.setProperty(VelocityEngine.VM_LIBRARY, ""); 95 vEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "file"); 96 vEngine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, 97 TemplateDirUtil.getTemplateDir().concat("/ws")); 98 try { 99 vEngine.init(); 100 } catch (Exception e) { 101 fatalError("unable to initilise Velocity engine (" + e + ")"); 102 } 103 generate("deploy.wsdd", outputDir + "/deploy.wsdd"); 104 } catch (Exception e) { 105 error(e.toString()); 106 } 107 try{ project.getProject().refreshLocal( IResource.DEPTH_INFINITE, null ); } 109 catch( CoreException e ) {} 110 111 } 112 113 public void setPkgFolder( IFolder f ) 114 { 115 pkgfolder = f; 116 } 117 118 122 public static String [] concat( String [] s1, String s2, String s3 ) 123 { 124 String [] full = new String [ s1.length + 2 ]; 125 System.arraycopy( s1, 0, full, 0, s1.length ); 126 full[ full.length-2 ] = s2; 127 full[ full.length-1 ] = s3; 128 return full; 129 } 130 131 135 public static String [] concat( String [] s1, String s2 ) 136 { 137 String [] full = new String [ s1.length + 1 ]; 138 System.arraycopy( s1, 0, full, 0, s1.length ); 139 full[ full.length-1 ] = s2; 140 return full; 141 } 142 143 static void fatalError(String errMsg) { 144 System.err.println("NewBean fatal error: " + errMsg); 145 System.exit(EXIT_FAILURE); 146 } 147 148 153 private void generate(String templateFileName, 154 String targetFileName) throws Exception , IOException , ResourceNotFoundException, ParseErrorException, MethodInvocationException { 155 FileWriter fileWriter = null; 156 fileWriter = new FileWriter (targetFileName); 157 vEngine.mergeTemplate(templateFileName, vContext, fileWriter); 158 fileWriter.close(); 159 } 160 161 165 static void error(String errMsg) { 166 System.err.println("NewBean error: " + errMsg); 167 } 168 169 170 } 171 | Popular Tags |