Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 45334 invoked from network); 29 Jul 2010 17:15:32 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 29 Jul 2010 17:15:32 -0000 Received: (qmail 28981 invoked by uid 500); 29 Jul 2010 17:15:32 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 28951 invoked by uid 500); 29 Jul 2010 17:15:32 -0000 Mailing-List: contact chemistry-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: chemistry-dev@incubator.apache.org Delivered-To: mailing list chemistry-commits@incubator.apache.org Received: (qmail 28874 invoked by uid 99); 29 Jul 2010 17:15:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Jul 2010 17:15:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Jul 2010 17:15:16 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D5AC12388B45; Thu, 29 Jul 2010 17:13:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r980513 [13/15] - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-server: chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/dummy/ chemistry-opencmis-server-bindings/src/main/java/org/apach... Date: Thu, 29 Jul 2010 17:13:30 -0000 To: chemistry-commits@incubator.apache.org From: fguillaume@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100729171331.D5AC12388B45@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseGrammar.g URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseGrammar.g?rev=980513&r1=980512&r2=980513&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseGrammar.g (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseGrammar.g Thu Jul 29 17:13:28 2010 @@ -1,253 +1,253 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * Authors: - * Stefane Fermigier, Nuxeo - * Florent Guillaume, Nuxeo - */ - -parser grammar CmisBaseGrammar; - -// Note: The following tokenVocab option generates a warning: -// warning(160): CMISBaseGrammar.g:27:5: tokenVocab option ignored in imported gram -// mar CMISBaseGrammar -// If you omit this it results in compilation errors, may be a maven issue (not sure -// of outside of maven this needs file needs to be compilable -// options must have AST options otherwise - -options { - tokenVocab = CmisQlStrictLexer; - output = AST; -} - -@rulecatch { - catch (RecognitionException e) { - throw e; - } -} - -query: - SELECT select_list from_clause where_clause? order_by_clause? - -> ^(SELECT select_list from_clause order_by_clause? where_clause?) - ; - -select_list - : STAR - | select_sublist ( COMMA select_sublist )* - -> ^(SEL_LIST select_sublist+) - ; - -select_sublist - : value_expression ( AS!? column_name )? - | qualifier DOT STAR - //| multi_valued_column_reference - ; - -value_expression: - column_reference - | numeric_value_function - ; - -column_reference: - ( qualifier DOT )? column_name - -> ^(COL qualifier? column_name) - ; - -multi_valued_column_reference: - ( qualifier DOT )? multi_valued_column_name - -> ^(COL qualifier? multi_valued_column_name) - ; - -numeric_value_function: - SCORE LPAR RPAR -> ^(SCORE); - -qualifier: - table_name - //| correlation_name - ; - -from_clause: FROM^ table_reference; - -table_reference: - one_table table_join* - ; - -table_join: - join_kind one_table join_specification? - -> ^(JOIN join_kind one_table join_specification?) - ; - -one_table: - LPAR! table_reference RPAR! - | table_name - -> ^(TABLE table_name) - | table_name AS? correlation_name - -> ^(TABLE table_name correlation_name) - ; - -join_kind: - JOIN - -> INNER - | INNER JOIN - -> INNER - | LEFT OUTER? JOIN - -> LEFT - | RIGHT OUTER? JOIN - -> RIGHT - ; - -join_specification: - ON^ column_reference EQ column_reference - ; - -/////////////////////////////////////////////////////////// -// Begin Where - -where_clause: WHERE^ search_condition; - -search_condition: - boolean_term (OR^ boolean_term)*; - -boolean_term: - boolean_factor (AND^ boolean_factor)*; - -boolean_factor: - NOT^ boolean_test - | boolean_test - ; - -boolean_test: - predicate - | LPAR search_condition RPAR -> search_condition - ; - -predicate: - comparison_predicate - | in_predicate - | like_predicate - | null_predicate - | quantified_comparison_predicate - | quantified_in_predicate - | text_search_predicate - | folder_predicate - ; - -comparison_predicate: - value_expression EQ literal - -> ^(EQ value_expression literal) - | value_expression NEQ literal - -> ^(NEQ value_expression literal) - | value_expression LT literal - -> ^(LT value_expression literal) - | value_expression GT literal - -> ^(GT value_expression literal) - | value_expression LTEQ literal - -> ^(LTEQ value_expression literal) - | value_expression GTEQ literal - -> ^(GTEQ value_expression literal) - ; - -literal: - NUM_LIT - | STRING_LIT - | TIME_LIT - | BOOL_LIT - ; - -in_predicate: - column_reference IN LPAR in_value_list RPAR - -> ^(IN column_reference in_value_list) - | column_reference NOT IN LPAR in_value_list RPAR - -> ^(NOT_IN column_reference in_value_list) - ; - -in_value_list: - literal ( COMMA literal )* - -> ^(IN_LIST literal+) - ; - -like_predicate: - column_reference LIKE STRING_LIT - -> ^(LIKE column_reference STRING_LIT) - | column_reference NOT LIKE STRING_LIT - -> ^(NOT_LIKE column_reference STRING_LIT) - ; - -null_predicate: - // second alternative commented out to remove left recursion for now. - //( column_reference | multi_valued_column_reference ) 'IS' 'NOT'? 'NULL'; - column_reference IS - ( NOT NULL -> ^(IS_NOT_NULL column_reference) - | NULL -> ^(IS_NULL column_reference) - ) - ; - -quantified_comparison_predicate: - literal EQ ANY multi_valued_column_reference - -> ^(EQ_ANY literal multi_valued_column_reference) - ; - -quantified_in_predicate: - ANY multi_valued_column_reference - ( NOT IN LPAR in_value_list RPAR - -> ^(NOT_IN_ANY multi_valued_column_reference in_value_list ) - | IN LPAR in_value_list RPAR - -> ^(IN_ANY multi_valued_column_reference in_value_list ) - ) - ; - -text_search_predicate: - CONTAINS LPAR (qualifier COMMA)? text_search_expression RPAR - -> ^(CONTAINS qualifier? text_search_expression) - ; - -// end where -///////////////////////////////////////////////////////////////// - -folder_predicate: - ( f=IN_FOLDER | f=IN_TREE ) LPAR (qualifier COMMA)? folder_id RPAR - -> ^($f qualifier? folder_id) - ; - -order_by_clause: - ORDER BY sort_specification ( COMMA sort_specification )* - -> ^(ORDER_BY sort_specification+) - ; - -sort_specification: - column_reference -> column_reference ASC - | column_reference ( ASC | DESC ) - ; - -correlation_name: - ID; - -table_name: - ID; - -column_name: - ID; - -multi_valued_column_name: - ID; - -folder_id: - STRING_LIT; - -text_search_expression: - STRING_LIT; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + * Authors: + * Stefane Fermigier, Nuxeo + * Florent Guillaume, Nuxeo + */ + +parser grammar CmisBaseGrammar; + +// Note: The following tokenVocab option generates a warning: +// warning(160): CMISBaseGrammar.g:27:5: tokenVocab option ignored in imported gram +// mar CMISBaseGrammar +// If you omit this it results in compilation errors, may be a maven issue (not sure +// of outside of maven this needs file needs to be compilable +// options must have AST options otherwise + +options { + tokenVocab = CmisQlStrictLexer; + output = AST; +} + +@rulecatch { + catch (RecognitionException e) { + throw e; + } +} + +query: + SELECT select_list from_clause where_clause? order_by_clause? + -> ^(SELECT select_list from_clause order_by_clause? where_clause?) + ; + +select_list + : STAR + | select_sublist ( COMMA select_sublist )* + -> ^(SEL_LIST select_sublist+) + ; + +select_sublist + : value_expression ( AS!? column_name )? + | qualifier DOT STAR + //| multi_valued_column_reference + ; + +value_expression: + column_reference + | numeric_value_function + ; + +column_reference: + ( qualifier DOT )? column_name + -> ^(COL qualifier? column_name) + ; + +multi_valued_column_reference: + ( qualifier DOT )? multi_valued_column_name + -> ^(COL qualifier? multi_valued_column_name) + ; + +numeric_value_function: + SCORE LPAR RPAR -> ^(SCORE); + +qualifier: + table_name + //| correlation_name + ; + +from_clause: FROM^ table_reference; + +table_reference: + one_table table_join* + ; + +table_join: + join_kind one_table join_specification? + -> ^(JOIN join_kind one_table join_specification?) + ; + +one_table: + LPAR! table_reference RPAR! + | table_name + -> ^(TABLE table_name) + | table_name AS? correlation_name + -> ^(TABLE table_name correlation_name) + ; + +join_kind: + JOIN + -> INNER + | INNER JOIN + -> INNER + | LEFT OUTER? JOIN + -> LEFT + | RIGHT OUTER? JOIN + -> RIGHT + ; + +join_specification: + ON^ column_reference EQ column_reference + ; + +/////////////////////////////////////////////////////////// +// Begin Where + +where_clause: WHERE^ search_condition; + +search_condition: + boolean_term (OR^ boolean_term)*; + +boolean_term: + boolean_factor (AND^ boolean_factor)*; + +boolean_factor: + NOT^ boolean_test + | boolean_test + ; + +boolean_test: + predicate + | LPAR search_condition RPAR -> search_condition + ; + +predicate: + comparison_predicate + | in_predicate + | like_predicate + | null_predicate + | quantified_comparison_predicate + | quantified_in_predicate + | text_search_predicate + | folder_predicate + ; + +comparison_predicate: + value_expression EQ literal + -> ^(EQ value_expression literal) + | value_expression NEQ literal + -> ^(NEQ value_expression literal) + | value_expression LT literal + -> ^(LT value_expression literal) + | value_expression GT literal + -> ^(GT value_expression literal) + | value_expression LTEQ literal + -> ^(LTEQ value_expression literal) + | value_expression GTEQ literal + -> ^(GTEQ value_expression literal) + ; + +literal: + NUM_LIT + | STRING_LIT + | TIME_LIT + | BOOL_LIT + ; + +in_predicate: + column_reference IN LPAR in_value_list RPAR + -> ^(IN column_reference in_value_list) + | column_reference NOT IN LPAR in_value_list RPAR + -> ^(NOT_IN column_reference in_value_list) + ; + +in_value_list: + literal ( COMMA literal )* + -> ^(IN_LIST literal+) + ; + +like_predicate: + column_reference LIKE STRING_LIT + -> ^(LIKE column_reference STRING_LIT) + | column_reference NOT LIKE STRING_LIT + -> ^(NOT_LIKE column_reference STRING_LIT) + ; + +null_predicate: + // second alternative commented out to remove left recursion for now. + //( column_reference | multi_valued_column_reference ) 'IS' 'NOT'? 'NULL'; + column_reference IS + ( NOT NULL -> ^(IS_NOT_NULL column_reference) + | NULL -> ^(IS_NULL column_reference) + ) + ; + +quantified_comparison_predicate: + literal EQ ANY multi_valued_column_reference + -> ^(EQ_ANY literal multi_valued_column_reference) + ; + +quantified_in_predicate: + ANY multi_valued_column_reference + ( NOT IN LPAR in_value_list RPAR + -> ^(NOT_IN_ANY multi_valued_column_reference in_value_list ) + | IN LPAR in_value_list RPAR + -> ^(IN_ANY multi_valued_column_reference in_value_list ) + ) + ; + +text_search_predicate: + CONTAINS LPAR (qualifier COMMA)? text_search_expression RPAR + -> ^(CONTAINS qualifier? text_search_expression) + ; + +// end where +///////////////////////////////////////////////////////////////// + +folder_predicate: + ( f=IN_FOLDER | f=IN_TREE ) LPAR (qualifier COMMA)? folder_id RPAR + -> ^($f qualifier? folder_id) + ; + +order_by_clause: + ORDER BY sort_specification ( COMMA sort_specification )* + -> ^(ORDER_BY sort_specification+) + ; + +sort_specification: + column_reference -> column_reference ASC + | column_reference ( ASC | DESC ) + ; + +correlation_name: + ID; + +table_name: + ID; + +column_name: + ID; + +multi_valued_column_name: + ID; + +folder_id: + STRING_LIT; + +text_search_expression: + STRING_LIT; Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseGrammar.g ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlExtParser.g ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlStrictLexer.g ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlStrictParser.g ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CmisServiceWrapper.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeManager.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeManager.java?rev=980513&r1=980512&r2=980513&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeManager.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeManager.java Thu Jul 29 17:13:28 2010 @@ -1,74 +1,74 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.chemistry.opencmis.server.support; - -import java.util.Collection; -import java.util.List; - -import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition; -import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer; - -public interface TypeManager { - - /** - * return a type definition from the type definition id - * - * @param typeId - * id of the type definition - * @return type definition for this id - */ - public abstract TypeDefinitionContainer getTypeById(String typeId); - - /** - * return a type definition from the type query name or null if not found - * - * @param typeQueryName - * query name of the type definition - * @return type definition for this query name - */ - public abstract TypeDefinition getTypeByQueryName(String typeQueryName); - - /** - * return a list of all types known in this repository - * - * @return - */ - public abstract Collection getTypeDefinitionList(); - - /** - * return a list of the root types as defined in the CMIS spec (for - * document, folder, policy and relationship - * - * @return - */ - public abstract List getRootTypes(); - - /** - * retrieve the property id from a type for a given property query name - * - * @param typeDefinition - * type definition containing query name - * @param propQueryName - * query name of property - * @return - * property id of property or null if not found - */ - public abstract String getPropertyIdForQueryName(TypeDefinition typeDefinition, String propQueryName); - +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.chemistry.opencmis.server.support; + +import java.util.Collection; +import java.util.List; + +import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition; +import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer; + +public interface TypeManager { + + /** + * return a type definition from the type definition id + * + * @param typeId + * id of the type definition + * @return type definition for this id + */ + public abstract TypeDefinitionContainer getTypeById(String typeId); + + /** + * return a type definition from the type query name or null if not found + * + * @param typeQueryName + * query name of the type definition + * @return type definition for this query name + */ + public abstract TypeDefinition getTypeByQueryName(String typeQueryName); + + /** + * return a list of all types known in this repository + * + * @return + */ + public abstract Collection getTypeDefinitionList(); + + /** + * return a list of the root types as defined in the CMIS spec (for + * document, folder, policy and relationship + * + * @return + */ + public abstract List getRootTypes(); + + /** + * retrieve the property id from a type for a given property query name + * + * @param typeDefinition + * type definition containing query name + * @param propQueryName + * query name of property + * @return + * property id of property or null if not found + */ + public abstract String getPropertyIdForQueryName(TypeDefinition typeDefinition, String propQueryName); + } \ No newline at end of file Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeManager.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java?rev=980513&r1=980512&r2=980513&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java Thu Jul 29 17:13:28 2010 @@ -1,424 +1,424 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.chemistry.opencmis.server.support; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.chemistry.opencmis.commons.PropertyIds; -import org.apache.chemistry.opencmis.commons.data.Properties; -import org.apache.chemistry.opencmis.commons.data.PropertyData; -import org.apache.chemistry.opencmis.commons.data.PropertyDecimal; -import org.apache.chemistry.opencmis.commons.data.PropertyInteger; -import org.apache.chemistry.opencmis.commons.definitions.Choice; -import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition; -import org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition; -import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition; -import org.apache.chemistry.opencmis.commons.definitions.PropertyIntegerDefinition; -import org.apache.chemistry.opencmis.commons.definitions.PropertyStringDefinition; -import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition; -import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; -import org.apache.chemistry.opencmis.commons.enums.Cardinality; -import org.apache.chemistry.opencmis.commons.enums.VersioningState; -import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; - -/** - * @author Jens - */ -public class TypeValidator { - - public static void validateRequiredSystemProperties(Properties properties) { - if (properties == null || properties.getProperties() == null) - throw new RuntimeException("Cannot create object, no properties are given"); - - if (!properties.getProperties().containsKey(PropertyIds.OBJECT_TYPE_ID)) - throw new RuntimeException("Cannot create object, type id is missing"); - - } - - private static boolean isMandatorySystemProperty(String propertyId) { - // TODO Auto-generated method stub - return propertyId.equals(PropertyIds.OBJECT_TYPE_ID); - } - - @SuppressWarnings("unchecked") - static PropertyValidator createPropertyValidator(PropertyDefinition propDef) { - PropertyValidator result = null; - if (propDef instanceof PropertyIntegerDefinition) { - result = (PropertyValidator) new PropertyValidatorInteger(); - } else if (propDef instanceof PropertyDecimalDefinition) { - result = (PropertyValidator) new PropertyValidatorDecimal(); - } else if (propDef instanceof PropertyStringDefinition) { - result = (PropertyValidator) new PropertyValidatorString(); - } else { - result = new PropertyValidator(); - } - return result; - } - - /* - * property validations: not readonly, all required are given, all are known - * in type cardinality: no multi values for single value, def min max check - * for Integer and Decimal, choices and in list Strings, max length set - * default value for omitted properties - */ - static class PropertyValidator { - - public void validate(PropertyDefinition propDef, PropertyData prop) { - - // check general constraints for all property types - if (propDef.getCardinality() == Cardinality.SINGLE && prop.getValues().size() > 1) - throw new CmisConstraintException("The property with id " + propDef.getId() - + " is single valued, but multiple values are passed " + prop.getValues()); - - if (propDef.getChoices() != null && propDef.getChoices().size() > 0) { - validateChoices(propDef, prop); - } - } - - private void validateChoices(PropertyDefinition propDef, PropertyData prop) { - boolean isAllowedValue = true; - boolean hasMultiValueChoiceLists = false; - for (Choice allowedValue : propDef.getChoices()) { - if (allowedValue.getValue() != null && allowedValue.getValue().size() > 1) - hasMultiValueChoiceLists = true; - } - - // check if value is in list - if (hasMultiValueChoiceLists) { - // do a complex check if this combination of actual values is - // allowed - // check if value is in list - isAllowedValue = false; - List actualValues = prop.getValues(); - for (Choice allowedValue : propDef.getChoices()) { - if (allowedValue.getValue().size() == actualValues.size()) { - boolean listValuesAreEqual = true; - Iterator it = allowedValue.getValue().iterator(); - for (Object actualValue : actualValues) { - if (!actualValue.equals(it.next())) { - listValuesAreEqual = false; - break; - } - } - if (listValuesAreEqual) { - isAllowedValue = true; - } - } - - if (isAllowedValue) - break; - } - - } else { - List allowedValues = getAllowedValues(propDef.getChoices()); - // do a simpler check if all values are choice elements - - for (Object actualValue : prop.getValues()) { - if (!allowedValues.contains(actualValue)) { - isAllowedValue = false; - break; - } - } - } - - if (!isAllowedValue) - throw new CmisConstraintException("The property with id " + propDef.getId() - + " has a fixed set of values. Value(s) " + prop.getValues() + " are not listed."); - } - - /** - * Calculate the list of allowed values for this property definition by - * recursively collecting all choice values from property definition - * - * @param propDef - * property definition - * @return list of possible values in complete hierarchy - */ - private List getAllowedValues(List> choices) { - List allowedValues = new ArrayList(choices.size()); - for (Choice choice : choices) { - if (choice.getValue() != null) - allowedValues.add(choice.getValue().get(0)); - if (choice.getChoice() != null) { - List> x = choice.getChoice(); - allowedValues.addAll(getAllowedValues(x)); - } - } - return allowedValues; - } - } - - static class PropertyValidatorInteger extends PropertyValidator { - - public void validate(PropertyDefinition propDef, PropertyData property) { - - super.validate(propDef, property); - - BigInteger propVal = ((PropertyInteger) property).getFirstValue(); - BigInteger minVal = ((PropertyIntegerDefinition) propDef).getMinValue(); - BigInteger maxVal = ((PropertyIntegerDefinition) propDef).getMaxValue(); - - // check min and max - if (minVal != null && propVal != null && propVal.compareTo(minVal) == -1) { - throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal - + " is less than the minimum value " + minVal); - } - if (maxVal != null && propVal != null && propVal.compareTo(maxVal) == 1) { - throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal - + " is bigger than the maximum value " + maxVal); - } - } - } - - static class PropertyValidatorDecimal extends PropertyValidator { - - public void validate(PropertyDefinition propDef, PropertyData property) { - - super.validate(propDef, property); - - BigDecimal propVal = ((PropertyDecimal) property).getFirstValue(); - BigDecimal minVal = ((PropertyDecimalDefinition) propDef).getMinValue(); - BigDecimal maxVal = ((PropertyDecimalDefinition) propDef).getMaxValue(); - - // check min and max - if (minVal != null && propVal != null && propVal.compareTo(minVal) == -1) { - throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal - + " is less than the minimum value " + minVal); - } - if (maxVal != null && propVal != null && propVal.compareTo(maxVal) == 1) { - throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal - + " is bigger than the maximum value " + maxVal); - } - } - } - - static class PropertyValidatorString extends PropertyValidator { - - public void validate(PropertyDefinition propDef, PropertyData property) { - - super.validate(propDef, property); - - long maxLen = ((PropertyStringDefinition) propDef).getMaxLength() == null ? -1 - : ((PropertyStringDefinition) propDef).getMaxLength().longValue(); - long len = ((PropertyData) property).getFirstValue() == null ? -1 - : ((PropertyData) property).getFirstValue().length(); - - // check max length - if (maxLen >= 0 && len >= 0 && maxLen < len) { - throw new CmisConstraintException("For property with id " + propDef.getId() + " the length of " + len - + "is bigger than the maximum allowed length " + maxLen); - } - } - } - - @SuppressWarnings("unchecked") - public static void validateProperties(TypeDefinition typeDef, Properties properties, boolean checkMandatory) { - - List propDefsRequired = getMandatoryPropDefs(typeDef.getPropertyDefinitions()); - - for (PropertyData prop : properties.getProperties().values()) { - String propertyId = prop.getId(); - BaseTypeId baseTypeId = typeDef.getBaseTypeId(); - - if (isSystemProperty(baseTypeId, propertyId)) - continue; // ignore system properties for validation - - // Check if all properties are known in the type - if (!typeContainsProperty(typeDef, propertyId)) { - throw new CmisConstraintException("Unknown property " + propertyId + " in type " + typeDef.getId()); - } - - // check that all mandatory attributes are present - if (checkMandatory && propDefsRequired.contains(propertyId)) - propDefsRequired.remove(propertyId); - - // check all type specific constraints: - PropertyDefinition propDef = getPropertyDefinition(typeDef, propertyId); - PropertyValidator validator = createPropertyValidator(propDef); - validator.validate(propDef, (PropertyData) prop); - } - - if (checkMandatory && !propDefsRequired.isEmpty()) - throw new CmisConstraintException("The following mandatory properties are missing: " + propDefsRequired); - } - - public static void validateVersionStateForCreate(DocumentTypeDefinition typeDef, VersioningState verState) { - if (null == verState) - return; - if (typeDef.isVersionable() && verState.equals(VersioningState.NONE) || !typeDef.isVersionable() - && !verState.equals(VersioningState.NONE)) { - throw new CmisConstraintException("The versioning state flag is imcompatible to the type definition."); - } - - } - - public static void validateAllowedChildObjectTypes(TypeDefinition childTypeDef, List allowedChildTypes) { - - if (null == allowedChildTypes) - return; // all types are allowed - - for (String allowedChildType : allowedChildTypes) { - if (allowedChildType.equals(childTypeDef.getId())) - return; - } - throw new RuntimeException("The requested type " + childTypeDef.getId() + " is not allowed in this folder"); - } - - private static List getMandatoryPropDefs(Map> propDefs) { - List res = new ArrayList(); - if (null != propDefs) { - for (PropertyDefinition propDef : propDefs.values()) { - if (propDef.isRequired() && !isMandatorySystemProperty(propDef.getId())) - res.add(propDef.getId()); - } - } - return res; - } - - public static boolean typeContainsProperty(TypeDefinition typeDef, String propertyId) { - - Map> propDefs = typeDef.getPropertyDefinitions(); - if (null == propDefs) - return false; - - PropertyDefinition propDef = propDefs.get(propertyId); - - if (null == propDef) - return false; // unknown property id in this type - else - return true; - } - - public static boolean typeContainsPropertyWithQueryName(TypeDefinition typeDef, String propertyQueryName) { - - Map> propDefs = typeDef.getPropertyDefinitions(); - if (null == propDefs) - return false; - - for (PropertyDefinition propDef : propDefs.values()) { - if (propDef.getQueryName().equals(propertyQueryName)) - return true; - } - - return false; // unknown property query name in this type - } - - @SuppressWarnings("unchecked") - private static PropertyDefinition getPropertyDefinition(TypeDefinition typeDef, String propertyId) { - - Map> propDefs = typeDef.getPropertyDefinitions(); - if (null == propDefs) - return null; - - PropertyDefinition propDef = propDefs.get(propertyId); - - if (null == propDef) - return null; // not found - else - return (PropertyDefinition) propDef; - } - - private static boolean isSystemProperty(BaseTypeId baseTypeId, String propertyId) { - - if (propertyId.equals(PropertyIds.NAME)) { - return true; - } else if (propertyId.equals(PropertyIds.OBJECT_ID)) { - return true; - } else if (propertyId.equals(PropertyIds.OBJECT_TYPE_ID)) { - return true; - } else if (propertyId.equals(PropertyIds.BASE_TYPE_ID)) { - return true; - } else if (propertyId.equals(PropertyIds.CREATED_BY)) { - return true; - } else if (propertyId.equals(PropertyIds.CREATION_DATE)) { - return true; - } else if (propertyId.equals(PropertyIds.LAST_MODIFIED_BY)) { - return true; - } else if (propertyId.equals(PropertyIds.LAST_MODIFICATION_DATE)) { - return true; - } else if (propertyId.equals(PropertyIds.CHANGE_TOKEN)) { - return true; - } - - if (baseTypeId.equals(BaseTypeId.CMIS_DOCUMENT)) { - if (propertyId.equals(PropertyIds.IS_IMMUTABLE)) { - return true; - } else if (propertyId.equals(PropertyIds.IS_LATEST_VERSION)) { - return true; - } else if (propertyId.equals(PropertyIds.IS_MAJOR_VERSION)) { - return true; - } else if (propertyId.equals(PropertyIds.VERSION_SERIES_ID)) { - return true; - } else if (propertyId.equals(PropertyIds.IS_LATEST_MAJOR_VERSION)) { - return true; - } else if (propertyId.equals(PropertyIds.VERSION_LABEL)) { - return true; - } else if (propertyId.equals(PropertyIds.VERSION_SERIES_ID)) { - return true; - } else if (propertyId.equals(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT)) { - return true; - } else if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY)) { - return true; - } else if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID)) { - return true; - } else if (propertyId.equals(PropertyIds.CHECKIN_COMMENT)) { - return true; - } else if (propertyId.equals(PropertyIds.CONTENT_STREAM_LENGTH)) { - return true; - } else if (propertyId.equals(PropertyIds.CONTENT_STREAM_MIME_TYPE)) { - return true; - } else if (propertyId.equals(PropertyIds.CONTENT_STREAM_FILE_NAME)) { - return true; - } else if (propertyId.equals(PropertyIds.CONTENT_STREAM_ID)) { - return true; - } else { - return false; - } - } else if (baseTypeId.equals(BaseTypeId.CMIS_FOLDER)) { - if (propertyId.equals(PropertyIds.PARENT_ID)) { - return true; - } else if (propertyId.equals(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS)) { - return true; - } else if (propertyId.equals(PropertyIds.PATH)) { - return true; - } else { - return false; - } - } else if (baseTypeId.equals(BaseTypeId.CMIS_POLICY)) { - if (propertyId.equals(PropertyIds.SOURCE_ID)) { - return true; - } else if (propertyId.equals(PropertyIds.TARGET_ID)) { - return true; - } else { - return false; - } - } else { // relationship - if (propertyId.equals(PropertyIds.POLICY_TEXT)) { - return true; - } else { - return false; - } - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.chemistry.opencmis.server.support; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.apache.chemistry.opencmis.commons.data.Properties; +import org.apache.chemistry.opencmis.commons.data.PropertyData; +import org.apache.chemistry.opencmis.commons.data.PropertyDecimal; +import org.apache.chemistry.opencmis.commons.data.PropertyInteger; +import org.apache.chemistry.opencmis.commons.definitions.Choice; +import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition; +import org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition; +import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition; +import org.apache.chemistry.opencmis.commons.definitions.PropertyIntegerDefinition; +import org.apache.chemistry.opencmis.commons.definitions.PropertyStringDefinition; +import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition; +import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; +import org.apache.chemistry.opencmis.commons.enums.Cardinality; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; + +/** + * @author Jens + */ +public class TypeValidator { + + public static void validateRequiredSystemProperties(Properties properties) { + if (properties == null || properties.getProperties() == null) + throw new RuntimeException("Cannot create object, no properties are given"); + + if (!properties.getProperties().containsKey(PropertyIds.OBJECT_TYPE_ID)) + throw new RuntimeException("Cannot create object, type id is missing"); + + } + + private static boolean isMandatorySystemProperty(String propertyId) { + // TODO Auto-generated method stub + return propertyId.equals(PropertyIds.OBJECT_TYPE_ID); + } + + @SuppressWarnings("unchecked") + static PropertyValidator createPropertyValidator(PropertyDefinition propDef) { + PropertyValidator result = null; + if (propDef instanceof PropertyIntegerDefinition) { + result = (PropertyValidator) new PropertyValidatorInteger(); + } else if (propDef instanceof PropertyDecimalDefinition) { + result = (PropertyValidator) new PropertyValidatorDecimal(); + } else if (propDef instanceof PropertyStringDefinition) { + result = (PropertyValidator) new PropertyValidatorString(); + } else { + result = new PropertyValidator(); + } + return result; + } + + /* + * property validations: not readonly, all required are given, all are known + * in type cardinality: no multi values for single value, def min max check + * for Integer and Decimal, choices and in list Strings, max length set + * default value for omitted properties + */ + static class PropertyValidator { + + public void validate(PropertyDefinition propDef, PropertyData prop) { + + // check general constraints for all property types + if (propDef.getCardinality() == Cardinality.SINGLE && prop.getValues().size() > 1) + throw new CmisConstraintException("The property with id " + propDef.getId() + + " is single valued, but multiple values are passed " + prop.getValues()); + + if (propDef.getChoices() != null && propDef.getChoices().size() > 0) { + validateChoices(propDef, prop); + } + } + + private void validateChoices(PropertyDefinition propDef, PropertyData prop) { + boolean isAllowedValue = true; + boolean hasMultiValueChoiceLists = false; + for (Choice allowedValue : propDef.getChoices()) { + if (allowedValue.getValue() != null && allowedValue.getValue().size() > 1) + hasMultiValueChoiceLists = true; + } + + // check if value is in list + if (hasMultiValueChoiceLists) { + // do a complex check if this combination of actual values is + // allowed + // check if value is in list + isAllowedValue = false; + List actualValues = prop.getValues(); + for (Choice allowedValue : propDef.getChoices()) { + if (allowedValue.getValue().size() == actualValues.size()) { + boolean listValuesAreEqual = true; + Iterator it = allowedValue.getValue().iterator(); + for (Object actualValue : actualValues) { + if (!actualValue.equals(it.next())) { + listValuesAreEqual = false; + break; + } + } + if (listValuesAreEqual) { + isAllowedValue = true; + } + } + + if (isAllowedValue) + break; + } + + } else { + List allowedValues = getAllowedValues(propDef.getChoices()); + // do a simpler check if all values are choice elements + + for (Object actualValue : prop.getValues()) { + if (!allowedValues.contains(actualValue)) { + isAllowedValue = false; + break; + } + } + } + + if (!isAllowedValue) + throw new CmisConstraintException("The property with id " + propDef.getId() + + " has a fixed set of values. Value(s) " + prop.getValues() + " are not listed."); + } + + /** + * Calculate the list of allowed values for this property definition by + * recursively collecting all choice values from property definition + * + * @param propDef + * property definition + * @return list of possible values in complete hierarchy + */ + private List getAllowedValues(List> choices) { + List allowedValues = new ArrayList(choices.size()); + for (Choice choice : choices) { + if (choice.getValue() != null) + allowedValues.add(choice.getValue().get(0)); + if (choice.getChoice() != null) { + List> x = choice.getChoice(); + allowedValues.addAll(getAllowedValues(x)); + } + } + return allowedValues; + } + } + + static class PropertyValidatorInteger extends PropertyValidator { + + public void validate(PropertyDefinition propDef, PropertyData property) { + + super.validate(propDef, property); + + BigInteger propVal = ((PropertyInteger) property).getFirstValue(); + BigInteger minVal = ((PropertyIntegerDefinition) propDef).getMinValue(); + BigInteger maxVal = ((PropertyIntegerDefinition) propDef).getMaxValue(); + + // check min and max + if (minVal != null && propVal != null && propVal.compareTo(minVal) == -1) { + throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal + + " is less than the minimum value " + minVal); + } + if (maxVal != null && propVal != null && propVal.compareTo(maxVal) == 1) { + throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal + + " is bigger than the maximum value " + maxVal); + } + } + } + + static class PropertyValidatorDecimal extends PropertyValidator { + + public void validate(PropertyDefinition propDef, PropertyData property) { + + super.validate(propDef, property); + + BigDecimal propVal = ((PropertyDecimal) property).getFirstValue(); + BigDecimal minVal = ((PropertyDecimalDefinition) propDef).getMinValue(); + BigDecimal maxVal = ((PropertyDecimalDefinition) propDef).getMaxValue(); + + // check min and max + if (minVal != null && propVal != null && propVal.compareTo(minVal) == -1) { + throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal + + " is less than the minimum value " + minVal); + } + if (maxVal != null && propVal != null && propVal.compareTo(maxVal) == 1) { + throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal + + " is bigger than the maximum value " + maxVal); + } + } + } + + static class PropertyValidatorString extends PropertyValidator { + + public void validate(PropertyDefinition propDef, PropertyData property) { + + super.validate(propDef, property); + + long maxLen = ((PropertyStringDefinition) propDef).getMaxLength() == null ? -1 + : ((PropertyStringDefinition) propDef).getMaxLength().longValue(); + long len = ((PropertyData) property).getFirstValue() == null ? -1 + : ((PropertyData) property).getFirstValue().length(); + + // check max length + if (maxLen >= 0 && len >= 0 && maxLen < len) { + throw new CmisConstraintException("For property with id " + propDef.getId() + " the length of " + len + + "is bigger than the maximum allowed length " + maxLen); + } + } + } + + @SuppressWarnings("unchecked") + public static void validateProperties(TypeDefinition typeDef, Properties properties, boolean checkMandatory) { + + List propDefsRequired = getMandatoryPropDefs(typeDef.getPropertyDefinitions()); + + for (PropertyData prop : properties.getProperties().values()) { + String propertyId = prop.getId(); + BaseTypeId baseTypeId = typeDef.getBaseTypeId(); + + if (isSystemProperty(baseTypeId, propertyId)) + continue; // ignore system properties for validation + + // Check if all properties are known in the type + if (!typeContainsProperty(typeDef, propertyId)) { + throw new CmisConstraintException("Unknown property " + propertyId + " in type " + typeDef.getId()); + } + + // check that all mandatory attributes are present + if (checkMandatory && propDefsRequired.contains(propertyId)) + propDefsRequired.remove(propertyId); + + // check all type specific constraints: + PropertyDefinition propDef = getPropertyDefinition(typeDef, propertyId); + PropertyValidator validator = createPropertyValidator(propDef); + validator.validate(propDef, (PropertyData) prop); + } + + if (checkMandatory && !propDefsRequired.isEmpty()) + throw new CmisConstraintException("The following mandatory properties are missing: " + propDefsRequired); + } + + public static void validateVersionStateForCreate(DocumentTypeDefinition typeDef, VersioningState verState) { + if (null == verState) + return; + if (typeDef.isVersionable() && verState.equals(VersioningState.NONE) || !typeDef.isVersionable() + && !verState.equals(VersioningState.NONE)) { + throw new CmisConstraintException("The versioning state flag is imcompatible to the type definition."); + } + + } + + public static void validateAllowedChildObjectTypes(TypeDefinition childTypeDef, List allowedChildTypes) { + + if (null == allowedChildTypes) + return; // all types are allowed + + for (String allowedChildType : allowedChildTypes) { + if (allowedChildType.equals(childTypeDef.getId())) + return; + } + throw new RuntimeException("The requested type " + childTypeDef.getId() + " is not allowed in this folder"); + } + + private static List getMandatoryPropDefs(Map> propDefs) { + List res = new ArrayList(); + if (null != propDefs) { + for (PropertyDefinition propDef : propDefs.values()) { + if (propDef.isRequired() && !isMandatorySystemProperty(propDef.getId())) + res.add(propDef.getId()); + } + } + return res; + } + + public static boolean typeContainsProperty(TypeDefinition typeDef, String propertyId) { + + Map> propDefs = typeDef.getPropertyDefinitions(); + if (null == propDefs) + return false; + + PropertyDefinition propDef = propDefs.get(propertyId); + + if (null == propDef) + return false; // unknown property id in this type + else + return true; + } + + public static boolean typeContainsPropertyWithQueryName(TypeDefinition typeDef, String propertyQueryName) { + + Map> propDefs = typeDef.getPropertyDefinitions(); + if (null == propDefs) + return false; + + for (PropertyDefinition propDef : propDefs.values()) { + if (propDef.getQueryName().equals(propertyQueryName)) + return true; + } + + return false; // unknown property query name in this type + } + + @SuppressWarnings("unchecked") + private static PropertyDefinition getPropertyDefinition(TypeDefinition typeDef, String propertyId) { + + Map> propDefs = typeDef.getPropertyDefinitions(); + if (null == propDefs) + return null; + + PropertyDefinition propDef = propDefs.get(propertyId); + + if (null == propDef) + return null; // not found + else + return (PropertyDefinition) propDef; + } + + private static boolean isSystemProperty(BaseTypeId baseTypeId, String propertyId) { + + if (propertyId.equals(PropertyIds.NAME)) { + return true; + } else if (propertyId.equals(PropertyIds.OBJECT_ID)) { + return true; + } else if (propertyId.equals(PropertyIds.OBJECT_TYPE_ID)) { + return true; + } else if (propertyId.equals(PropertyIds.BASE_TYPE_ID)) { + return true; + } else if (propertyId.equals(PropertyIds.CREATED_BY)) { + return true; + } else if (propertyId.equals(PropertyIds.CREATION_DATE)) { + return true; + } else if (propertyId.equals(PropertyIds.LAST_MODIFIED_BY)) { + return true; + } else if (propertyId.equals(PropertyIds.LAST_MODIFICATION_DATE)) { + return true; + } else if (propertyId.equals(PropertyIds.CHANGE_TOKEN)) { + return true; + } + + if (baseTypeId.equals(BaseTypeId.CMIS_DOCUMENT)) { + if (propertyId.equals(PropertyIds.IS_IMMUTABLE)) { + return true; + } else if (propertyId.equals(PropertyIds.IS_LATEST_VERSION)) { + return true; + } else if (propertyId.equals(PropertyIds.IS_MAJOR_VERSION)) { + return true; + } else if (propertyId.equals(PropertyIds.VERSION_SERIES_ID)) { + return true; + } else if (propertyId.equals(PropertyIds.IS_LATEST_MAJOR_VERSION)) { + return true; + } else if (propertyId.equals(PropertyIds.VERSION_LABEL)) { + return true; + } else if (propertyId.equals(PropertyIds.VERSION_SERIES_ID)) { + return true; + } else if (propertyId.equals(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT)) { + return true; + } else if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY)) { + return true; + } else if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID)) { + return true; + } else if (propertyId.equals(PropertyIds.CHECKIN_COMMENT)) { + return true; + } else if (propertyId.equals(PropertyIds.CONTENT_STREAM_LENGTH)) { + return true; + } else if (propertyId.equals(PropertyIds.CONTENT_STREAM_MIME_TYPE)) { + return true; + } else if (propertyId.equals(PropertyIds.CONTENT_STREAM_FILE_NAME)) { + return true; + } else if (propertyId.equals(PropertyIds.CONTENT_STREAM_ID)) { + return true; + } else { + return false; + } + } else if (baseTypeId.equals(BaseTypeId.CMIS_FOLDER)) { + if (propertyId.equals(PropertyIds.PARENT_ID)) { + return true; + } else if (propertyId.equals(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS)) { + return true; + } else if (propertyId.equals(PropertyIds.PATH)) { + return true; + } else { + return false; + } + } else if (baseTypeId.equals(BaseTypeId.CMIS_POLICY)) { + if (propertyId.equals(PropertyIds.SOURCE_ID)) { + return true; + } else if (propertyId.equals(PropertyIds.TARGET_ID)) { + return true; + } else { + return false; + } + } else { // relationship + if (propertyId.equals(PropertyIds.POLICY_TEXT)) { + return true; + } else { + return false; + } + } + } +} Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractQueryConditionProcessor.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractQueryConditionProcessor.java?rev=980513&r1=980512&r2=980513&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractQueryConditionProcessor.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractQueryConditionProcessor.java Thu Jul 29 17:13:28 2010 @@ -1,135 +1,135 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.chemistry.opencmis.server.support.query; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.GregorianCalendar; -import java.util.List; - -import org.antlr.runtime.ANTLRInputStream; -import org.antlr.runtime.CharStream; -import org.antlr.runtime.CommonTokenStream; -import org.antlr.runtime.RecognitionException; -import org.antlr.runtime.TokenSource; -import org.antlr.runtime.TokenStream; -import org.antlr.runtime.tree.CommonTree; -import org.antlr.runtime.tree.CommonTreeNodeStream; -import org.antlr.runtime.tree.Tree; -import org.apache.chemistry.opencmis.server.support.query.CmisQueryWalker; -import org.apache.chemistry.opencmis.server.support.query.CmisQlStrictParser_CmisBaseGrammar.query_return; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public abstract class AbstractQueryConditionProcessor implements QueryConditionProcessor { - - private static Log LOG = LogFactory.getLog(AbstractQueryConditionProcessor.class); - - abstract public void onStartProcessing(Tree whereNode); - abstract public void onStopProcessing(); - - // Compare operators - abstract public void onEquals(Tree eqNode, Tree leftNode, Tree rightNode); - abstract public void onNotEquals(Tree neNode, Tree leftNode, Tree rightNode); - abstract public void onGreaterThan(Tree gtNode, Tree leftNode, Tree rightNode); - abstract public void onGreaterOrEquals(Tree geNode, Tree leftNode, Tree rightNode); - abstract public void onLessThan(Tree ltNode, Tree leftNode, Tree rightNode); - abstract public void onLessOrEquals(Tree leqNode, Tree leftNode, Tree rightNode); - - // Boolean operators - abstract public void onNot(Tree opNode, Tree leftNode); - abstract public void onAnd(Tree opNode, Tree leftNode, Tree rightNode); - abstract public void onOr(Tree opNode, Tree leftNode, Tree rightNode); - - // Multi-value: - abstract public void onIn(Tree node, Tree colNode, Tree listNode); - abstract public void onNotIn(Tree node, Tree colNode, Tree listNode); - abstract public void onInAny(Tree node, Tree colNode, Tree listNode); - abstract public void onNotInAny(Tree node, Tree colNode, Tree listNode); - abstract public void onEqAny(Tree node, Tree literalNode, Tree colNode); - - // Null comparisons: - abstract public void onIsNull(Tree nullNode, Tree colNode); - abstract public void onIsNotNull(Tree notNullNode, Tree colNode); - - // String matching: - abstract public void onIsLike(Tree node, Tree colNode, Tree stringNode); - abstract public void onIsNotLike(Tree node, Tree colNode, Tree stringNode); - - // Functions: - abstract public void onContains(Tree node, Tree colNode, Tree paramNode); - abstract public void onInFolder(Tree node, Tree colNode, Tree paramNode); - abstract public void onInTree(Tree node, Tree colNode, Tree paramNode); - abstract public void onScore(Tree node, Tree paramNode); - - // convenience method because everybody needs this piece of code - static public CmisQueryWalker getWalker(String statement) throws UnsupportedEncodingException, IOException, RecognitionException { - CharStream input = new ANTLRInputStream(new ByteArrayInputStream(statement.getBytes("UTF-8"))); - TokenSource lexer = new CmisQlStrictLexer(input); - TokenStream tokens = new CommonTokenStream(lexer); - CmisQlStrictParser parser = new CmisQlStrictParser(tokens); - CommonTree parserTree; // the ANTLR tree after parsing phase - - query_return parsedStatement = parser.query(); -// if (parser.errorMessage != null) { -// throw new RuntimeException("Cannot parse query: " + statement + " (" + parser.errorMessage + ")"); -// } - parserTree = (CommonTree) parsedStatement.getTree(); - - CommonTreeNodeStream nodes = new CommonTreeNodeStream(parserTree); - nodes.setTokenStream(tokens); - CmisQueryWalker walker = new CmisQueryWalker(nodes); - return walker; - } - - // helper functions that are needed by most query tree walkers - - protected Object onLiteral(Tree node) { - int type = node.getType(); - String text = node.getText(); - switch (type) { - case CmisQlStrictLexer.BOOL_LIT: - return Boolean.parseBoolean(node.getText()); - case CmisQlStrictLexer.NUM_LIT: - if (text.contains(".") || text.contains("e") || text.contains("E")) - return Double.parseDouble(text); - else - return Long.parseLong(text); - case CmisQlStrictLexer.STRING_LIT: - return text.substring(1, text.length()-1); - case CmisQlStrictLexer.TIME_LIT: - GregorianCalendar gc = CalendarHelper.fromString(text.substring(text.indexOf('\'')+1, text.lastIndexOf('\''))); - return gc; - default: - throw new RuntimeException("Unknown literal. " + node); - } - } - - protected List onLiteralList(Tree node) { - List res = new ArrayList(node.getChildCount()); - for (int i=0; i onLiteralList(Tree node) { + List res = new ArrayList(node.getChildCount()); + for (int i=0; i