KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > maven > plugin > jbi > JbiSharedLibraryDescriptorWriter


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.maven.plugin.jbi;
18
19 import java.io.File JavaDoc;
20 import java.io.FileWriter JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.Writer JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
27 import org.codehaus.plexus.util.xml.XMLWriter;
28
29 /**
30  * Helper that is used to write the jbi.xml for a shared library
31  *
32  */

33 public class JbiSharedLibraryDescriptorWriter {
34
35     private final String JavaDoc encoding;
36
37     public JbiSharedLibraryDescriptorWriter(String JavaDoc encoding) {
38         this.encoding = encoding;
39     }
40
41     public void write(File JavaDoc descriptor, String JavaDoc name, String JavaDoc description,
42             String JavaDoc version, String JavaDoc classLoaderDelegation, List JavaDoc uris)
43             throws JbiPluginException {
44         FileWriter JavaDoc w;
45         try {
46             w = new FileWriter JavaDoc(descriptor);
47         } catch (IOException JavaDoc 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 JavaDoc 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 JavaDoc closeable) {
86         if (closeable != null) {
87             try {
88                 closeable.close();
89             } catch (Exception JavaDoc e) {
90                 // TODO: warn
91
}
92         }
93     }
94
95 }
96
Popular Tags