KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Run > TRAccess


1 /* $Id: TRAccess.java,v 1.2 2004/05/20 14:23:52 bures Exp $ */
2 package SOFA.SOFAnode.Run;
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5
6 import javax.xml.parsers.DocumentBuilder JavaDoc;
7 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
8
9 import org.w3c.dom.Document JavaDoc;
10
11 /** Methods for simple access to TR.
12   *
13   * @author Petr Hnetynka
14   */

15 public class TRAccess {
16
17   /** Returns depldescr of the given application from TR (it can access TR remotely).
18     * It use property sofa.tr.url.
19     *
20     * @param applname full application name
21     * @param ddname name of the descriptor
22     * @return deplyment descriptor
23     * @throws java.net.MalformedURLException malformed url
24     * @throws java.io.IOException io exception
25     * @throws javax.xml.parsers.ParserConfigurationException xml exception
26     * @throws org.xml.sax.SAXException xml exception
27     */

28   public static SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor getDeplDescr(String JavaDoc applname, String JavaDoc ddname) throws java.net.MalformedURLException JavaDoc, java.io.IOException JavaDoc, javax.xml.parsers.ParserConfigurationException JavaDoc, org.xml.sax.SAXException JavaDoc {
29     String JavaDoc trString = System.getProperty("sofa.tr.url","file:/sofa/tr/");
30     String JavaDoc path = trString+"impl";
31     path = path + fullNameToURLName(applname, ddname);
32     java.net.URL JavaDoc url = new java.net.URL JavaDoc(path);
33     java.net.URLConnection JavaDoc con = url.openConnection();
34     java.io.InputStream JavaDoc is = con.getInputStream();
35     SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor dd = new SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl(is);
36     is.close();
37     return dd;
38   }
39
40   /** Returns depldescr of the given application from TR (it can access TR directly).
41     * It use property sofa.tr.dir.
42     *
43     * @param applname full application name
44     * @param ddname name of the descriptor
45     * @return deplyment descriptor
46     * @throws java.io.IOException io exception
47     * @throws javax.xml.parsers.ParserConfigurationException xml exception
48     * @throws org.xml.sax.SAXException xml exception
49     */

50   public static SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor getDeplDescrLocal(String JavaDoc applname, String JavaDoc ddname) throws java.net.MalformedURLException JavaDoc, java.io.IOException JavaDoc, javax.xml.parsers.ParserConfigurationException JavaDoc, org.xml.sax.SAXException JavaDoc {
51     String JavaDoc trString = System.getProperty("sofa.tr.dir","/sofa/tr");
52     String JavaDoc path = trString+File.separator+"impl";
53     path = path + fullNameToURLName(applname, ddname);
54     java.io.FileInputStream JavaDoc is = new FileInputStream JavaDoc(path);
55     SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor dd = new SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl(is);
56     is.close();
57     return dd;
58   }
59
60   /** Returns depldescr as an XML document of the given application (it can access TR remotely).
61     * It use property sofa.tr.url.
62     *
63     * @param applname full application name
64     * @param ddname name of the descriptor
65     * @return XML document
66     * @throws java.net.MalformedURLException malformed url
67     * @throws java.io.IOException io exception
68     * @throws javax.xml.parsers.ParserConfigurationException xml exception
69     * @throws org.xml.sax.SAXException xml exception
70     */

71   public static Document JavaDoc getDeplDescrXML(String JavaDoc applname, String JavaDoc ddname) throws java.net.MalformedURLException JavaDoc, java.io.IOException JavaDoc, javax.xml.parsers.ParserConfigurationException JavaDoc, org.xml.sax.SAXException JavaDoc {
72     String JavaDoc trString = System.getProperty("sofa.tr.url","file:/sofa/tr/");
73     String JavaDoc path = trString+"impl";
74     path = path + fullNameToURLName(applname, ddname);
75     java.net.URL JavaDoc url = new java.net.URL JavaDoc(path);
76     java.net.URLConnection JavaDoc con = url.openConnection();
77     java.io.InputStream JavaDoc is = con.getInputStream();
78     DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
79     DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
80     Document JavaDoc document = builder.parse(is);
81     is.close();
82     return document;
83   }
84
85   /** Returns depldescr as an XML document of the given application (it can access TR directly).
86     * It use property sofa.tr.dir.
87     *
88     * @param applname full application name
89     * @param ddname name of the descriptor
90     * @return XML document
91     * @throws java.io.IOException io exception
92     * @throws javax.xml.parsers.ParserConfigurationException xml exception
93     * @throws org.xml.sax.SAXException xml exception
94     */

95   public static Document JavaDoc getDeplDescrXMLLocal(String JavaDoc applname, String JavaDoc ddname) throws java.net.MalformedURLException JavaDoc, java.io.IOException JavaDoc, javax.xml.parsers.ParserConfigurationException JavaDoc, org.xml.sax.SAXException JavaDoc {
96     String JavaDoc trString = System.getProperty("sofa.tr.dir","/sofa/tr");
97     String JavaDoc path = trString+File.separator+"impl";
98     path = path + fullNameToURLName(applname, ddname);
99     java.io.FileInputStream JavaDoc is = new FileInputStream JavaDoc(path);
100     DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
101     DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
102     Document JavaDoc document = builder.parse(is);
103     is.close();
104     return document;
105   }
106
107   /** Converts full application name to the URL path and append appendName.
108     *
109     * @param clname full application name
110     * @param appendName append this string to path
111     * @return URL path ("::" converted to "/")
112     */

113   public static String JavaDoc fullNameToURLName(String JavaDoc clname, String JavaDoc appendName) {
114     clname = clname.replaceAll("::", "/");
115     clname = clname.replace('[', '/');
116     clname = clname.replace(']', '/');
117     clname = clname + appendName;
118     if (clname.charAt(0) != '/')
119       clname = "/" + clname;
120     return clname;
121   }
122   
123 }
124
Popular Tags