ZorbaXQMetaData.java
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2012 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.zorbaxquery.api.xqj;
17 
18 import java.util.HashSet;
19 import java.util.Set;
20 import javax.xml.xquery.XQConnection;
21 import javax.xml.xquery.XQException;
22 import org.zorbaxquery.api.Zorba;
23 
24  /**
25  * ZorbaXQMetaData class provides information about the data source, in various aspects, such as the product name and version identification, supported features, specific behaviors, user information, product limits and so forth.
26  *
27  * An object from this class is obtained from the connection object by calling the getMetaData() method, for example:
28  * \code{.java}
29  * ZorbaXQMetaData metaData = connection.getMetaData();
30  * String productVersion = metaData.getProductVersion();
31  * ...
32  * \endcode
33  *
34  * Since the metadata object depends on the connection, all its methods would raise an exception if the connection it is created from is no longer valid.
35  */
36 public class ZorbaXQMetaData implements javax.xml.xquery.XQMetaData {
37 
38  private int XQJ_MAJOR = 1;
39  private int XQJ_MINOR = 1;
40 
41  private XQConnection connection;
42  private Zorba zorba;
43  public ZorbaXQMetaData(XQConnection conn) throws XQException {
44  if (conn.isClosed()) {
45  throw new XQException("This connection is closed");
46  }
47  connection = conn;
48  zorba = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance();
49  }
50 
51  /** \brief Gets the major version of this product.
52  *
53  * @return a integer indicating the major version of this product
54  * @throw XQException - if the connection is no longer valid
55  */
56  @Override
57  public int getProductMajorVersion() throws XQException {
58  isClosedXQException();
59  return zorba.getMajorVersion();
60  }
61 
62  /** \brief Gets the minor version of this product.
63  *
64  * @return a integer indicating the minor version of this product
65  * @throw XQException - if the connection is no longer valid
66  */
67  @Override
68  public int getProductMinorVersion() throws XQException {
69  isClosedXQException();
70  return zorba.getMinorVersion();
71  }
72 
73  /** \brief Gets the name of this product.
74  *
75  * @return a string indicating the product name
76  * @throw XQException - if the connection is no longer valid
77  */
78  @Override
79  public String getProductName() throws XQException {
80  isClosedXQException();
81  return "Zorba - The XQuery Processor";
82  }
83 
84  /** \brief Gets the full version of this product.
85  *
86  * @return a string indicating the product version
87  * @throw XQException - if the connection is no longer valid
88  */
89  @Override
90  public String getProductVersion() throws XQException {
91  isClosedXQException();
92  return zorba.getVersion();
93  }
94 
95  /** \brief Gets the major version number of XQJ specification supported by this implementation.
96  *
97  * @return an integer indicating the XQJ major version
98  * @throw XQException - if the connection is no longer valid
99  */
100  @Override
101  public int getXQJMajorVersion() throws XQException {
102  isClosedXQException();
103  return XQJ_MAJOR;
104  }
105 
106  /** \brief Gets the minor version number of XQJ specification supported by this implementation.
107  *
108  * @return an integer indicating the XQJ minor version
109  * @throw XQException - if the connection is no longer valid
110  */
111  @Override
112  public int getXQJMinorVersion() throws XQException {
113  isClosedXQException();
114  return XQJ_MINOR;
115  }
116 
117  /** \brief Gets the full version of XQJ specification supported by this implementation.
118  *
119  * @return a string indicating the version of XQJ specification
120  * @throw XQException - if the connection is no longer valid
121  */
122  @Override
123  public String getXQJVersion() throws XQException {
124  isClosedXQException();
125  return new String().concat(new Integer(XQJ_MAJOR).toString()).concat(".").concat(new Integer(XQJ_MINOR).toString());
126  }
127 
128  /** \brief Query if the associated conection is restricted for read only use.
129  *
130  * @return true if the associated connection is for read-only; false otherwise
131  * @throw XQException - if the connection is no longer valid
132  */
133  @Override
134  public boolean isReadOnly() throws XQException {
135  isClosedXQException();
136  return false;
137  }
138 
139  /** \brief Query if XQueryX format is supported in this data source.
140  *
141  * @return true if so; otherwise false
142  * @throw XQException - if the connection is no longer valid
143  */
144  @Override
145  public boolean isXQueryXSupported() throws XQException {
146  isClosedXQException();
147  return zorba.isXQueryXSupported();
148  }
149 
150  /** \brief Query if transaction is supported in this data source.
151  *
152  * @return true if so; otherwise false
153  * @throw XQException - if the connection is no longer valid
154  */
155  @Override
156  public boolean isTransactionSupported() throws XQException {
157  isClosedXQException();
158  return false;
159  }
160 
161  /** \brief Query if XQuery static typing feature is supported in this data source.
162  *
163  * @return true if so; otherwise false
164  * @throw XQException - if the connection is no longer valid
165  */
166  @Override
167  public boolean isStaticTypingFeatureSupported() throws XQException {
168  isClosedXQException();
169  return false;
170  }
171 
172  /** \brief Query if XQuery schema import feature is supported in this connection.
173  *
174  * @return true if so; otherwise false
175  * @throw XQException - if the connection is no longer valid
176  */
177  @Override
178  public boolean isSchemaImportFeatureSupported() throws XQException {
179  isClosedXQException();
180  return true;
181  }
182 
183  /** \brief Query if XQuery schema validation feature is supported in this connection.
184  *
185  * @return true if so; otherwise false
186  * @throw XQException - if the connection is no longer valid
187  */
188  @Override
189  public boolean isSchemaValidationFeatureSupported() throws XQException {
190  isClosedXQException();
191  return true;
192  }
193 
194  /** \brief Query if XQuery full axis feature is supported in this connection.
195  *
196  * @return true if so; otherwise false
197  * @throw XQException - if the connection is no longer valid
198  */
199  @Override
200  public boolean isFullAxisFeatureSupported() throws XQException {
201  isClosedXQException();
202  return true;
203  }
204 
205  /** \brief Query if XQuery module feature is supported in this connection.
206  *
207  * @return true if so; otherwise false
208  * @throw XQException - if the connection is no longer valid
209  */
210  @Override
211  public boolean isModuleFeatureSupported() throws XQException {
212  isClosedXQException();
213  return true;
214  }
215 
216  /** \brief Query if XQuery serialization feature is supported in this connection.
217  *
218  * @return true if so; otherwise false
219  * @throw XQException - if the connection is no longer valid
220  */
221  @Override
222  public boolean isSerializationFeatureSupported() throws XQException {
223  isClosedXQException();
224  return true;
225  }
226 
227  /** \brief Query if XQuery static typing extensions are supported in this connection.
228  *
229  * @return true if so; otherwise false
230  * @throw XQException - if the connection is no longer valid
231  */
232  @Override
233  public boolean isStaticTypingExtensionsSupported() throws XQException {
234  isClosedXQException();
235  return false;
236  }
237 
238  /** \brief Gets the user name associated with this connection.
239  *
240  * @return the user's name
241  * @throw XQException - if the connection is no longer valid
242  */
243  @Override
244  public String getUserName() throws XQException {
245  isClosedXQException();
246  return null;
247  }
248 
249  /** \brief Gets the maximum number of characters allowed in an expression in this data source.
250  *
251  * @return the maximum length of expression as an integer. A zero value means that there is no limit or the limit is unknown.
252  * @throw XQException - if the connection is no longer valid
253  */
254  @Override
255  public int getMaxExpressionLength() throws XQException {
256  isClosedXQException();
257  return 0;
258  }
259 
260  /** \brief Gets the maximum number of characters allowed in a user name.
261  *
262  * @return the maximum length of user name as an integer. A zero value means that there is no limit or the limit is unknown.
263  * @throw XQException - if the connection is no longer valid
264  */
265  @Override
266  public int getMaxUserNameLength() throws XQException {
267  isClosedXQException();
268  return 0;
269  }
270 
271  /** \brief Query if this connection was created from a JDBC connection.
272  *
273  * @return true, if this connection was created from a JDBC connection, false otherwise.
274  * @throw XQException - if the connection is no longer valid
275  */
276  @Override
277  public boolean wasCreatedFromJDBCConnection() throws XQException {
278  isClosedXQException();
279  return false;
280  }
281 
282  /** \brief Query if the XQuery encoding declaration is supported by the XQJ implementation.
283  *
284  * @return true if the XQuery encoding declaration is supported; false otherwise
285  * @throw XQException - if the connection is no longer valid
286  */
287  @Override
288  public boolean isXQueryEncodingDeclSupported() throws XQException {
289  isClosedXQException();
290  return false;
291  }
292 
293  /** \brief Returns a set of java.lang.String, each of which specifies a character encoding method the XQJ implmentation supports to parse the XQuery query text.
294  *
295  * For an example, for an XQJ impmentation which is able to parse the XQuery encoded in "UTF-8" or "UTF-16", it returns a java.util.Set of "UTF-8" and "UTF-16". If the implemetation is not able to generate a list of encodings supported, an empty set is returned. If a non-empty set is returned, the encodings returned in this set are guaranteed to be supported. Note that encodings not in the returned set might also be supported. For example, if the set has two encoding methods: 'UTF-8' and 'UTF-16', they are supported by the implementation. However, this does not mean 'Shift-Js' is not supported. It might be supported.
296  *
297  * @return a java.util.Set of java.lang.String, each of which is an XQuery query text encoding method
298  * @throw XQException - if the connection is no longer valid
299  */
300  @Override
301  public Set getSupportedXQueryEncodings() throws XQException {
302  isClosedXQException();
303  Set<String> set = new HashSet<String>();
304  set.add("UTF8");
305  return set;
306 
307  }
308 
309  /** \brief Query if a character encoding method of the XQuery query text is supported by the XQJ implmentation.
310  *
311  * @param string - String representing the character encoding method of the XQuery query text.
312  * @return true if an XQuery query character encoding method is supported, false otherwise
313  * @throw XQException - if (1) the connection is no longer valid, or (2) the specified encoding parameter is null
314  */
315  @Override
316  public boolean isXQueryEncodingSupported(String string) throws XQException {
317  isClosedXQException();
318  isNullXQException(string);
319  return string.equals("UTF8");
320  }
321 
322  /** \brief Check if the user defined XML schema type is supported in this connection.
323  *
324  * If this method returns true, then XQItemAccessor.instanceOf(XQItemType) must be able to determine if the type of an XQItemAccessor is an instance of the XQItemType even if either of them is a user defined XML schema type which is defined by the non-predefined XML schema. The pre-defined XML Schema refers to the XML schema whose schema URL is "http://www.w3.org/2001/XMLSchema"
325  *
326  * @return true if the user defined XML schema type is supported in this connection, false otherwise.
327  * @throw XQException - if the connection is no longer valid
328  */
329  @Override
330  public boolean isUserDefinedXMLSchemaTypeSupported() throws XQException {
331  isClosedXQException();
332  return true;
333  }
334 
335  private void isClosedXQException() throws XQException {
336  if (connection.isClosed()) {
337  throw new XQException("This connection is closed");
338  }
339  }
340  private void isNullXQException(Object value) throws XQException {
341  if (value==null) {
342  throw new XQException("Parameter shouldn't be null");
343  }
344  }
345 
346 }
blog comments powered by Disqus