2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.northbound.commons.query;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
13 /*package*/ class QueryContextImpl implements QueryContext {
15 private static final Logger LOGGER = LoggerFactory.getLogger(QueryContext.class);
18 public <T> Query<T> createQuery(String queryString, Class<T> type) throws QueryException {
19 if (queryString == null || queryString.trim().length() == 0) {
23 if (LOGGER.isDebugEnabled()) {
24 LOGGER.debug("Processing query: {}", queryString);
26 // FiqlParser is a parser generated by javacc
27 Expression expression = FiqlParser.parse(queryString);
28 if (LOGGER.isDebugEnabled()) {
29 LOGGER.debug("Query expression: {}", expression);
31 // create Query and return;
32 return new QueryImpl<T>(type, expression);
33 } catch (Exception ex) {
34 if (LOGGER.isDebugEnabled()) {
35 LOGGER.error("Query processing failed = {}",
38 throw new QueryException("Unable to parse query.", ex);