HsqldbDataSourceComponent.java

biz/hammurapi/sql/hsqldb/HsqldbDataSourceComponent.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 089 Undocumented top level type 2 48:1
Java Inspector 089 Undocumented method 2 52:9
Java Inspector 089 Undocumented method 2 60:9
Java Inspector 089 Undocumented method 2 99:9
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 70:45
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 72:52
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 75:91
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 77:52
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 87:74
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 94:58

Source code

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.sql.hsqldb;
24
25import java.io.ByteArrayInputStream;
26import java.io.ByteArrayOutputStream;
27import java.io.File;
28import java.io.FileInputStream;
29import java.io.IOException;
30import java.io.InputStream;
31import java.io.InputStreamReader;
32import java.io.Reader;
33import java.net.URL;
34
35import org.w3c.dom.Element;
36import org.w3c.dom.Node;
37import org.w3c.dom.NodeList;
38
39import biz.hammurapi.config.Component;
40import biz.hammurapi.config.ConfigurationException;
41import biz.hammurapi.config.Context;
42import biz.hammurapi.config.DomConfigurable;
43import biz.hammurapi.config.Wrapper;
44import biz.hammurapi.util.StreamPumper;
45import biz.hammurapi.xml.dom.DOMUtils;
46
47
48public abstract class HsqldbDataSourceComponent implements Wrapper, DomConfigurable, Component {
49
50 private byte[] scriptBuf;
51
52 protected Reader getReader() {
53 try {
54 return new InputStreamReader(new ByteArrayInputStream(scriptBuf));
55 } finally {
56 scriptBuf=null;
57 }
58 }
59
60 public void configure(Node configNode, Context context, ClassLoader classLoader) throws ConfigurationException {
61 ByteArrayOutputStream baos=new ByteArrayOutputStream();
62 NodeList children=configNode.getChildNodes();
63 for (int i=0, length=children.getLength(); i<length; i++) {
64 Node child=children.item(i);
65 if (child instanceof Element) {
66 try {
67 String value=DOMUtils.getElementText((Element) child);
68 InputStream in;
69
70 if ("file".equals(child.getNodeName())) {
71 in = new FileInputStream(new File(value));
72 } else if ("resource".equals(child.getNodeName())) {
73 in = getClass().getClassLoader().getResourceAsStream(value);
74 if (in==null) {
75 throw new ConfigurationException("Resource not found: "+value);
76 }
77 } else if ("url".equals(child.getNodeName())) {
78 in = new URL(value).openStream();
79 } else {
80 continue;
81 }
82
83 new StreamPumper(in, baos, null, false).run();
84 in.close();
85
86 } catch (Exception e) {
87 throw new ConfigurationException("Could not load script: "+e, e);
88 }
89 }
90 }
91 try {
92 baos.close();
93 } catch (IOException e) {
94 throw new ConfigurationException("Should never happen: "+e, e);
95 }
96 scriptBuf=baos.toByteArray();
97 }
98
99 public void setOwner(Object owner) {
100 // No functionality
101 }
102}
103