1 17 package org.apache.servicemix.maven.plugin.jbi; 18 19 import java.io.File ; 20 import java.io.FileWriter ; 21 import java.io.IOException ; 22 import java.io.Writer ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; 27 import org.codehaus.plexus.util.xml.XMLWriter; 28 29 public class JbiComponentDescriptorWriter { 30 31 private final String encoding; 32 33 public JbiComponentDescriptorWriter(String encoding) { 34 this.encoding = encoding; 35 } 36 37 public void write(File descriptor, String component, String bootstrap, 38 String type, String name, String description, 39 String componentClassLoaderDelegation, String bootstrapClassLoaderDelegation, 40 List uris) 41 throws JbiPluginException { 42 FileWriter w; 43 try { 44 w = new FileWriter (descriptor); 45 } catch (IOException ex) { 46 throw new JbiPluginException("Exception while opening file[" 47 + descriptor.getAbsolutePath() + "]", ex); 48 } 49 50 XMLWriter writer = new PrettyPrintXMLWriter(w, encoding, null); 51 writer.startElement("jbi"); 52 writer.addAttribute("xmlns", "http://java.sun.com/xml/ns/jbi"); 53 writer.addAttribute("version", "1.0"); 54 55 writer.startElement("component"); 56 writer.addAttribute("type", type); 57 writer.addAttribute("component-class-loader-delegation", componentClassLoaderDelegation); 58 writer.addAttribute("bootstrap-class-loader-delegation", bootstrapClassLoaderDelegation); 59 60 writer.startElement("identification"); 61 writer.startElement("name"); 62 writer.writeText(name); 63 writer.endElement(); 64 writer.startElement("description"); 65 writer.writeText(description); 66 writer.endElement(); 67 writer.endElement(); 68 69 writer.startElement("component-class-name"); 70 writer.writeText(component); 71 writer.endElement(); 72 writer.startElement("component-class-path"); 73 for (Iterator it = uris.iterator(); it.hasNext();) { 74 DependencyInformation info = (DependencyInformation) it.next(); 75 if ("jar".equals(info.getType())) { 76 writer.startElement("path-element"); 77 writer.writeText(info.getFilename()); 78 writer.endElement(); 79 } 80 } 81 writer.endElement(); 82 83 writer.startElement("bootstrap-class-name"); 84 writer.writeText(bootstrap); 85 writer.endElement(); 86 writer.startElement("bootstrap-class-path"); 87 for (Iterator it = uris.iterator(); it.hasNext();) { 88 DependencyInformation info = (DependencyInformation) it.next(); 89 if ("jar".equals(info.getType())) { 90 writer.startElement("path-element"); 91 writer.writeText(info.getFilename()); 92 writer.endElement(); 93 } 94 } 95 writer.endElement(); 96 97 for (Iterator it = uris.iterator(); it.hasNext();) { 98 DependencyInformation info = (DependencyInformation) it.next(); 99 if ("jbi-shared-library".equals(info.getType())) { 100 writer.startElement("shared-library"); 101 writer.addAttribute("version", info.getVersion()); 102 writer.writeText(info.getName()); 103 writer.endElement(); 104 } 105 } 106 107 writer.endElement(); 108 109 writer.endElement(); 110 111 close(w); 112 } 113 114 private void close(Writer closeable) { 115 if (closeable != null) { 116 try { 117 closeable.close(); 118 } catch (Exception e) { 119 } 121 } 122 } 123 124 } 125 | Popular Tags |