1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.jdbc4olap.xmla;
23
24 import java.util.ArrayList;
25 import java.util.Enumeration;
26 import java.util.List;
27 import java.util.Properties;
28 import java.util.Arrays;
29
30 import javax.xml.soap.SOAPElement;
31 import javax.xml.soap.SOAPException;
32 import javax.xml.soap.SOAPFactory;
33
34
35
36
37
38 class XmlaProperties {
39
40 private static final String[] FORBIDDEN_PROPERTIES = {XmlaLogin.PROPERTY_NAME_USER, XmlaLogin.PROPERTY_NAME_PASSWORD};
41 private static final List<String> FORBIDDEN_LIST = new ArrayList<String>(Arrays.asList(FORBIDDEN_PROPERTIES));
42
43 private final Properties properties;
44
45 XmlaProperties() {
46 properties = new Properties();
47 }
48
49 XmlaProperties(final Properties props) {
50 this();
51 addProperties(props);
52 }
53
54 void addProperties(final Properties props) {
55 if (props != null) {
56 for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
57 String key = (String) e.nextElement();
58 String value = props.getProperty(key);
59 setProperty(key, value);
60 }
61 }
62 }
63
64 String getProperty(final String key) {
65 return properties.getProperty(key);
66 }
67
68 void setProperty(final String key, final String value) {
69 if (key != null && value != null && !FORBIDDEN_LIST.contains(key.toLowerCase())) {
70 properties.setProperty(key, value);
71 }
72 }
73
74 boolean containsProperty(final String key) {
75 return properties.containsKey(key);
76 }
77
78 SOAPElement getXMLA() throws SOAPException {
79 final SOAPFactory factory = XmlaConn.SOAP_FACTORY;
80 final SOAPElement props = factory.createElement("Properties", "", "urn:schemas-microsoft-com:xml-analysis");
81 final SOAPElement propertyList = props.addChildElement(factory.createName("PropertyList", "", "urn:schemas-microsoft-com:xml-analysis"));
82 for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
83 final String key = (String) e.nextElement();
84 final String value = properties.getProperty(key);
85 if (value != null && !"".equals(value)) {
86 final SOAPElement soapProperty = propertyList.addChildElement(factory.createName(key));
87 soapProperty.addTextNode(value);
88 }
89 }
90 return props;
91 }
92 }