KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > binding > axis2 > Axis2Bootstrap


1 package org.objectweb.petals.binding.axis2;
2
3 import java.io.File JavaDoc;
4 import java.io.FileOutputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.util.Properties JavaDoc;
7
8 import javax.jbi.JBIException;
9 import javax.jbi.component.InstallationContext;
10
11 import org.objectweb.petals.component.common.SimpleBootstrap;
12 import org.objectweb.petals.tools.jbicommon.util.XMLUtil;
13 import org.w3c.dom.DocumentFragment JavaDoc;
14 import org.w3c.dom.Node JavaDoc;
15
16 public class Axis2Bootstrap extends SimpleBootstrap {
17
18     InstallationContext installContext = null;
19
20     /*
21      * non-Javadoc)
22      *
23      * @see org.objectweb.petals.component.common.basic.AbstractBasicComponent#init(javax.jbi.component.InstallationContext)
24      */

25     @Override JavaDoc
26     public void init(InstallationContext installContext) throws JBIException {
27         this.installContext = installContext;
28     }
29
30     /*
31      * (non-Javadoc)
32      *
33      * @see org.objectweb.petals.component.common.basic.AbstractBasicComponent#cleanUp()
34      */

35     @Override JavaDoc
36     public void cleanUp() throws JBIException {
37         installContext = null;
38     }
39
40     /*
41      * (non-Javadoc)
42      *
43      * @see org.objectweb.petals.component.common.basic.AbstractBasicComponent#onInstall()
44      */

45     @Override JavaDoc
46     public void onInstall() throws JBIException {
47
48         // install modules and services to correct directories
49
copyAxisConfFiles();
50
51         // retrieve the specified htmlPort for http server
52
String JavaDoc htmlPort = retrieveHttpServerPort();
53
54         if (htmlPort == null) {
55             htmlPort = "8080";
56         }
57
58         // store htmlPort for later execution
59
Properties JavaDoc p = new Properties JavaDoc();
60         p.put("axis2.server.port", htmlPort);
61
62         File JavaDoc propertieFile = new File JavaDoc(installContext.getInstallRoot()
63             + File.separator + "axis2.properties");
64         try {
65             FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(propertieFile);
66             p.store(fos, "html port used to start the axis2 http server");
67         } catch (IOException JavaDoc e) {
68             throw new JBIException(e);
69         }
70     }
71
72     /*
73      * (non-Javadoc)
74      *
75      * @see org.objectweb.petals.component.common.basic.AbstractBasicComponent#onUninstall()
76      */

77     @Override JavaDoc
78     public void onUninstall() throws JBIException {
79     }
80
81     /**
82      * Axis2 needs a repository composed of a "modules" and "services"
83      * directory. Modules (.mar) must be copies into it
84      */

85     protected void copyAxisConfFiles() {
86         File JavaDoc installPath = new File JavaDoc(installContext.getInstallRoot());
87
88         File JavaDoc modules = new File JavaDoc(installPath, "modules");
89         File JavaDoc services = new File JavaDoc(installPath, "services");
90
91         modules.mkdirs();
92         services.mkdirs();
93
94         // copy .mar files to the modules directory
95

96         File JavaDoc[] metaInfFiles = new File JavaDoc(installPath, "META-INF").listFiles();
97         for (File JavaDoc file : metaInfFiles) {
98             if (file.getName().endsWith(".mar")) {
99                 file.renameTo(new File JavaDoc(modules, file.getName()));
100             }
101             if (file.getName().equals("axis2.xml")) {
102                 file.renameTo(new File JavaDoc(installPath, file.getName()));
103             }
104         }
105     }
106
107     /**
108      * Retrieve from the jbi.xml extension the HTML port to be used for Axis2
109      * server. The port is defined in the installation context (jbi.xml file)
110      * like this :
111      *
112      * <code><petals-extensions:httpPort>8084</petals-extensions:httpPort></code>
113      *
114      * @return axis2 html port, null if no one is specified
115      */

116     protected String JavaDoc retrieveHttpServerPort() {
117         String JavaDoc result = null;
118         DocumentFragment JavaDoc ext = installContext
119             .getInstallationDescriptorExtension();
120         Node JavaDoc httpPort = ext.getFirstChild();
121         if (httpPort != null && httpPort.getNodeName().contains("http")) {
122             result = XMLUtil.getTextContent(httpPort);
123         }
124         return result;
125     }
126
127 }
128
Popular Tags