1 package com.sslexplorer.agent.client.util; 2 3 import java.io.IOException ; 4 import java.io.File ; 5 import java.io.ByteArrayOutputStream ; 6 import java.io.FileInputStream ; 7 8 14 public class ParameterTransformation { 15 16 private XMLElement el; 17 private AbstractApplicationLauncher launcher; 18 private String outputParam; 19 private String inputParam; 20 21 29 ParameterTransformation(XMLElement el, AbstractApplicationLauncher launcher) throws IOException { 30 31 if (el.getAttribute("class") == null || el.getAttribute("input") == null || el.getAttribute("output") == null) throw new IOException (Messages.getString("ParameterTransformation.transformRequiresClassInputAndOutputAttributes")); 34 this.el = el; 35 this.launcher = launcher; 36 37 } 38 39 44 public void processTransformation() throws IOException { 45 46 String classFile = el.getAttribute("class").toString(); inputParam = el.getAttribute("input").toString(); outputParam = el.getAttribute("output").toString(); 50 File f = new File (launcher.getInstallDir(), classFile + ".class"); 52 if (!f.exists()) 53 throw new IOException (classFile + Messages.getString("ParameterTransformation.8")); 55 FileInputStream in = new FileInputStream (f); 56 ByteArrayOutputStream out = new ByteArrayOutputStream (); 57 58 byte[] buf = new byte[16384]; 59 int read; 60 61 while ((read = in.read(buf)) > -1) { 62 out.write(buf, 0, read); 63 } 64 65 in.close(); 66 buf = out.toByteArray(); 67 try { 68 69 launcher.events.debug(Messages.getString("ParameterTransformation.loadingTransformationClass") + classFile); Class cls = ByteArrayClassLoader.getInstance().createFromByteArray(classFile, buf, 0, buf.length); 71 72 launcher.events.debug(Messages.getString("ParameterTransformation.creatingTransformationInstance")); Transformation t = (Transformation) cls.newInstance(); 74 75 launcher.events.debug(Messages.getString("ParameterTransformation.invokingTransformation")); launcher.addParameter(outputParam, t.transform(launcher.replaceTokens(inputParam))); 77 } catch (Exception ex) { 78 launcher.events.debug(Messages.getString("ParameterTransformation.exceptionInTransformation") + ex.getMessage()); } 80 81 } 82 } 83 | Popular Tags |