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) return null;
21 if (LOGGER.isDebugEnabled()) LOGGER.debug("Processing query: {}", queryString);
22 // FiqlParser is a parser generated by javacc
23 Expression expression = FiqlParser.parse(queryString);
24 if (LOGGER.isDebugEnabled()) LOGGER.debug("Query expression: {}", expression);
25 // create Query and return;
26 return new QueryImpl<T>(type, expression);
27 } catch (Exception ex) {
28 if (LOGGER.isDebugEnabled()) LOGGER.error("Query processing failed = {}",
30 throw new QueryException("Unable to parse query.", ex);