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 33 public class JbiSharedLibraryDescriptorWriter { 34 35 private final String encoding; 36 37 public JbiSharedLibraryDescriptorWriter(String encoding) { 38 this.encoding = encoding; 39 } 40 41 public void write(File descriptor, String name, String description, 42 String version, String classLoaderDelegation, List uris) 43 throws JbiPluginException { 44 FileWriter w; 45 try { 46 w = new FileWriter (descriptor); 47 } catch (IOException ex) { 48 throw new JbiPluginException("Exception while opening file[" 49 + descriptor.getAbsolutePath() + "]", ex); 50 } 51 52 XMLWriter writer = new PrettyPrintXMLWriter(w, encoding, null); 53 writer.startElement("jbi"); 54 writer.addAttribute("xmlns", "http://java.sun.com/xml/ns/jbi"); 55 writer.addAttribute("version", "1.0"); 56 57 writer.startElement("shared-library"); 58 writer.addAttribute("class-loader-delegation", classLoaderDelegation); 59 writer.addAttribute("version", version); 60 61 writer.startElement("identification"); 62 writer.startElement("name"); 63 writer.writeText(name); 64 writer.endElement(); 65 writer.startElement("description"); 66 writer.writeText(description); 67 writer.endElement(); 68 writer.endElement(); 69 70 writer.startElement("shared-library-class-path"); 71 for (Iterator it = uris.iterator(); it.hasNext();) { 72 DependencyInformation dependency = (DependencyInformation) it.next(); 73 writer.startElement("path-element"); 74 writer.writeText(dependency.getFilename()); 75 writer.endElement(); 76 } 77 writer.endElement(); 78 79 writer.endElement(); 80 writer.endElement(); 81 82 close(w); 83 } 84 85 private void close(Writer closeable) { 86 if (closeable != null) { 87 try { 88 closeable.close(); 89 } catch (Exception e) { 90 } 92 } 93 } 94 95 } 96 | Popular Tags |