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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
101 }
102}
103