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.repository.query.expression; 017 018/** 019 * Constructs an {@link Expression} corresponding to the boolean comparison with a metadata. 020 */ 021public class BooleanExpression implements Expression 022{ 023 private boolean _value; 024 private MetadataExpression _metadata; 025 private Operator _operator; 026 027 /** 028 * Creates the comparison Expression. 029 * @param metadata the metadata name 030 * @param value the boolean value 031 */ 032 public BooleanExpression(String metadata, boolean value) 033 { 034 this(metadata, Operator.EQ, value); 035 } 036 037 /** 038 * Creates the comparison Expression. 039 * @param metadata the metadata name 040 * @param operator the operator to make the comparison 041 * @param value the boolean value 042 */ 043 public BooleanExpression(String metadata, Operator operator, boolean value) 044 { 045 _value = value; 046 _operator = operator; 047 _metadata = new MetadataExpression(metadata); 048 } 049 050 /** 051 * Creates the comparison Expression. 052 * @param metadata the metadata name 053 * @param value the boolean value 054 * @param context the expression context 055 */ 056 public BooleanExpression(String metadata, boolean value, ExpressionContext context) 057 { 058 this(metadata, Operator.EQ, value, context); 059 } 060 061 /** 062 * Creates the comparison Expression. 063 * @param metadata the metadata name 064 * @param operator the operator to make the comparison 065 * @param value the boolean value 066 * @param context the expression context 067 */ 068 public BooleanExpression(String metadata, Operator operator, boolean value, ExpressionContext context) 069 { 070 _value = value; 071 _operator = operator; 072 _metadata = new MetadataExpression(metadata, context); 073 } 074 075 076 public String build() 077 { 078 return _metadata.build() + " " + _operator + " " + Boolean.toString(_value) + "()"; 079 } 080}