• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java QueryParseException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.jena.query.QueryParseException的典型用法代码示例。如果您正苦于以下问题:Java QueryParseException类的具体用法?Java QueryParseException怎么用?Java QueryParseException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



QueryParseException类属于org.apache.jena.query包,在下文中一共展示了QueryParseException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: toResponse

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
@Override
   public Response toResponse(QueryParseException ex)
   {
       return com.atomgraph.core.model.impl.Response.fromRequest(getRequest()).
               getResponseBuilder(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR,
                       ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")).
                   getModel(), getVariants()).
               status(Response.Status.INTERNAL_SERVER_ERROR).
               build();

       /*
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
               entity(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR,
                       ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")).
                   getModel()).
	build();
       */
   }
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:19,代码来源:QueryParseExceptionMapper.java


示例2: toResponse

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
@Override
public Response toResponse(final QueryParseException e) {

    LOGGER.error("Captured a query parse exception {}", e.getMessage());
    debugException(this, e, LOGGER);
    if (e.getMessage().matches(".* Unresolved prefixed name: .*")) {
        final Pattern namespacePattern =
            Pattern.compile("Unresolved prefixed name: (\\w+:\\w+)");
        final Matcher namespaceMatch =
            namespacePattern.matcher(e.getMessage());
        if (namespaceMatch.find()) {
            final String msg =
                String.format(
                    "There are one or more undefined namespace(s) in your request [ %s ], " +
                    "please define them before retrying",
                    namespaceMatch.group(1));
            return status(BAD_REQUEST).entity(msg).type(TEXT_PLAIN_WITH_CHARSET).build();
        }
    }

    return status(BAD_REQUEST).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build();
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:23,代码来源:QueryParseExceptionMapper.java


示例3: create

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
/**
 * A factory that creates a {@link RootPlan} from a SPARQL-Generate query.
 *
 * @param queryStr the string representation of the SPARQL-Generate query.
 * @return the RootPlan that may be used to execute the SPARQL-Generate
 * query.
 */
public static final RootPlan create(final String queryStr) {
    Objects.requireNonNull(queryStr, "Parameter string must not be null");
    SPARQLGenerateQuery query;
    try {
        query = (SPARQLGenerateQuery) QueryFactory.create(queryStr,
                SPARQLGenerate.SYNTAX);
    } catch (QueryParseException ex) {
        throw new SPARQLGenerateException(
                "Error while parsing the query \n" + queryStr, ex);
    }
    LOG.trace("Creating plan for query: \n" + query);
    return create(query);
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:21,代码来源:PlanFactory.java


示例4: AbstractSPARQLExecutor

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
protected AbstractSPARQLExecutor(Constraint constraint) {
	this.queryString = getSPARQL(constraint);
	try {
		this.query = ARQFactory.get().createQuery(queryString);
	}
	catch(QueryParseException ex) {
		throw new SHACLException("Invalid SPARQL constraint (" + ex.getLocalizedMessage() + "):\n" + queryString);
	}

	if(!query.isSelectType()) {
		throw new IllegalArgumentException("SHACL constraints must be SELECT queries");
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:14,代码来源:AbstractSPARQLExecutor.java


示例5: getJenaPath

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
/**
 * Attempts to parse a given string into a Jena Path.
 * Throws an Exception if the string cannot be parsed.
 * @param string  the string to parse
 * @param model  the Model to operate on (for prefixes)
 * @return a Path or a Resource if this is a URI
 */
public static Object getJenaPath(String string, Model model) throws QueryParseException {
	Query query = ARQFactory.get().createQuery(model, "ASK { ?a \n" + string + "\n ?b }");
	Element element = query.getQueryPattern();
	if(element instanceof ElementGroup) {
		Element e = ((ElementGroup)element).getElements().get(0);
		if(e instanceof ElementPathBlock) {
			return ((ElementPathBlock) e).getPattern().get(0).getPath();
		}
		else if(e instanceof ElementTriplesBlock) {
			return model.asRDFNode(((ElementTriplesBlock) e).getPattern().get(0).getPredicate());
		}
	}
	throw new QueryParseException("Not a SPARQL 1.1 Path expression", 2, 1);
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:22,代码来源:SHACLPaths.java


示例6: testInvalidNamespace

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
@Test
public void testInvalidNamespace() {
    final QueryParseException input = new QueryParseException(
        "Unresolved prefixed name: invalidNS:title", 14, 10);
    final Response actual = testObj.toResponse(input);
    assertEquals(BAD_REQUEST.getStatusCode(), actual.getStatus());
    assertEquals(actual.getEntity(), input.getMessage());
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:9,代码来源:QueryParseExceptionMapperTest.java


示例7: testToResponse

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
@Test
public void testToResponse() {
    final QueryParseException input = new QueryParseException("An error occurred", 14, 10);
    final Response actual = testObj.toResponse(input);
    assertEquals(BAD_REQUEST.getStatusCode(), actual.getStatus());
    assertNotNull(actual.getEntity());
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:8,代码来源:QueryParseExceptionMapperTest.java


示例8: getSparqlQuery

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
@Override
public Query getSparqlQuery(TestCase testCase) {
    String query = this.getSparqlQueryAsString(testCase);
    try {
        return QueryFactory.create(query);
    } catch (QueryParseException e) {
        throw new IllegalArgumentException("Illegal query: \n" + query, e);
    }
}
 
开发者ID:AKSW,项目名称:RDFUnit,代码行数:10,代码来源:QueryGenerationSelectFactory.java


示例9: validateSPARQL

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
private void validateSPARQL(String sparql, String type)  {
    try {
        QueryFactory.create(sparql);
    } catch (QueryParseException e) {
        String message = "QueryParseException in " + type + " query (line " + e.getLine() + ", column " + e.getColumn() + " for Test: " + testCase.getTestURI() + "\n" + PrefixNSService.getSparqlPrefixDecl() + sparql;
        //throw new TestCaseInstantiationException(message, e);
        log.warn(message,e);
    }
}
 
开发者ID:AKSW,项目名称:RDFUnit,代码行数:10,代码来源:TestCaseValidator.java


示例10: parseDo

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
private void parseDo(SPARQLParser11 parser) throws ParseException {
	do {
		int beginLine = parser.getToken(1).beginLine;
		int beginColumn = parser.getToken(1).beginColumn;

		Query query = new Query(result.getPrologue());

		// You'd assume that a query initialized via "new Query(prologue)"
		// has the IRI resolver from prologue.getResolver(), but that doesn't
		// appear to be the case in Jena 2.12.0, so we set it manually
		query.getPrologue().setResolver(result.getPrologue().getResolver());

		result.addQuery(query);
		parser.setQuery(query);
		parser.Query();

		if (query.isSelectType() || query.isAskType()) {
			seenSelectOrAsk = true;
		}
		if (seenSelectOrAsk && result.getQueries().size() > 1) {
			throw new QueryParseException("" +
					"Multiple queries per file are only supported for CONSTRUCT", 
					beginLine, beginColumn);
		}
		
		// From Parser.validateParsedQuery, which we can't call directly
		SyntaxVarScope.check(query);
		
		result.getPrologue().usePrologueFrom(query);
		if (log.isDebugEnabled()) {
			log.debug(query.toString());
		}
	} while (parser.getToken(1).kind != SPARQLParser11.EOF);
	removeTarqlPrefix();
}
 
开发者ID:tarql,项目名称:tarql,代码行数:36,代码来源:TarqlParser.java


示例11: testMultipleSELECT

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
@Test
public void testMultipleSELECT() throws Exception {
	try {
		String s = "SELECT * {} SELECT * {}";
		TarqlParser x = new TarqlParser(new StringReader(s));
		x.getResult().getQueries();
		fail("Expected exception due to multiple queries");
	} catch (QueryParseException ex) {
		// Expected
	}
}
 
开发者ID:tarql,项目名称:tarql,代码行数:12,代码来源:TarqlParserTest.java


示例12: testSELECTAndCONSTRUCT

import org.apache.jena.query.QueryParseException; //导入依赖的package包/类
@Test
public void testSELECTAndCONSTRUCT() throws Exception {
	try {
		String s = "CONSTRUCT { [] a [] } WHERE {} SELECT * {}";
		TarqlParser x = new TarqlParser(new StringReader(s));
		x.getResult().getQueries();
		fail("Expected exception due to multiple queries");
	} catch (QueryParseException ex) {
		// Expected
	}
}
 
开发者ID:tarql,项目名称:tarql,代码行数:12,代码来源:TarqlParserTest.java



注:本文中的org.apache.jena.query.QueryParseException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JsonJavaFactory类代码示例发布时间:2022-05-23
下一篇:
Java JAXBContextFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap