001/* 002 * (C) Copyright 2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.query.core; 023 024import org.nuxeo.common.xmap.annotation.XNode; 025import org.nuxeo.common.xmap.annotation.XNodeList; 026import org.nuxeo.common.xmap.annotation.XObject; 027import org.nuxeo.ecm.platform.query.api.PredicateDefinition; 028import org.nuxeo.ecm.platform.query.api.PredicateFieldDefinition; 029 030/** 031 * Predicate descriptor accepting a schema and field, an operator, and a parameter. 032 * 033 * @author Anahide Tchertchian 034 * @since 5.4 035 */ 036@XObject(value = "predicate") 037public class PredicateDescriptor implements PredicateDefinition { 038 039 @XNode("@parameter") 040 protected String parameter; 041 042 @XNode("@type") 043 protected String type = ATOMIC_PREDICATE; 044 045 protected String operator; 046 047 @XNode("@operatorField") 048 protected String operatorField; 049 050 @XNode("@operatorSchema") 051 protected String operatorSchema; 052 053 @XNodeList(value = "field", componentType = FieldDescriptor.class, type = PredicateFieldDefinition[].class) 054 protected PredicateFieldDefinition[] values; 055 056 @Override 057 @XNode("@operator") 058 public void setOperator(String operator) { 059 this.operator = operator.toUpperCase(); 060 } 061 062 // @since 7.3 063 @XNode("@hint") 064 protected String hint; 065 066 @Override 067 public String getOperator() { 068 return operator; 069 } 070 071 @Override 072 public String getParameter() { 073 return parameter; 074 } 075 076 @Override 077 public void setParameter(String parameter) { 078 this.parameter = parameter; 079 } 080 081 @Override 082 public PredicateFieldDefinition[] getValues() { 083 return values; 084 } 085 086 @Override 087 public void setValues(PredicateFieldDefinition[] values) { 088 this.values = values; 089 } 090 091 @Override 092 public String getType() { 093 return type; 094 } 095 096 @Override 097 public String getOperatorField() { 098 return operatorField; 099 } 100 101 @Override 102 public String getOperatorSchema() { 103 return operatorSchema; 104 } 105 106 @Override 107 public String getHint() { 108 return hint; 109 } 110 111 @Override 112 public void setHint(String hint) { 113 this.hint = hint; 114 } 115 116 /** 117 * @since 5.6 118 */ 119 @Override 120 public PredicateDescriptor clone() { 121 PredicateDescriptor clone = new PredicateDescriptor(); 122 clone.parameter = parameter; 123 clone.type = type; 124 clone.operator = operator; 125 clone.operatorField = operatorField; 126 clone.operatorSchema = operatorSchema; 127 clone.hint = hint; 128 if (values != null) { 129 clone.values = new PredicateFieldDefinition[values.length]; 130 for (int i = 0; i < values.length; i++) { 131 clone.values[i] = values[i].clone(); 132 } 133 } 134 135 return clone; 136 } 137 138}