org.apache.chemistry.opencmis.jcr.query
Class QueryTranslator

java.lang.Object
  extended by org.apache.chemistry.opencmis.jcr.query.QueryTranslator

public abstract class QueryTranslator
extends java.lang.Object

Abstract base class for translating a CMIS query statement to a JCR XPath query statement. Overriding class need to implement methods for mapping CMIS ids to JCR paths, CMIS property names to JCR property names, CMIS type names to JCR type name and in addition a method for adding further constraints to a query based on a CMIS type.


Constructor Summary
QueryTranslator(JcrTypeManager typeManager)
          Create a new query translator which uses the provided typeManager to resolve CMIS type names to CMIS types.
 
Method Summary
protected  java.lang.String buildElementTest(TypeDefinition fromType)
          Build a XPath element test for the given CMIS type.
protected  java.lang.String buildOrderByClause(TypeDefinition fromType, java.util.List<QueryObject.SortSpec> orderBys)
          Build a XPath order by clause for the given CMIS type and a list of QueryObject.SortSpecs.
protected  java.lang.String buildPathExpression(TypeDefinition fromType, java.lang.String folderPredicate)
          Build a XPath path expression for the CMIS type queried for and a folder predicate.
protected  java.lang.String buildPredicates(TypeDefinition fromType, java.lang.String condition)
          Build a XPath predicate for the given CMIS type and an additional condition.
 QueryObject getQueryObject()
           
protected abstract  java.lang.String jcrPathFromCol(TypeDefinition fromType, java.lang.String name)
          Map a column name in the CMIS query to the corresponding relative JCR path.
protected abstract  java.lang.String jcrPathFromId(java.lang.String id)
          Map a CMIS objectId to an absolute JCR path.
protected abstract  java.lang.String jcrTypeCondition(TypeDefinition fromType)
          Create and additional condition in order for the query to only return nodes of the right type.
protected abstract  java.lang.String jcrTypeName(TypeDefinition fromType)
          Map a CMIS type to the corresponding JCR type name.
 java.lang.String translateToXPath(java.lang.String statement)
          Translate a CMIS query statement to a JCR XPath query statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryTranslator

public QueryTranslator(JcrTypeManager typeManager)
Create a new query translator which uses the provided typeManager to resolve CMIS type names to CMIS types.

Parameters:
typeManager -
Method Detail

getQueryObject

public QueryObject getQueryObject()
Returns:
the QueryObject from the last translation performed through translateToXPath(String).

translateToXPath

public java.lang.String translateToXPath(java.lang.String statement)
Translate a CMIS query statement to a JCR XPath query statement.

Parameters:
statement -
Returns:

jcrPathFromId

protected abstract java.lang.String jcrPathFromId(java.lang.String id)
Map a CMIS objectId to an absolute JCR path. This method is called to resolve the folder if of folder predicates (i.e. IN_FOLDER, IN_TREE).

Parameters:
id - objectId
Returns:
absolute JCR path corresponding to id.

jcrPathFromCol

protected abstract java.lang.String jcrPathFromCol(TypeDefinition fromType,
                                                   java.lang.String name)
Map a column name in the CMIS query to the corresponding relative JCR path. The path must be relative to the context node.

Parameters:
fromType - Type on which the CMIS query is performed
name - column name
Returns:
relative JCR path

jcrTypeName

protected abstract java.lang.String jcrTypeName(TypeDefinition fromType)
Map a CMIS type to the corresponding JCR type name.

Parameters:
fromType - CMIS type
Returns:
name of the JCR type corresponding to fromType
See Also:
jcrTypeCondition(TypeDefinition)

jcrTypeCondition

protected abstract java.lang.String jcrTypeCondition(TypeDefinition fromType)
Create and additional condition in order for the query to only return nodes of the right type. This condition and-ed to the condition determined by the CMIS query's where clause.

A CMIS query for non versionable documents should for example result in the following XPath query:

   element(*, nt:file)[not(@jcr:mixinTypes = 'mix:simpleVersionable')]
 
Here the element test is covered by jcrTypeName(TypeDefinition) while the predicate is covered by this method.

Parameters:
fromType -
Returns:
Additional condition or null if none.
See Also:
jcrTypeName(TypeDefinition)

buildPathExpression

protected java.lang.String buildPathExpression(TypeDefinition fromType,
                                               java.lang.String folderPredicate)
Build a XPath path expression for the CMIS type queried for and a folder predicate.

Parameters:
fromType - CMIS type queried for
folderPredicate - folder predicate
Returns:
a valid XPath path expression or null if none.

buildElementTest

protected java.lang.String buildElementTest(TypeDefinition fromType)
Build a XPath element test for the given CMIS type.

Parameters:
fromType - CMIS type queried for
Returns:
a valid XPath element test.

buildPredicates

protected java.lang.String buildPredicates(TypeDefinition fromType,
                                           java.lang.String condition)
Build a XPath predicate for the given CMIS type and an additional condition. The additional condition should be and-ed to the condition resulting from evaluating fromType.

Parameters:
fromType - CMIS type queried for
condition - additional condition.
Returns:
a valid XPath predicate or null if none.

buildOrderByClause

protected java.lang.String buildOrderByClause(TypeDefinition fromType,
                                              java.util.List<QueryObject.SortSpec> orderBys)
Build a XPath order by clause for the given CMIS type and a list of QueryObject.SortSpecs.

Parameters:
fromType - CMIS type queried for
orderBys - SortSpecs
Returns:
a valid XPath order by clause


Copyright © 2009-2011 The Apache Software Foundation. All Rights Reserved.