001/*
002 *  Copyright 2010 Anyware Services
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 */
016package org.ametys.plugins.workflow;
017
018import com.opensymphony.workflow.query.Expression;
019
020/**
021 * PropertySet expressions are used when constructing a workflow query
022 * on a property associated with a workflow.<br>
023 * PropertySet expressions have three attributes.<br>
024 * These are:
025 * <ul>
026 * <li>operator: This is the operator to apply on the expression.
027 * <li>type: The PropertySet item type to test agains.
028 * <li>key: The PropertySet item key to test agains.
029 * </ul>
030 * For the moment, only string type is supported.<br>
031 * <b>Warning: PropertySet expressions can only be nested with others PropertySet
032 * expressions (not with FieldExpression)!</b>
033 */
034public class PropertySetExpression extends Expression
035{
036    /**
037     * Constant for the equality operator.
038     */
039    public static final int EQUALS = 1;
040
041    /**
042     * Constant for the wildcard equality operator.
043     */
044    public static final int WILDCARD_EQUALS = 2;
045
046    private Object _value;
047
048    private String _key;
049
050    private int _type;
051
052    private int _operator;
053
054    /**
055     * Create a property set expression.
056     * @param operator The operator.
057     * @param type The type of the operand.
058     * @param key The item key to test agains.
059     * @param value The operand value.
060     */
061    public PropertySetExpression(int operator, int type, String key, Object value)
062    {
063        _operator = operator;
064        _type = type;
065        _key = key;
066        _value = value;
067    }
068
069    /**
070     * Create a negative property set expression.
071     * @param operator The operator.
072     * @param type The type of the operand.
073     * @param key The item key to test agains.
074     * @param value The operand value.
075     * @param isNegated The negative state of the operator.
076     */
077    public PropertySetExpression(int operator, int type, String key, Object value, boolean isNegated)
078    {
079        this(operator, type, key, value);
080        super.negate = isNegated;
081    }
082
083    /**
084     * Get the operator of the expression.
085     * @return The operator.
086     */
087    public int getOperator()
088    {
089        return _operator;
090    }
091
092    /**
093     * Set the operator of the expression.
094     * @param operator The operator.
095     */
096    public void setOperator(int operator)
097    {
098        _operator = operator;
099    }
100
101    /**
102     * Get the type of the operand.
103     * @return The type.
104     */
105    public int getType()
106    {
107        return _type;
108    }
109
110    /**
111     * Set the type of the operand.
112     * @param type The type.
113     */
114    public void setType(int type)
115    {
116        _type = type;
117    }
118
119    /**
120     * Get the operator of the expression.
121     * @return The operator.
122     */
123    public String getKey()
124    {
125        return _key;
126    }
127
128    /**
129     * Set the key to test agains.
130     * @param key The key.
131     */
132    public void setKey(String key)
133    {
134        _key = key;
135    }
136
137    /**
138     * Get the value to test agains.
139     * @return The value.
140     */
141    public Object getValue()
142    {
143        return _value;
144    }
145
146    /**
147     * Set the value to test agains.
148     * @param value The value.
149     */
150    public void setValue(Object value)
151    {
152        _value = value;
153    }
154
155    @Override
156    public boolean isNested()
157    {
158        return false;
159    }
160}