Inspector | Message | Severity | Location |
---|---|---|---|
Java Inspector 048 | Copyrights information should be present in each file. | 1 | |
Java Inspector 089 | Undocumented constructor | 2 | 50:9 |
Java Inspector 089 | Undocumented method | 2 | 54:9 |
Java Inspector 089 | Undocumented method | 2 | 63:9 |
Java Inspector 089 | Undocumented method | 2 | 73:9 |
Java Inspector 089 | Undocumented method | 2 | 81:9 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 77:65 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 77:96 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 83:75 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 87:52 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 88:111 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 90:61 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 93:45 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 94:56 |
Java Inspector 040 | Parameter name name clashes with field name in JndiBridge | 3 | 73:35 |
1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.config;
24
25import java.util.Hashtable;
26
27import javax.naming.InitialContext;
28import javax.naming.NamingException;
29
30import org.w3c.dom.Element;
31import org.w3c.dom.Node;
32import org.w3c.dom.NodeList;
33
34import biz.hammurapi.convert.ConvertingService;
35import biz.hammurapi.xml.dom.DOMUtils;
36
37/**
38 * Binds to jndi context and bridges pv-naming with jndi naming.
39 *
40 * @author Pavel Vlasov
41 * @revision $Revision$
42 */
43public class JndiBridge extends ComponentBase implements DomConfigurable {
44 private Hashtable ctxProps = new Hashtable();
45
46 private javax.naming.Context master;
47
48 private String name;
49
50 public JndiBridge() {
51 super();
52 }
53
54 public void start() throws ConfigurationException {
55 try {
56 InitialContext jndiContext = new InitialContext(ctxProps);
57 master = (javax.naming.Context) (name == null ? jndiContext : jndiContext.lookup(name));
58 } catch (NamingException e) {
59 throw new ConfigurationException(e);
60 }
61 }
62
63 public void stop() throws ConfigurationException {
64 if (master != null) {
65 try {
66 master.close();
67 } catch (NamingException e) {
68 throw new ConfigurationException(e);
69 }
70 }
71 }
72
73 protected Object getChild(String name) {
74 try {
75 return master.lookup(name);
76 } catch (NamingException e) {
77 throw new RuntimeConfigurationException("Lookup failed for '" + name + "' " + e, e);
78 }
79 }
80
81 public void configure(Node configNode, Context context, ClassLoader classLoader) throws ConfigurationException {
82 try {
83 NodeList nl = DOMUtils.selectNodeList(configNode, "environment-property");
84 for (int i=0, l=nl.getLength(); i<l; ++i) {
85 Element e = (Element) nl.item(i);
86 Object value = DOMUtils.getNonBlankElementText(e);
87 if (e.hasAttribute("type")) {
88 value = ConvertingService.convert(value, Class.forName(e.getAttribute("type")));
89 }
90 ctxProps.put(e.getAttribute("name"), value);
91 }
92 Element ce = (Element) configNode;
93 if (ce.hasAttribute("jndi-name")) {
94 name = ce.getAttribute("jndi-name");
95 }
96 } catch (Exception e) {
97 throw new ConfigurationException(e);
98 }
99 }
100
101}
102