001/*
002 * (C) Copyright 2007 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.query.core;
021
022import org.nuxeo.common.xmap.annotation.XNode;
023import org.nuxeo.common.xmap.annotation.XNodeList;
024import org.nuxeo.common.xmap.annotation.XObject;
025import org.nuxeo.ecm.platform.query.api.PredicateDefinition;
026import org.nuxeo.ecm.platform.query.api.PredicateFieldDefinition;
027
028/**
029 * Predicate descriptor accepting a schema and field, an operator, and a parameter.
030 *
031 * @author Anahide Tchertchian
032 * @since 5.4
033 */
034@XObject(value = "predicate")
035public class PredicateDescriptor implements PredicateDefinition {
036
037    @XNode("@parameter")
038    protected String parameter;
039
040    @XNode("@type")
041    protected String type = ATOMIC_PREDICATE;
042
043    protected String operator;
044
045    @XNode("@operatorField")
046    protected String operatorField;
047
048    @XNode("@operatorSchema")
049    protected String operatorSchema;
050
051    @XNodeList(value = "field", componentType = FieldDescriptor.class, type = PredicateFieldDefinition[].class)
052    protected PredicateFieldDefinition[] values;
053
054    @Override
055    @XNode("@operator")
056    public void setOperator(String operator) {
057        this.operator = operator.toUpperCase();
058    }
059
060    // @since 7.3
061    @XNode("@hint")
062    protected String hint;
063
064    @Override
065    public String getOperator() {
066        return operator;
067    }
068
069    @Override
070    public String getParameter() {
071        return parameter;
072    }
073
074    @Override
075    public void setParameter(String parameter) {
076        this.parameter = parameter;
077    }
078
079    @Override
080    public PredicateFieldDefinition[] getValues() {
081        return values;
082    }
083
084    @Override
085    public void setValues(PredicateFieldDefinition[] values) {
086        this.values = values;
087    }
088
089    @Override
090    public String getType() {
091        return type;
092    }
093
094    @Override
095    public String getOperatorField() {
096        return operatorField;
097    }
098
099    @Override
100    public String getOperatorSchema() {
101        return operatorSchema;
102    }
103
104    @Override
105    public String getHint() {
106        return hint;
107    }
108
109    @Override
110    public void setHint(String hint) {
111        this.hint = hint;
112    }
113
114    /**
115     * @since 5.6
116     */
117    @Override
118    public PredicateDescriptor clone() {
119        PredicateDescriptor clone = new PredicateDescriptor();
120        clone.parameter = parameter;
121        clone.type = type;
122        clone.operator = operator;
123        clone.operatorField = operatorField;
124        clone.operatorSchema = operatorSchema;
125        clone.hint = hint;
126        if (values != null) {
127            clone.values = new PredicateFieldDefinition[values.length];
128            for (int i = 0; i < values.length; i++) {
129                clone.values[i] = values[i].clone();
130            }
131        }
132
133        return clone;
134    }
135
136}