org.eclipse.persistence.jpa.jpql.tools.model.query.KeywordExpressionStateObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eclipselink Show documentation
Show all versions of eclipselink Show documentation
EclipseLink build based upon Git transaction 180e602
/*******************************************************************************
* Copyright (c) 2011, 2013 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Oracle - initial API and implementation
*
******************************************************************************/
package org.eclipse.persistence.jpa.jpql.tools.model.query;
import org.eclipse.persistence.jpa.jpql.Assert;
import org.eclipse.persistence.jpa.jpql.parser.KeywordExpression;
import static org.eclipse.persistence.jpa.jpql.parser.Expression.*;
/**
* The expression representing some keywords: TRUE
, FALSE
or NULL
.
*
* @see KeywordExpression
*
* @version 2.4
* @since 2.4
* @author Pascal Filion
*/
@SuppressWarnings("nls")
public class KeywordExpressionStateObject extends SimpleStateObject {
/**
* Creates a new KeywordExpressionStateObject
.
*
* @param parent The parent of this state object, which cannot be null
* @exception NullPointerException The given parent cannot be null
*/
public KeywordExpressionStateObject(StateObject parent) {
super(parent);
}
/**
* Creates a new KeywordExpressionStateObject
.
*
* @param parent The parent of this state object, which cannot be null
* @param text Either {@link org.eclipse.persistence.jpa.jpql.parser.Expression#TRUE TRUE},
* {@link org.eclipse.persistence.jpa.jpql.parser.Expression#FALSE FALSE} or
* {@link org.eclipse.persistence.jpa.jpql.parser.Expression#NULL NULL}
* @exception NullPointerException The given parent cannot be null
*/
public KeywordExpressionStateObject(StateObject parent, String text) {
super(parent, text);
validateIdentifier(text);
}
/**
* {@inheritDoc}
*/
public void accept(StateObjectVisitor visitor) {
visitor.visit(this);
}
/**
* {@inheritDoc}
*/
@Override
public KeywordExpression getExpression() {
return (KeywordExpression) super.getExpression();
}
/**
* Keeps a reference of the {@link KeywordExpression parsed object} object, which should only be
* done when this object is instantiated during the conversion of a parsed JPQL query into
* {@link StateObject StateObjects}.
*
* @param expression The {@link KeywordExpression parsed object} representing one of the three
* possible keyword: TRUE
, FALSE
or NULL
*/
public void setExpression(KeywordExpression expression) {
super.setExpression(expression);
}
/**
* {@inheritDoc}
*/
@Override
public void setText(String text) {
validateIdentifier(text);
super.setText(text);
}
protected void validateIdentifier(String text) {
Assert.isValid(text, "Only TRUE, FALSE, and NULL are valid identifiers.", TRUE, FALSE, NULL);
}
}